Examples of Checksum


Examples of co.paralleluniverse.common.io.Checksum

    private boolean writeData(CacheLine line, Persistable object) {
        if (object.size() > maxItemSize)
            throw new IllegalArgumentException("Object size is " + object.size() + " bytes and exceeds the limit of " + maxItemSize + " bytes: " + object);

        if (compareBeforeWrite) {
            final Checksum chksm = getChecksum();
            if (line.data != null && object.size() == line.data.remaining()) {
                final int n = line.data.remaining();

                chksm.update(line.data);
                line.data.rewind();
                final byte[] hash = chksm.getChecksum();

                object.write(line.data);
                line.data.flip();

                chksm.reset();
                chksm.update(line.data);
                line.data.rewind();

                if (!Arrays.equals(hash, chksm.getChecksum()))
                    return true;
                return false;
            }
        }
View Full Code Here

Examples of com.emc.esu.api.Checksum

            throw new EsuException("Failed to get object size");
        }
       
        if( checksumming ) {
          try {
        checksum = new Checksum( Algorithm.SHA0 );
      } catch (NoSuchAlgorithmException e) {
        throw new RuntimeException( "Could not initialize SHA0 hash algorithm" );
      }
        }
View Full Code Here

Examples of eu.planets_project.services.datatypes.Checksum

    public void setChecksum(Checksum checksum) {
        this.check = checksum;
    }
   
    public void setChecksum(String algorithm, byte[] digest) {
      check = new Checksum(algorithm, Arrays.toString(digest));
    }
View Full Code Here

Examples of it.stefanobertini.zebra.cpcl.utility.CheckSum

public class CheckSumTest {

    @Test
    public void test() {
  CheckSum command = new CheckSum();

  CommandOutputBuilder output = new CommandOutputBuilder();
  output.printLn("! UTILITIES");
  output.printLn("CHECKSUM");
  output.printLn("PRINT");
View Full Code Here

Examples of java.util.zip.Checksum

    static class CommitLogHeaderSerializer implements ICompactSerializer2<CommitLogHeader>
    {
        public void serialize(CommitLogHeader clHeader, DataOutput dos) throws IOException
        {
            Checksum checksum = new CRC32();

            // write the first checksum after the fixed-size part, so we won't read garbage lastFlushedAt data.
            dos.writeInt(clHeader.cfDirtiedAt.size()); // 4
            checksum.update(clHeader.cfDirtiedAt.size());
            dos.writeLong(checksum.getValue());

            // write the 2nd checksum after the lastflushedat map
            for (Map.Entry<Integer, Integer> entry : clHeader.cfDirtiedAt.entrySet())
            {
                dos.writeInt(entry.getKey()); // 4
                checksum.update(entry.getKey());
                dos.writeInt(entry.getValue()); // 4
                checksum.update(entry.getValue());
            }
            dos.writeLong(checksum.getValue());
        }
View Full Code Here

Examples of java.util.zip.Checksum

            dos.writeLong(checksum.getValue());
        }

        public CommitLogHeader deserialize(DataInput dis) throws IOException
        {
            Checksum checksum = new CRC32();

            int lastFlushedAtSize = dis.readInt();
            checksum.update(lastFlushedAtSize);
            if (checksum.getValue() != dis.readLong())
            {
                throw new IOException("Invalid or corrupt commitlog header");
            }
            Map<Integer, Integer> lastFlushedAt = new HashMap<Integer, Integer>();
            for (int i = 0; i < lastFlushedAtSize; i++)
            {
                int key = dis.readInt();
                checksum.update(key);
                int value = dis.readInt();
                checksum.update(value);
                lastFlushedAt.put(key, value);
            }
            if (checksum.getValue() != dis.readLong())
            {
                throw new IOException("Invalid or corrupt commitlog header");
            }

            return new CommitLogHeader(lastFlushedAt);
View Full Code Here

Examples of java.util.zip.Checksum

                }
            }

            // write mutation, w/ checksum on the size and data
            byte[] bytes;
            Checksum checksum = new CRC32();
            if (serializedRow instanceof DataOutputBuffer)
            {
                bytes = ((DataOutputBuffer) serializedRow).getData();
            }
            else
            {
                assert serializedRow instanceof byte[];
                bytes = (byte[]) serializedRow;
            }

            checksum.update(bytes.length);
            logWriter.writeInt(bytes.length);
            logWriter.writeLong(checksum.getValue());
            logWriter.write(bytes);
            checksum.update(bytes, 0, bytes.length);
            logWriter.writeLong(checksum.getValue());

            return cLogCtx;
        }
        catch (IOException e)
        {
View Full Code Here

Examples of java.util.zip.Checksum

                {
                    if (logger.isDebugEnabled())
                        logger.debug("Reading mutation at " + reader.getFilePointer());

                    long claimedCRC32;
                    Checksum checksum = new CRC32();
                    int serializedSize;
                    try
                    {
                        // any of the reads may hit EOF
                        serializedSize = reader.readInt();
                        // RowMutation must be at LEAST 10 bytes:
                        // 3 each for a non-empty Table and Key (including the 2-byte length from
                        // writeUTF/writeWithShortLength) and 4 bytes for column count.
                        // This prevents CRC by being fooled by special-case garbage in the file; see CASSANDRA-2128
                        if (serializedSize < 10)
                            break;
                        long claimedSizeChecksum = reader.readLong();
                        checksum.update(serializedSize);
                        if (checksum.getValue() != claimedSizeChecksum)
                            break; // entry wasn't synced correctly/fully.  that's ok.

                        if (serializedSize > bytes.length)
                            bytes = new byte[(int) (1.2 * serializedSize)];
                        reader.readFully(bytes, 0, serializedSize);
                        claimedCRC32 = reader.readLong();
                    }
                    catch(EOFException eof)
                    {
                        break; // last CL entry didn't get completely written.  that's ok.
                    }

                    checksum.update(bytes, 0, serializedSize);
                    if (claimedCRC32 != checksum.getValue())
                    {
                        // this entry must not have been fsynced.  probably the rest is bad too,
                        // but just in case there is no harm in trying them (since we still read on an entry boundary)
                        continue;
                    }
View Full Code Here

Examples of java.util.zip.Checksum

    }

    @Test
    public void testRecoveryWithBadSizeChecksum() throws Exception
    {
        Checksum checksum = new CRC32();
        checksum.update(100);
        testRecoveryWithBadSizeArgument(100, 100, ~checksum.getValue());
    }
View Full Code Here

Examples of java.util.zip.Checksum

        // Note: this can actually happen (in periodic mode) when data is flushed
        // before it had time to hit the commitlog (since the header is flushed by the system)
        // see https://issues.apache.org/jira/browse/CASSANDRA-2285
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        DataOutputStream dos = new DataOutputStream(out);
        Checksum checksum = new CRC32();

        // write the first checksum after the fixed-size part, so we won't read garbage lastFlushedAt data.
        dos.writeInt(1);
        checksum.update(1);
        dos.writeLong(checksum.getValue());
        dos.writeInt(0);
        checksum.update(0);
        dos.writeInt(200);
        checksum.update(200);
        dos.writeLong(checksum.getValue());
        dos.close();

        testRecovery(out.toByteArray(), new byte[0]);
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.