@Test public void testOutputIsCorrectlySized() throws IOException { Random rndm = new Random(); for (int i = 0; i < 100; i++) { int size = rndm.nextInt(1024); int initial = rndm.nextInt(1024); MemoryEfficientByteArrayOutputStream out = new MemoryEfficientByteArrayOutputStream(initial); out.write(new byte[size]); Assert.assertEquals(size, out.getBytes().length); } }
public synchronized byte getBytes()[] { if (buf.length == size()) { return buf; } else { byte[] copy = new byte[size()]; System.arraycopy(buf, 0, copy, 0, size()); return copy; } }
MemoryEfficientByteArrayOutputStream extends ByteArrayOutputStream { public synchronized byte getBytes()[] { if (buf.length == size()) { return buf; } else { byte[] copy = new byte[size()]; System.arraycopy(buf, 0, copy, 0, size()); return copy; } } }
MemoryEfficientByteArrayOutputStream extends ByteArrayOutputStream { public synchronized byte getBytes()[] { if (buf.length == size()) { return buf; } else { byte[] copy = new byte[size()]; System.arraycopy(buf, 0, copy, 0, size()); return copy; } } MemoryEfficientByteArrayOutputStream(int size); }
MemoryEfficientByteArrayOutputStream extends ByteArrayOutputStream { public synchronized byte getBytes()[] { if (buf.length == size()) { return buf; } else { byte[] copy = new byte[size()]; System.arraycopy(buf, 0, copy, 0, size()); return copy; } } MemoryEfficientByteArrayOutputStream(int size); synchronized byte getBytes(); static MemoryEfficientByteArrayOutputStream serialize(Serializable serializable, int estimatedPayloadSize); static MemoryEfficientByteArrayOutputStream serialize(Serializable serializable); }
MemoryEfficientByteArrayOutputStream extends ByteArrayOutputStream { public synchronized byte getBytes()[] { if (buf.length == size()) { return buf; } else { byte[] copy = new byte[size()]; System.arraycopy(buf, 0, copy, 0, size()); return copy; } } MemoryEfficientByteArrayOutputStream(int size); synchronized byte getBytes(); static MemoryEfficientByteArrayOutputStream serialize(Serializable serializable, int estimatedPayloadSize); static MemoryEfficientByteArrayOutputStream serialize(Serializable serializable);  }