static void testUnicodeRead(String filename) throws IOException { BufferedReader in = new BufferedReader( new InputStreamReader(new FileInputStream(filename), "UTF-8")); int count = 0; String line; while (null != (line = in.readLine())) { System.out.println("ULine "+count++); System.out.println(line); System.out.println(showBytes(line.getBytes(CDM.utf8Charset))); } in.close(); }
static void testRead(String filename) throws IOException { DataInputStream in = new DataInputStream( new BufferedInputStream(new FileInputStream(filename))); int count = 0; String line; while (null != (line = in.readLine())) { System.out.println("Line "+count++); System.out.println(line); System.out.println(showBytes(line.getBytes(CDM.utf8Charset))); } in.close(); }
String makeString(int[] codes, boolean debug) throws UnsupportedEncodingException { byte[] b = new byte[codes.length]; for (int i=0; i<codes.length; i++) b[i] = (byte) codes[i]; if (debug) System.out.println(" orgBytes= "+showBytes(b)); String s = new String(b, "UTF-8"); if (debug) System.out.println("convBytes= "+showString( s)); return s; }
static void testRAF(String filename) throws IOException { ucar.unidata.io.RandomAccessFile raf = new ucar.unidata.io.RandomAccessFile(filename, "r"); int nelems = 37; byte[] b = new byte[nelems]; raf.read(b); String line = new String(b, "UTF-8"); // all strings are considered to be UTF-8 unicode. System.out.println(line); System.out.println(showBytes(b)); System.out.println(showBytes(line.getBytes(CDM.utf8Charset))); }
System.out.println(" UTF-8= "+showBytes(helloGreek.getBytes("UTF-8"))); System.out.println(" UTF-16= "+showBytes(helloGreek.getBytes("UTF-16"))); System.out.println(" default= "+showBytes(helloGreek.getBytes())); System.out.println("norm values= "+showString(s2)); System.out.println(" UTF-8= "+showBytes(s2.getBytes("UTF-8"))); System.out.println(" UTF-16= "+showBytes(s2.getBytes("UTF-16"))); System.out.println(" default= "+showBytes(s2.getBytes()));