Class StreamUtil

java.lang.Object
org.cryptacular.util.StreamUtil

public final class StreamUtil extends Object
Utility methods for stream handling.
Author:
Middleware Services
  • Field Details

  • Method Details

    • readAll

      public static byte[] readAll(String path) throws StreamException
      Reads all the data from the file at the given path.
      Parameters:
      path - Path to file.
      Returns:
      Byte array of data read from file.
      Throws:
      StreamException - on stream IO errors.
    • readAll

      public static byte[] readAll(File file) throws StreamException
      Reads all the data from the given file.
      Parameters:
      file - File to read.
      Returns:
      Byte array of data read from file.
      Throws:
      StreamException - on stream IO errors.
    • readAll

      public static byte[] readAll(InputStream input) throws StreamException
      Reads all the data from the given input stream.
      Parameters:
      input - Input stream to read.
      Returns:
      Byte array of data read from stream.
      Throws:
      StreamException - on stream IO errors.
    • readAll

      public static byte[] readAll(InputStream input, int sizeHint) throws StreamException
      Reads all the data from the given input stream.
      Parameters:
      input - Input stream to read.
      sizeHint - Estimate of amount of data to be read in bytes.
      Returns:
      Byte array of data read from stream.
      Throws:
      StreamException - on stream IO errors.
    • readAll

      public static String readAll(Reader reader) throws StreamException
      Reads all data from the given reader.
      Parameters:
      reader - Reader over character data.
      Returns:
      Data read from reader.
      Throws:
      StreamException - on stream IO errors.
    • readAll

      public static String readAll(Reader reader, int sizeHint) throws StreamException
      Reads all data from the given reader.
      Parameters:
      reader - Reader over character data.
      sizeHint - Estimate of amount of data to be read in number of characters.
      Returns:
      Data read from reader.
      Throws:
      StreamException - on stream IO errors.
    • pipeAll

      public static void pipeAll(InputStream in, OutputStream out, ChunkHandler handler) throws StreamException
      Pipes an input stream into an output stream with chunked processing.
      Parameters:
      in - Input stream providing data to process.
      out - Output stream holding processed data.
      handler - Arbitrary handler for processing input stream.
      Throws:
      StreamException - on stream IO errors.
    • makeStream

      public static InputStream makeStream(File file) throws StreamException
      Creates an input stream around the given file.
      Parameters:
      file - Input stream source.
      Returns:
      Input stream around file.
      Throws:
      StreamException - on stream IO errors.
    • makeReader

      public static Reader makeReader(File file) throws StreamException
      Creates a reader around the given file that presumably contains character data.
      Parameters:
      file - Reader source.
      Returns:
      Reader around file.
      Throws:
      StreamException - on stream IO errors.
    • closeStream

      public static void closeStream(InputStream in)
      Closes the given stream and swallows exceptions that may arise during the process.
      Parameters:
      in - Input stream to close.
    • closeStream

      public static void closeStream(OutputStream out)
      Closes the given stream and swallows exceptions that may arise during the process.
      Parameters:
      out - Output stream to close.
    • closeReader

      public static void closeReader(Reader reader)
      Closes the given reader and swallows exceptions that may arise during the process.
      Parameters:
      reader - Reader to close.
    • closeWriter

      public static void closeWriter(Writer writer)
      Closes the given writer and swallows exceptions that may arise during the process.
      Parameters:
      writer - Writer to close.