|
Rakesh API | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjava.io.Writer
org.rakeshv.io.TeeWriter
public class TeeWriter
A implementation of the UNIX tee command. This class
enables writing the contents of an InputStream to
multiple Writers.
The following code shows sample usage of this class.
import org.rakeshv.io.TeeWriter;
import java.io.BufferedReader;
import java.io.FileReader;
public class test
{
public static void main( String[] args )
{
try
{
String[] files = {"/tmp/one", "/tmp/two", "/tmp/three"};;
TeeWriter writer = new TeeWriter( files );
BufferedReader reader = new BufferedReader(
new FileReader( "/tmp/test.java" ) );
String line = "";
while ( ( line = reader.readLine() ) != null )
{
writer.write( line );
writer.write( System.getProperty( "line.separator" ) );
}
reader.close();
writer.flush();
writer.close();
}
catch ( Throwable t )
{
t.printStackTrace();
}
}
}
FileUtilities.writeToFiles( InputStream, String[] ),
© Copyright 2005, Rakesh Vidyadharan
| Field Summary | |
|---|---|
private java.io.Writer[] |
writers
The Array of Writers to which
the content is to be written. |
| Fields inherited from class java.io.Writer |
|---|
lock |
| Constructor Summary | |
|---|---|
TeeWriter(java.io.File[] files)
Create a new instance that writes all the data to the specified files. |
|
TeeWriter(java.lang.String[] names)
Create a new instance that writes all the data to the specified files. |
|
TeeWriter(java.io.Writer[] writers)
Create a new instance that writes all the data to the specified writers. |
|
| Method Summary | |
|---|---|
void |
addWriter(java.io.Writer writer)
Add the specified Writer to the writers. |
void |
close()
Close the stream, flushing it first. |
private void |
createWriters(java.io.File[] files)
Initialise the writers with the files specified. |
private void |
createWriters(java.lang.String[] names)
Initialise the writers with files representing the
names specified. |
void |
flush()
Flush the stream. |
java.io.Writer[] |
getWriters()
Returns writers. |
void |
setWriters(java.io.Writer[] writers)
Set writers. |
void |
write(char[] chars)
Writes chars.length characters from the specified
char array to all the output streams. |
void |
write(char[] chars,
int offset,
int length)
Writes length characters from the specified char
array starting at offset offset to the writers. |
void |
write(int character)
Write a single character. |
void |
write(java.lang.String string)
Write the string to the writers. |
void |
write(java.lang.String string,
int offset,
int length)
Write the portion of the string to the writers. |
| Methods inherited from class java.io.Writer |
|---|
append, append, append |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
private java.io.Writer[] writers
Array of Writers to which
the content is to be written.
| Constructor Detail |
|---|
public TeeWriter(java.io.Writer[] writers)
writers - The array of
Writers to which the contents are to be
written.
public TeeWriter(java.lang.String[] names)
throws java.io.IOException
flush()
method if this constructor is used.
Note: If the file(s) specified point to paths that do not yet exist, the required directory structure will be created.
names - The array of fully qualified filenames to which
the data is to be written.
java.io.IOException - If errors are encountered while creating the
specified files.createWriters( String[] )
public TeeWriter(java.io.File[] files)
throws java.io.IOException
flush()
method if this constructor is used.
Note: If the file(s) specified point to paths that do not yet exist, the required directory structure will be created.
files - The array of files to which the data is to be
written.
java.io.IOException - If errors are encountered while creating the
specified files.createWriters( File[] )| Method Detail |
|---|
public final void addWriter(java.io.Writer writer)
Writer to the writers.
public void close()
throws java.io.IOException
write(int) or flush() invocations
will cause an IOException to be thrown. Closing a
previously-closed stream, however, has no effect.
Iterates through the writers and closes each of them.
close in interface java.io.Closeableclose in class java.io.Writerjava.io.IOException - If errors are encountered while closing any
of the configured output streams.
public void flush()
throws java.io.IOException
write(int) methods in a buffer, write them
immediately to their intended destination. Then, if that
destination is another character or byte stream, flush it. Thus
one flush() invocation will flush all the buffers in
a chain of Writers and OutputStreams. Iteratores through the
writers and flushes each sequentially.
flush in interface java.io.Flushableflush in class java.io.Writerjava.io.IOException - If errors are encountered while flushing any
of the configured output streams.
public void write(int character)
throws java.io.IOException
write in class java.io.Writercharacter - The character to be written.
java.io.IOException - If errors are encountered while writing the
byte to any of the configured output streams.
public void write(char[] chars)
throws java.io.IOException
chars.length characters from the specified
char array to all the output streams.
write in class java.io.Writerchars - The data that is to be written.
java.io.IOException - If errors are encountered while writing the
data to any of the configured output streams.
public void write(char[] chars,
int offset,
int length)
throws java.io.IOException,
java.lang.NullPointerException,
java.lang.IndexOutOfBoundsException
length characters from the specified char
array starting at offset offset to the writers.
write in class java.io.Writerchars - The data to be written.offset - The start offset in the array.length - The number of characters to write.
java.io.IOException - If an I/O error occurs. In particular, an
IOException is thrown if the writer is closed.
java.lang.NullPointerException
java.lang.IndexOutOfBoundsException
public void write(java.lang.String string)
throws java.io.IOException
writers.
write in class java.io.Writerstring - The string to be written.
java.io.IOException - If an I/O error occurs. In particular, an
IOException is thrown if the writer is closed.
public void write(java.lang.String string,
int offset,
int length)
throws java.io.IOException
writers.
write in class java.io.Writerstring - The string to be written.offset - The start offset in the string.length - The number of characters to write.
java.io.IOException - If an I/O error occurs. In particular, an
IOException is thrown if the writer is closed.
private void createWriters(java.lang.String[] names)
throws java.io.IOException
writers with files representing the
names specified.
names - The array of files to which the output is to be
written.
java.io.IOException - If a file specified could not be created.FileUtilities.mkdirs(java.io.File)
private void createWriters(java.io.File[] files)
throws java.io.IOException
writers with the files specified.
files - The array of files to which the output is to be
written.
java.io.IOException - If a file specified could not be accessed.FileUtilities.mkdirs(java.io.File)public final java.io.Writer[] getWriters()
writers.
public final void setWriters(java.io.Writer[] writers)
writers.
writers - The value to set.
|
Rakesh API | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||