Created
January 11, 2016 05:27
-
-
Save gythialy/bcfeeafa6b72b81c82d5 to your computer and use it in GitHub Desktop.
Encode/Decode E language text
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.io.UnsupportedEncodingException; | |
| import java.nio.charset.Charset; | |
| import com.google.common.io.BaseEncoding; | |
| public class Test { | |
| public static void main(String[] args) { | |
| String string = "3C 21 20 45 6E 74 69 74 79 3D 44 54 48 53 54 20 74 79 70 65 3D 4E 54 43 20 74 69 6D 65 3D 27 32 30 31 33 2D 30 39 2D 32 33 20 31 36 3A 31 38 3A 32 39 27 20 21 3E 0A 3C 6E 74 63 3A 3A 44 54 48 53 54 3E 0A 40 CD A8 D6 AA B1 E0 BA C5 20 20 20 20 20 20 20 20 CD A8 D6 AA C4 DA C8 DD 0A 23 31 33 37 39 39 35 33 31 30 39 20 20 20 20 20 20 20 20 41 47 43 B2 E2 CA D4 A3 A1 0A 3C 2F 6E 74 63 3A 3A 44 54 48 53 54 3E 0A"; | |
| String test3 = "<! Entity=JNSD_ type=NTC time='2013-10-10 15:47:58' !>\n" | |
| + "<ntc::JNSD_>\n" | |
| + "@通知编号 通知内容\n" | |
| + "#1381420078 各场登录nmdtzx@163.com邮箱(密码000000)下载《2013年第二期发电厂值长持证上岗培训班》的通知,并按要求回复!具体内容见通知要求。\n" | |
| + "</ntc::JNSD_>\n"; | |
| try { | |
| System.out.println(new String(toByteArray(string.trim()), "GBK")); | |
| Charset gbk = Charset.forName("GBK"); | |
| System.out.println(toHexString(test3.getBytes(gbk))); | |
| } | |
| catch (UnsupportedEncodingException e) { | |
| e.printStackTrace(); | |
| } | |
| } | |
| public static String toHexString(byte[] array) { | |
| return BaseEncoding.base16().withSeparator(" ", 2).encode(array); | |
| } | |
| public static byte[] toByteArray(String s) { | |
| return BaseEncoding.base16().withSeparator(" ", 2).decode(s); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment