Class InputStreamTool

java.lang.Object
io.datarouter.bytes.io.InputStreamTool

public class InputStreamTool extends Object
  • Constructor Details

    • InputStreamTool

      public InputStreamTool()
  • Method Details

    • close

      public static void close(InputStream inputStream)
    • count

      public static long count(InputStream inputStream, int bufferSize)
    • countByte

      public static long countByte(InputStream inputStream, int bufferSize, byte matchByte)
    • readRequiredByte

      public static byte readRequiredByte(InputStream inputStream)
      Read 1 byte, throwing if it wasn't found.
    • readUntilLength

      public static int readUntilLength(InputStream inputStream, byte[] buffer, int offset, int length)
      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

      public static byte[] readNBytes(InputStream inputStream, int len)
    • toArray

      public static byte[] toArray(InputStream inputStream)
    • toArray

      public static byte[] toArray(InputStream inputStream, ByteArrayOutputStream buffer)
    • transferTo

      public static long transferTo(InputStream inputStream, OutputStream outputStream)
    • transferToAndClose

      public static long transferToAndClose(InputStream inputStream, OutputStream outputStream)
    • closeAtEnd

      public static InputStream closeAtEnd(InputStream inputStream)
      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.