Package nl.siegmann.epublib.util
Class IOUtil
java.lang.Object
nl.siegmann.epublib.util.IOUtil
Most 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 -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected static intcalcNewNrReadSize(int nrRead, int totalNrNread) if totalNrRead invalid input: '<' 0 then totalNrRead is returned, if (nrRead + totalNrRead) invalid input: '<' Integer.MAX_VALUE then nrRead + totalNrRead is returned, -1 otherwise.static intcopy(InputStream in, OutputStream out) Copies the contents of the InputStream to the OutputStream.static intCopies the contents of the Reader to the Writer.static byte[]Returns the contents of the InputStream as a byte[]static byte[]toByteArray(InputStream in, int size) Reads data from the InputStream, using the specified buffer size.static byte[]toByteArray(Reader in, String encoding) Gets the contents of the Reader as a byte[], with the given character encoding.
-
Field Details
-
IO_COPY_BUFFER_SIZE
public static final int IO_COPY_BUFFER_SIZE- See Also:
-
-
Constructor Details
-
IOUtil
public IOUtil()
-
-
Method Details
-
toByteArray
Gets 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:
IOException
-
toByteArray
Returns the contents of the InputStream as a byte[]- Parameters:
in-- Returns:
- the contents of the InputStream as a byte[]
- Throws:
IOException
-
toByteArray
Reads 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:
IOException
-
calcNewNrReadSize
protected static int calcNewNrReadSize(int nrRead, int totalNrNread) if totalNrRead invalid input: '<' 0 then totalNrRead is returned, if (nrRead + totalNrRead) invalid input: '<' Integer.MAX_VALUE then nrRead + totalNrRead is returned, -1 otherwise.- Parameters:
nrRead-totalNrNread-- Returns:
- if totalNrRead invalid input: '<' 0 then totalNrRead is returned, if (nrRead + totalNrRead) invalid input: '<' Integer.MAX_VALUE then nrRead + totalNrRead is returned, -1 otherwise.
-
copy
Copies 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:
IOException
-
copy
Copies 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:
IOException
-