@Test public void testWrite() { UnsafeByteArrayOutputStream outputStream = new UnsafeByteArrayOutputStream(1); outputStream.write((int) 'a'); outputStream.write("bc".getBytes(), 0, 2); assertThat(outputStream.size(), is(3)); assertThat(outputStream.toString(), is("abc")); }
@Override public void write(int b) { int newcount = mCount + 1; if (newcount > mBuffer.length) mBuffer = Bytes.copyOf(mBuffer, Math.max(mBuffer.length << 1, newcount)); mBuffer[mCount] = (byte) b; mCount = newcount; }
UnsafeByteArrayOutputStream extends OutputStream { @Override public void write(int b) { int newcount = mCount + 1; if (newcount > mBuffer.length) mBuffer = Bytes.copyOf(mBuffer, Math.max(mBuffer.length << 1, newcount)); mBuffer[mCount] = (byte) b; mCount = newcount; } }
UnsafeByteArrayOutputStream extends OutputStream { @Override public void write(int b) { int newcount = mCount + 1; if (newcount > mBuffer.length) mBuffer = Bytes.copyOf(mBuffer, Math.max(mBuffer.length << 1, newcount)); mBuffer[mCount] = (byte) b; mCount = newcount; } UnsafeByteArrayOutputStream();  UnsafeByteArrayOutputStream(int size); }
UnsafeByteArrayOutputStream extends OutputStream { @Override public void write(int b) { int newcount = mCount + 1; if (newcount > mBuffer.length) mBuffer = Bytes.copyOf(mBuffer, Math.max(mBuffer.length << 1, newcount)); mBuffer[mCount] = (byte) b; mCount = newcount; } UnsafeByteArrayOutputStream();  UnsafeByteArrayOutputStream(int size); @Override void write(int b); @Override void write(byte b[], int off, int len); int size(); void reset(); byte[] toByteArray(); ByteBuffer toByteBuffer(); void writeTo(OutputStream out); @Override String toString(); String toString(String charset); @Override void close(); }
UnsafeByteArrayOutputStream extends OutputStream { @Override public void write(int b) { int newcount = mCount + 1; if (newcount > mBuffer.length) mBuffer = Bytes.copyOf(mBuffer, Math.max(mBuffer.length << 1, newcount)); mBuffer[mCount] = (byte) b; mCount = newcount; } UnsafeByteArrayOutputStream();  UnsafeByteArrayOutputStream(int size); @Override void write(int b); @Override void write(byte b[], int off, int len); int size(); void reset(); byte[] toByteArray(); ByteBuffer toByteBuffer(); void writeTo(OutputStream out); @Override String toString(); String toString(String charset); @Override void close();  }