private void testCreateStorageOutputStream(StorageProvider provider, int size) throws IOException { byte[] data = createData(size); Assert.assertEquals(size, data.length); StorageOutputStream out = provider.createStorageOutputStream(); ContentUtil.copy(new ByteArrayInputStream(data), out); Storage storage = out.toStorage(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); ContentUtil.copy(storage.getInputStream(), baos); verifyData(data, baos.toByteArray()); }
@Override protected Storage toStorage0() throws IOException { if (tail == null) return new MemoryStorageProvider.MemoryStorage(head.buffer(), head.length()); return new ThresholdStorage(head.buffer(), head.length(), tail.toStorage()); }
@Override protected void write0(byte[] buffer, int offset, int length) throws IOException { int remainingHeadSize = thresholdSize - head.length(); if (remainingHeadSize > 0) { int n = Math.min(remainingHeadSize, length); head.append(buffer, offset, n); offset += n; length -= n; } if (length > 0) { if (tail == null) tail = backend.createStorageOutputStream(); tail.write(buffer, offset, length); } }
@Override public void close() throws IOException { super.close(); if (tail != null) tail.close(); }