public final class IOUtilities extends Object
(This is a cut-down version of the Class of the same name in ph-commons-util.)
| Modifier and Type | Field and Description |
|---|---|
static int |
BUFFER_SIZE
Buffer size when transferring streams
|
static int |
MAX_TEXT_STREAM_SIZE
Maximum size of characters we'll read from a text stream before complaining
|
| Constructor and Description |
|---|
IOUtilities() |
| Modifier and Type | Method and Description |
|---|---|
static void |
ensureClose(Closeable... streams)
Ensures that as many of the given
Closeables are closed. |
static File |
ensureDirectoryCreated(File directory)
Simple method to ensure that a given directory exists.
|
static File |
ensureFileCreated(File file)
Simple method to ensure that a given File exists.
|
static String |
readCharacterStream(Reader reader)
Reads all character data from the given Reader, returning a String
containing all of the data.
|
static String |
readUnicodeFile(File file)
Same as
readUnicodeStream(InputStream) but accepts a plain
File object for convenience |
static String |
readUnicodeStream(InputStream in)
Same as
readCharacterStream(Reader) but assumes the
stream is encoded as UTF-8. |
static void |
transfer(FileInputStream fileInStream,
FileOutputStream fileOutStream)
Version of
transfer(InputStream, OutputStream) for File streams that uses
NIO to do a hopefully more efficient transfer. |
static void |
transfer(InputStream inStream,
OutputStream outStream)
"Transfers" data from the given InputStream to the given OutputStream,
closing both streams once the InputStream has been exhausted.
|
static void |
transfer(InputStream inStream,
OutputStream outStream,
boolean closeOutputStream)
"Transfers" data from the given InputStream to the given OutputStream,
closing the InputStream afterwards.
|
static void |
transfer(InputStream inStream,
OutputStream outStream,
boolean closeInputStream,
boolean closeOutputStream)
"Transfers" data from the given InputStream to the given OutputStream,
optionally closing the given input and output streams afterwards.
|
public static final int BUFFER_SIZE
public static final int MAX_TEXT_STREAM_SIZE
public static File ensureDirectoryCreated(File directory) throws IOException
IOException - if creation could not succeed for some reason.public static File ensureFileCreated(File file) throws IOException
IOException - if creation could not succeed for some reason.public static void ensureClose(Closeable... streams) throws IOException
Closeables are closed. If any fail to close, the
first Exception is thrown after an attempt has been made to close the rest.
For convenience, any number of the stream may be null, in which case they will be ignored.
streams - "streams" to closeIOExceptionpublic static void transfer(InputStream inStream, OutputStream outStream) throws IOException
This will check to see if both streams are File streams and, if so, use the
transfer(FileInputStream, FileOutputStream) version of this method instead.
inStream - outStream - IOExceptionpublic static void transfer(FileInputStream fileInStream, FileOutputStream fileOutStream) throws IOException
transfer(InputStream, OutputStream) for File streams that uses
NIO to do a hopefully more efficient transfer.IOExceptionpublic static void transfer(InputStream inStream, OutputStream outStream, boolean closeOutputStream) throws IOException
inStream - outStream - IOExceptionpublic static void transfer(InputStream inStream, OutputStream outStream, boolean closeInputStream, boolean closeOutputStream) throws IOException
Even if not closing the output stream, it will still be flushed.
inStream - outStream - IOExceptionpublic static String readCharacterStream(Reader reader) throws IOException
reader - source of string dataIOExceptionpublic static String readUnicodeStream(InputStream in) throws IOException
readCharacterStream(Reader) but assumes the
stream is encoded as UTF-8.in - InputStream supplying character dataIOExceptionpublic static String readUnicodeFile(File file) throws IOException
readUnicodeStream(InputStream) but accepts a plain
File object for conveniencefile - File to read fromIOExceptionCopyright © 2008–2026 The University of Edinburgh. All rights reserved.