publicclass WriteUTF {
@Test publicstaticvoid overcountWrittenField() throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
DataOutputStream dos = new DataOutputStream(baos);
dos.writeUTF("Hello, World!"); // 15
dos.flush(); if (baos.size() != dos.size()) thrownew RuntimeException("Miscounted bytes in DataOutputStream.");
}
privatestaticvoid writeUTF(int size) throws IOException { // this character gives 3 bytes when encoded using UTF-8
String s = "\u0800".repeat(size);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
DataOutputStream dos = new DataOutputStream(bos);
dos.writeUTF(s);
}
// Without 8219196 fix, throws ArrayIndexOutOfBoundsException instead of // expected UTFDataFormatException. Requires 4GB of heap (-Xmx4g) to run // without throwing an OutOfMemoryError.
@Test(expectedExceptions = UTFDataFormatException.class) publicvoid arrayIndexOutOfBoundsException() throws IOException {
writeUTF(Integer.MAX_VALUE / 3 + 1);
}
}
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.11Bemerkung:
(vorverarbeitet am 2026-06-10)
¤
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.