@Test public void testNormal() { byte[] lastStringArray = "client".getBytes(UTF_8); byte[] lastArray = Arrays.copyOf(lastStringArray, lastStringArray.length + 32); arraycopy(lastStringArray, 0, lastArray, 0, lastStringArray.length); List<byte[]> buffers = ImmutableList.of( "hello ".getBytes(UTF_8), "this ".getBytes(UTF_8), "is ".getBytes(UTF_8), "http ".getBytes(UTF_8), lastArray); byte[] expectedAll = "hello this is http client".getBytes(); byte[] expectedPartial = "hello this".getBytes(); try (GatheringByteArrayInputStream in = new GatheringByteArrayInputStream(buffers, expectedAll.length)) { byte[] buffer = new byte[expectedAll.length + 32]; assertEquals(in.read(buffer, 0, expectedPartial.length), expectedPartial.length); assertByteArrayEquals(buffer, 0, expectedPartial, 0, expectedPartial.length); assertEquals(in.read(buffer, expectedPartial.length, buffer.length - expectedPartial.length), expectedAll.length - expectedPartial.length); assertByteArrayEquals(buffer, 0, expectedAll, 0, expectedAll.length); assertEquals(-1, in.read(buffer, 0, expectedAll.length)); } }
@Override public synchronized int read(byte[] buffer) { return read(buffer, 0, buffer.length); }
GatheringByteArrayInputStream extends InputStream { @Override public synchronized int read(byte[] buffer) { return read(buffer, 0, buffer.length); } }
GatheringByteArrayInputStream extends InputStream { @Override public synchronized int read(byte[] buffer) { return read(buffer, 0, buffer.length); } GatheringByteArrayInputStream(List<byte[]> buffers, long totalBytes); }
GatheringByteArrayInputStream extends InputStream { @Override public synchronized int read(byte[] buffer) { return read(buffer, 0, buffer.length); } GatheringByteArrayInputStream(List<byte[]> buffers, long totalBytes); @Override synchronized int read(byte[] buffer); @Override synchronized int read(); @Override synchronized long skip(long n); @Override synchronized int read(byte[] buffer, int offset, int length); @Override void close(); }
GatheringByteArrayInputStream extends InputStream { @Override public synchronized int read(byte[] buffer) { return read(buffer, 0, buffer.length); } GatheringByteArrayInputStream(List<byte[]> buffers, long totalBytes); @Override synchronized int read(byte[] buffer); @Override synchronized int read(); @Override synchronized long skip(long n); @Override synchronized int read(byte[] buffer, int offset, int length); @Override void close();  }