Package libcore.util
Class CountingOutputStream
- java.lang.Object
-
- java.io.OutputStream
-
- java.io.FilterOutputStream
-
- libcore.util.CountingOutputStream
-
- All Implemented Interfaces:
Closeable,Flushable,AutoCloseable
public class CountingOutputStream extends FilterOutputStream
An output stream that keeps count of the number of bytes written to it. Useful when we need to make decisions based on the size of the output, such as deciding what sort of metadata to writes to zip files.
-
-
Field Summary
-
Fields inherited from class java.io.FilterOutputStream
out
-
-
Constructor Summary
Constructors Constructor Description CountingOutputStream(OutputStream out)Constructs a newFilterOutputStreamwithoutas its target stream.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description longgetCount()voidwrite(byte[] buffer, int offset, int length)Writescountbytes from the byte arraybufferstarting atoffsetto the target stream.voidwrite(int oneByte)Writes one byte to the target stream.-
Methods inherited from class java.io.FilterOutputStream
close, flush
-
Methods inherited from class java.io.OutputStream
write
-
-
-
-
Constructor Detail
-
CountingOutputStream
public CountingOutputStream(OutputStream out)
Constructs a newFilterOutputStreamwithoutas its target stream.- Parameters:
out- the target stream that this stream writes to.
-
-
Method Detail
-
write
public void write(byte[] buffer, int offset, int length) throws IOExceptionDescription copied from class:FilterOutputStreamWritescountbytes from the byte arraybufferstarting atoffsetto the target stream.- Overrides:
writein classFilterOutputStream- Parameters:
buffer- the buffer to write.offset- the index of the first byte inbufferto write.length- the number of bytes inbufferto write.- Throws:
IOException- if an I/O error occurs while writing to this stream.
-
write
public void write(int oneByte) throws IOExceptionDescription copied from class:FilterOutputStreamWrites one byte to the target stream. Only the low order byte of the integeroneByteis written.- Overrides:
writein classFilterOutputStream- Parameters:
oneByte- the byte to be written.- Throws:
IOException- if an I/O error occurs while writing to this stream.
-
getCount
public long getCount()
-
-