Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public void encode(final DataPacket dataPacket, final OutputStream encodedOut) t
out.writeLong(dataPacket.getSize());

final InputStream in = dataPacket.getData();
StreamUtils.copy(in, encodedOut);
in.transferTo(encodedOut);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
import org.apache.nifi.remote.protocol.http.HttpHeaders;
import org.apache.nifi.remote.protocol.http.HttpProxy;
import org.apache.nifi.security.cert.StandardPrincipalFormatter;
import org.apache.nifi.stream.io.StreamUtils;
import org.apache.nifi.web.api.dto.ControllerDTO;
import org.apache.nifi.web.api.dto.remote.PeerDTO;
import org.apache.nifi.web.api.entity.ControllerEntity;
Expand Down Expand Up @@ -505,7 +504,7 @@ private IOException handleErrResponse(final int responseCode, final InputStream
private TransactionResultEntity readResponse(final InputStream inputStream) throws IOException {
final ByteArrayOutputStream bos = new ByteArrayOutputStream();

StreamUtils.copy(inputStream, bos);
inputStream.transferTo(bos);
String responseMessage = null;

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import org.apache.nifi.remote.Transaction;
import org.apache.nifi.remote.TransactionCompletion;
import org.apache.nifi.remote.util.StandardDataPacket;
import org.apache.nifi.stream.io.StreamUtils;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
Expand All @@ -43,7 +42,7 @@ public static DataPacket createDataPacket(String contents) {

public static String readContents(DataPacket packet) throws IOException {
ByteArrayOutputStream os = new ByteArrayOutputStream((int) packet.getSize());
StreamUtils.copy(packet.getData(), os);
packet.getData().transferTo(os);
return os.toString(StandardCharsets.UTF_8);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@

public class StreamUtils {

/**
* Copies from <code>source</code> to <code>destination</code>.
* @param source source InputStream
* @param destination destination OutputStream
* @return Total number of bytes copied
* @throws IOException If an error occurs when copying.
* @deprecated Use {@link InputStream#transferTo(OutputStream)} instead.
*/
@Deprecated(since = "2.12.0", forRemoval = true)
public static long copy(final InputStream source, final OutputStream destination) throws IOException {
final byte[] buffer = new byte[8192];
int len;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,23 @@ public class LimitingInputStreamTest {
@Test
public void testReadLimitNotReached() throws IOException {
final LimitingInputStream is = new LimitingInputStream(new ByteArrayInputStream(TEST_BUFFER), 50);
long bytesRead = StreamUtils.copy(is, new ByteArrayOutputStream());
long bytesRead = is.transferTo(new ByteArrayOutputStream());
assertEquals(bytesRead, TEST_BUFFER.length);
assertFalse(is.hasReachedLimit());
}

@Test
public void testReadLimitMatched() throws IOException {
final LimitingInputStream is = new LimitingInputStream(new ByteArrayInputStream(TEST_BUFFER), 10);
long bytesRead = StreamUtils.copy(is, new ByteArrayOutputStream());
long bytesRead = is.transferTo(new ByteArrayOutputStream());
assertEquals(bytesRead, TEST_BUFFER.length);
assertTrue(is.hasReachedLimit());
}

@Test
public void testReadLimitExceeded() throws IOException {
final LimitingInputStream is = new LimitingInputStream(new ByteArrayInputStream(TEST_BUFFER), 9);
final long bytesRead = StreamUtils.copy(is, new ByteArrayOutputStream());
final long bytesRead = is.transferTo(new ByteArrayOutputStream());
assertEquals(9, bytesRead);
assertTrue(is.hasReachedLimit());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import org.apache.nifi.registry.flow.git.client.GitCommit;
import org.apache.nifi.registry.flow.git.client.GitCreateContentRequest;
import org.apache.nifi.registry.flow.git.client.GitRepositoryClient;
import org.apache.nifi.stream.io.StreamUtils;
import org.apache.nifi.web.client.api.HttpResponseEntity;
import org.apache.nifi.web.client.api.HttpUriBuilder;
import org.apache.nifi.web.client.api.StandardHttpContentType;
Expand Down Expand Up @@ -1255,7 +1254,7 @@ private String getFileName(final String resolvedPath) {

private byte[] toByteArray(final InputStream inputStream) throws FlowRegistryException {
try (inputStream; ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
StreamUtils.copy(inputStream, outputStream);
inputStream.transferTo(outputStream);
return outputStream.toByteArray();
} catch (IOException e) {
throw new FlowRegistryException("Failed to prepare multipart request", e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
import org.apache.nifi.processors.compress.property.CompressionStrategy;
import org.apache.nifi.processors.compress.property.FilenameStrategy;
import org.apache.nifi.stream.io.GZIPOutputStream;
import org.apache.nifi.stream.io.StreamUtils;
import org.apache.nifi.util.StopWatch;
import org.apache.nifi.util.StringUtils;
import org.tukaani.xz.LZMA2Options;
Expand Down Expand Up @@ -239,7 +238,7 @@ public void onTrigger(final ProcessContext context, final ProcessSession session
final BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(flowFileOutputStream, STREAM_BUFFER_SIZE);
final OutputStream outputStream = getCompressionOutputStream(outputCompressionStrategy, outputCompressionLevel, mimeTypeRef, bufferedOutputStream)
) {
StreamUtils.copy(inputStream, outputStream);
inputStream.transferTo(outputStream);
}
});
stopWatch.stop();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
import org.apache.nifi.processor.ProcessSession;
import org.apache.nifi.processor.Relationship;
import org.apache.nifi.processor.exception.FlowFileHandlingException;
import org.apache.nifi.stream.io.StreamUtils;

import java.io.BufferedInputStream;
import java.io.IOException;
Expand Down Expand Up @@ -135,7 +134,7 @@ public void onTrigger(final ProcessContext context, final ProcessSession session
String parentUuid = originalFlowFile.getAttribute(CoreAttributes.UUID.key());
attributes.put(ATTACHMENT_ORIGINAL_UUID, parentUuid);
attributes.put(ATTACHMENT_ORIGINAL_FILENAME, originalFlowFileName);
split = session.append(split, out -> StreamUtils.copy(data.getInputStream(), out));
split = session.append(split, out -> data.getInputStream().transferTo(out));
split = session.putAllAttributes(split, attributes);
attachmentsList.add(split);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@
import org.apache.nifi.processor.util.StandardValidators;
import org.apache.nifi.processors.hadoop.util.GSSExceptionRollbackYieldSessionHandler;
import org.apache.nifi.processors.transfer.ResourceTransferSource;
import org.apache.nifi.stream.io.StreamUtils;
import org.apache.nifi.util.StopWatch;

import java.io.BufferedInputStream;
Expand Down Expand Up @@ -444,7 +443,7 @@ public Object run() {
}
} else {
BufferedInputStream bis = new BufferedInputStream(in);
StreamUtils.copy(bis, fos);
bis.transferTo(fos);
bis = null;
fos.flush();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
import org.apache.nifi.processors.pgp.attributes.DecryptionStrategy;
import org.apache.nifi.processors.pgp.exception.PGPDecryptionException;
import org.apache.nifi.processors.pgp.exception.PGPProcessException;
import org.apache.nifi.stream.io.StreamUtils;
import org.apache.nifi.util.StringUtils;
import org.bouncycastle.bcpg.KeyIdentifier;
import org.bouncycastle.openpgp.PGPCompressedData;
Expand Down Expand Up @@ -280,7 +279,7 @@ public void process(final InputStream inputStream, final OutputStream outputStre
if (DecryptionStrategy.PACKAGED == decryptionStrategy) {
try {
final InputStream decryptedDataStream = getDecryptedDataStream(encryptedData);
StreamUtils.copy(decryptedDataStream, outputStream);
decryptedDataStream.transferTo(outputStream);
} catch (final PGPException e) {
final String message = String.format("PGP Decryption Failed [%s]", getEncryptedDataType(encryptedData));
throw new PGPDecryptionException(message, e);
Expand All @@ -291,7 +290,7 @@ public void process(final InputStream inputStream, final OutputStream outputStre
attributes.put(PGPAttributeKey.LITERAL_DATA_MODIFIED, Long.toString(literalData.getModificationTime().getTime()));

getLogger().debug("PGP Decrypted File Name [{}] Modified [{}]", literalData.getFileName(), literalData.getModificationTime());
StreamUtils.copy(literalData.getInputStream(), outputStream);
literalData.getInputStream().transferTo(outputStream);
}

if (isVerified(encryptedData)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ protected void processEncoding(final InputStream inputStream, final OutputStream
) {
if (isPacketFound(pushbackInputStream)) {
// Write OpenPGP packets to encrypted stream without additional encoding
StreamUtils.copy(pushbackInputStream, encryptedOutputStream);
pushbackInputStream.transferTo(encryptedOutputStream);
} else {
super.processEncoding(pushbackInputStream, encryptedOutputStream);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import org.apache.nifi.processor.Relationship;
import org.apache.nifi.processor.io.StreamCallback;
import org.apache.nifi.processors.pgp.exception.PGPProcessException;
import org.apache.nifi.stream.io.StreamUtils;
import org.bouncycastle.openpgp.PGPCompressedData;
import org.bouncycastle.openpgp.PGPException;
import org.bouncycastle.openpgp.PGPLiteralData;
Expand Down Expand Up @@ -260,7 +259,7 @@ private void processLiteralData(final PGPLiteralData literalData,
setLiteralDataAttributes(literalData);
final InputStream literalInputStream = literalData.getInputStream();
if (onePassSignature == null) {
StreamUtils.copy(literalInputStream, outputStream);
literalInputStream.transferTo(outputStream);
} else {
processSignedStream(literalInputStream, outputStream, onePassSignature);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import org.apache.nifi.processors.pgp.attributes.CompressionAlgorithm;
import org.apache.nifi.processors.pgp.attributes.FileEncoding;
import org.apache.nifi.processors.pgp.exception.PGPProcessException;
import org.apache.nifi.stream.io.StreamUtils;
import org.bouncycastle.bcpg.ArmoredOutputStream;
import org.bouncycastle.openpgp.PGPCompressedDataGenerator;
import org.bouncycastle.openpgp.PGPException;
Expand Down Expand Up @@ -103,7 +102,7 @@ protected void processEncoding(final InputStream inputStream, final OutputStream
protected void processCompression(final InputStream inputStream, final OutputStream compressedOutputStream) throws IOException, PGPException {
final PGPLiteralDataGenerator generator = new PGPLiteralDataGenerator();
try (final OutputStream literalOutputStream = openLiteralOutputStream(generator, compressedOutputStream)) {
StreamUtils.copy(inputStream, literalOutputStream);
inputStream.transferTo(literalOutputStream);
}
generator.close();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import org.apache.nifi.processors.pgp.exception.PGPDecryptionException;
import org.apache.nifi.processors.pgp.exception.PGPProcessException;
import org.apache.nifi.reporting.InitializationException;
import org.apache.nifi.stream.io.StreamUtils;
import org.apache.nifi.util.LogMessage;
import org.apache.nifi.util.MockFlowFile;
import org.apache.nifi.util.TestRunner;
Expand Down Expand Up @@ -402,7 +401,7 @@ private void assertLiteralDataEquals(final Object object) throws IOException {
assertEquals(MODIFIED, literalData.getModificationTime());

final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
StreamUtils.copy(literalData.getDataStream(), outputStream);
literalData.getDataStream().transferTo(outputStream);
final String literal = outputStream.toString(DATA_CHARSET);
assertEquals(DATA, literal);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import org.apache.nifi.processors.pgp.attributes.FileEncoding;
import org.apache.nifi.processors.pgp.attributes.SymmetricKeyAlgorithm;
import org.apache.nifi.reporting.InitializationException;
import org.apache.nifi.stream.io.StreamUtils;
import org.apache.nifi.util.MockFlowFile;
import org.apache.nifi.util.TestRunner;
import org.apache.nifi.util.TestRunners;
Expand Down Expand Up @@ -336,11 +335,11 @@ private byte[] getDecryptedData(final PGPPublicKeyEncryptedData publicKeyEncrypt
private byte[] getDecryptedData(final InputStream decryptedDataStream, final DecryptionStrategy decryptionStrategy) throws PGPException, IOException {
final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
if (DecryptionStrategy.PACKAGED == decryptionStrategy) {
StreamUtils.copy(decryptedDataStream, outputStream);
decryptedDataStream.transferTo(outputStream);
} else {
final PGPObjectFactory objectFactory = new JcaPGPObjectFactory(decryptedDataStream);
final PGPLiteralData literalData = getLiteralData(objectFactory);
StreamUtils.copy(literalData.getDataStream(), outputStream);
literalData.getDataStream().transferTo(outputStream);
}
return outputStream.toByteArray();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import org.apache.nifi.processors.pgp.attributes.CompressionAlgorithm;
import org.apache.nifi.processors.pgp.attributes.FileEncoding;
import org.apache.nifi.stream.io.StreamUtils;
import org.bouncycastle.openpgp.PGPCompressedData;
import org.bouncycastle.openpgp.PGPException;
import org.bouncycastle.openpgp.PGPLiteralData;
Expand Down Expand Up @@ -90,7 +89,7 @@ private void assertLiteralDataEquals(final InputStream inputStream) throws IOExc
assertEquals(PGPLiteralData.BINARY, literalData.getFormat());

final ByteArrayOutputStream literalOutputStream = new ByteArrayOutputStream();
StreamUtils.copy(literalData.getDataStream(), literalOutputStream);
literalData.getDataStream().transferTo(literalOutputStream);
assertArrayEquals(DATA, literalOutputStream.toByteArray());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
import org.apache.nifi.processors.standard.encoding.LineOutputMode;
import org.apache.nifi.processors.standard.util.ValidatingBase32InputStream;
import org.apache.nifi.processors.standard.util.ValidatingBase64InputStream;
import org.apache.nifi.stream.io.StreamUtils;
import org.apache.nifi.util.StopWatch;

import java.io.IOException;
Expand Down Expand Up @@ -201,7 +200,7 @@ public void process(final InputStream in, final OutputStream out) throws IOExcep
.setLineSeparator(this.lineSeparator.getBytes())
.get())
.get()) {
StreamUtils.copy(in, bos);
in.transferTo(bos);
}
}
}
Expand All @@ -211,7 +210,7 @@ private static class DecodeBase64 implements StreamCallback {
@Override
public void process(final InputStream in, final OutputStream out) throws IOException {
try (Base64InputStream bis = new Base64InputStream(new ValidatingBase64InputStream(in))) {
StreamUtils.copy(bis, out);
bis.transferTo(out);
}
}
}
Expand Down Expand Up @@ -239,7 +238,7 @@ public void process(final InputStream in, final OutputStream out) throws IOExcep
.setLineSeparator(this.lineSeparator.getBytes())
.get())
.get()) {
StreamUtils.copy(in, bos);
in.transferTo(bos);
}
}
}
Expand All @@ -249,7 +248,7 @@ private static class DecodeBase32 implements StreamCallback {
@Override
public void process(final InputStream in, final OutputStream out) throws IOException {
try (Base32InputStream bis = new Base32InputStream(new ValidatingBase32InputStream(in))) {
StreamUtils.copy(bis, out);
bis.transferTo(out);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
import org.apache.nifi.processors.standard.util.ArgumentUtils;
import org.apache.nifi.processors.standard.util.SoftLimitBoundedByteArrayOutputStream;
import org.apache.nifi.stream.io.LimitingInputStream;
import org.apache.nifi.stream.io.StreamUtils;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
Expand Down Expand Up @@ -569,7 +568,7 @@ public void process(final InputStream incomingFlowFileIS) throws IOException {
if (putToAttribute) {
try (SoftLimitBoundedByteArrayOutputStream softLimitBoundedBAOS = new SoftLimitBoundedByteArrayOutputStream(attributeSize)) {
readStdoutReadable(ignoreStdin, stdinWritable, logger, incomingFlowFileIS);
final long longSize = StreamUtils.copy(stdoutReadable, softLimitBoundedBAOS);
final long longSize = stdoutReadable.transferTo(softLimitBoundedBAOS);

// Because the outputStream has a cap that the copy doesn't know about, adjust
// the actual size
Expand All @@ -591,7 +590,7 @@ public void process(final InputStream incomingFlowFileIS) throws IOException {
} else {
outputFlowFile = session.write(outputFlowFile, out -> {
readStdoutReadable(ignoreStdin, stdinWritable, logger, incomingFlowFileIS);
StreamUtils.copy(stdoutReadable, out);
stdoutReadable.transferTo(out);
try {
exitCode = process.waitFor();
} catch (InterruptedException e) {
Expand All @@ -607,7 +606,7 @@ private static void readStdoutReadable(final boolean ignoreStdin, final OutputSt
Thread writerThread = new Thread(() -> {
if (!ignoreStdin) {
try {
StreamUtils.copy(incomingFlowFileIS, stdinWritable);
incomingFlowFileIS.transferTo(stdinWritable);
} catch (IOException e) {
// This is unlikely to occur, and isn't handled at the moment
// Bug captured in NIFI-1194
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
import org.apache.nifi.processor.Relationship;
import org.apache.nifi.processor.util.StandardValidators;
import org.apache.nifi.scheduling.SchedulingStrategy;
import org.apache.nifi.stream.io.StreamUtils;

import java.io.IOException;
import java.io.InputStream;
Expand Down Expand Up @@ -135,7 +134,7 @@ public void onTrigger(final ProcessContext context, final ProcessSession session
FlowFile flowFile = session.create();

try (final InputStream inputStream = context.getProperty(FILE_RESOURCE).asResource().read()) {
flowFile = session.write(flowFile, out -> StreamUtils.copy(inputStream, out));
flowFile = session.write(flowFile, inputStream::transferTo);
} catch (IOException e) {
getLogger().error("Could not create FlowFile from Resource [{}]", context.getProperty(FILE_RESOURCE).getValue(), e);
}
Expand Down
Loading
Loading