java.util.zip.Checksum#getValue ( )源码实例Demo

下面列出了java.util.zip.Checksum#getValue ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: netbeans   文件: GeneratedFilesHelper.java
/**
 * Compute the CRC-32 of the contents of a stream.
 * \r\n and \r are both normalized to \n for purposes of the calculation.
 */
static String computeCrc32(InputStream is) throws IOException {
    Checksum crc = new CRC32();
    int last = -1;
    int curr;
    while ((curr = is.read()) != -1) {
        if (curr != '\n' && last == '\r') {
            crc.update('\n');
        }
        if (curr != '\r') {
            crc.update(curr);
        }
        last = curr;
    }
    if (last == '\r') {
        crc.update('\n');
    }
    int val = (int)crc.getValue();
    String hex = Integer.toHexString(val);
    while (hex.length() < 8) {
        hex = "0" + hex; // NOI18N
    }
    return hex;
}
 
源代码2 项目: mnemonic   文件: MneMapreduceChunkDataTest.java
@Test(enabled = true)
public void testWriteChunkData() throws Exception {
  NullWritable nada = NullWritable.get();
  MneDurableOutputSession<DurableChunk<?>> sess =
      new MneDurableOutputSession<DurableChunk<?>>(m_tacontext, null,
          MneConfigHelper.DEFAULT_OUTPUT_CONFIG_PREFIX);
  MneDurableOutputValue<DurableChunk<?>> mdvalue =
      new MneDurableOutputValue<DurableChunk<?>>(sess);
  OutputFormat<NullWritable, MneDurableOutputValue<DurableChunk<?>>> outputFormat =
      new MneOutputFormat<MneDurableOutputValue<DurableChunk<?>>>();
  RecordWriter<NullWritable, MneDurableOutputValue<DurableChunk<?>>> writer =
      outputFormat.getRecordWriter(m_tacontext);
  DurableChunk<?> dchunk = null;
  Checksum cs = new CRC32();
  cs.reset();
  for (int i = 0; i < m_reccnt; ++i) {
    dchunk = genupdDurableChunk(sess, cs);
    Assert.assertNotNull(dchunk);
    writer.write(nada, mdvalue.of(dchunk));
  }
  m_checksum = cs.getValue();
  writer.close(m_tacontext);
  sess.close();
}
 
源代码3 项目: big-c   文件: FSEditLogOp.java
/**
 * Validate a transaction's checksum
 */
private void validateChecksum(DataInputStream in,
                              Checksum checksum,
                              long txid)
    throws IOException {
  if (checksum != null) {
    int calculatedChecksum = (int)checksum.getValue();
    int readChecksum = in.readInt(); // read in checksum
    if (readChecksum != calculatedChecksum) {
      throw new ChecksumException(
          "Transaction is corrupt. Calculated checksum is " +
          calculatedChecksum + " but read checksum " + readChecksum, txid);
    }
  }
}
 
源代码4 项目: openjdk-8   文件: CRCTest.java
private static void check(Checksum crc1, Checksum crc2) throws Exception {
    if (crc1.getValue() != crc2.getValue()) {
        String s = "value 1 = " + crc1.getValue() + ", value 2 = " + crc2.getValue();
        System.err.println(s);
        throw new Exception(s);
    }
}
 
源代码5 项目: jdk8u60   文件: CRCTest.java
private static void check(Checksum crc1, Checksum crc2) throws Exception {
    if (crc1.getValue() != crc2.getValue()) {
        String s = "value 1 = " + crc1.getValue() + ", value 2 = " + crc2.getValue();
        System.err.println(s);
        throw new Exception(s);
    }
}
 
源代码6 项目: openjdk-jdk9   文件: ChecksumBase.java
private static void checkChecksum(Checksum checksum, long expected) {
    if (checksum.getValue() != expected) {
        throw new RuntimeException("Calculated checksum result was invalid."
                + " Expected " + Long.toHexString(expected)
                + ", but got " + Long.toHexString(checksum.getValue()) + ".");
    }
}
 
源代码7 项目: xDrip-plus   文件: JoH.java
public static boolean isOldVersion(Context context) {
    try {
        final Signature[] pinfo = context.getPackageManager().getPackageInfo(context.getPackageName(), PackageManager.GET_SIGNATURES).signatures;
        if (pinfo.length == 1) {
            final Checksum s = new CRC32();
            final byte[] ba = pinfo[0].toByteArray();
            s.update(ba, 0, ba.length);
            if (s.getValue() == 2009579833) return true;
        }
    } catch (Exception e) {
        Log.d(TAG, "exception: " + e);
    }
    return false;
}
 
源代码8 项目: openjdk-jdk9   文件: ChecksumBase.java
private static void checkChecksumOffset(Checksum checksum, long expected, int offset) {
    if (checksum.getValue() != expected) {
        throw new RuntimeException("Calculated CRC32C result was invalid. Array offset "
                + offset + ". Expected: " + Long.toHexString(expected) + ", Got: "
                + Long.toHexString(checksum.getValue()));
    }
}
 
源代码9 项目: openjdk-jdk9   文件: TestCRC32.java
private static void check(Checksum crc, long crcReference) throws Exception {
    if (crc.getValue() != crcReference) {
        System.err.printf("ERROR: crc = %08x, crcReference = %08x\n",
                          crc.getValue(), crcReference);
        throw new Exception("TestCRC32 Error");
    }
}
 
源代码10 项目: xDrip-plus   文件: JoH.java
public static boolean isOldVersion(Context context) {
    try {
        final Signature[] pinfo = context.getPackageManager().getPackageInfo(context.getPackageName(), PackageManager.GET_SIGNATURES).signatures;
        if (pinfo.length == 1) {
            final Checksum s = new CRC32();
            final byte[] ba = pinfo[0].toByteArray();
            s.update(ba, 0, ba.length);
            if (s.getValue() == 2009579833) return true;
        }
    } catch (Exception e) {
        Log.d(TAG, "exception: " + e);
    }
    return false;
}
 
源代码11 项目: zooadmin   文件: ZooLog.java
/**
 * 读取多行日志
 * @param total 读取的行数
 * @return
 * @throws IOException
 */
public String getLastLog(int total) throws IOException {
    StringBuilder sb=new StringBuilder(1024);
    FileInputStream fis = new FileInputStream(this.logFile);
    BinaryInputArchive logStream = BinaryInputArchive.getArchive(fis);
    FileHeader fhdr = new FileHeader();
    fhdr.deserialize(logStream, "fileheader");

    if (fhdr.getMagic() != FileTxnLog.TXNLOG_MAGIC) {
        return "Invalid magic number for " + logFile;
    }
    sb.append("ZooKeeper Transactional Log File with dbid "
            + fhdr.getDbid() + " txnlog format version "
            + fhdr.getVersion()+"\r\n");
    int count=0;
    while (count<total) {
        long crcValue;
        byte[] bytes;
        try {
            crcValue = logStream.readLong("crcvalue");
            bytes = logStream.readBuffer("txnEntry");
        } catch (EOFException e) {
            sb.append("EOF reached after " + count + " txns.\r\n");
            break;
        }
        if (bytes.length == 0) {
            // Since we preallocate, we define EOF to be an
            // empty transaction
            sb.append("EOF reached after " + count + " txns.\r\n");
            break;
        }
        Checksum crc = new Adler32();
        crc.update(bytes, 0, bytes.length);
        if (crcValue != crc.getValue()) {
            throw new IOException("CRC doesn't match " + crcValue +
                    " vs " + crc.getValue());
        }
        TxnHeader hdr = new TxnHeader();
        Record txn = SerializeUtils.deserializeTxn(bytes, hdr);
        sb.append(DateFormat.getDateTimeInstance(DateFormat.SHORT,
                DateFormat.LONG).format(new Date(hdr.getTime()))
                + " session 0x"
                + Long.toHexString(hdr.getClientId())
                + " cxid 0x"
                + Long.toHexString(hdr.getCxid())
                + " zxid 0x"
                + Long.toHexString(hdr.getZxid())
                + " " + ZooLog.op2String(hdr.getType()) + " " + txn+"\r\n");
        if (logStream.readByte("EOR") != 'B') {
            sb.append("Last transaction was partial.");
        }
        count++;
    }
    return sb.toString();
}
 
源代码12 项目: jdk8u60   文件: CRCTest.java
private static void updateSerialSlow(Checksum crc, byte[] b, int start, int length) {
    for (int i = 0; i < length; i++)
        crc.update(b[i+start]);
    crc.getValue();
}
 
源代码13 项目: openjdk-8   文件: CRCTest.java
private static void updateSerialSlow(Checksum crc, byte[] b, int start, int length) {
    for (int i = 0; i < length; i++)
        crc.update(b[i+start]);
    crc.getValue();
}
 
源代码14 项目: openjdk-8-source   文件: CRCTest.java
private static void updateSerialSlow(Checksum crc, byte[] b, int start, int length) {
    for (int i = 0; i < length; i++)
        crc.update(b[i+start]);
    crc.getValue();
}
 
源代码15 项目: hadoop   文件: BlockReceiver.java
/**
 * reads in the partial crc chunk and computes checksum
 * of pre-existing data in partial chunk.
 */
private Checksum computePartialChunkCrc(long blkoff, long ckoff)
    throws IOException {

  // find offset of the beginning of partial chunk.
  //
  int sizePartialChunk = (int) (blkoff % bytesPerChecksum);
  blkoff = blkoff - sizePartialChunk;
  if (LOG.isDebugEnabled()) {
    LOG.debug("computePartialChunkCrc for " + block
        + ": sizePartialChunk=" + sizePartialChunk
        + ", block offset=" + blkoff
        + ", metafile offset=" + ckoff);
  }

  // create an input stream from the block file
  // and read in partial crc chunk into temporary buffer
  //
  byte[] buf = new byte[sizePartialChunk];
  byte[] crcbuf = new byte[checksumSize];
  try (ReplicaInputStreams instr =
      datanode.data.getTmpInputStreams(block, blkoff, ckoff)) {
    IOUtils.readFully(instr.getDataIn(), buf, 0, sizePartialChunk);

    // open meta file and read in crc value computer earlier
    IOUtils.readFully(instr.getChecksumIn(), crcbuf, 0, crcbuf.length);
  }

  // compute crc of partial chunk from data read in the block file.
  final Checksum partialCrc = DataChecksum.newDataChecksum(
      diskChecksum.getChecksumType(), diskChecksum.getBytesPerChecksum());
  partialCrc.update(buf, 0, sizePartialChunk);
  if (LOG.isDebugEnabled()) {
    LOG.debug("Read in partial CRC chunk from disk for " + block);
  }

  // paranoia! verify that the pre-computed crc matches what we
  // recalculated just now
  if (partialCrc.getValue() != checksum2long(crcbuf)) {
    String msg = "Partial CRC " + partialCrc.getValue() +
                 " does not match value computed the " +
                 " last time file was closed " +
                 checksum2long(crcbuf);
    throw new IOException(msg);
  }
  return partialCrc;
}
 
源代码16 项目: zooadmin   文件: ZooLog.java
/**
 * 读取多行日志
 * @param total 读取的行数
 * @return
 * @throws IOException
 */
public String getLastLog(int total) throws IOException {
    StringBuilder sb=new StringBuilder(1024);
    FileInputStream fis = new FileInputStream(this.logFile);
    BinaryInputArchive logStream = BinaryInputArchive.getArchive(fis);
    FileHeader fhdr = new FileHeader();
    fhdr.deserialize(logStream, "fileheader");

    if (fhdr.getMagic() != FileTxnLog.TXNLOG_MAGIC) {
        return "Invalid magic number for " + logFile;
    }
    sb.append("ZooKeeper Transactional Log File with dbid "
            + fhdr.getDbid() + " txnlog format version "
            + fhdr.getVersion()+"\r\n");
    int count=0;
    while (count<total) {
        long crcValue;
        byte[] bytes;
        try {
            crcValue = logStream.readLong("crcvalue");
            bytes = logStream.readBuffer("txnEntry");
        } catch (EOFException e) {
            sb.append("EOF reached after " + count + " txns.\r\n");
            break;
        }
        if (bytes.length == 0) {
            // Since we preallocate, we define EOF to be an
            // empty transaction
            sb.append("EOF reached after " + count + " txns.\r\n");
            break;
        }
        Checksum crc = new Adler32();
        crc.update(bytes, 0, bytes.length);
        if (crcValue != crc.getValue()) {
            throw new IOException("CRC doesn't match " + crcValue +
                    " vs " + crc.getValue());
        }
        TxnHeader hdr = new TxnHeader();
        Record txn = SerializeUtils.deserializeTxn(bytes, hdr);
        sb.append(DateFormat.getDateTimeInstance(DateFormat.SHORT,
                DateFormat.LONG).format(new Date(hdr.getTime()))
                + " session 0x"
                + Long.toHexString(hdr.getClientId())
                + " cxid 0x"
                + Long.toHexString(hdr.getCxid())
                + " zxid 0x"
                + Long.toHexString(hdr.getZxid())
                + " " + ZooLog.op2String(hdr.getType()) + " " + txn+"\r\n");
        if (logStream.readByte("EOR") != 'B') {
            sb.append("Last transaction was partial.");
        }
        count++;
    }
    return sb.toString();
}
 
源代码17 项目: big-c   文件: BlockReceiver.java
/**
 * reads in the partial crc chunk and computes checksum
 * of pre-existing data in partial chunk.
 */
private Checksum computePartialChunkCrc(long blkoff, long ckoff)
    throws IOException {

  // find offset of the beginning of partial chunk.
  //
  int sizePartialChunk = (int) (blkoff % bytesPerChecksum);
  blkoff = blkoff - sizePartialChunk;
  if (LOG.isDebugEnabled()) {
    LOG.debug("computePartialChunkCrc for " + block
        + ": sizePartialChunk=" + sizePartialChunk
        + ", block offset=" + blkoff
        + ", metafile offset=" + ckoff);
  }

  // create an input stream from the block file
  // and read in partial crc chunk into temporary buffer
  //
  byte[] buf = new byte[sizePartialChunk];
  byte[] crcbuf = new byte[checksumSize];
  try (ReplicaInputStreams instr =
      datanode.data.getTmpInputStreams(block, blkoff, ckoff)) {
    IOUtils.readFully(instr.getDataIn(), buf, 0, sizePartialChunk);

    // open meta file and read in crc value computer earlier
    IOUtils.readFully(instr.getChecksumIn(), crcbuf, 0, crcbuf.length);
  }

  // compute crc of partial chunk from data read in the block file.
  final Checksum partialCrc = DataChecksum.newDataChecksum(
      diskChecksum.getChecksumType(), diskChecksum.getBytesPerChecksum());
  partialCrc.update(buf, 0, sizePartialChunk);
  if (LOG.isDebugEnabled()) {
    LOG.debug("Read in partial CRC chunk from disk for " + block);
  }

  // paranoia! verify that the pre-computed crc matches what we
  // recalculated just now
  if (partialCrc.getValue() != checksum2long(crcbuf)) {
    String msg = "Partial CRC " + partialCrc.getValue() +
                 " does not match value computed the " +
                 " last time file was closed " +
                 checksum2long(crcbuf);
    throw new IOException(msg);
  }
  return partialCrc;
}
 
源代码18 项目: hottub   文件: CRCTest.java
private static void updateSerialSlow(Checksum crc, byte[] b, int start, int length) {
    for (int i = 0; i < length; i++)
        crc.update(b[i+start]);
    crc.getValue();
}
 
源代码19 项目: openjdk-jdk8u-backup   文件: CRCTest.java
private static void updateSerialSlow(Checksum crc, byte[] b, int start, int length) {
    for (int i = 0; i < length; i++)
        crc.update(b[i+start]);
    crc.getValue();
}
 
源代码20 项目: feeyo-redisproxy   文件: Crc32C.java
/**
 * Compute the CRC32C (Castagnoli) of the segment of the byte array given by the specified size and offset
 *
 * @param bytes The bytes to checksum
 * @param offset the offset at which to begin the checksum computation
 * @param size the number of bytes to checksum
 * @return The CRC32C
 */
public static long compute(byte[] bytes, int offset, int size) {
    Checksum crc = create();
    crc.update(bytes, offset, size);
    return crc.getValue();
}
 
 方法所在类