|
Rakesh API | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjava.io.OutputStream
org.rakeshv.io.TeeOutputStream
public class TeeOutputStream
A implementation of the UNIX tee command. This class
enables writing the contents of an InputStream to
multiple OutputStreams.
The following code shows sample usage of this class.
import org.rakeshv.io.TeeOutputStream;
import java.io.BufferedInputStream;
import java.io.FileInputStream;
public class test
{
public static void main( String[] args )
{
String[] names = {"/tmp/one.m4a", "/tmp/two.m4a"};
try
{
InputStream inputStream = new BufferedInputStream(
new FileInputStream( "/tmp/song.m4a" ) );
TeeOutputStream tee = new TeeOutputStream( names );
// Read data from your stream
byte[] buffer = new byte[ 2048 ];
int length = 0;
while ( ( length = inputStream.read( buffer, 0, buffer.length ) ) != -1 )
{
tee.write( buffer, 0, length );
}
}
catch ( Throwable t )
{
t.printStackTrace();
}
}
}
TeeOutputStream,
© Copyright 2005, Rakesh Vidyadharan
| Field Summary | |
|---|---|
private java.io.OutputStream[] |
outputStreams
The Array of OutputStreams to which
the content is to be written. |
| Constructor Summary | |
|---|---|
TeeOutputStream(java.io.File[] files)
Create a new instance that writes all the data to the specified files. |
|
TeeOutputStream(java.io.OutputStream[] outputStreams)
Create a new instance that writes all the data to the specified output streams. |
|
TeeOutputStream(java.lang.String[] names)
Create a new instance that writes all the data to the specified files. |
|
| Method Summary | |
|---|---|
void |
addOutputStream(java.io.OutputStream outputStream)
Add the specified OutputStream to the outputStreams. |
void |
close()
Closes this output stream and releases any system resources associated with this stream. |
private void |
createOutputStreams(java.io.File[] files)
Initialise the outputStreams with the files specified. |
private void |
createOutputStreams(java.lang.String[] names)
Initialise the outputStreams with files representing the
names specified. |
void |
flush()
Flushes all the configured output streams and forces any buffered output bytes to be written out. |
java.io.OutputStream[] |
getOutputStreams()
Returns outputStreams. |
void |
setOutputStreams(java.io.OutputStream[] outputStreams)
Set outputStreams. |
void |
write(byte[] bytes)
Writes b.length bytes from the specified byte array to all the output streams. |
void |
write(byte[] bytes,
int offset,
int length)
Writes length bytes from the specified byte array starting at offset offset to the output streams. |
void |
write(int b)
Writes the specified byte to all the output streams. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
private java.io.OutputStream[] outputStreams
Array of OutputStreams to which
the content is to be written.
| Constructor Detail |
|---|
public TeeOutputStream(java.io.OutputStream[] outputStreams)
outputStreams - The array of
OutputStreams to which the contents are to be
written.
public TeeOutputStream(java.lang.String[] names)
throws java.io.FileNotFoundException
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.FileNotFoundException - If a file corresponding to a name
specified could not be created.createOutputStreams( String[] )
public TeeOutputStream(java.io.File[] files)
throws java.io.FileNotFoundException
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.FileNotFoundException - If a file that was specified could
could not be accessed.createOutputStreams( File[] )| Method Detail |
|---|
public final void addOutputStream(java.io.OutputStream outputStream)
OutputStream to the outputStreams.
public void close()
throws java.io.IOException
outputStreams and closes each of them.
close in interface java.io.Closeableclose in class java.io.OutputStreamjava.io.IOException - If errors are encountered while closing any
of the configured output streams.
public void flush()
throws java.io.IOException
flush in interface java.io.Flushableflush in class java.io.OutputStreamjava.io.IOException - If errors are encountered while flushing any
of the configured output streams.
public void write(int b)
throws java.io.IOException
write in class java.io.OutputStreamb - The byte to be written.
java.io.IOException - If errors are encountered while writing the
byte to any of the configured output streams.
public void write(byte[] bytes)
throws java.io.IOException
write(b)
is that it should have exactly the same effect as the call write(byte[], int, int).
write in class java.io.OutputStreambytes - 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(byte[] bytes,
int offset,
int length)
throws java.io.IOException,
java.lang.NullPointerException,
java.lang.IndexOutOfBoundsException
offset offset to the output streams. The general
contract for write( bytes, offset, length) is that
some of the bytes in the array
bytes are written to the output stream in order;
element bytes[offset] is the first byte written and
b[offset+length-1] is the last byte written by this
operation.
The write method of OutputStream calls the
write(int) method on each of the bytes to be written out.
If bytes is null, a
NullPointerException is thrown.
If offset is negative, or length is
negative, or offset+length is greater than the length
of the array bytes, then an
IndexOutOfBoundsException is thrown.
write in class java.io.OutputStreambytes - The data to be written.offset - The start offset in the data.length - The number of bytes to write.
java.io.IOException - If an I/O error occurs. In particular, an
IOException is thrown if the output stream is closed.
java.lang.NullPointerException
java.lang.IndexOutOfBoundsException
private void createOutputStreams(java.lang.String[] names)
throws java.io.FileNotFoundException,
java.lang.SecurityException
outputStreams with files representing the
names specified.
names - The array of files to which the output is to be
written.
java.io.FileNotFoundException - If a file corresponding to a name
specified could not be created.
java.lang.SecurityException - If the SecurityManager
prevents creating the directory tree for the file(s).FileUtilities.mkdirs(java.io.File)
private void createOutputStreams(java.io.File[] files)
throws java.io.FileNotFoundException
outputStreams with the files specified.
files - The array of files to which the output is to be
written.
java.io.FileNotFoundException - If a file specified could not be
accessed.
java.lang.SecurityException - If the SecurityManager
prevents creating the directory tree for the file(s).FileUtilities.mkdirs(java.io.File)public final java.io.OutputStream[] getOutputStreams()
outputStreams.
public final void setOutputStreams(java.io.OutputStream[] outputStreams)
outputStreams.
outputStreams - The value to set.
|
Rakesh API | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||