Package java.util.zip

Examples of java.util.zip.CRC32


  {
    if (containerInfo == null)
      containerInfo = new byte[CONTAINER_INFO_SIZE];

    if (checksum == null)
      checksum = new CRC32();
    else
      checksum.reset();

    if (allocCache == null)
      allocCache = new AllocationCache();
View Full Code Here


                           boolean overwrite,
                           short replication, long blockSize,
                           Progressable progress,
                           int buffersize
                           ) throws IOException {
      super(new CRC32(), conf.getInt("io.bytes.per.checksum", 512), 4);
      this.src = src;
      this.blockSize = blockSize;
      this.buffersize = buffersize;
      this.progress = progress;
      if (progress != null) {
View Full Code Here

        return sb.toString();
      }

      // The identifier is not unique because we omitted part, so add a
      // checksum as a hashcode.
      CRC32 crc32 = new CRC32();
      crc32.update(s.getBytes());
      long hash = crc32.getValue() & unitTestHashReductionMask;
      sb.append('_');
      sb.append(Long.toHexString(hash));
      String encoded = sb.toString();
      if (!usedHashedAliases.add(encoded)) {
        // A collision has been detected (which is very rare). Use the sequence
View Full Code Here

                final int readThisTime = pis.read(allCRCBytes.array(), readAllCRCBytes, 4 - readAllCRCBytes);
                if (readThisTime == -1) return false;
                readAllCRCBytes += readThisTime;
            }
            final int allCRCExpected = allCRCBytes.getInt();
            final CRC32 allCRC = new CRC32();
            ByteBuffer entryBuffer = ByteBuffer.allocate(ENTRY_WITH_CHECKSUM_SIZE).order(ByteOrder.nativeOrder());

            while (true) {
                entryBuffer.clear();
                int read = 0;

                while (read < ENTRY_WITH_CHECKSUM_SIZE) {
                    final int readThisTime = pis.read(entryBuffer.array(), read, entryBuffer.capacity() - read);
                    if (readThisTime == -1) break;
                    read += readThisTime;
                }

                if (read == 0 || read < ENTRY_WITH_CHECKSUM_SIZE) {
                    final int actualAllCRC = (int)allCRC.getValue();
                    if (actualAllCRC != allCRCExpected) {
                        m_channel.close();
                        return false;
                    }
                    return true;
                }
                final int expectedCRC = entryBuffer.getInt();
                final CRC32 crc = new CRC32();
                crc.update(entryBuffer.array(), 4, entryBuffer.capacity() - 4);
                final int actualCRC = (int)crc.getValue();

                if (expectedCRC != actualCRC) {
                    m_channel.close();
                    return false;
                }
View Full Code Here

                    "Length (" + entryLength + ") is probably not a valid value, retrieved from " +
                    m_path + " position " + position);
        }
        final byte entryBytes[] = new byte[entryLength];
        dup.get(entryBytes);
        CRC32 crc = new CRC32();
        crc.update(entryBytes);
        final int actualCRC = (int)crc.getValue();

        if (actualCRC != originalCRC) {
            throw new IOException("CRC mismatch in record, retrieved from " +
                    m_path + " position " + position);
        }
View Full Code Here

                    //Need to CRC the length as well
                    final int compressedLength = view.getInt();
                    byte compressedBytes[] = new byte[compressedLength ];
                    view.get(compressedBytes);

                    final CRC32 crc = new CRC32();
                    crc.update(compressedBytes);

                    final int actualCRC = (int)crc.getValue();
                    if (actualCRC != originalCRC) {
                        throw new RuntimeException("CRC mismatch");
                    }

                    ByteBuffer entry;
View Full Code Here

        finalBuf.position(4);
        finalBuf.putInt(compressedBytes.length);
        finalBuf.put(compressedBytes);

        final CRC32 crc = new CRC32();
        crc.update(finalBuf.array(), 8, finalBuf.capacity() - 8);
        finalBuf.putInt(0, (int)crc.getValue());

        return new Object[] { finalBuf.array(), keyHash };
    }
View Full Code Here

        entryBuf.position(4);
        entryBuf.putInt(-1);
        entryBuf.put(keyHash);
        entryBuf.putLong(timestamp);

        final CRC32 crc = new CRC32();
        crc.update(entryBuf.array(), 4, entryBuf.capacity() - 4);
        entryBuf.putInt(0, (int)crc.getValue());

        return entryBuf.array();
    }
View Full Code Here

  }

  public static String getSerializationSignature(Class<?> instanceType) {
    String result = getCachedCRCForClass(instanceType);
    if (result == null) {
      CRC32 crc = new CRC32();
      try {
        generateSerializationSignature(instanceType, crc);
      } catch (UnsupportedEncodingException e) {
        throw new RuntimeException(
            "Could not compute the serialization signature", e);
      }
      result = Long.toString(crc.getValue());
      putCachedCRCForClass(instanceType, result);
    }
    return result;
  }
View Full Code Here

    switch (randomInt(2)) {
    case 0:
      checksum = new Adler32();
      break;
    case 1:
      checksum = new CRC32();
      break;
    default:
      checksum = XXHashFactory.fastestInstance().newStreamingHash32(randomInt()).asChecksum();
      break;
    }
View Full Code Here

TOP

Related Classes of java.util.zip.CRC32

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.