Package libcore.util

Class 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.
    • Constructor Detail

      • CountingOutputStream

        public CountingOutputStream​(OutputStream out)
        Constructs a new FilterOutputStream with out as 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 IOException
        Description copied from class: FilterOutputStream
        Writes count bytes from the byte array buffer starting at offset to the target stream.
        Overrides:
        write in class FilterOutputStream
        Parameters:
        buffer - the buffer to write.
        offset - the index of the first byte in buffer to write.
        length - the number of bytes in buffer to write.
        Throws:
        IOException - if an I/O error occurs while writing to this stream.
      • write

        public void write​(int oneByte)
                   throws IOException
        Description copied from class: FilterOutputStream
        Writes one byte to the target stream. Only the low order byte of the integer oneByte is written.
        Overrides:
        write in class FilterOutputStream
        Parameters:
        oneByte - the byte to be written.
        Throws:
        IOException - if an I/O error occurs while writing to this stream.
      • getCount

        public long getCount()