Package java.util.zip

Examples of java.util.zip.Adler32.update()


            if (isChecksum()) {
                long expectedChecksum = buffer.getLong();
                byte data[] = new byte[buffer.remaining()];
                Checksum checksum = new Adler32();
                buffer.get(data);
                checksum.update(data, 0, data.length);
                if (expectedChecksum != checksum.getValue()) {
                    throw new IOException("Bad checksum for location: " + currentUserBatch);
                }
            }
            Location next = goToNextLocation(currentUserBatch, Location.BATCH_CONTROL_RECORD_TYPE, true);
View Full Code Here


            // Now we can fill in the batch control record properly.
            buffer.position(Journal.HEADER_SIZE);
            buffer.putInt(size - Journal.BATCH_CONTROL_RECORD_SIZE);
            if (checksum) {
                Checksum adler32 = new Adler32();
                adler32.update(buffer.array(),
                        Journal.BATCH_CONTROL_RECORD_SIZE,
                        size - Journal.BATCH_CONTROL_RECORD_SIZE);
                buffer.putLong(adler32.getValue());
            }
View Full Code Here

                Location nextLocation = goToNextLocation(currentBatch, Location.ANY_RECORD_TYPE, true);
                long expectedChecksum = currentBatchBuffer.getLong();
                checksummedLocations.clear();
                while (nextLocation != null && nextLocation.getType() != Location.BATCH_CONTROL_RECORD_TYPE) {
                    byte data[] = accessor.readLocation(nextLocation, false);
                    actualChecksum.update(data, 0, data.length);
                    checksummedLocations.add(nextLocation);
                    nextLocation = goToNextLocation(nextLocation, Location.ANY_RECORD_TYPE, true);
                }
                if (expectedChecksum != actualChecksum.getValue()) {
                    recoveryErrorHandler.onError(this, checksummedLocations);
View Full Code Here

                buffer.putInt(current.location.getPointer());
                buffer.putInt(current.location.getSize());
                buffer.put(current.location.getType());
                buffer.put(current.getData());
                if (checksum) {
                    adler32.update(current.getData(), 0, current.getData().length);
                }
            }

            // Now we can fill in the batch control record properly.
            buffer.position(Journal.HEADER_SIZE);
View Full Code Here

                            long expectedChecksum = currentBatchBuffer.getLong();
                            checksummedLocations.clear();
                            while (nextLocation != null && nextLocation.getType() != Location.BATCH_CONTROL_RECORD_TYPE) {
                                assert currentLocation.compareTo(nextLocation) < 0;
                                byte data[] = accessor.readLocation(nextLocation, false);
                                actualChecksum.update(data, 0, data.length);
                                checksummedLocations.add(nextLocation);
                                currentLocation = nextLocation;
                                nextLocation = goToNextLocation(nextLocation, Location.ANY_RECORD_TYPE, false);
                            }
                            if (checksummedLocations.isEmpty()) {
View Full Code Here

                buffer.putInt(current.location.getPointer());
                buffer.putInt(current.location.getSize());
                buffer.put(current.location.getType());
                buffer.put(current.getData());
                if (checksum) {
                    adler32.update(current.getData(), 0, current.getData().length);
                }
            }

            // Now we can fill in the batch control record properly.
            buffer.position(Journal.RECORD_HEADER_SIZE);
View Full Code Here

                if (length < 0)
                {
                    break;
                }

                checksum.update(buffer, 0, length);
            }

            // Reduces it down to just 32 bits which we express in hex.
            return Long.toHexString(checksum.getValue());
        } finally
View Full Code Here

      data[i++] = (byte) c;
    }
    fis.close();

    final Adler32 digester = new Adler32();
    digester.update(data);

    return (int) digester.getValue();
  }

  @Test
View Full Code Here

    InputStream in = new BufferedInputStream(new FileInputStream(file));
    try {
      byte[] buf = new byte[10000];
      int count = in.read(buf);
      while (count >= 0) {
        crc.update(buf, 0, count);
        count = in.read(buf);
      }
    } finally {
      in.close();
    }
View Full Code Here

    }

    public void reseed(String val) {
        Adler32 chksum = new Adler32();
        try {
            chksum.update(val.getBytes("UTF8"));
        } catch(RuntimeException ex) {
            throw ex;
        } catch(Exception ex) {
            throw new RuntimeException(ex);
        }
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.