|
SPT Core API | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjava.io.OutputStream
com.sptci.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 com.sptci.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, Sans Pareil Technologies, Inc.
| Constructor Summary | |
|---|---|
TeeOutputStream(File[] files)
Create a new instance that writes all the data to the specified files. |
|
TeeOutputStream(OutputStream[] outputStreams)
Create a new instance that writes all the data to the specified output streams. |
|
TeeOutputStream(String[] names)
Create a new instance that writes all the data to the specified files. |
|
| Method Summary | |
|---|---|
void |
addOutputStream(OutputStream outputStream)
Add the specified OutputStream to the outputStreams. |
void |
close()
Closes this output stream and releases any system resources associated with this stream. |
void |
flush()
Flushes all the configured output streams and forces any buffered output bytes to be written out. |
OutputStream[] |
getOutputStreams()
Returns outputStreams. |
void |
setOutputStreams(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 |
| Constructor Detail |
|---|
public TeeOutputStream(OutputStream[] outputStreams)
outputStreams - The array of
OutputStreams to which the contents are to be
written.
public TeeOutputStream(String[] names)
throws 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.
FileNotFoundException - If a file corresponding to a name
specified could not be created.createOutputStreams( String[] )
public TeeOutputStream(File[] files)
throws 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.
FileNotFoundException - If a file that was specified could
could not be accessed.createOutputStreams( File[] )| Method Detail |
|---|
public final void addOutputStream(OutputStream outputStream)
OutputStream to the outputStreams.
outputStream - The output stream to be added.
public void close()
throws IOException
outputStreams and closes each of them.
close in interface Closeableclose in class OutputStreamIOException - If errors are encountered while closing any
of the configured output streams.
public void flush()
throws IOException
flush in interface Flushableflush in class OutputStreamIOException - If errors are encountered while flushing any
of the configured output streams.
public void write(int b)
throws IOException
write in class OutputStreamb - The byte to be written.
IOException - If errors are encountered while writing the
byte to any of the configured output streams.
public void write(byte[] bytes)
throws IOException
write(b)
is that it should have exactly the same effect as the call write(byte[], int, int).
write in class OutputStreambytes - 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(byte[] bytes,
int offset,
int length)
throws IOException,
NullPointerException,
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 OutputStreambytes - The data to be written.offset - The start offset in the data.length - The number of bytes to write.
IOException - If an I/O error occurs. In particular, an
IOException is thrown if the output stream is closed.
NullPointerException
IndexOutOfBoundsExceptionpublic final OutputStream[] getOutputStreams()
outputStreams.
public final void setOutputStreams(OutputStream[] outputStreams)
outputStreams.
outputStreams - The value to set.
|
SPT Core API | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||