Package com.onenetwork.platform.tools.io
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 contentstatic java.lang.String
readFully(java.io.Reader reader)
Reads the reader fully and returns the stringstatic 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 Writerstatic void
transfer(java.io.Reader reader, java.lang.StringBuffer buf)
Reads the contents of the supplied Reader & writes them to the supplied StringBufferstatic void
transfer(java.io.Reader reader, java.lang.StringBuilder buf)
Reads the contents of the supplied Reader & writes them to the supplied StringBuilderprotected 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 OutputStreamprotected 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
-
Constructor Details
-
Streams
public Streams()
-
-
Method Details
-
transferByBufferSize
protected static void transferByBufferSize(java.io.InputStream inputStream, java.io.OutputStream outputStream, boolean closeStreamsWhenDone, int bufferSize) throws java.io.IOExceptionReads the contents of the supplied InputStream & writes them to the supplied OutputStream- Parameters:
inputStream
- read bytes from this streamoutputStream
- write bytes to this streamcloseStreamsWhenDone
- indicates whether the streams should be closed when the operation is completebufferSize
- 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.IOExceptionReads 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.IOExceptionReads 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.IOExceptionReads the contents of the supplied InputStream & writes them to the supplied OutputStream- Parameters:
inputStream
- read bytes from this streamoutputStream
- write bytes to this streamcloseStreamsWhenDone
- indicates whether the streams should be closed when the operation is completebytesToTransfer
- number of bytes to transfer during this operationbufferSize
- 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.IOExceptionReads the contents of the supplied Reader & writes them to the supplied StringBuffer- Parameters:
reader
- read chars from this streambuf
- 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.IOExceptionReads the contents of the supplied Reader & writes them to the supplied StringBuilder- Parameters:
reader
- read chars from this streambuf
- 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.IOExceptionReads the contents of the supplied Reader & writes them to the supplied Writer- Parameters:
reader
- read chars from this streamwriter
- 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.IOExceptionReads 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.IOExceptionReads 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
-