public final class IOUtilities
extends java.lang.Object
(This is a cut-down version of the Class of the same name in ph-commons-util.)
| 限定符和类型 | 字段和说明 |
|---|---|
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
|
| 构造器和说明 |
|---|
IOUtilities() |
| 限定符和类型 | 方法和说明 |
|---|---|
static void |
ensureClose(java.io.Closeable... streams)
Ensures that as many of the given
Closeables are closed. |
static java.io.File |
ensureDirectoryCreated(java.io.File directory)
Simple method to ensure that a given directory exists.
|
static java.io.File |
ensureFileCreated(java.io.File file)
Simple method to ensure that a given File exists.
|
static java.lang.String |
readCharacterStream(java.io.Reader reader)
Reads all character data from the given Reader, returning a String
containing all of the data.
|
static java.lang.String |
readUnicodeFile(java.io.File file)
Same as
readUnicodeStream(InputStream) but accepts a plain
File object for convenience |
static java.lang.String |
readUnicodeStream(java.io.InputStream in)
Same as
readCharacterStream(Reader) but assumes the
stream is encoded as UTF-8. |
static void |
transfer(java.io.FileInputStream fileInStream,
java.io.FileOutputStream fileOutStream)
Version of
transfer(InputStream, OutputStream) for File streams that uses
NIO to do a hopefully more efficient transfer. |
static void |
transfer(java.io.InputStream inStream,
java.io.OutputStream outStream)
"Transfers" data from the given InputStream to the given OutputStream,
closing both streams once the InputStream has been exhausted.
|
static void |
transfer(java.io.InputStream inStream,
java.io.OutputStream outStream,
boolean closeOutputStream)
"Transfers" data from the given InputStream to the given OutputStream,
closing the InputStream afterwards.
|
static void |
transfer(java.io.InputStream inStream,
java.io.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 java.io.File ensureDirectoryCreated(java.io.File directory)
throws java.io.IOException
java.io.IOException - if creation could not succeed for some reason.public static java.io.File ensureFileCreated(java.io.File file)
throws java.io.IOException
java.io.IOException - if creation could not succeed for some reason.public static void ensureClose(java.io.Closeable... streams)
throws java.io.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 closejava.io.IOExceptionpublic static void transfer(java.io.InputStream inStream,
java.io.OutputStream outStream)
throws java.io.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 - java.io.IOExceptionpublic static void transfer(java.io.FileInputStream fileInStream,
java.io.FileOutputStream fileOutStream)
throws java.io.IOException
transfer(InputStream, OutputStream) for File streams that uses
NIO to do a hopefully more efficient transfer.java.io.IOExceptionpublic static void transfer(java.io.InputStream inStream,
java.io.OutputStream outStream,
boolean closeOutputStream)
throws java.io.IOException
inStream - outStream - java.io.IOExceptionpublic static void transfer(java.io.InputStream inStream,
java.io.OutputStream outStream,
boolean closeInputStream,
boolean closeOutputStream)
throws java.io.IOException
Even if not closing the output stream, it will still be flushed.
inStream - outStream - java.io.IOExceptionpublic static java.lang.String readCharacterStream(java.io.Reader reader)
throws java.io.IOException
reader - source of string datajava.io.IOExceptionpublic static java.lang.String readUnicodeStream(java.io.InputStream in)
throws java.io.IOException
readCharacterStream(Reader) but assumes the
stream is encoded as UTF-8.in - InputStream supplying character datajava.io.IOExceptionpublic static java.lang.String readUnicodeFile(java.io.File file)
throws java.io.IOException
readUnicodeStream(InputStream) but accepts a plain
File object for conveniencefile - File to read fromjava.io.IOException