// We have 4 bytes
InputStream in = new ByteArrayInputStream(newbyte[10]); byte[] bs = IOUtils.readExactlyNBytes(in, 4); if (bs.length != 4 || in.available() != 6) { thrownew Exception("First read error");
} // But only 6 left
bs = in.readNBytes(10); if (bs.length != 6 || in.available() != 0) { thrownew Exception("Second read error");
} // MAX length results in exception
in = new ByteArrayInputStream(newbyte[10]); try {
bs = IOUtils.readExactlyNBytes(in, Integer.MAX_VALUE); thrownew Exception("No exception on MAX_VALUE length");
} catch (EOFException ex) { // this is expected
} catch (IOException ex) { throw ex;
} // -1 length results in exception
in = new ByteArrayInputStream(newbyte[10]); try {
bs = IOUtils.readExactlyNBytes(in, -1); thrownew Exception("No exception on -1 length");
} catch (IOException ex) { // this is expected
}
// 20>10, readAll means failure
in = new ByteArrayInputStream(newbyte[10]); try {
bs = IOUtils.readExactlyNBytes(in, 20); thrownew Exception("No exception on EOF");
} catch (EOFException e) { // OK
} int bignum = 10 * 1024 * 1024;
bs = IOUtils.readExactlyNBytes(new SuperSlowStream(bignum), bignum); if (bs.length != bignum) { thrownew Exception("Read returned small array");
}
// Test DerValue byte[] input = {0x04, (byte)0x84, 0x40, 0x00, 0x42, 0x46, 0x4b}; try { new DerValue(new ByteArrayInputStream(input));
} catch (IOException ioe) { // This is OK
}
}
}
/** *AnInputStreamcontainsagivennumberofbytes,butonlyreturnsonebyte *perread.
*/ class SuperSlowStream extends InputStream { privateint p; /** *@paramInitialcapacity
*/ public SuperSlowStream(int capacity) {
p = capacity;
}
@Override publicint read() throws IOException { if (p > 0) {
p--; return0;
} else { return -1;
}
}
@Override publicint read(byte b[], int off, int len) throws IOException { if (len == 0) return0; if (p > 0) {
p--;
b[off] = 0; return1;
} else { return -1;
}
}
}
Messung V0.5 in Prozent
¤ Diese beiden folgenden Angebotsgruppen bietet das Unternehmen0.1Angebot
(Wie Sie bei der Firma Beratungs- und Dienstleistungen beauftragen können 2026-10-11)
¤
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.