List of usage examples for java.util.zip Checksum reset
public void reset();
From source file:org.apache.mnemonic.DurablePersonNGTest.java
@Test(dependsOnMethods = { "testGenPeople" }) public void testCheckPeople() throws RetrieveDurableEntityError { NonVolatileMemAllocator act = new NonVolatileMemAllocator( Utils.getNonVolatileMemoryAllocatorService("pmalloc"), 1024 * 1024 * 8, "./pobj_person.dat", false); act.setBufferReclaimer(new Reclaim<ByteBuffer>() { @Override// w w w .j a v a2 s . c om public boolean reclaim(ByteBuffer mres, Long sz) { System.out.println(String.format("Reclaim Memory Buffer: %X Size: %s", System.identityHashCode(mres), null == sz ? "NULL" : sz.toString())); return false; } }); act.setChunkReclaimer(new Reclaim<Long>() { @Override 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; } }); Checksum pic_cs = new CRC32(); pic_cs.reset(); Checksum fp_cs = new CRC32(); fp_cs.reset(); long size; byte[] buf; long val; for (long i = 0; i < cKEYCAPACITY; ++i) { System.out.printf("----------Key %d--------------\n", i); val = act.getHandler(i); if (0L == val) { break; } Person<Integer> person = PersonFactory.restore(act, val, true); while (null != person) { person.testOutput(); person.getPicture().get().clear(); buf = new byte[person.getPicture().get().capacity()]; person.getPicture().get().get(buf); pic_cs.update(buf, 0, buf.length); byte b; for (int j = 0; j < person.getPreference().getSize(); ++j) { b = unsafe.getByte(person.getPreference().get() + j); fp_cs.update(b); } person = person.getMother(); } } act.close(); Assert.assertEquals(pic_cs.getValue(), pic_checksum); Assert.assertEquals(fp_cs.getValue(), fp_checksum); }
From source file:org.apache.mnemonic.DurablePersonNGTest.java
@Test(expectedExceptions = { OutOfHybridMemory.class }) public void testGenPeople() throws OutOfHybridMemory, RetrieveDurableEntityError { Random rand = Utils.createRandom(); NonVolatileMemAllocator act = new NonVolatileMemAllocator( Utils.getNonVolatileMemoryAllocatorService("pmalloc"), 1024L * 1024 * 1024, "./pobj_person.dat", true);/* w w w .ja va 2 s . c om*/ cKEYCAPACITY = act.handlerCapacity(); act.setBufferReclaimer(new Reclaim<ByteBuffer>() { @Override public boolean reclaim(ByteBuffer mres, Long sz) { System.out.println(String.format("Reclaim Memory Buffer: %X Size: %s", System.identityHashCode(mres), null == sz ? "NULL" : sz.toString())); return false; } }); act.setChunkReclaimer(new Reclaim<Long>() { @Override 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; } }); for (long i = 0; i < cKEYCAPACITY; ++i) { act.setHandler(i, 0L); } Person<Integer> mother; Person<Integer> person; Checksum pic_cs = new CRC32(); pic_cs.reset(); Checksum fp_cs = new CRC32(); fp_cs.reset(); long keyidx = 0; long val; try { while (true) { // if (keyidx >= KEYCAPACITY) break; keyidx %= cKEYCAPACITY; System.out.printf("************ Generating People on Key %d ***********\n", keyidx); val = act.getHandler(keyidx); if (0L != val) { PersonFactory.restore(act, val, true); } person = PersonFactory.create(act); person.setAge((short) rand.nextInt(50)); person.setName(String.format("Name: [%s]", UUID.randomUUID().toString()), true); person.setName(String.format("Name: [%s]", UUID.randomUUID().toString()), true); person.setName(String.format("Name: [%s]", UUID.randomUUID().toString()), true); person.setName(String.format("Name: [%s]", UUID.randomUUID().toString()), true); person.setPicture(genuptBuffer(act, pic_cs, genRandSize()), true); person.setPreference(genuptChunk(act, fp_cs, genRandSize()), true); act.setHandler(keyidx, person.getHandler()); pic_checksum = pic_cs.getValue(); fp_checksum = fp_cs.getValue(); for (int deep = 0; deep < rand.nextInt(100); ++deep) { mother = PersonFactory.create(act); mother.setAge((short) (50 + rand.nextInt(50))); mother.setName(String.format("Name: [%s]", UUID.randomUUID().toString()), true); mother.setPicture(genuptBuffer(act, pic_cs, genRandSize()), true); mother.setPreference(genuptChunk(act, fp_cs, genRandSize()), true); person.setMother(mother, true); pic_checksum = pic_cs.getValue(); fp_checksum = fp_cs.getValue(); person = mother; } ++keyidx; } } finally { act.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 w w w . ja va2s . 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.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(); for (int i = 0; i < capacity; i++) { array.set(i, genuptChunk(m_act, chunkCheckSum, genRandSize())); }//from ww w.j av a 2s. c o m 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;/*from w ww . j a va 2 s . c o 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(); }
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 *//*w ww. j a v a 2 s .co m*/ 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:PngEncoder.java
/** * writes the IHDR (Image Header) 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 *//* w w w . java 2s .c o m*/ private void writeIhdrChunk(OutputStream out, Checksum csum) throws IOException { writeInt(out, 13); // Chunk Size csum.reset(); out.write(IHDR); writeInt(out, width); writeInt(out, height); out.write(BIT_DEPTH); switch (outputBpp) { case 1: out.write(COLOR_TYPE_INDEXED); break; case 3: out.write(COLOR_TYPE_RGB); break; case 4: out.write(COLOR_TYPE_RGBA); break; default: throw new IllegalStateException("Invalid bytes per pixel"); } out.write(0); // Compression Method out.write(0); // Filter Method out.write(0); // Interlace writeInt(out, (int) csum.getValue()); }
From source file:PngEncoder.java
/** * Writes the PLTE (Palate) 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 */// ww w . ja va 2 s . co m private void writePlteChunk(OutputStream out, Checksum csum) throws IOException { IndexColorModel icm = (IndexColorModel) image.getColorModel(); writeInt(out, 768); // Chunk Size csum.reset(); out.write(PLTE); byte[] reds = new byte[256]; icm.getReds(reds); byte[] greens = new byte[256]; icm.getGreens(greens); byte[] blues = new byte[256]; icm.getBlues(blues); for (int index = 0; index < 256; ++index) { out.write(reds[index]); out.write(greens[index]); out.write(blues[index]); } writeInt(out, (int) csum.getValue()); }
From source file:org.apache.mnemonic.collections.DurableHashMapNGTest.java
@Test(enabled = true) public void testMapValueBuffer() { DurableType gtypes[] = { DurableType.STRING, DurableType.BUFFER }; DurableHashMap<String, DurableBuffer> map = DurableHashMapFactory.create(m_act, null, gtypes, 1, false); long bufVal;/*from w w w . ja v a 2 s . co m*/ Checksum bufferCheckSum = new CRC32(); bufferCheckSum.reset(); Long handler = map.getHandler(); for (int i = 0; i < 10; i++) { map.put("buffer" + i, genuptBuffer(m_act, bufferCheckSum, genRandSize())); } bufVal = bufferCheckSum.getValue(); bufferCheckSum.reset(); for (int i = 0; i < 10; i++) { DurableBuffer<NonVolatileMemAllocator> db = map.get("buffer" + i); Assert.assertNotNull(db); byte buf[] = new byte[db.get().capacity()]; db.get().get(buf); bufferCheckSum.update(buf, 0, buf.length); } Assert.assertEquals(bufferCheckSum.getValue(), bufVal); bufferCheckSum.reset(); DurableHashMap<String, DurableBuffer> restoredMap = DurableHashMapFactory.restore(m_act, null, gtypes, handler, false); for (int i = 0; i < 10; i++) { DurableBuffer<NonVolatileMemAllocator> db = restoredMap.get("buffer" + i); Assert.assertNotNull(db); byte buf[] = new byte[db.get().capacity()]; db.get().get(buf); bufferCheckSum.update(buf, 0, buf.length); } Assert.assertEquals(bufferCheckSum.getValue(), bufVal); restoredMap.destroy(); }
From source file:org.apache.mnemonic.collections.DurableHashMapNGTest.java
@Test(enabled = true) public void testMapValueChunk() { DurableType gtypes[] = { DurableType.STRING, DurableType.CHUNK }; DurableHashMap<String, DurableChunk> map = DurableHashMapFactory.create(m_act, null, gtypes, 1, false); long chunkVal; Checksum chunkCheckSum = new CRC32(); chunkCheckSum.reset(); Long handler = map.getHandler(); for (int i = 0; i < 10; i++) { map.put("chunk" + i, genuptChunk(m_act, chunkCheckSum, genRandSize())); }/*from ww w . java 2 s.co m*/ chunkVal = chunkCheckSum.getValue(); chunkCheckSum.reset(); for (int i = 0; i < 10; i++) { DurableChunk<NonVolatileMemAllocator> dc = map.get("chunk" + i); for (int j = 0; j < dc.getSize(); ++j) { byte b = unsafe.getByte(dc.get() + j); chunkCheckSum.update(b); } } chunkVal = chunkCheckSum.getValue(); Assert.assertEquals(chunkCheckSum.getValue(), chunkVal); chunkCheckSum.reset(); DurableHashMap<String, DurableChunk> restoredMap = DurableHashMapFactory.restore(m_act, null, gtypes, handler, false); for (int i = 0; i < 10; i++) { DurableChunk<NonVolatileMemAllocator> dc = restoredMap.get("chunk" + i); for (int j = 0; j < dc.getSize(); ++j) { byte b = unsafe.getByte(dc.get() + j); chunkCheckSum.update(b); } } chunkVal = chunkCheckSum.getValue(); Assert.assertEquals(chunkCheckSum.getValue(), chunkVal); restoredMap.destroy(); }