Class Streams

java.lang.Object
com.onenetwork.platform.tools.io.Streams

public class Streams
extends java.lang.Object
Utility class for manipulating java streams and other I/O classes.
  • Constructor Summary

    Constructors 
    Constructor Description
    Streams()  
  • Method Summary

    Modifier and Type Method Description
    static void close​(java.io.Closeable... closeables)
    Closes Streams/Readers/Writers without throwing an exception (LOGs a warning if there are any problems)
    static void close​(java.util.zip.ZipFile... zips)
    Closes ZipFiles without throwing an exception (LOGs a warning if there are any problems)
    static byte[] readFully​(java.io.InputStream in)
    Reads the input stream fully and returns the byte content
    static java.lang.String readFully​(java.io.Reader reader)
    Reads the reader fully and returns the string
    static void transfer​(java.io.InputStream inputStream, java.io.OutputStream outputStream)
    Reads the contents of the supplied InputStream & writes them to the supplied OutputStream Attempts to close streams when done.
    static void transfer​(java.io.InputStream inputStream, java.io.OutputStream outputStream, boolean closeStreamsWhenDone)
    Reads the contents of the supplied InputStream & writes them to the supplied OutputStream Whether to close streams when done is a parameter.
    static void transfer​(java.io.Reader reader, java.io.Writer writer)
    Reads the contents of the supplied Reader & writes them to the supplied Writer
    static void transfer​(java.io.Reader reader, java.lang.StringBuffer buf)
    Reads the contents of the supplied Reader & writes them to the supplied StringBuffer
    static void transfer​(java.io.Reader reader, java.lang.StringBuilder buf)
    Reads the contents of the supplied Reader & writes them to the supplied StringBuilder
    protected static void transferByBufferSize​(java.io.InputStream inputStream, java.io.OutputStream outputStream, boolean closeStreamsWhenDone, int bufferSize)
    Reads the contents of the supplied InputStream & writes them to the supplied OutputStream
    protected static boolean transferNumBytes​(java.io.InputStream inputStream, java.io.OutputStream outputStream, boolean closeStreamsWhenDone, int bytesToTransfer, int bufferSize)
    Reads the contents of the supplied InputStream & writes them to the supplied OutputStream

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

  • Method Details

    • transferByBufferSize

      protected static void transferByBufferSize​(java.io.InputStream inputStream, java.io.OutputStream outputStream, boolean closeStreamsWhenDone, int bufferSize) throws java.io.IOException
      Reads the contents of the supplied InputStream & writes them to the supplied OutputStream
      Parameters:
      inputStream - read bytes from this stream
      outputStream - write bytes to this stream
      closeStreamsWhenDone - indicates whether the streams should be closed when the operation is complete
      bufferSize - size of the in-memory buffer used to hold bytes during transfer; the entire buffer is read/written in each call to the underlying streams
      Throws:
      java.io.IOException - thrown if there is an I/O problem
    • close

      public static void close​(java.io.Closeable... closeables)
      Closes Streams/Readers/Writers without throwing an exception (LOGs a warning if there are any problems)
      Parameters:
      closeables - Closeables to be closed
    • close

      public static void close​(java.util.zip.ZipFile... zips)
      Closes ZipFiles without throwing an exception (LOGs a warning if there are any problems)
      Parameters:
      zips - ZipFiles to be closed
    • transfer

      public static void transfer​(java.io.InputStream inputStream, java.io.OutputStream outputStream, boolean closeStreamsWhenDone) throws java.io.IOException
      Reads the contents of the supplied InputStream & writes them to the supplied OutputStream Whether to close streams when done is a parameter.
      Throws:
      java.io.IOException
    • transfer

      public static void transfer​(java.io.InputStream inputStream, java.io.OutputStream outputStream) throws java.io.IOException
      Reads the contents of the supplied InputStream & writes them to the supplied OutputStream Attempts to close streams when done.
      Throws:
      java.io.IOException
    • transferNumBytes

      protected static boolean transferNumBytes​(java.io.InputStream inputStream, java.io.OutputStream outputStream, boolean closeStreamsWhenDone, int bytesToTransfer, int bufferSize) throws java.io.IOException
      Reads the contents of the supplied InputStream & writes them to the supplied OutputStream
      Parameters:
      inputStream - read bytes from this stream
      outputStream - write bytes to this stream
      closeStreamsWhenDone - indicates whether the streams should be closed when the operation is complete
      bytesToTransfer - number of bytes to transfer during this operation
      bufferSize - size of the in-memory buffer used to hold bytes during transfer; the entire buffer is read/written in each call to the underyling streams
      Returns:
      true if inputStream has reached end of stream
      Throws:
      java.io.IOException - thrown if there is an I/O problem
    • transfer

      public static void transfer​(java.io.Reader reader, java.lang.StringBuffer buf) throws java.io.IOException
      Reads the contents of the supplied Reader & writes them to the supplied StringBuffer
      Parameters:
      reader - read chars from this stream
      buf - write chars to this buffer
      Throws:
      java.io.IOException - thrown if there is an I/O problem
    • transfer

      public static void transfer​(java.io.Reader reader, java.lang.StringBuilder buf) throws java.io.IOException
      Reads the contents of the supplied Reader & writes them to the supplied StringBuilder
      Parameters:
      reader - read chars from this stream
      buf - write chars to this buffer
      Throws:
      java.io.IOException - thrown if there is an I/O problem
    • transfer

      public static void transfer​(java.io.Reader reader, java.io.Writer writer) throws java.io.IOException
      Reads the contents of the supplied Reader & writes them to the supplied Writer
      Parameters:
      reader - read chars from this stream
      writer - write chars to this stream
      Throws:
      java.io.IOException - thrown if there is an I/O problem
    • readFully

      public static java.lang.String readFully​(java.io.Reader reader) throws java.io.IOException
      Reads the reader fully and returns the string
      Parameters:
      reader - Reader to be drained
      Returns:
      String contents of fully drained reader
      Throws:
      java.io.IOException
    • readFully

      public static byte[] readFully​(java.io.InputStream in) throws java.io.IOException
      Reads the input stream fully and returns the byte content
      Parameters:
      in - InputStream to be drained
      Returns:
      byte contents of fully drained input stream
      Throws:
      java.io.IOException