Java 8 Checksum - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 Checksum class.

This code example shows how to use the following methods:getValue, reset, update
  private int write1(byte b[], int off, int len) throws IOException {
    if(count==0 && len>=buf.length) {
      // local buffer is empty and user data has one chunk 
      // checksum and output data 
      final int length = buf.length;
      sum.update(b, off, length);
      writeChecksumChunk(b, off, length, false);
      return length;
    } 
     
    // copy user data to local buffer 
    int bytesToCopy = buf.length-count;
    bytesToCopy = (len<bytesToCopy) ? len : bytesToCopy;
    sum.update(b, off, bytesToCopy);
    System.arraycopy(b, off, buf, count, bytesToCopy);
    count += bytesToCopy;
    if (count == buf.length) {
      // local buffer is full 
      flushBuffer(); 
    }  

8
CodeRank
This code example shows how to use the following methods:update
    } 
 
    @Override 
    public void writeBytes(byte[] b, int offset, int length) throws IOException {
        out.writeBytes(b, offset, length);
        digest.update(b, offset, length);
    } 
 
    @Override 
    public void flush() throws IOException { 
        out.flush();
    } 
 
    @Override 
    public void close() throws IOException { 
        out.close();
    } 
 
    @Override 
    public long getFilePointer() { 
8
CodeRank
This code example shows how to use the following methods:update
    } 
 
    @Override 
    protected void flushBuffer(byte[] b, int offset, int len) throws IOException {
        out.writeBytes(b, offset, len);
        digest.update(b, offset, len);
    } 
 
    // don't override it, base class method simple reads from input and writes to this output 
//        @Override public void copyBytes(IndexInput input, long numBytes) throws IOException { 
//            delegate.copyBytes(input, numBytes); 
//        } 
 
    @Override 
    public void flush() throws IOException { 
        super.flush(); 
        out.flush();
    } 
 
    @Override 
8
CodeRank
This code example shows how to use the following methods:getValue, update
 
    @Implementation 
    public static Bitmap decodeByteArray(byte[] data, int offset, int length, BitmapFactory.Options opts) {
        String desc = new String(data);
        if (!Charset.forName("US-ASCII").newEncoder().canEncode(desc)) {
            Checksum checksumEngine = new CRC32();
            checksumEngine.update(data, 0, data.length);
 
            desc = "byte array, checksum: " + checksumEngine.getValue();
        } 
 
        if (offset != 0 || length != data.length) {
            desc += " bytes " + offset + ".." + length;
        } 
        return create(desc, opts);
    } 
     
    static Bitmap create(String name) {
        return create(name, null);
    } 
8
CodeRank
This code example shows how to use the following methods:getValue
        this.out = out;
        this.digest = new BufferedChecksum(new CRC32());
    } 
 
    public long getChecksum() { 
        return this.digest.getValue();
    } 
 
    @Override 
    public void writeByte(byte b) throws IOException {
        out.writeByte(b);
        digest.update(b);
    } 
 
    @Override 
    public void writeBytes(byte[] b, int offset, int length) throws IOException {
        out.writeBytes(b, offset, length);
        digest.update(b, offset, length);
    } 
 
7
CodeRank
This code example shows how to use the following methods:getValue, reset
     if ( type.size <= 0 ) {
       return 0; 
     } 
 
     if ( type.size == 4 ) {
       out.writeInt( (int) summer.getValue() );
     } else { 
       throw new IOException( "Unknown Checksum " + type );
     } 
      
     if ( reset ) {
       reset(); 
     } 
      
     return type.size;
   } 
    
   /** 
    * Writes the current checksum to a buffer. 
    * If <i>reset</i> is true, then resets the checksum. 

7
CodeRank
This code example shows how to use the following methods:getValue, update
  } 
 
  @Override 
  public long getValue() { 
    flush(); 
    return in.getValue();
  } 
 
  @Override 
  public void reset() { 
    upto = 0;
    in.reset();
  } 
   
  private void flush() { 
    if (upto > 0) {
      in.update(buffer, 0, upto);
    } 
    upto = 0;
  } 

7
CodeRank
This code example shows how to use the following methods:getValue
        this.in = in;
        this.digest = new BufferedChecksum(new CRC32());
    } 
 
    public long getChecksum() { 
        return this.digest.getValue();
    } 
 
    @Override 
    public byte readByte() throws IOException {
        final byte b = in.readByte();
        digest.update(b);
        return b;
    } 
 
    @Override 
    public void readBytes(byte[] b, int offset, int len) throws IOException {
        in.readBytes(b, offset, len);
        digest.update(b, offset, len);
    } 
7
CodeRank
This code example shows how to use the following methods:getValue, reset, update
  private int write1(byte b[], int off, int len) throws IOException {
    if(count==0 && len>=buf.length) {
      // local buffer is empty and user data has one chunk 
      // checksum and output data 
      final int length = buf.length;
      sum.update(b, off, length);
      writeChecksumChunk(b, off, length, false);
      return length;
    } 
     
    // copy user data to local buffer 
    int bytesToCopy = buf.length-count;
    bytesToCopy = (len<bytesToCopy) ? len : bytesToCopy;
    sum.update(b, off, bytesToCopy);
    System.arraycopy(b, off, buf, count, bytesToCopy);
    count += bytesToCopy;
    if (count == buf.length) {
      // local buffer is full 
      flushBuffer(); 
    }  

7
CodeRank
This code example shows how to use the following methods:getValue, reset, update
  private int write1(byte b[], int off, int len) throws IOException {
    if(count==0 && len>=buf.length) {
      // local buffer is empty and user data has one chunk 
      // checksum and output data 
      final int length = buf.length;
      sum.update(b, off, length);
      writeChecksumChunk(b, off, length, false);
      return length;
    } 
     
    // copy user data to local buffer 
    int bytesToCopy = buf.length-count;
    bytesToCopy = (len<bytesToCopy) ? len : bytesToCopy;
    sum.update(b, off, bytesToCopy);
    System.arraycopy(b, off, buf, count, bytesToCopy);
    count += bytesToCopy;
    if (count == buf.length) {
      // local buffer is full 
      flushBuffer(); 
    }  

6
CodeRank

Related Java 8 Checksum Questions & Answers:

See Code Examples for Java 8 Checksum Methods: