List of usage examples for java.util.zip Checksum reset
public void reset();
From source file:Main.java
public static void main(String[] argv) throws Exception { byte[] bytes = "some data".getBytes(); // Compute Adler-32 checksum Checksum checksumEngine = new CRC32(); checksumEngine.update(bytes, 0, bytes.length); long checksum = checksumEngine.getValue(); checksumEngine.reset(); }
From source file:org.apache.hadoop.mapred.TestShuffleHandler.java
private static void createIndexFile(File indexFile, Configuration conf) throws IOException { if (indexFile.exists()) { System.out.println("Deleting existing file"); indexFile.delete();//from w w w .j a va 2s. c o m } 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)); output.writeLong(chk.getChecksum().getValue()); output.close(); }
From source file:org.apache.mnemonic.ChunkBufferNGTest.java
@Test(dependsOnMethods = { "testGenChunkBuffers" }) public void testCheckChunkBuffers() { Checksum cs = new CRC32(); cs.reset(); NonVolatileMemAllocator act = new NonVolatileMemAllocator( Utils.getNonVolatileMemoryAllocatorService("pmalloc"), 1L, "./pmchunkbuffertest.dat", false); act.setChunkReclaimer(new Reclaim<Long>() { @Override//from w w w .ja va 2 s .c o m public boolean reclaim(Long mres, Long sz) { System.out.println(String.format("Reclaim Memory Chunk: %X Size: %s", System.identityHashCode(mres), null == sz ? "NULL" : sz.toString())); return false; } }); DurableChunk<NonVolatileMemAllocator> mch; mch = act.retrieveChunk(act.getHandler(m_keyid)); Assert.assertNotNull(mch); long bufcnt = mch.getSize() / m_bufsize; ChunkBuffer ckbuf; byte[] buf; for (long idx = 0; idx < bufcnt; ++idx) { ckbuf = mch.getChunkBuffer(idx * m_bufsize, m_bufsize); Assert.assertNotNull(ckbuf); buf = new byte[m_bufsize]; ckbuf.get().clear(); ckbuf.get().get(buf); cs.update(buf, 0, buf.length); } act.close(); Assert.assertEquals(m_checksum, cs.getValue()); Assert.assertEquals(m_count, bufcnt); System.out.println( String.format("The checksum of chunk buffers are %d, Total count is %d", m_checksum, m_count)); }
From source file:org.apache.mnemonic.ChunkBufferNGTest.java
@Test public void testGenChunkBuffers() { Checksum cs = new CRC32(); cs.reset(); NonVolatileMemAllocator act = new NonVolatileMemAllocator( Utils.getNonVolatileMemoryAllocatorService("pmalloc"), 1024 * 1024 * 1024L, "./pmchunkbuffertest.dat", true); act.setChunkReclaimer(new Reclaim<Long>() { @Override//from ww w .ja v a2 s.com public boolean reclaim(Long mres, Long sz) { System.out.println(String.format("Reclaim Memory Chunk: %X Size: %s", System.identityHashCode(mres), null == sz ? "NULL" : sz.toString())); return false; } }); DurableChunk<NonVolatileMemAllocator> mch; mch = act.createChunk(1000 * 1024 * 1024L); Assert.assertNotNull(mch); act.setHandler(m_keyid, mch.getHandler()); long bufcnt = mch.getSize() / m_bufsize; ChunkBuffer ckbuf; byte[] rdbytes; for (long idx = 0; idx < bufcnt; ++idx) { // System.err.println(String.format("---- bufcnt: %d, bufsize: %d, idx: %d", bufcnt, m_bufsize, idx)); ckbuf = mch.getChunkBuffer(idx * m_bufsize, m_bufsize); Assert.assertNotNull(ckbuf); rdbytes = RandomUtils.nextBytes(m_bufsize); Assert.assertNotNull(rdbytes); ckbuf.get().clear(); ckbuf.get().put(rdbytes); cs.update(rdbytes, 0, rdbytes.length); } m_checksum = cs.getValue(); m_count = bufcnt; act.close(); }
From source file:kr.ac.cau.mecs.cass.signal.payload.JSONObjectPayload.java
@Override public void serializeRawData(Payload payload) { String data = this.data.toString(); Checksum crc32 = new CRC32(); Base64 base64 = new Base64(); byte[] bytedata = data.getBytes(Charset.forName("UTF-8")); crc32.reset(); crc32.update(bytedata, 0, bytedata.length); String encoded = base64.encode(bytedata); payload.setCrc(crc32.getValue());//w w w. j av a 2 s.c o m payload.setLength(encoded.length()); payload.setRawdata(encoded); payload.setType(0x11); }
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 ww . ja va2 s. co 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 av a 2 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.apache.mnemonic.mapreduce.MneMapreduceBufferDataTest.java
@Test(enabled = true, dependsOnMethods = { "testWriteBufferData" }) public void testReadBufferData() throws Exception { long reccnt = 0L; long tsize = 0L; byte[] buf;//from w w w .ja v a2 s. c o m Checksum cs = new CRC32(); cs.reset(); File folder = new File(m_workdir.toString()); File[] listfiles = folder.listFiles(); for (int idx = 0; idx < listfiles.length; ++idx) { if (listfiles[idx].isFile() && listfiles[idx].getName().startsWith(MneConfigHelper.getBaseOutputName(m_conf, null)) && listfiles[idx].getName().endsWith(MneConfigHelper.DEFAULT_FILE_EXTENSION)) { m_partfns.add(listfiles[idx].getName()); } } Collections.sort(m_partfns); // keep the order for checksum for (int idx = 0; idx < m_partfns.size(); ++idx) { System.out.println(String.format("Verifying : %s", m_partfns.get(idx))); FileSplit split = new FileSplit(new Path(m_workdir, m_partfns.get(idx)), 0, 0L, new String[0]); InputFormat<NullWritable, MneDurableInputValue<DurableBuffer<?>>> inputFormat = new MneInputFormat<MneDurableInputValue<DurableBuffer<?>>, DurableBuffer<?>>(); RecordReader<NullWritable, MneDurableInputValue<DurableBuffer<?>>> reader = inputFormat .createRecordReader(split, m_tacontext); MneDurableInputValue<DurableBuffer<?>> dbufval = null; while (reader.nextKeyValue()) { dbufval = reader.getCurrentValue(); assert dbufval.getValue().getSize() == dbufval.getValue().get().capacity(); dbufval.getValue().get().clear(); buf = new byte[dbufval.getValue().get().capacity()]; dbufval.getValue().get().get(buf); cs.update(buf, 0, buf.length); tsize += dbufval.getValue().getSize(); ++reccnt; } reader.close(); } AssertJUnit.assertEquals(m_reccnt, reccnt); AssertJUnit.assertEquals(m_totalsize, tsize); AssertJUnit.assertEquals(m_checksum, cs.getValue()); System.out.println(String.format("The checksum of buffer is %d", m_checksum)); }
From source file:org.apache.mnemonic.mapred.MneMapredBufferDataTest.java
@Test(enabled = true, dependsOnMethods = { "testWriteBufferData" }) public void testReadBufferData() throws Exception { long reccnt = 0L; long tsize = 0L; byte[] buf;/* ww w. j a v a2 s.c om*/ Checksum cs = new CRC32(); cs.reset(); File folder = new File(m_workdir.toString()); File[] listfiles = folder.listFiles(); for (int idx = 0; idx < listfiles.length; ++idx) { if (listfiles[idx].isFile() && listfiles[idx].getName().startsWith(MneConfigHelper.getBaseOutputName(m_conf, null)) && listfiles[idx].getName().endsWith(MneConfigHelper.DEFAULT_FILE_EXTENSION)) { m_partfns.add(listfiles[idx].getName()); } } Collections.sort(m_partfns); // keep the order for checksum for (int idx = 0; idx < m_partfns.size(); ++idx) { System.out.println(String.format("Verifying : %s", m_partfns.get(idx))); FileSplit split = new FileSplit(new Path(m_workdir, m_partfns.get(idx)), 0, 0L, new String[0]); InputFormat<NullWritable, MneDurableInputValue<DurableBuffer<?>>> inputFormat = new MneInputFormat<MneDurableInputValue<DurableBuffer<?>>, DurableBuffer<?>>(); RecordReader<NullWritable, MneDurableInputValue<DurableBuffer<?>>> reader = inputFormat .getRecordReader((InputSplit) split, m_conf, null); NullWritable dbufkey = reader.createKey(); MneDurableInputValue<DurableBuffer<?>> dbufval = null; while (true) { dbufval = reader.createValue(); if (reader.next(dbufkey, dbufval)) { assert dbufval.getValue().getSize() == dbufval.getValue().get().capacity(); dbufval.getValue().get().clear(); buf = new byte[dbufval.getValue().get().capacity()]; dbufval.getValue().get().get(buf); cs.update(buf, 0, buf.length); tsize += dbufval.getValue().getSize(); ++reccnt; } else { break; } } reader.close(); } AssertJUnit.assertEquals(m_reccnt, reccnt); AssertJUnit.assertEquals(m_totalsize, tsize); AssertJUnit.assertEquals(m_checksum, cs.getValue()); System.out.println(String.format("The checksum of buffer is %d", m_checksum)); }
From source file:org.anarres.lzo.LzopOutputStream.java
private void writeChecksum(Checksum csum, byte[] data, int off, int len) throws IOException { if (csum == null) return;//from ww w . ja va2 s . co m csum.reset(); csum.update(data, off, len); long value = csum.getValue(); // LOG.info("Writing checksum " + csum); writeInt((int) (value & 0xFFFFFFFF)); }