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 longcopy(InputStream in, OutputStream out) static longcopy(InputStream in, OutputStream out, boolean close) static longcopy(InputStream in, OutputStream out, byte[] buffer) static longcopy(InputStream in, OutputStream out, byte[] buffer, boolean close) Copy the contents of the given InputStream to the given OutputStream.static OutputStreamnoCloseStream(OutputStream stream) Wraps anOutputStreamsuch that it'sclosemethod becomes a noopstatic intread(InputStream input, ByteBuffer buffer, int count) Read up to {code count} bytes frominputand store them intobuffer.static intreadFully(InputStream reader, byte[] dest) static intreadFully(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 frominputand 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 anOutputStreamsuch that it'sclosemethod becomes a noop- Parameters:
stream-OutputStreamto wrap- Returns:
- wrapped
OutputStream
-