private final String readUnicodeFileUTF8(String filename) { StringBuffer sb = new StringBuffer(256); try { int[] surrogatePair = new int[2]; InputStream is = this.getClass().getResourceAsStream(filename);
int val = 0; int unicharCount = 0; while ((val = readNextCharFromStreamUTF8(is))!=-1) { unicharCount++; if (val <= 0xFFFF) { // if first value is the Byte Order Mark (BOM), do not add if (! (unicharCount == 1 && val == 0xFEFF)) { sb.append((char)val); } } else { supplementCodePointToSurrogatePair(val, surrogatePair); sb.append((char)surrogatePair[0]); sb.append((char)surrogatePair[1]); } } is.close(); } catch (Exception e) {};
return new String(sb); }
private final static int readNextCharFromStreamUTF8(InputStream is) { int c = -1; if (is==null) return c; boolean complete = false;
try { int byteVal; int expecting=0; int composedVal=0;