Package io.datarouter.bytes.io
Class InputStreamTool
java.lang.Object
io.datarouter.bytes.io.InputStreamTool
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidclose(InputStream inputStream) static InputStreamcloseAtEnd(InputStream inputStream) For cases where it's difficult to use try-with-resources.static longcount(InputStream inputStream, int bufferSize) static longcountByte(InputStream inputStream, int bufferSize, byte matchByte) static byte[]readNBytes(InputStream inputStream, int len) static bytereadRequiredByte(InputStream inputStream) Read 1 byte, throwing if it wasn't found.static intreadUntilLength(InputStream inputStream, byte[] buffer, int offset, int length) Keeps reading from the InputStream until length bytes are found, or we're out of data.static byte[]toArray(InputStream inputStream) static byte[]toArray(InputStream inputStream, ByteArrayOutputStream buffer) static longtransferTo(InputStream inputStream, OutputStream outputStream) static longtransferToAndClose(InputStream inputStream, OutputStream outputStream)
-
Constructor Details
-
InputStreamTool
public InputStreamTool()
-
-
Method Details
-
close
-
count
-
countByte
-
readRequiredByte
Read 1 byte, throwing if it wasn't found. -
readUntilLength
Keeps reading from the InputStream until length bytes are found, or we're out of data. Can be used on InputStreams that return data incrementally but you prefer to block until length bytes are found. -
readNBytes
-
toArray
-
toArray
-
transferTo
-
transferToAndClose
-
closeAtEnd
For cases where it's difficult to use try-with-resources. This should close the InputStream when it's been consumed. But it won't close if not fully consumed. It adds memory allocation overhead to a normal InputStream, but removes the need for BufferedInputStream.
-