private InputStream createReplicator(@NotNull final VirtualFile file, final InputStream nativeStream, final long fileLength, final boolean readOnly) throws IOException { if (nativeStream instanceof BufferExposingByteArrayInputStream) { // optimization BufferExposingByteArrayInputStream byteStream = (BufferExposingByteArrayInputStream )nativeStream; byte[] bytes = byteStream.getInternalBuffer(); storeContentToStorage(fileLength, file, readOnly, bytes, bytes.length); return nativeStream; } @SuppressWarnings("IOResourceOpenedButNotSafelyClosed") final BufferExposingByteArrayOutputStream cache = new BufferExposingByteArrayOutputStream((int)fileLength); return new ReplicatorInputStream(nativeStream, cache) { @Override public void close() throws IOException { super.close(); storeContentToStorage(fileLength, file, readOnly, cache.getInternalBuffer(), cache.size()); } }; }
private InputStream createReplicator(@Nonnull final VirtualFile file, final InputStream nativeStream, final long fileLength, final boolean readOnly) throws IOException { if (nativeStream instanceof BufferExposingByteArrayInputStream) { // optimization BufferExposingByteArrayInputStream byteStream = (BufferExposingByteArrayInputStream)nativeStream; byte[] bytes = byteStream.getInternalBuffer(); storeContentToStorage(fileLength, file, readOnly, bytes, bytes.length); return nativeStream; } @SuppressWarnings("IOResourceOpenedButNotSafelyClosed") final BufferExposingByteArrayOutputStream cache = new BufferExposingByteArrayOutputStream((int)fileLength); return new ReplicatorInputStream(nativeStream, cache) { @Override public void close() throws IOException { super.close(); storeContentToStorage(fileLength, file, readOnly, cache.getInternalBuffer(), cache.size()); } }; }