@Override public void process(final OutputStream rawOut) throws IOException { try (final OutputStream bufferedOut = new BufferedOutputStream(rawOut)) { // we don't want the packager closing the stream. V1 creates a TAR Output Stream, which then gets // closed, which in turn closes the underlying OutputStream, and we want to protect ourselves against that. final OutputStream out = new NonCloseableOutputStream(bufferedOut); for (final FlowFile flowFile : contents) { bin.getSession().read(flowFile, false, new InputStreamCallback() { @Override public void process(final InputStream rawIn) throws IOException { try (final InputStream in = new BufferedInputStream(rawIn)) { final Map<String, String> attributes = new HashMap<>(flowFile.getAttributes()); // for backward compatibility purposes, we add the "legacy" NiFi attributes attributes.put("nf.file.name", attributes.get(CoreAttributes.FILENAME.key())); attributes.put("nf.file.path", attributes.get(CoreAttributes.PATH.key())); if (attributes.containsKey(CoreAttributes.MIME_TYPE.key())) { attributes.put("content-type", attributes.get(CoreAttributes.MIME_TYPE.key())); } packager.packageFlowFile(in, out, attributes, flowFile.getSize()); } } }); } } } });
final OutputStream writableStream = new BufferedOutputStream(new GZIPOutputStream(new NonCloseableOutputStream(rawOutStream), 1), 65536); this.byteCountingOut = new ByteCountingOutputStream(writableStream, byteOffset); } else {
final long blockStartOffset = byteCountingOut.getBytesWritten(); try (final OutputStream ncos = new NonCloseableOutputStream(byteCountingOut); final OutputStream gzipOut = new GZIPOutputStream(ncos, 1)) { StreamUtils.copy(fis, gzipOut, blockEnd - blockStart);
@Override public void process(final OutputStream rawOut) throws IOException { try (final OutputStream bufferedOut = new BufferedOutputStream(rawOut)) { // we don't want the packager closing the stream. V1 creates a TAR Output Stream, which then gets // closed, which in turn closes the underlying OutputStream, and we want to protect ourselves against that. final OutputStream out = new NonCloseableOutputStream(bufferedOut); for (final FlowFile flowFile : contents) { bin.getSession().read(flowFile, false, new InputStreamCallback() { @Override public void process(final InputStream rawIn) throws IOException { try (final InputStream in = new BufferedInputStream(rawIn)) { final Map<String, String> attributes = new HashMap<>(flowFile.getAttributes()); // for backward compatibility purposes, we add the "legacy" NiFi attributes attributes.put("nf.file.name", attributes.get(CoreAttributes.FILENAME.key())); attributes.put("nf.file.path", attributes.get(CoreAttributes.PATH.key())); if (attributes.containsKey(CoreAttributes.MIME_TYPE.key())) { attributes.put("content-type", attributes.get(CoreAttributes.MIME_TYPE.key())); } packager.packageFlowFile(in, out, attributes, flowFile.getSize()); } } }); } } } });