List of usage examples for java.util.zip Checksum getValue
public long getValue();
From source file:org.apache.mnemonic.mapreduce.MneMapreduceBufferDataTest.java
@Test(enabled = true) public void testWriteBufferData() throws Exception { NullWritable nada = NullWritable.get(); MneDurableOutputSession<DurableBuffer<?>> sess = new MneDurableOutputSession<DurableBuffer<?>>(m_tacontext, null, MneConfigHelper.DEFAULT_OUTPUT_CONFIG_PREFIX); MneDurableOutputValue<DurableBuffer<?>> mdvalue = new MneDurableOutputValue<DurableBuffer<?>>(sess); OutputFormat<NullWritable, MneDurableOutputValue<DurableBuffer<?>>> outputFormat = new MneOutputFormat<MneDurableOutputValue<DurableBuffer<?>>>(); RecordWriter<NullWritable, MneDurableOutputValue<DurableBuffer<?>>> writer = outputFormat .getRecordWriter(m_tacontext); DurableBuffer<?> dbuf = null;/*from w w w .j a v a 2 s. c o m*/ Checksum cs = new CRC32(); cs.reset(); for (int i = 0; i < m_reccnt; ++i) { dbuf = genupdDurableBuffer(sess, cs); Assert.assertNotNull(dbuf); writer.write(nada, mdvalue.of(dbuf)); } m_checksum = cs.getValue(); writer.close(m_tacontext); sess.close(); }
From source file:org.apache.mnemonic.mapred.MneMapredBufferDataTest.java
@Test(enabled = true) public void testWriteBufferData() throws Exception { NullWritable nada = NullWritable.get(); MneDurableOutputSession<DurableBuffer<?>> sess = new MneDurableOutputSession<DurableBuffer<?>>(null, m_conf, MneConfigHelper.DEFAULT_OUTPUT_CONFIG_PREFIX); MneDurableOutputValue<DurableBuffer<?>> mdvalue = new MneDurableOutputValue<DurableBuffer<?>>(sess); OutputFormat<NullWritable, MneDurableOutputValue<DurableBuffer<?>>> outputFormat = new MneOutputFormat<MneDurableOutputValue<DurableBuffer<?>>>(); RecordWriter<NullWritable, MneDurableOutputValue<DurableBuffer<?>>> writer = outputFormat .getRecordWriter(m_fs, m_conf, null, null); DurableBuffer<?> dbuf = null;//from w w w . j a v a2 s . c om Checksum cs = new CRC32(); cs.reset(); for (int i = 0; i < m_reccnt; ++i) { dbuf = genupdDurableBuffer(sess, cs); Assert.assertNotNull(dbuf); writer.write(nada, mdvalue.of(dbuf)); } m_checksum = cs.getValue(); writer.close(null); sess.close(); }
From source file:org.anarres.lzo.LzopInputStream.java
private void testChecksum(Checksum csum, int value, byte[] data, int off, int len) throws IOException { if (csum == null) return;/*from ww w .j av a 2 s . c o m*/ csum.reset(); csum.update(data, off, len); if (value != (int) csum.getValue()) throw new IOException("Checksum failure: " + "Expected " + Integer.toHexString(value) + "; got " + Long.toHexString(csum.getValue())); }
From source file:org.apache.zookeeper.server.persistence.TxnLogToolkit.java
public void dump(Scanner scanner) throws Exception { crcFixed = 0;//from w w w .j a va 2 s .c o m FileHeader fhdr = new FileHeader(); fhdr.deserialize(logStream, "fileheader"); if (fhdr.getMagic() != TXNLOG_MAGIC) { throw new TxnLogToolkitException(ExitCode.INVALID_INVOCATION.getValue(), "Invalid magic number for %s", txnLogFile.getName()); } System.out.println("ZooKeeper Transactional Log File with dbid " + fhdr.getDbid() + " txnlog format version " + fhdr.getVersion()); if (recoveryMode) { fhdr.serialize(recoveryOa, "fileheader"); recoveryFos.flush(); filePadding.setCurrentSize(recoveryFos.getChannel().position()); } int count = 0; while (true) { long crcValue; byte[] bytes; try { crcValue = logStream.readLong("crcvalue"); bytes = logStream.readBuffer("txnEntry"); } catch (EOFException e) { System.out.println("EOF reached after " + count + " txns."); return; } if (bytes.length == 0) { // Since we preallocate, we define EOF to be an // empty transaction System.out.println("EOF reached after " + count + " txns."); return; } Checksum crc = new Adler32(); crc.update(bytes, 0, bytes.length); if (crcValue != crc.getValue()) { if (recoveryMode) { if (!force) { printTxn(bytes, "CRC ERROR"); if (askForFix(scanner)) { crcValue = crc.getValue(); ++crcFixed; } } else { crcValue = crc.getValue(); printTxn(bytes, "CRC FIXED"); ++crcFixed; } } else { printTxn(bytes, "CRC ERROR"); } } if (!recoveryMode || verbose) { printTxn(bytes); } if (logStream.readByte("EOR") != 'B') { throw new TxnLogToolkitException(ExitCode.UNEXPECTED_ERROR.getValue(), "Last transaction was partial."); } if (recoveryMode) { filePadding.padFile(recoveryFos.getChannel()); recoveryOa.writeLong(crcValue, "crcvalue"); recoveryOa.writeBuffer(bytes, "txnEntry"); recoveryOa.writeByte((byte) 'B', "EOR"); } count++; } }
From source file:com.yattatech.dbtc.facade.SystemFacade.java
private boolean isChecksumValid(long checksumValue, String json) { final byte[] input = json.getBytes(); final Checksum checksum = new CRC32(); checksum.update(input, 0, input.length); final long returned = checksum.getValue(); if (Debug.isDebugable()) { Debug.d(TAG, "validate checksum for json=" + json + "\nexpected=" + checksumValue + "\nretrieve=" + returned);/* w w w .ja v a 2 s . c o m*/ } return checksumValue == returned; }
From source file:com.yattatech.dbtc.facade.SystemFacade.java
private long calculateChecksum(String json) { final byte[] input = json.getBytes(); final Checksum checksum = new CRC32(); checksum.update(input, 0, input.length); final long checksumValue = checksum.getValue(); if (Debug.isDebugable()) { Debug.d(TAG, "calculate checksum for json=" + json + "\nvalue=" + checksumValue); }//from ww w . j a va2 s . co m return checksumValue; }
From source file:com.asakusafw.runtime.util.cache.HadoopFileCacheRepository.java
private long computeChecksum(FileSystem fs, Path file) throws IOException { if (LOG.isDebugEnabled()) { LOG.debug(MessageFormat.format("Computing checksum: {0}", //$NON-NLS-1$ file));// www . jav a 2s .c o m } Checksum checksum = new CRC32(); byte[] buf = byteBuffers.get(); try (FSDataInputStream input = fs.open(file)) { while (true) { int read = input.read(buf); if (read < 0) { break; } checksum.update(buf, 0, read); } } return checksum.getValue(); }
From source file:PngEncoder.java
/** * Writes the IEND (End-of-file) chunk to the output stream. * * @param out the OutputStream to write the chunk to * @param csum the Checksum that is updated as data is written * to the passed-in OutputStream * @throws IOException if a problem is encountered writing the output *//*from w ww . j a v a 2 s . com*/ private void writeIendChunk(OutputStream out, Checksum csum) throws IOException { writeInt(out, 0); csum.reset(); out.write(IEND); writeInt(out, (int) csum.getValue()); }
From source file:org.apache.mnemonic.collections.DurableArrayNGTest.java
@Test(enabled = true) public void testGetSetArrayChunk() { DurableType gtypes[] = { DurableType.CHUNK }; int capacity = 10; DurableArray<DurableChunk> array = DurableArrayFactory.create(m_act, null, gtypes, capacity, false); Long handler = array.getHandler(); long chunkVal; Checksum chunkCheckSum = new CRC32(); chunkCheckSum.reset();/*from ww w . j a va 2 s .com*/ for (int i = 0; i < capacity; i++) { array.set(i, genuptChunk(m_act, chunkCheckSum, genRandSize())); } chunkVal = chunkCheckSum.getValue(); chunkCheckSum.reset(); for (int i = 0; i < capacity; i++) { DurableChunk<NonVolatileMemAllocator> dc = array.get(i); Assert.assertNotNull(dc); for (int j = 0; j < dc.getSize(); ++j) { byte b = unsafe.getByte(dc.get() + j); chunkCheckSum.update(b); } } Assert.assertEquals(chunkCheckSum.getValue(), chunkVal); chunkCheckSum.reset(); DurableArray<DurableChunk> restoredArray = DurableArrayFactory.restore(m_act, null, gtypes, handler, false); for (int i = 0; i < capacity; i++) { DurableChunk<NonVolatileMemAllocator> dc = restoredArray.get(i); Assert.assertNotNull(dc); for (int j = 0; j < dc.getSize(); ++j) { byte b = unsafe.getByte(dc.get() + j); chunkCheckSum.update(b); } } Assert.assertEquals(chunkCheckSum.getValue(), chunkVal); chunkCheckSum.reset(); Iterator<DurableChunk> itr = restoredArray.iterator(); int val = 0; while (itr.hasNext()) { DurableChunk<NonVolatileMemAllocator> dc = itr.next(); Assert.assertNotNull(dc); for (int j = 0; j < dc.getSize(); ++j) { byte b = unsafe.getByte(dc.get() + j); chunkCheckSum.update(b); } val++; } Assert.assertEquals(val, capacity); Assert.assertEquals(chunkCheckSum.getValue(), chunkVal); restoredArray.destroy(); }
From source file:org.apache.mnemonic.collections.DurableArrayNGTest.java
@Test(enabled = true) public void testGetSetArrayBuffer() { DurableType gtypes[] = { DurableType.BUFFER }; int capacity = 10; DurableArray<DurableBuffer> array = DurableArrayFactory.create(m_act, null, gtypes, capacity, false); Long handler = array.getHandler(); long bufVal;// w ww . j a v a 2s . co m Checksum bufferCheckSum = new CRC32(); bufferCheckSum.reset(); for (int i = 0; i < capacity; i++) { array.set(i, genuptBuffer(m_act, bufferCheckSum, genRandSize())); } bufVal = bufferCheckSum.getValue(); bufferCheckSum.reset(); for (int i = 0; i < capacity; i++) { DurableBuffer<NonVolatileMemAllocator> db = array.get(i); Assert.assertNotNull(db); byte buf[] = new byte[db.get().capacity()]; db.get().get(buf); bufferCheckSum.update(buf, 0, buf.length); db.get().clear(); } Assert.assertEquals(bufferCheckSum.getValue(), bufVal); bufferCheckSum.reset(); DurableArray<DurableBuffer> restoredArray = DurableArrayFactory.restore(m_act, null, gtypes, handler, false); for (int i = 0; i < capacity; i++) { DurableBuffer<NonVolatileMemAllocator> db = restoredArray.get(i); Assert.assertNotNull(db); byte buf[] = new byte[db.get().capacity()]; db.get().get(buf); bufferCheckSum.update(buf, 0, buf.length); db.get().clear(); } Assert.assertEquals(bufferCheckSum.getValue(), bufVal); bufferCheckSum.reset(); Iterator<DurableBuffer> itr = restoredArray.iterator(); int val = 0; while (itr.hasNext()) { DurableBuffer<NonVolatileMemAllocator> db = itr.next(); Assert.assertNotNull(db); byte buf[] = new byte[db.get().capacity()]; db.get().get(buf); bufferCheckSum.update(buf, 0, buf.length); db.get().clear(); val++; } Assert.assertEquals(val, capacity); Assert.assertEquals(bufferCheckSum.getValue(), bufVal); restoredArray.destroy(); }