本文整理匯總了Java中java.util.zip.Adler32.reset方法的典型用法代碼示例。如果您正苦於以下問題:Java Adler32.reset方法的具體用法?Java Adler32.reset怎麽用?Java Adler32.reset使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.util.zip.Adler32
的用法示例。
在下文中一共展示了Adler32.reset方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: test_getValue
import java.util.zip.Adler32; //導入方法依賴的package包/類
/**
* @tests java.util.zip.Adler32#getValue()
*/
public void test_getValue() {
// test methods of java.util.zip.getValue()
Adler32 adl = new Adler32();
assertEquals("GetValue should return a zero as a result of construction an object of Adler32",
1, adl.getValue());
adl.reset();
adl.update(1);
// System.out.print("value of adl"+adl.getValue());
// The value of the adl should be 131074
assertEquals("update(int) failed to update the checksum to the correct value ",
131074, adl.getValue());
adl.reset();
assertEquals("reset failed to reset the checksum value to zero", 1, adl
.getValue());
adl.reset();
adl.update(Integer.MIN_VALUE);
// System.out.print("value of adl " + adl.getValue());
// The value of the adl should be 65537
assertEquals("update(min) failed to update the checksum to the correct value ",
65537L, adl.getValue());
}
示例2: test_updateI
import java.util.zip.Adler32; //導入方法依賴的package包/類
/**
* @tests java.util.zip.Adler32#update(int)
*/
public void test_updateI() {
// test methods of java.util.zip.update(int)
Adler32 adl = new Adler32();
adl.update(1);
// The value of the adl should be 131074
assertEquals("update(int) failed to update the checksum to the correct value ",
131074, adl.getValue());
adl.reset();
adl.update(Integer.MAX_VALUE);
// System.out.print("value of adl " + adl.getValue());
// The value of the adl should be 16777472
assertEquals("update(max) failed to update the checksum to the correct value ",
16777472L, adl.getValue());
adl.reset();
adl.update(Integer.MIN_VALUE);
// System.out.print("value of adl " + adl.getValue());
// The value of the adl should be 65537
assertEquals("update(min) failed to update the checksum to the correct value ",
65537L, adl.getValue());
}
示例3: Adler32
import java.util.zip.Adler32; //導入方法依賴的package包/類
/**
* @tests java.util.zip.Adler32#update(byte[])
*/
public void test_update$B() {
// test method of java.util.zip.update(byte[])
byte byteArray[] = { 1, 2 };
Adler32 adl = new Adler32();
adl.update(byteArray);
// System.out.print("value of adl"+adl.getValue());
// The value of the adl should be 393220
assertEquals("update(byte[]) failed to update the checksum to the correct value ",
393220, adl.getValue());
adl.reset();
byte byteEmpty[] = new byte[10000];
adl.update(byteEmpty);
// System.out.print("value of adl"+adl.getValue());
// The value of the adl should be 655360001
assertEquals("update(byte[]) failed to update the checksum to the correct value ",
655360001L, adl.getValue());
}
示例4: testAdler32
import java.util.zip.Adler32; //導入方法依賴的package包/類
private void testAdler32() {
Adler32 ad = new Adler32();
byte[] data = new byte[10000];
for (int n = 0; n < data.length; n++) data[n] = (byte) (n * n);
ad.reset();
ad.update(data, 0, 10000);
System.out.println(ad.getValue());
ad.update(data, 5000, 5000);
System.out.println(ad.getValue());
}
示例5: adler32Test
import java.util.zip.Adler32; //導入方法依賴的package包/類
private void adler32Test(byte[] values, long expected) {
Adler32 adler = new Adler32();
// try it all at once
adler.update(values);
assertEquals(adler.getValue(), expected);
// try resetting and computing one byte at a time
adler.reset();
for (int i = 0; i < values.length; i++) {
adler.update(values[i]);
}
assertEquals(adler.getValue(), expected);
}
示例6: wrongChecksumWithAdler32Test
import java.util.zip.Adler32; //導入方法依賴的package包/類
private void wrongChecksumWithAdler32Test() {
byte[] bytes = {1, 0, 5, 0, 15, 0, 1, 11, 0, 1};
Adler32 adler = new Adler32();
adler.update(bytes);
long arrayChecksum = adler.getValue();
adler.reset();
for (int i = 0; i < bytes.length; i++) {
adler.update(bytes[i]);
}
assertEquals("Checksums not equal: expected: " + arrayChecksum +
" actual: " + adler.getValue(), arrayChecksum, adler.getValue());
}
示例7: test_reset
import java.util.zip.Adler32; //導入方法依賴的package包/類
/**
* @tests java.util.zip.Adler32#reset()
*/
public void test_reset() {
// test methods of java.util.zip.reset()
Adler32 adl = new Adler32();
adl.update(1);
// System.out.print("value of adl"+adl.getValue());
// The value of the adl should be 131074
assertEquals("update(int) failed to update the checksum to the correct value ",
131074, adl.getValue());
adl.reset();
assertEquals("reset failed to reset the checksum value to zero", 1, adl
.getValue());
}
示例8: testConstructTree_4LeafEntries
import java.util.zip.Adler32; //導入方法依賴的package包/類
@Test
public void testConstructTree_4LeafEntries() {
MerkleTree m4tree = construct4LeafTree();
MerkleTree.Node root = m4tree.getRoot();
ByteBuffer buf = ByteBuffer.allocate(8);
buf.put(root.sig);
buf.rewind();
// pop off the leading 0 or 1 byte
assertEquals(MerkleTree.INTERNAL_SIG_TYPE, root.type);
long rootSig = buf.getLong();
assertTrue(rootSig > 1);
assertEquals(2, m4tree.getHeight());
assertEquals(7, m4tree.getNumNodes());
MerkleTree.Node lev1Node0 = root.left;
assertEquals(MerkleTree.INTERNAL_SIG_TYPE, lev1Node0.type);
MerkleTree.Node lev1Node1 = root.right;
assertEquals(MerkleTree.INTERNAL_SIG_TYPE, lev1Node1.type);
MerkleTree.Node lev2Node0 = lev1Node0.left;
assertEquals(MerkleTree.LEAF_SIG_TYPE, lev2Node0.type);
assertEquals("52e422506d8238ef3196b41db4c41ee0afd659b6", new String(lev2Node0.sig, UTF_8));
MerkleTree.Node lev2Node1 = lev1Node0.right;
assertEquals(MerkleTree.LEAF_SIG_TYPE, lev2Node1.type);
assertEquals("6d0b51991ac3806192f3cb524a5a5d73ebdaacf8", new String(lev2Node1.sig, UTF_8));
MerkleTree.Node lev2Node2 = lev1Node1.left;
assertEquals(MerkleTree.LEAF_SIG_TYPE, lev2Node2.type);
assertEquals("461848c8b70e5a57bd94008b2622796ec26db657", new String(lev2Node2.sig, UTF_8));
MerkleTree.Node lev2Node3 = lev1Node1.right;
assertEquals(MerkleTree.LEAF_SIG_TYPE, lev2Node3.type);
assertEquals("c938037dc70d107b3386a86df7fef17a9983cf53", new String(lev2Node3.sig, UTF_8));
// check that internal Node signatures are correct
Adler32 adler = new Adler32();
adler.update(lev2Node0.sig);
adler.update(lev2Node1.sig);
buf.clear();
buf.put(lev1Node0.sig);
buf.rewind();
assertEquals(buf.getLong(), adler.getValue());
adler.reset();
adler.update(lev2Node2.sig);
adler.update(lev2Node3.sig);
buf.clear();
buf.put(lev1Node1.sig);
buf.rewind();
assertEquals(buf.getLong(), adler.getValue());
adler.reset();
adler.update(lev1Node0.sig);
adler.update(lev1Node1.sig);
buf.clear();
buf.put(root.sig);
buf.rewind();
assertEquals(buf.getLong(), adler.getValue());
}
示例9: testConstructTree_9LeafEntries
import java.util.zip.Adler32; //導入方法依賴的package包/類
@Test
public void testConstructTree_9LeafEntries() {
MerkleTree m9tree = construct9LeafTree();
MerkleTree.Node root = m9tree.getRoot();
ByteBuffer buf = ByteBuffer.allocate(8);
buf.put(root.sig);
buf.rewind();
// pop off the leading 0 or 1 byte
assertEquals(MerkleTree.INTERNAL_SIG_TYPE, root.type);
long rootSig = buf.getLong();
assertTrue(rootSig > 1);
assertEquals(4, m9tree.getHeight());
assertEquals(20, m9tree.getNumNodes());
MerkleTree.Node lev1Node0 = root.left;
assertEquals(MerkleTree.INTERNAL_SIG_TYPE, lev1Node0.type);
MerkleTree.Node lev1Node1 = root.right;
assertEquals(MerkleTree.INTERNAL_SIG_TYPE, lev1Node1.type);
// right hand tree should just be a linked list of promoted node sigs
assertNull(lev1Node1.right);
MerkleTree.Node lev2Node2 = lev1Node1.left;
assertEquals(MerkleTree.INTERNAL_SIG_TYPE, lev2Node2.type);
assertArrayEquals(lev1Node1.sig, lev2Node2.sig);
assertNull(lev2Node2.right);
MerkleTree.Node lev3Node4 = lev2Node2.left;
assertEquals(MerkleTree.INTERNAL_SIG_TYPE, lev3Node4.type);
assertArrayEquals(lev2Node2.sig, lev3Node4.sig);
assertNull(lev3Node4.right);
MerkleTree.Node lev4Node8 = lev3Node4.left;
assertEquals(MerkleTree.LEAF_SIG_TYPE, lev4Node8.type);
assertArrayEquals(lev3Node4.sig, lev4Node8.sig);
// check some of the left hand trees to ensure correctness
MerkleTree.Node lev2Node0 = lev1Node0.left;
MerkleTree.Node lev3Node1 = lev2Node0.right;
MerkleTree.Node lev4Node3 = lev3Node1.right;
assertEquals(MerkleTree.INTERNAL_SIG_TYPE, lev2Node0.type);
assertEquals(MerkleTree.INTERNAL_SIG_TYPE, lev3Node1.type);
assertEquals(MerkleTree.LEAF_SIG_TYPE, lev4Node3.type);
assertNull(lev4Node3.left);
assertNull(lev4Node3.right);
// check some of the internal parent node signatures
Adler32 adler = new Adler32();
adler.update(lev3Node1.left.sig);
adler.update(lev3Node1.right.sig);
buf.clear();
buf.put(lev3Node1.sig);
buf.rewind();
assertEquals(buf.getLong(), adler.getValue());
adler.reset();
adler.update(lev2Node0.left.sig);
adler.update(lev2Node0.right.sig);
buf.clear();
buf.put(lev2Node0.sig);
buf.rewind();
assertEquals(buf.getLong(), adler.getValue());
}
示例10: testSerializationDeserialization4LeafTree
import java.util.zip.Adler32; //導入方法依賴的package包/類
@Test
public void testSerializationDeserialization4LeafTree() {
MerkleTree m4tree = construct4LeafTree();
byte[] serializedTree = m4tree.serialize();
ByteBuffer buf = ByteBuffer.wrap(serializedTree);
assertEquals(MerkleTree.MAGIC_HDR, buf.getInt());
assertEquals(m4tree.getNumNodes(), buf.getInt());
// root node
MerkleTree.Node root = new MerkleTree.Node();
root.type = buf.get();
assertEquals(MerkleTree.INTERNAL_SIG_TYPE, root.type);
int len = buf.getInt();
assertEquals(MerkleTree.LONG_BYTES, len);
root.sig = new byte[len];
buf.get(root.sig);
long rootSig = convertSigToLong(root.sig);
long expectedRootSig = convertSigToLong(m4tree.getRoot().sig);
assertEquals(expectedRootSig, rootSig);
MerkleTree dtree = MerkleDeserializer.deserialize(serializedTree);
assertEquals(MerkleTree.INTERNAL_SIG_TYPE, dtree.getRoot().type);
assertArrayEquals(root.sig, dtree.getRoot().sig);
root = dtree.getRoot();
assertEquals(2, dtree.getHeight());
assertEquals(7, dtree.getNumNodes());
MerkleTree.Node lev1Node0 = root.left;
assertEquals(MerkleTree.INTERNAL_SIG_TYPE, lev1Node0.type);
MerkleTree.Node lev1Node1 = root.right;
assertEquals(MerkleTree.INTERNAL_SIG_TYPE, lev1Node1.type);
MerkleTree.Node lev2Node0 = lev1Node0.left;
assertEquals(MerkleTree.LEAF_SIG_TYPE, lev2Node0.type);
assertEquals("52e422506d8238ef3196b41db4c41ee0afd659b6", new String(lev2Node0.sig, UTF_8));
MerkleTree.Node lev2Node1 = lev1Node0.right;
assertEquals(MerkleTree.LEAF_SIG_TYPE, lev2Node1.type);
assertEquals("6d0b51991ac3806192f3cb524a5a5d73ebdaacf8", new String(lev2Node1.sig, UTF_8));
MerkleTree.Node lev2Node2 = lev1Node1.left;
assertEquals(MerkleTree.LEAF_SIG_TYPE, lev2Node2.type);
assertEquals("461848c8b70e5a57bd94008b2622796ec26db657", new String(lev2Node2.sig, UTF_8));
MerkleTree.Node lev2Node3 = lev1Node1.right;
assertEquals(MerkleTree.LEAF_SIG_TYPE, lev2Node3.type);
assertEquals("c938037dc70d107b3386a86df7fef17a9983cf53", new String(lev2Node3.sig, UTF_8));
// check that internal Node signatures are correct
Adler32 adler = new Adler32();
adler.update(lev2Node0.sig);
adler.update(lev2Node1.sig);
buf.clear();
buf.put(lev1Node0.sig);
buf.rewind();
assertEquals(buf.getLong(), adler.getValue());
adler.reset();
adler.update(lev2Node2.sig);
adler.update(lev2Node3.sig);
buf.clear();
buf.put(lev1Node1.sig);
buf.rewind();
assertEquals(buf.getLong(), adler.getValue());
adler.reset();
adler.update(lev1Node0.sig);
adler.update(lev1Node1.sig);
buf.clear();
buf.put(root.sig);
buf.rewind();
assertEquals(buf.getLong(), adler.getValue());
}
示例11: testSerializationDeserialization9LeafTree
import java.util.zip.Adler32; //導入方法依賴的package包/類
@Test
public void testSerializationDeserialization9LeafTree() {
MerkleTree m9tree = construct9LeafTree();
byte[] serializedTree = m9tree.serialize();
ByteBuffer buf = ByteBuffer.wrap(serializedTree);
assertEquals(MerkleTree.MAGIC_HDR, buf.getInt());
assertEquals(m9tree.getNumNodes(), buf.getInt());
// root node
MerkleTree.Node root = new MerkleTree.Node();
root.type = buf.get();
assertEquals(MerkleTree.INTERNAL_SIG_TYPE, root.type);
int len = buf.getInt();
assertEquals(MerkleTree.LONG_BYTES, len);
root.sig = new byte[len];
buf.get(root.sig);
long rootSig = convertSigToLong(root.sig);
long expectedRootSig = convertSigToLong(m9tree.getRoot().sig);
assertEquals(expectedRootSig, rootSig);
MerkleTree dtree = MerkleDeserializer.deserialize(serializedTree);
assertEquals(MerkleTree.INTERNAL_SIG_TYPE, dtree.getRoot().type);
assertArrayEquals(root.sig, dtree.getRoot().sig);
assertEquals(4, dtree.getHeight());
assertEquals(20, dtree.getNumNodes());
root = dtree.getRoot();
MerkleTree.Node lev1Node0 = root.left;
assertEquals(MerkleTree.INTERNAL_SIG_TYPE, lev1Node0.type);
MerkleTree.Node lev1Node1 = root.right;
assertEquals(MerkleTree.INTERNAL_SIG_TYPE, lev1Node1.type);
// right hand tree should just be a linked list of promoted node sigs
assertNull(lev1Node1.right);
MerkleTree.Node lev2Node2 = lev1Node1.left;
assertEquals(MerkleTree.INTERNAL_SIG_TYPE, lev2Node2.type);
assertArrayEquals(lev1Node1.sig, lev2Node2.sig);
assertNull(lev2Node2.right);
MerkleTree.Node lev3Node4 = lev2Node2.left;
assertEquals(MerkleTree.INTERNAL_SIG_TYPE, lev3Node4.type);
assertArrayEquals(lev2Node2.sig, lev3Node4.sig);
assertNull(lev3Node4.right);
MerkleTree.Node lev4Node8 = lev3Node4.left;
assertEquals(MerkleTree.LEAF_SIG_TYPE, lev4Node8.type);
assertArrayEquals(lev3Node4.sig, lev4Node8.sig);
// check some of the left hand trees to ensure correctness
MerkleTree.Node lev2Node0 = lev1Node0.left;
MerkleTree.Node lev3Node1 = lev2Node0.right;
MerkleTree.Node lev4Node3 = lev3Node1.right;
assertEquals(MerkleTree.INTERNAL_SIG_TYPE, lev2Node0.type);
assertEquals(MerkleTree.INTERNAL_SIG_TYPE, lev3Node1.type);
assertEquals(MerkleTree.LEAF_SIG_TYPE, lev4Node3.type);
assertNull(lev4Node3.left);
assertNull(lev4Node3.right);
// check some of the internal parent node signatures
Adler32 adler = new Adler32();
adler.update(lev3Node1.left.sig);
adler.update(lev3Node1.right.sig);
buf.clear();
buf.put(lev3Node1.sig);
buf.rewind();
assertEquals(buf.getLong(), adler.getValue());
adler.reset();
adler.update(lev2Node0.left.sig);
adler.update(lev2Node0.right.sig);
buf.clear();
buf.put(lev2Node0.sig);
buf.rewind();
assertEquals(buf.getLong(), adler.getValue());
}
示例12: getFrameSECTOR_WR
import java.util.zip.Adler32; //導入方法依賴的package包/類
/**
* Generate SECTOR_WR frame for writing an application memory sector
*
* @param sector_id number of sector 0 .. 1023
* @param sector_data byte array containing the sector data
* @return frame object
*/
public static Frame getFrameSECTOR_WR(int sector_id, byte[] sector_data) {
byte[] sector_address;
/* parameter checks */
if (sector_id > 1023) throw new IllegalArgumentException("Illegal sector ID");
if (sector_data.length != 4096) throw new IllegalArgumentException("Illegal sector size");
/* determine sector_address */
sector_address = new byte[2];
sector_address[0] = (byte)(sector_id & 0xFF); // lowbyte 0..0xff
sector_address[1] = (byte)((sector_id & 0x300) >> 8); // highbyte 0..0x3
/* concatenate addresses and data */
byte[] address_data = new byte[2+APPMEM_SECTOR_SIZE];
System.arraycopy(sector_address, 0, address_data, 0 , 2);
System.arraycopy(sector_data, 0, address_data, 2, APPMEM_SECTOR_SIZE);
/* calculate adler32 checksum */
Adler32 adler = new Adler32();
adler.reset();
adler.update(address_data, 0, address_data.length);
long tempChecksum = adler.getValue();
/* package checksum */
Byte[] checksum = new Byte[4];
checksum[0] = (byte) (tempChecksum & 0x000000FF);
checksum[1] = (byte) ((tempChecksum & 0x0000FF00) >> 8);
checksum[2] = (byte) ((tempChecksum & 0x00FF0000) >> 16);
checksum[3] = (byte) ((tempChecksum & 0xFF000000) >> 24);
/* package frame */
Byte[] rawBytes = new Byte[LEN_SECTOR_WR];
rawBytes[0] = OPC_SECTOR_WR;
for (int i = 0; i < APPMEM_SECTOR_SIZE + 2; i++) {
rawBytes[i + 1] = address_data[i];
}
System.arraycopy(checksum, 0, rawBytes, 3 + APPMEM_SECTOR_SIZE, 4);
return new Frame(-1, LEN_SECTOR_WR, rawBytes);
}