Package com.google.common.io
Class CountingOutputStream
- java.lang.Object
-
- java.io.OutputStream
-
- java.io.FilterOutputStream
-
- com.google.common.io.CountingOutputStream
-
- All Implemented Interfaces:
Closeable
,Flushable
,AutoCloseable
@Beta @GwtIncompatible public final class CountingOutputStream extends FilterOutputStream
An OutputStream that counts the number of bytes written.- Since:
- 1.0
- Author:
- Chris Nokleberg
-
-
Field Summary
-
Fields inherited from class java.io.FilterOutputStream
out
-
-
Constructor Summary
Constructors Constructor Description CountingOutputStream(OutputStream out)
Wraps another output stream, counting the number of bytes written.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
Closes this output stream and releases any system resources associated with the stream.long
getCount()
Returns the number of bytes written.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
flush, write
-
Methods inherited from class java.io.OutputStream
nullOutputStream
-
-
-
-
Constructor Detail
-
CountingOutputStream
public CountingOutputStream(OutputStream out)
Wraps another output stream, counting the number of bytes written.- Parameters:
out
- the output stream to be wrapped
-
-
Method Detail
-
getCount
public long getCount()
Returns the number of bytes written.
-
write
public void write(byte[] b, int off, int len) throws IOException
Description copied from class:java.io.FilterOutputStream
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 output 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:
FilterOutputStream.write(int)
-
write
public void write(int b) throws IOException
Description copied from class:java.io.FilterOutputStream
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.
-
close
public void close() throws IOException
Description copied from class:java.io.FilterOutputStream
Closes this output stream and releases any system resources associated with the stream.When not already closed, the
close
method ofFilterOutputStream
calls itsflush
method, and then calls theclose
method of its underlying output stream.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Overrides:
close
in classFilterOutputStream
- Throws:
IOException
- if an I/O error occurs.- See Also:
FilterOutputStream.flush()
,FilterOutputStream.out
-
-