@Test
public void testBufferGrow() throws IOException {
int length = 100;
byte[] buffer = new byte[length / 10];
UnsafeByteArrayOutputStream ubaos = new UnsafeByteArrayOutputStream(buffer);
for (int i = 0; i < length; i++) {
ubaos.write((byte) i);
}
byte[] result = ubaos.toByteArray();
assertEquals(length, ubaos.length());
for (int j = 0; j < length; ++j) {
assertEquals(result[j], j);
}
buffer = ubaos.toByteArray();
int length2 = 10;
byte[] buffer2 = new byte[length2];
for (int i = 0; i < length2; i++) {
buffer2[i] = (byte) (8 + i);
}
ubaos.reInit(buffer2);
for (int i = 0; i < length2; i++) {
ubaos.write(7 + i);
}
byte[] result2 = ubaos.toByteArray();
assertEquals(length2, ubaos.length());
for (int j = 0; j < length2; ++j) {
assertEquals(result2[j], j + 7);
}