Package org.docx4j.org.apache.poi.util
Class IOUtils
java.lang.Object
org.docx4j.org.apache.poi.util.IOUtils
-
Method Summary
Modifier and TypeMethodDescriptionstatic longcalculateChecksum(byte[] data) static voidcloseQuietly(Closeable closeable) Quietly (no exceptions) close Closable resource.static voidcopy(InputStream inp, OutputStream out) Copies all the data from the given InputStream to the OutputStream.static byte[]peekFirst8Bytes(InputStream stream) Peeks at the first 8 bytes of the stream.static intreadFully(InputStream in, byte[] b) Helper method, just calls readFully(in, b, 0, b.length)static intreadFully(InputStream in, byte[] b, int off, int len) Same as the normal in.read(b, off, len), but tries to ensure that the entire len number of bytes is read.static intreadFully(ReadableByteChannel channel, ByteBuffer b) Same as the normal channel.read(b), but tries to ensure that the entire len number of bytes is read.static byte[]toByteArray(InputStream stream) Reads all the data from the input stream, and returns the bytes read.static byte[]toByteArray(ByteBuffer buffer, int length) Returns an array (that shouldn't be written to!) of the ByteBuffer.
-
Method Details
-
peekFirst8Bytes
Peeks at the first 8 bytes of the stream. Returns those bytes, but with the stream unaffected. Requires a stream that supports mark/reset, or a PushbackInputStream. If the stream has >0 but <8 bytes, remaining bytes will be zero.- Throws:
EmptyFileException- if the stream is emptyIOException
-
toByteArray
Reads all the data from the input stream, and returns the bytes read.- Throws:
IOException
-
toByteArray
Returns an array (that shouldn't be written to!) of the ByteBuffer. Will be of the requested length, or possibly longer if that's easier. -
readFully
Helper method, just calls readFully(in, b, 0, b.length)- Throws:
IOException
-
readFully
Same as the normal in.read(b, off, len), but tries to ensure that the entire len number of bytes is read.If the end of file is reached before any bytes are read, returns -1. If the end of the file is reached after some bytes are read, returns the number of bytes read. If the end of the file isn't reached before len bytes have been read, will return len bytes.
- Throws:
IOException
-
readFully
Same as the normal channel.read(b), but tries to ensure that the entire len number of bytes is read.If the end of file is reached before any bytes are read, returns -1. If the end of the file is reached after some bytes are read, returns the number of bytes read. If the end of the file isn't reached before len bytes have been read, will return len bytes.
- Throws:
IOException
-
copy
Copies all the data from the given InputStream to the OutputStream. It leaves both streams open, so you will still need to close them once done.- Throws:
IOException
-
calculateChecksum
public static long calculateChecksum(byte[] data) -
closeQuietly
Quietly (no exceptions) close Closable resource. In case of error it will be printed toIOUtilsclass logger.- Parameters:
closeable- resource to close
-