publicstaticvoid testSurrogateWithReplacement(Charset cs, String surrogate) throws IOException {
CharsetEncoder en = cs.newEncoder();
CharsetDecoder de = cs.newDecoder(); if (!en.canEncode(NORMAL_SURROGATE)) { return;
}
String expected = null;
String replace = new String(en.replacement(), cs); switch (surrogate) { case MALFORMED_SURROGATE: case REVERSED_SURROGATE:
expected = PREFIX + replace + replace + SUFFIX; break; case SOLITARY_HIGH_SURROGATE: case SOLITARY_LOW_SURROGATE:
expected = PREFIX + replace + SUFFIX; break; default:
expected = NORMAL_SURROGATE;
}
try {
en.onMalformedInput(CodingErrorAction.REPLACE);
en.onUnmappableCharacter(CodingErrorAction.REPLACE);
ByteBuffer bbuf = en.encode(CharBuffer.wrap(surrogate));
CharBuffer cbuf = de.decode(bbuf); if (!cbuf.toString().equals(expected)) { thrownew RuntimeException("charset " + cs.name() + " (en)decoded the surrogate " + surrogate + " to " + cbuf.toString() + " which is not same as the expected " + expected);
}
} finally {
en.reset();
de.reset();
}
try (ByteArrayOutputStream bos = new ByteArrayOutputStream();
OutputStreamWriter osw = new OutputStreamWriter(bos, en);) {
osw.write(surrogate);
osw.flush(); try (InputStreamReader isr = new InputStreamReader(new ByteArrayInputStream(bos.toByteArray()), de)) {
CharBuffer cbuf = CharBuffer.allocate(expected.length());
isr.read(cbuf);
cbuf.rewind(); if (!cbuf.toString().equals(expected)) { thrownew RuntimeException("charset " + cs.name() + " (en)decoded the surrogate " + surrogate + " to " + cbuf.toString() + " which is not same as the expected " + expected);
}
}
}
}
}
Messung V0.5 in Prozent
¤ Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.0.5Bemerkung:
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.