@Test public void testCopy2() throws Exception { final ByteArrayOutputStream proxy = new ByteArrayOutputStream(40500); final MemorySegementingOutputStream out = new MemorySegementingOutputStream(proxy, 32768); final byte[] content = RandomUtils.nextBytes(40500); out.write(content, 0, 32768); out.write(content, 32768, 7732); out.close(); assertArrayEquals(content, proxy.toByteArray()); }
@Override public void close() throws IOException { if(close.get()) { log.warn(String.format("Skip double close of stream %s", this)); return; } try { if(buffer.size() > 0) { proxy.write(buffer.toByteArray()); } buffer.reset(); super.close(); } finally { close.set(true); } }
MemorySegementingOutputStream extends SegmentingOutputStream { @Override public void close() throws IOException { if(close.get()) { log.warn(String.format("Skip double close of stream %s", this)); return; } try { if(buffer.size() > 0) { proxy.write(buffer.toByteArray()); } buffer.reset(); super.close(); } finally { close.set(true); } } }
MemorySegementingOutputStream extends SegmentingOutputStream { @Override public void close() throws IOException { if(close.get()) { log.warn(String.format("Skip double close of stream %s", this)); return; } try { if(buffer.size() > 0) { proxy.write(buffer.toByteArray()); } buffer.reset(); super.close(); } finally { close.set(true); } } MemorySegementingOutputStream(final OutputStream proxy, final Integer threshold);  MemorySegementingOutputStream(final OutputStream proxy, final Integer threshold, final ByteArrayOutputStream buffer); }
MemorySegementingOutputStream extends SegmentingOutputStream { @Override public void close() throws IOException { if(close.get()) { log.warn(String.format("Skip double close of stream %s", this)); return; } try { if(buffer.size() > 0) { proxy.write(buffer.toByteArray()); } buffer.reset(); super.close(); } finally { close.set(true); } } MemorySegementingOutputStream(final OutputStream proxy, final Integer threshold);  MemorySegementingOutputStream(final OutputStream proxy, final Integer threshold, final ByteArrayOutputStream buffer); @Override void flush(); @Override void close(); }
MemorySegementingOutputStream extends SegmentingOutputStream { @Override public void close() throws IOException { if(close.get()) { log.warn(String.format("Skip double close of stream %s", this)); return; } try { if(buffer.size() > 0) { proxy.write(buffer.toByteArray()); } buffer.reset(); super.close(); } finally { close.set(true); } } MemorySegementingOutputStream(final OutputStream proxy, final Integer threshold);  MemorySegementingOutputStream(final OutputStream proxy, final Integer threshold, final ByteArrayOutputStream buffer); @Override void flush(); @Override void close();  }