|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectde.unkrig.commons.io.IoUtil
public final class IoUtil
Various java.io-related utility methods.
| Nested Class Summary | |
|---|---|
static interface |
IoUtil.WritingRunnable
An entity which writes characters to a Writer. |
| Field Summary | |
|---|---|
static java.io.InputStream |
EMPTY_INPUT_STREAM
An InputStream that produces exactly 0 bytes. |
static java.io.OutputStream |
NULL_OUTPUT_STREAM
An OutputStream that discards all bytes written to it. |
static java.io.InputStream |
ZERO_INPUT_STREAM
An input stream that reads an endless stream of zeros. |
| Method Summary | |
|---|---|
static java.io.OutputStream |
byteConsumerOutputStream(ConsumerWhichThrows<java.lang.Byte,java.io.IOException> delegate)
|
static java.io.InputStream |
byteProducerInputStream(Producer<java.lang.Byte> delegate)
|
static java.io.InputStream |
byteProducerInputStream(ProducerWhichThrows<java.lang.Byte,? extends java.io.IOException> delegate)
|
static java.io.OutputStream[] |
compareOutput(int n,
java.lang.Runnable whenIdentical,
java.lang.Runnable whenNotIdentical)
Creates and returns an array of n OutputStreams. |
static java.io.InputStream |
constantInputStream(byte b)
|
static long |
copy(java.io.File inputFile,
java.io.File outFile)
Copies the contents of the inputFile to the outputFile. |
static long |
copy(java.io.File inputFile,
java.io.OutputStream outputStream,
boolean closeOutputStream)
Copies the contents of the inputFile to the outputStream. |
static long |
copy(java.io.InputStream inputStream,
boolean closeInputStream,
java.io.File outputFile)
Copies the contents of the inputStream to the outputFile. |
static long |
copy(java.io.InputStream inputStream,
boolean closeInputStream,
java.io.File outputFile,
boolean append)
Copies the contents of the inputStream to the outputFile. |
static long |
copy(java.io.InputStream inputStream,
boolean closeInputStream,
java.io.OutputStream outputStream,
boolean closeOutputStream)
Copies the contents of the inputStream to the outputStream. |
static long |
copy(java.io.InputStream inputStream,
java.io.OutputStream outputStream)
Reads the input stream until end-of-input and writes all data to the output stream. |
static long |
copy(java.io.InputStream inputStream,
java.io.OutputStream outputStream,
long n)
Reads at most n bytes from the input stream and writes all data to the output stream. |
static long |
copy(java.lang.Readable r,
java.lang.Appendable a)
Reads the Readable until end-of-input and writes all data to the Appendable. |
static long |
copy(java.io.Reader reader,
boolean closeReader,
java.io.File outputFile,
boolean append,
java.nio.charset.Charset outputCharset)
Copies the contents of the reader to the outputFile, encoded with the given outputCharset. |
static long |
copy(java.io.Reader reader,
boolean closeReader,
java.io.Writer writer,
boolean closeWriter)
Copies the contents of the reader to the writer. |
static long |
copy(java.io.Reader reader,
java.io.OutputStream outputStream,
java.nio.charset.Charset charset)
Reads the reader until end-of-input and writes all data to the output stream. |
static long |
copy(java.io.Reader reader,
java.io.Writer writer)
Reads the reader until end-of-input and writes all data to the writer. |
static ConsumerWhichThrows<java.io.OutputStream,java.io.IOException> |
copyFrom(java.io.InputStream is)
|
static RunnableWhichThrows<java.io.IOException> |
copyRunnable(java.io.InputStream in,
java.io.OutputStream out)
Creates and returns a RunnableWhichThrows that copies bytes from in to out until
end-of-input. |
protected static java.io.InputStream |
deleteOnClose(java.io.InputStream delegate,
java.io.File file)
|
static void |
fill(java.io.OutputStream outputStream,
byte b,
long count)
Writes count bytes of value b to the given output stream. |
static void |
parallel(IoUtil.WritingRunnable[] writingRunnables,
java.io.Writer writer)
Executes the writingRunnables in parallel, concatenates their output, and writes it to the writer, i.e. the output of the runnables does not mix, but the complete output of the first runnable
appears before that of the second runnable, and so on. |
static java.io.InputStream |
randomInputStream(long seed)
|
static byte[] |
readAll(java.io.InputStream is)
|
static java.lang.String |
readAll(java.io.InputStream inputStream,
java.nio.charset.Charset charset,
boolean closeInputStream)
|
static java.lang.String |
readAll(java.io.Reader r)
|
static java.io.OutputStream |
split(ProducerWhichThrows<java.io.OutputStream,java.io.IOException> delegates,
Producer<java.lang.Long> byteCountLimits)
Creates and returns an OutputStream which writes at most byteCountLimits.produce() bytes to
delegates.produce() before closing it and writing the next byteCountLimits.produce() bytes to
delegates.produce(), and so on. |
static java.io.OutputStream |
tee(java.io.OutputStream... delegates)
Creates and returns an OutputStream that delegates all work to the given delegates:
The write() methods write the given data to all the delegates;
if any of these throw an IOException, it is rethrown, and it is undefined whether all the data was
written to all the delegates. |
static long |
writeAndCount(ConsumerWhichThrows<java.io.OutputStream,java.io.IOException> writeContents,
java.io.OutputStream os)
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final java.io.InputStream EMPTY_INPUT_STREAM
InputStream that produces exactly 0 bytes.
public static final java.io.OutputStream NULL_OUTPUT_STREAM
OutputStream that discards all bytes written to it.
public static final java.io.InputStream ZERO_INPUT_STREAM
| Method Detail |
|---|
public static long copy(java.io.InputStream inputStream,
java.io.OutputStream outputStream)
throws java.io.IOException
java.io.IOException
public static long copy(java.io.InputStream inputStream,
java.io.OutputStream outputStream,
long n)
throws java.io.IOException
n bytes from the input stream and writes all data to the output stream. Closes neither of
the two streams.
java.io.IOException
public static long copy(java.io.InputStream inputStream,
boolean closeInputStream,
java.io.OutputStream outputStream,
boolean closeOutputStream)
throws java.io.IOException
inputStream to the outputStream.
closeInputStream - Whether to close the inputStream (also if an IOException is thrown)closeOutputStream - Whether to close the outputStream (also if an IOException is thrown)
java.io.IOException
public static RunnableWhichThrows<java.io.IOException> copyRunnable(java.io.InputStream in,
java.io.OutputStream out)
RunnableWhichThrows that copies bytes from in to out until
end-of-input.
public static long copy(java.io.Reader reader,
java.io.Writer writer)
throws java.io.IOException
java.io.IOException
public static long copy(java.io.Reader reader,
boolean closeReader,
java.io.Writer writer,
boolean closeWriter)
throws java.io.IOException
reader to the writer.
java.io.IOException
public static long copy(java.io.Reader reader,
java.io.OutputStream outputStream,
java.nio.charset.Charset charset)
throws java.io.IOException
java.io.IOException
public static long copy(java.lang.Readable r,
java.lang.Appendable a)
throws java.io.IOException
Readable until end-of-input and writes all data to the Appendable.
java.io.IOException
public static long copy(java.io.InputStream inputStream,
boolean closeInputStream,
java.io.File outputFile,
boolean append)
throws java.io.IOException
inputStream to the outputFile. Attempts to delete a partially written
output file if the operation fails.
java.io.IOException
public static long copy(java.io.Reader reader,
boolean closeReader,
java.io.File outputFile,
boolean append,
java.nio.charset.Charset outputCharset)
throws java.io.IOException
reader to the outputFile, encoded with the given outputCharset. Attempts to delete a partially written output file if the operation fails.
java.io.IOException
public static long copy(java.io.File inputFile,
java.io.OutputStream outputStream,
boolean closeOutputStream)
throws java.io.IOException
inputFile to the outputStream.
java.io.IOException
public static long copy(java.io.InputStream inputStream,
boolean closeInputStream,
java.io.File outputFile)
throws java.io.IOException
inputStream to the outputFile.
java.io.IOException
public static long copy(java.io.File inputFile,
java.io.File outFile)
throws java.io.IOException
inputFile to the outputFile.
java.io.IOExceptionpublic static ConsumerWhichThrows<java.io.OutputStream,java.io.IOException> copyFrom(java.io.InputStream is)
Comsumer<OutputStream> which copies is to its subjectpublic static java.io.OutputStream tee(java.io.OutputStream... delegates)
OutputStream that delegates all work to the given delegates:
write() methods write the given data to all the delegates;
if any of these throw an IOException, it is rethrown, and it is undefined whether all the data was
written to all the delegates.
flush() flushes the delegates; throws the first IOException that any
of the delegates throws.
close() attempts to close all the delegates; if any of these
throw IOExceptions, one of them is rethrown.
public static long writeAndCount(ConsumerWhichThrows<java.io.OutputStream,java.io.IOException> writeContents,
java.io.OutputStream os)
throws java.io.IOException
writeContents had written to its subject
java.io.IOException
public static void parallel(IoUtil.WritingRunnable[] writingRunnables,
java.io.Writer writer)
writingRunnables in parallel, concatenates their output, and writes it to the writer, i.e. the output of the runnables does not mix, but the complete output of the first runnable
appears before that of the second runnable, and so on.
Since the character buffer for each IoUtil.WritingRunnable has a limited size, the runnables with higher
indexes tend to block if the runnables with lower indexes do not complete quickly enough.
public static byte[] readAll(java.io.InputStream is)
throws java.io.IOException
InputStream produces
java.io.IOException
public static java.lang.String readAll(java.io.InputStream inputStream,
java.nio.charset.Charset charset,
boolean closeInputStream)
throws java.io.IOException
InputStream produces, decoded into a string
java.io.IOException
public static java.io.OutputStream split(ProducerWhichThrows<java.io.OutputStream,java.io.IOException> delegates,
Producer<java.lang.Long> byteCountLimits)
throws java.io.IOException
OutputStream which writes at most byteCountLimits.produce() bytes to
delegates.produce() before closing it and writing the next byteCountLimits.produce() bytes to
delegates.produce(), and so on.
delegates - Must produce a non-null series of OutputStreamsbyteCountLimits - Must produce a non-null series of Longs
java.io.IOExceptionpublic static java.io.InputStream constantInputStream(byte b)
b.
public static void fill(java.io.OutputStream outputStream,
byte b,
long count)
throws java.io.IOException
count bytes of value b to the given output stream.
java.io.IOExceptionpublic static java.io.InputStream byteProducerInputStream(ProducerWhichThrows<java.lang.Byte,? extends java.io.IOException> delegate)
delegate byte producer; null
products are returned as 'end-of-input'public static java.io.InputStream byteProducerInputStream(Producer<java.lang.Byte> delegate)
delegate byte producer; null
products are returned as 'end-of-input'public static java.io.InputStream randomInputStream(long seed)
delegate byte producer; null
products are returned as 'end-of-input'public static java.io.OutputStream byteConsumerOutputStream(ConsumerWhichThrows<java.lang.Byte,java.io.IOException> delegate)
delegate byte consumer
public static java.lang.String readAll(java.io.Reader r)
throws java.io.IOException
Reader produces
java.io.IOException
protected static java.io.InputStream deleteOnClose(java.io.InputStream delegate,
java.io.File file)
InputStream which first closes the delegate, and then attempts to delete the file
public static java.io.OutputStream[] compareOutput(int n,
java.lang.Runnable whenIdentical,
java.lang.Runnable whenNotIdentical)
n OutputStreams.
Iff exactly the same bytes are written to
all of these streams, and then all the streams are closed, then whenIdentical will be run (exactly once).
Otherwise, when the first non-identical byte is written to one of the streams, or at the latest when that stream
is closed, whenNotIdentical will be run (possibly more than once).
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||