Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package com.fasterxml.storemate.store.util;
 
 import java.io.*;
 
Simple helper class that counts number of bytes written; and can optionally also calculate checksum on the fly.
public class CountingOutputStream extends OutputStream
    protected final OutputStream _out;
    
    protected long _count = 0;
    protected final IncrementalHasher32 _hasher;
    
    public CountingOutputStream(OutputStream out) {
        this(outnull);
    }
    public CountingOutputStream(OutputStream outIncrementalHasher32 hasher) {
        this. = out;
         = hasher;
    }
    public long count() { return ; }
    
    @Override
    public void close() throws IOException {
        .close();
    }
    @Override
    public void flush() throws IOException {
        .flush();
    }
    
    @Override
    public void write(byte[] bthrows IOException {
        write(b, 0, b.length);
    }
    @Override
    public void write(byte[] bint offint len)  throws IOException {
         += len;
        .write(bofflen);
        if ( != null) {
            .update(bofflen);
        }
    }
    byte[] TMP = null;
    
    @Override
    public void write(int bthrows IOException {
        if ( == null) {
             = new byte[1];
        }
        [0] = (byteb;
        write(, 0, 1);
    }
    public int calculateHash() {
        return .calculateHash();
    }
New to GrepCode? Check out our FAQ X