|
SPT Core API | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjava.io.Writer
com.sptci.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 com.sptci.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(java.io.InputStream, String[]),
© Copyright 2005, Sans Pareil Technologies, Inc.
| Field Summary |
|---|
| Fields inherited from class java.io.Writer |
|---|
lock |
| Constructor Summary | |
|---|---|
TeeWriter(File[] files)
Create a new instance that writes all the data to the specified files. |
|
TeeWriter(String[] names)
Create a new instance that writes all the data to the specified files. |
|
TeeWriter(Writer[] writers)
Create a new instance that writes all the data to the specified writers. |
|
| Method Summary | |
|---|---|
void |
addWriter(Writer writer)
Add the specified Writer to the writers. |
void |
close()
Close the stream, flushing it first. |
void |
flush()
Flush the stream. |
Writer[] |
getWriters()
Returns writers. |
void |
setWriters(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(String string)
Write the string to the writers. |
void |
write(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 |
| Constructor Detail |
|---|
public TeeWriter(Writer[] writers)
writers - The array of
Writers to which the contents are to be
written.
public TeeWriter(String[] names)
throws 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.
IOException - If errors are encountered while creating the
specified files.createWriters( String[] )
public TeeWriter(File[] files)
throws 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.
IOException - If errors are encountered while creating the
specified files.createWriters( File[] )| Method Detail |
|---|
public final void addWriter(Writer writer)
Writer to the writers.
writer - The writer to add.
public void close()
throws 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 Closeableclose in class WriterIOException - If errors are encountered while closing any
of the configured output streams.
public void flush()
throws 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 Flushableflush in class WriterIOException - If errors are encountered while flushing any
of the configured output streams.
public void write(int character)
throws IOException
write in class Writercharacter - The character to be written.
IOException - If errors are encountered while writing the
byte to any of the configured output streams.
public void write(char[] chars)
throws IOException
chars.length characters from the specified
char array to all the output streams.
write in class Writerchars - The data that is to be written.
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 IOException,
NullPointerException,
IndexOutOfBoundsException
length characters from the specified char
array starting at offset offset to the writers.
write in class Writerchars - The data to be written.offset - The start offset in the array.length - The number of characters to write.
IOException - If an I/O error occurs. In particular, an
IOException is thrown if the writer is closed.
NullPointerException
IndexOutOfBoundsException
public void write(String string)
throws IOException
writers.
write in class Writerstring - The string to be written.
IOException - If an I/O error occurs. In particular, an
IOException is thrown if the writer is closed.
public void write(String string,
int offset,
int length)
throws IOException
writers.
write in class Writerstring - The string to be written.offset - The start offset in the string.length - The number of characters to write.
IOException - If an I/O error occurs. In particular, an
IOException is thrown if the writer is closed.public final Writer[] getWriters()
writers.
public final void setWriters(Writer[] writers)
writers.
writers - The value to set.
|
SPT Core API | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||