java.lang.Object
org.elasticsearch.core.Streams
Simple utility methods for file and stream copying. All copy methods close all affected streams when done.
Mainly for use within the framework, but also useful for application code.
-
Method Summary
Modifier and TypeMethodDescriptionstatic long
copy
(InputStream in, OutputStream out) static long
copy
(InputStream in, OutputStream out, boolean close) static long
copy
(InputStream in, OutputStream out, byte[] buffer) static long
copy
(InputStream in, OutputStream out, byte[] buffer, boolean close) Copy the contents of the given InputStream to the given OutputStream.static OutputStream
noCloseStream
(OutputStream stream) Wraps anOutputStream
such that it'sclose
method becomes a noop
-
Method Details
-
copy
public static long copy(InputStream in, OutputStream out, byte[] buffer, boolean close) throws IOException Copy the contents of the given InputStream to the given OutputStream. Optionally, closes both streams when done.- Parameters:
in
- the stream to copy fromout
- the stream to copy toclose
- whether to close both streams after copyingbuffer
- buffer to use for copying- Returns:
- the number of bytes copied
- Throws:
IOException
- in case of I/O errors
-
copy
- Throws:
IOException
- See Also:
-
copy
- Throws:
IOException
- See Also:
-
copy
- Throws:
IOException
- See Also:
-
noCloseStream
Wraps anOutputStream
such that it'sclose
method becomes a noop- Parameters:
stream
-OutputStream
to wrap- Returns:
- wrapped
OutputStream
-