Package nl.siegmann.epublib.util
Class IOUtil
- java.lang.Object
-
- nl.siegmann.epublib.util.IOUtil
-
public class IOUtil extends java.lang.ObjectMost of the functions herein are re-implementations of the ones in apache io IOUtils. The reason for re-implementing this is that the functions are fairly simple and using my own implementation saves the inclusion of a 200Kb jar file.
-
-
Field Summary
Fields Modifier and Type Field Description static intIO_COPY_BUFFER_SIZE
-
Constructor Summary
Constructors Constructor Description IOUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description protected static intcalcNewNrReadSize(int nrRead, int totalNrNread)if totalNrRead < 0 then totalNrRead is returned, if (nrRead + totalNrRead) < Integer.MAX_VALUE then nrRead + totalNrRead is returned, -1 otherwise.static intcopy(java.io.InputStream in, java.io.OutputStream out)Copies the contents of the InputStream to the OutputStream.static intcopy(java.io.Reader in, java.io.Writer out)Copies the contents of the Reader to the Writer.static byte[]toByteArray(java.io.InputStream in)Returns the contents of the InputStream as a byte[]static byte[]toByteArray(java.io.InputStream in, int size)Reads data from the InputStream, using the specified buffer size.static byte[]toByteArray(java.io.Reader in, java.lang.String encoding)Gets the contents of the Reader as a byte[], with the given character encoding.
-
-
-
Field Detail
-
IO_COPY_BUFFER_SIZE
public static final int IO_COPY_BUFFER_SIZE
- See Also:
- Constant Field Values
-
-
Method Detail
-
toByteArray
public static byte[] toByteArray(java.io.Reader in, java.lang.String encoding) throws java.io.IOExceptionGets the contents of the Reader as a byte[], with the given character encoding.- Parameters:
in-encoding-- Returns:
- the contents of the Reader as a byte[], with the given character encoding.
- Throws:
java.io.IOException
-
toByteArray
public static byte[] toByteArray(java.io.InputStream in) throws java.io.IOExceptionReturns the contents of the InputStream as a byte[]- Parameters:
in-- Returns:
- the contents of the InputStream as a byte[]
- Throws:
java.io.IOException
-
toByteArray
public static byte[] toByteArray(java.io.InputStream in, int size) throws java.io.IOExceptionReads data from the InputStream, using the specified buffer size. This is meant for situations where memory is tight, since it prevents buffer expansion.- Parameters:
in- the stream to read data fromsize- the size of the array to create- Returns:
- the array, or null
- Throws:
java.io.IOException
-
calcNewNrReadSize
protected static int calcNewNrReadSize(int nrRead, int totalNrNread)if totalNrRead < 0 then totalNrRead is returned, if (nrRead + totalNrRead) < Integer.MAX_VALUE then nrRead + totalNrRead is returned, -1 otherwise.- Parameters:
nrRead-totalNrNread-- Returns:
- if totalNrRead < 0 then totalNrRead is returned, if (nrRead + totalNrRead) < Integer.MAX_VALUE then nrRead + totalNrRead is returned, -1 otherwise.
-
copy
public static int copy(java.io.InputStream in, java.io.OutputStream out) throws java.io.IOExceptionCopies the contents of the InputStream to the OutputStream.- Parameters:
in-out-- Returns:
- the nr of bytes read, or -1 if the amount > Integer.MAX_VALUE
- Throws:
java.io.IOException
-
copy
public static int copy(java.io.Reader in, java.io.Writer out) throws java.io.IOExceptionCopies the contents of the Reader to the Writer.- Parameters:
in-out-- Returns:
- the nr of characters read, or -1 if the amount > Integer.MAX_VALUE
- Throws:
java.io.IOException
-
-