Package java.util.zip

Examples of java.util.zip.Checksum


        if (info == null || timeStamp != info.timeStamp) {
          try {
            is = new FileInputStream(file);
            if (is.available() < maxInputStreamBuffer)
              is = new BufferedInputStream(is);
            Checksum cksum = getChecksumCalculator();
            int filetype = getStreamType(is, cksum);
            info = new CacheInfo(filetype, cksum, timeStamp);
            cacheFiles.put(file, info);
          } catch (IOException e) {/*ignore*/
          }
 
View Full Code Here


      int buffSize, boolean close)
    throws IOException {
   
    PrintStream ps = out instanceof PrintStream ? (PrintStream)out : null;
    byte buf[] = new byte[buffSize];
    Checksum sum = new CRC32();
    sum.reset();
    try {
      int bytesRead = in.read(buf);
      while (bytesRead >= 0) {
        sum.update(buf, 0, bytesRead);
        out.write(buf, 0, bytesRead);
        if ((ps != null) && ps.checkError()) {
          throw new IOException("Unable to write to output stream.");
        }
        bytesRead = in.read(buf);
      }
    } finally {
      if(close) {
        out.close();
        in.close();
      }
    }
    return sum.getValue();
  }
View Full Code Here

      int start = buf.getLength();
      buf.writeByte(op.opCode.getOpCode());
      buf.writeLong(op.txid);
      op.writeFields(buf);
      int end = buf.getLength();
      Checksum checksum = FSEditLog.getChecksumForWrite();
      checksum.reset();
      checksum.update(buf.getData(), start, end-start);
      int sum = (int)checksum.getValue();
      buf.writeInt(sum);
    }
View Full Code Here

            try
            {
                currentPosition = logWriter_.getFilePointer();
                CommitLogContext cLogCtx = new CommitLogContext(logFile_, currentPosition);
                maybeUpdateHeader(rowMutation);
                Checksum checkum = new CRC32();
                if (serializedRow instanceof DataOutputBuffer)
                {
                    DataOutputBuffer buffer = (DataOutputBuffer) serializedRow;
                    logWriter_.writeLong(buffer.getLength());
                    logWriter_.write(buffer.getData(), 0, buffer.getLength());
                    checkum.update(buffer.getData(), 0, buffer.getLength());
                }
                else
                {
                    assert serializedRow instanceof byte[];
                    byte[] bytes = (byte[]) serializedRow;
                    logWriter_.writeLong(bytes.length);
                    logWriter_.write(bytes);
                    checkum.update(bytes, 0, bytes.length);
                }
                logWriter_.writeLong(checkum.getValue());
                maybeRollLog();
                return cLogCtx;
            }
            catch (IOException e)
            {
View Full Code Here

                {
                    // last CL entry didn't get completely written.  that's ok.
                    break;
                }
                bufIn.reset(bytes, bytes.length);
                Checksum checksum = new CRC32();
                checksum.update(bytes, 0, bytes.length);
                if (claimedCRC32 != checksum.getValue())
                {
                    // this part of the log must not have been fsynced.  probably the rest is bad too,
                    // but just in case there is no harm in trying them.
                    continue;
                }
View Full Code Here

            currentPosition = logWriter.getFilePointer();
            assert currentPosition <= Integer.MAX_VALUE;
            ReplayPosition cLogCtx = new ReplayPosition(id, (int) currentPosition);

            // write mutation, w/ checksum on the size and data
            Checksum checksum = new CRC32();
            byte[] serializedRow = rowMutation.getSerializedBuffer(MessagingService.version_);
            checksum.update(serializedRow.length);
            logWriter.writeInt(serializedRow.length);
            logWriter.writeLong(checksum.getValue());
            logWriter.write(serializedRow);
            checksum.update(serializedRow, 0, serializedRow.length);
            logWriter.writeLong(checksum.getValue());

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

                {
                    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

      indexFile.delete();
    }
    indexFile.createNewFile();
    FSDataOutputStream output = FileSystem.getLocal(conf).getRaw().append(
        new Path(indexFile.getAbsolutePath()));
    Checksum crc = new PureJavaCrc32();
    crc.reset();
    CheckedOutputStream chk = new CheckedOutputStream(output, crc);
    String msg = "Writing new index file. This file will be used only " +
        "for the testing.";
    chk.write(Arrays.copyOf(msg.getBytes(),
        MapTask.MAP_OUTPUT_INDEX_RECORD_LENGTH));
View Full Code Here

      if (info == null || timeStamp != info.timeStamp) {
        try {
          is = new FileInputStream(file);
          if (is.available() < maxInputStreamBuffer)
            is = new BufferedInputStream(is);
          Checksum cksum = getChecksumCalculator();
          int filetype = getStreamType(is, cksum);
          info = new CacheInfo(filetype, cksum, timeStamp);
          synchronized (cacheFiles) {
            cacheFiles.put(file, info);
          }
View Full Code Here

            // release the folks that were waiting for those writes to hit disk.
            checkpointLatch = this.checkpointLatch;
            this.checkpointLatch = null;
        }

        Checksum checksum = new Adler32();
        if (enableRecoveryFile) {
            recoveryFile.seek(RECOVERY_FILE_HEADER_SIZE);
        }
        for (PageWrite w : batch) {
            if (enableRecoveryFile) {
                try {
                    checksum.update(w.getDiskBound(), 0, pageSize);
                } catch (Throwable t) {
                    throw IOExceptionSupport.create("Cannot create recovery file. Reason: " + t, t);
                }
                recoveryFile.writeLong(w.page.getPageId());
                recoveryFile.write(w.getDiskBound(), 0, pageSize);
            }

            writeFile.seek(toOffset(w.page.getPageId()));
            writeFile.write(w.getDiskBound(), 0, pageSize);
            w.done();
        }

        try {
            if (enableRecoveryFile) {
                // Can we shrink the recovery buffer??
                if (recoveryPageCount > recoveryFileMaxPageCount) {
                    int t = Math.max(recoveryFileMinPageCount, batch.size());
                    recoveryFile.setLength(recoveryFileSizeForPages(t));
                }

                // Record the page writes in the recovery buffer.
                recoveryFile.seek(0);
                // Store the next tx id...
                recoveryFile.writeLong(nextTxid.get());
                // Store the checksum for thw write batch so that on recovery we
                // know if we have a consistent
                // write batch on disk.
                recoveryFile.writeLong(checksum.getValue());
                // Write the # of pages that will follow
                recoveryFile.writeInt(batch.size());
            }

            if (enableDiskSyncs) {
View Full Code Here

TOP

Related Classes of java.util.zip.Checksum

Copyright © 2018 www.massapicom. 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.