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 noopstatic int
read
(InputStream input, ByteBuffer buffer, int count) Read up to {code count} bytes frominput
and store them intobuffer
.static int
readFully
(InputStream reader, byte[] dest) static int
readFully
(InputStream reader, byte[] dest, int offset, int len)
-
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 tobuffer
- buffer to use for copyingclose
- whether to close both streams after 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:
-
read
Read up to {code count} bytes frominput
and store them intobuffer
. The buffers position will be incremented by the number of bytes read from the stream.- Parameters:
input
- stream to read frombuffer
- buffer to read intocount
- maximum number of bytes to read- Returns:
- number of bytes read from the stream
- Throws:
IOException
- in case of I/O errors
-
readFully
- Throws:
IOException
-
readFully
public static int readFully(InputStream reader, byte[] dest, int offset, int len) throws IOException - Throws:
IOException
-
noCloseStream
Wraps anOutputStream
such that it'sclose
method becomes a noop- Parameters:
stream
-OutputStream
to wrap- Returns:
- wrapped
OutputStream
-