Java 8 CRC32 - 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 CRC32 class.

This code example shows how to use the following methods:getValue, update
        return crc32(array, 0, array.length);
    } 
 
 
    public static final int crc32(byte[] array, int offset, int length) {
        CRC32 crc32 = new CRC32();
        crc32.update(array, offset, length);
        return (int) (crc32.getValue() & 0x7FFFFFFF);
    } 
} 
8
CodeRank
This code example shows how to use the following methods:
    private final StreamOutput out;
    private final Checksum digest;
 
    public BufferedChecksumStreamOutput(StreamOutput out) {
        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 {
7
CodeRank
This code example shows how to use the following methods:getValue, reset, update
	/** 
	 * @tests java.util.zip.CRC32#getValue() 
	 */ 
	public void test_getValue() { 
		// test methods of java.util.zip.crc32.getValue() 
		CRC32 crc = new CRC32();
		assertEquals("getValue() should return a zero as a result of constructing a CRC32 instance",
				0, crc.getValue());
 
		crc.reset();
		crc.update(Integer.MAX_VALUE);
		// System.out.print("value of crc " + crc.getValue()); 
		// Ran JDK and discovered that the value of the CRC should be 
		// 4278190080 
		assertEquals("update(max) failed to update the checksum to the correct value ",
				4278190080L, crc.getValue());
 
		crc.reset();
		byte byteEmpty[] = new byte[10000];
		crc.update(byteEmpty);

7
CodeRank
This code example shows how to use the following methods:getValue, update
This code example shows how to use the following methods:
    private final StreamInput in;
    private final Checksum digest;
 
    public BufferedChecksumStreamInput(StreamInput in) {
        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 
7
CodeRank
This code example shows how to use the following methods:getValue, update
     * @param input 
     *            String to check 
     * @return resulting checksum 
     */ 
    public static long checksum(final String input) {
        final CRC32 checksum = new CRC32();
        checksum.update(input.getBytes(CHARSET_UTF8));
        return checksum.getValue();
    } 
} 
7
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, update
 
    private void write(final char command, final JsonStateWriter writer) {
        connection.request(command, writer.getRequest());
        final String data = writer.getData();
 
        final CRC32 inputChecksum = new CRC32();
        inputChecksum.update(data.getBytes());
        inputChecksum.update('\n');
        final long checksum = inputChecksum.getValue();
        final String code = Long.toHexString(checksum);
 
        connection.requestData("00000000".substring(0, 8 - code.length()) + code + data);
        connection.endRequestSection();
    } 
 
} 
7
CodeRank
This code example shows how to use the following methods:getValue, update
        return crc32(array, 0, array.length);
    } 
 
 
    public static final int crc32(byte[] array, int offset, int length) {
        CRC32 crc32 = new CRC32();
        crc32.update(array, offset, length);
        return (int) (crc32.getValue() & 0x7FFFFFFF);
    } 
} 
7
CodeRank
This code example shows how to use the following methods:
    /** The CRC32 being calculated by this input stream */ 
    private CRC32 crc32;
 
    public CRC32ChecksumCalculatingInputStream(InputStream in) {
        super(in);
        crc32 = new CRC32();
    } 
 
    public long getCRC32Checksum() { 
        return crc32.getValue();
    } 
 
    /** 
     * Resets the wrapped input stream and the CRC32 computation. 
     * 
     * @see java.io.InputStream#reset() 
     */ 
    @Override 
    public synchronized void reset() throws IOException { 
        crc32.reset();
7
CodeRank

Related Java 8 CRC32 Questions & Answers:

See Code Examples for Java 8 CRC32 Methods: