Class CountingOutputStream
- All Implemented Interfaces:
Closeable
,Flushable
,AutoCloseable
- Author:
- Andrew Pavlin, KA2DDO
-
Field Summary
Modifier and TypeFieldDescriptionlong
Number of bytes forwarded to the encapsulated OutputStream.Fields inherited from class java.io.FilterOutputStream
out
-
Constructor Summary
ConstructorDescriptionWrap a stream that counts the number of bytes written around another OutputStream, -
Method Summary
Modifier and TypeMethodDescriptionlong
Get the number of bytes passed through this stream (so far).void
write
(byte[] b) Writesb.length
bytes to this output stream.void
write
(byte[] b, int off, int len) Writeslen
bytes from the specifiedbyte
array starting at offsetoff
to this output stream.void
write
(int b) Writes the specifiedbyte
to this output stream.Methods inherited from class java.io.FilterOutputStream
close, flush
Methods inherited from class java.io.OutputStream
nullOutputStream
-
Field Details
-
count
public long countNumber of bytes forwarded to the encapsulated OutputStream.
-
-
Constructor Details
-
CountingOutputStream
Wrap a stream that counts the number of bytes written around another OutputStream,- Parameters:
out
- OutputStream to received forwarded bytes
-
-
Method Details
-
write
Writes the specifiedbyte
to this output stream.The
write
method ofFilterOutputStream
calls thewrite
method of its underlying output stream, that is, it performsout.write(b)
.Implements the abstract
write
method ofOutputStream
.- Overrides:
write
in classFilterOutputStream
- Parameters:
b
- thebyte
.- Throws:
IOException
- if an I/O error occurs.
-
write
Writesb.length
bytes to this output stream.The
write
method ofFilterOutputStream
calls itswrite
method of three arguments with the argumentsb
,0
, andb.length
.Note that this method does not call the one-argument
write
method of its underlying stream with the single argumentb
.- Overrides:
write
in classFilterOutputStream
- Parameters:
b
- the data to be written.- Throws:
IOException
- if an I/O error occurs.- See Also:
-
write
Writeslen
bytes from the specifiedbyte
array starting at offsetoff
to this output stream.The
write
method ofFilterOutputStream
calls thewrite
method of one argument on eachbyte
to output.Note that this method does not call the
write
method of its underlying input stream with the same arguments. Subclasses ofFilterOutputStream
should provide a more efficient implementation of this method.- Overrides:
write
in classFilterOutputStream
- Parameters:
b
- the data.off
- the start offset in the data.len
- the number of bytes to write.- Throws:
IOException
- if an I/O error occurs.- See Also:
-
getByteCount
public long getByteCount()Get the number of bytes passed through this stream (so far).- Returns:
- the number of written bytes so far.
-