- java.lang.Object
-
- de.carne.io.IOUtil
-
public final class IOUtil extends java.lang.ObjectUtility class providing I/O related functions.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static intcopyBuffer(java.io.OutputStream dst, java.nio.ByteBuffer buffer)Copies all available bytes from a ByteBuffer to a OutputStream.static longcopyChannel(java.nio.channels.WritableByteChannel dst, java.nio.channels.ReadableByteChannel src)Copies all bytes from a ReadableByteChannel to a WritableByteChannel.static longcopyFile(java.io.File dst, java.io.File src)Copies all bytes from a File to a File.static longcopyFile(java.io.OutputStream dst, java.io.File src)Copies all bytes from a File to an OutputStream.static longcopyStream(java.io.File dst, java.io.InputStream src)Copies all bytes from an InputStream to a File.static longcopyStream(java.io.OutputStream dst, java.io.InputStream src)Copies all bytes from an InputStream to an OutputStream.static longcopyUrl(java.io.File dst, java.net.URL src)Copies all bytes from a URL to a File.static longcopyUrl(java.io.OutputStream dst, java.net.URL src)Copies all bytes from a URL to an OutputStream.static byte[]readAllBytes(java.io.File src)Read all bytes from a File.static byte[]readAllBytes(java.io.File src, int limit)Read up tolimitbytes from a File.static byte[]readAllBytes(java.io.InputStream src)Read all bytes from an InputStream.static byte[]readAllBytes(java.io.InputStream src, int limit)Read up tolimitbytes from an InputStream.static byte[]readAllBytes(java.net.URL src)Read all bytes from a URL.static byte[]readAllBytes(java.net.URL src, int limit)Read up tolimitbytes from a URL.static intreadBlocking(java.io.InputStream in, byte[] b)Reads up to the requested number of bytes and blocks until they are all read or EOF is reached.static intreadBlocking(java.io.InputStream in, byte[] b, int off, int len)Reads up to the requested number of bytes and blocks until they are all read or EOF is reached.static intreadEager(java.io.InputStream in, byte[] b)Reads eagerly the requested number of bytes and fails if they are not available.static intreadEager(java.io.InputStream in, byte[] b, int off, int len)Reads eagerly the requested number of bytes and fails if they are not available.
-
-
-
Method Detail
-
copyStream
public static long copyStream(java.io.OutputStream dst, java.io.InputStream src) throws java.io.IOExceptionCopies all bytes from an InputStream to an OutputStream.- Parameters:
dst- the OutputStream to copy to.src- the InputStream to copy from.- Returns:
- the number of copied bytes.
- Throws:
java.io.IOException- if an I/O error occurs.
-
copyStream
public static long copyStream(java.io.File dst, java.io.InputStream src) throws java.io.IOExceptionCopies all bytes from an InputStream to a File.- Parameters:
dst- the File to copy to.src- the InputStream to copy from.- Returns:
- the number of copied bytes.
- Throws:
java.io.IOException- if an I/O error occurs.
-
copyFile
public static long copyFile(java.io.OutputStream dst, java.io.File src) throws java.io.IOExceptionCopies all bytes from a File to an OutputStream.- Parameters:
dst- the OutputStream to copy to.src- the File to copy from.- Returns:
- the number of copied bytes.
- Throws:
java.io.IOException- if an I/O error occurs.
-
copyFile
public static long copyFile(java.io.File dst, java.io.File src) throws java.io.IOExceptionCopies all bytes from a File to a File.- Parameters:
dst- the File to copy to.src- the File to copy from.- Returns:
- the number of copied bytes.
- Throws:
java.io.IOException- if an I/O error occurs.
-
copyUrl
public static long copyUrl(java.io.OutputStream dst, java.net.URL src) throws java.io.IOExceptionCopies all bytes from a URL to an OutputStream.- Parameters:
dst- the OutputStream to copy to.src- the URL to copy from.- Returns:
- the number of copied bytes.
- Throws:
java.io.IOException- if an I/O error occurs.
-
copyUrl
public static long copyUrl(java.io.File dst, java.net.URL src) throws java.io.IOExceptionCopies all bytes from a URL to a File.- Parameters:
dst- the File to copy to.src- the URL to copy from.- Returns:
- the number of copied bytes.
- Throws:
java.io.IOException- if an I/O error occurs.
-
copyChannel
public static long copyChannel(java.nio.channels.WritableByteChannel dst, java.nio.channels.ReadableByteChannel src) throws java.io.IOExceptionCopies all bytes from a ReadableByteChannel to a WritableByteChannel.- Parameters:
dst- the WritableByteChannel to copy to.src- the ReadableByteChannel to copy from.- Returns:
- the number of copied bytes.
- Throws:
java.io.IOException- if an I/O error occurs.
-
copyBuffer
public static int copyBuffer(java.io.OutputStream dst, java.nio.ByteBuffer buffer) throws java.io.IOExceptionCopies all available bytes from a ByteBuffer to a OutputStream.- Parameters:
dst- the OutputStream to copy to.buffer- the ByteBuffer to copy from.- Returns:
- the number of copied bytes.
- Throws:
java.io.IOException- if an I/O error occurs.
-
readAllBytes
public static byte[] readAllBytes(java.io.InputStream src) throws java.io.IOExceptionRead all bytes from an InputStream.- Parameters:
src- the InputStream to read from.- Returns:
- the read bytes.
- Throws:
java.io.IOException- if an I/O error occurs.
-
readAllBytes
public static byte[] readAllBytes(java.io.InputStream src, int limit) throws java.io.IOExceptionRead up tolimitbytes from an InputStream.- Parameters:
src- the InputStream to read from.limit- the maximum number of bytes to read.- Returns:
- the read bytes.
- Throws:
java.io.IOException- if an I/O error occurs orlimitis reached.
-
readAllBytes
public static byte[] readAllBytes(java.io.File src) throws java.io.IOExceptionRead all bytes from a File.- Parameters:
src- the File to read from.- Returns:
- the read bytes.
- Throws:
java.io.IOException- if an I/O error occurs.
-
readAllBytes
public static byte[] readAllBytes(java.io.File src, int limit) throws java.io.IOExceptionRead up tolimitbytes from a File.- Parameters:
src- the File to read from.limit- the maximum number of bytes to read.- Returns:
- the read bytes.
- Throws:
java.io.IOException- if an I/O error occurs orlimitis reached.
-
readAllBytes
public static byte[] readAllBytes(java.net.URL src) throws java.io.IOExceptionRead all bytes from a URL.- Parameters:
src- the URL to read from.- Returns:
- the read bytes.
- Throws:
java.io.IOException- if an I/O error occurs.
-
readAllBytes
public static byte[] readAllBytes(java.net.URL src, int limit) throws java.io.IOExceptionRead up tolimitbytes from a URL.- Parameters:
src- the URL to read from.limit- the maximum number of bytes to read.- Returns:
- the read bytes.
- Throws:
java.io.IOException- if an I/O error occurs orlimitis reached.
-
readBlocking
public static int readBlocking(java.io.InputStream in, byte[] b) throws java.io.IOExceptionReads up to the requested number of bytes and blocks until they are all read or EOF is reached.- Parameters:
in- the InputStream to read from.b- the buffer to read into.- Returns:
- the number of read bytes.
- Throws:
java.io.IOException- if an I/O error occurs.
-
readBlocking
public static int readBlocking(java.io.InputStream in, byte[] b, int off, int len) throws java.io.IOExceptionReads up to the requested number of bytes and blocks until they are all read or EOF is reached.- Parameters:
in- the InputStream to read from.b- the buffer to read into.off- the buffer offset to use.len- the maximum number of bytes to read.- Returns:
- the number of read bytes.
- Throws:
java.io.IOException- if an I/O error occurs.
-
readEager
public static int readEager(java.io.InputStream in, byte[] b) throws java.io.IOExceptionReads eagerly the requested number of bytes and fails if they are not available.- Parameters:
in- the InputStream to read from.b- the buffer to read into.- Returns:
- the number of read bytes (always the size of the buffer).
- Throws:
java.io.IOException- if an I/O error occurs or a premature EOF has been reached.
-
readEager
public static int readEager(java.io.InputStream in, byte[] b, int off, int len) throws java.io.IOExceptionReads eagerly the requested number of bytes and fails if they are not available.- Parameters:
in- the InputStream to read from.b- the buffer to read into.off- the buffer offset to use.len- the number of bytes to read.- Returns:
- the number of read bytes (always the size of the buffer).
- Throws:
java.io.IOException- if an I/O error occurs or a premature EOF has been reached.
-
-