List of usage examples for java.util Arrays equals
public static boolean equals(Object[] a, Object[] a2)
From source file:baggage.BaseTestCase.java
protected static final void assertEquals(byte[] expected, byte[] actual) { if (!Arrays.equals(expected, actual)) { Assert.fail("Expected " + toString(expected) + ", got " + toString(actual)); }//from w ww. j a v a 2 s .c o m }
From source file:com.hadoop.compression.lzo.LzopInputStream.java
/** * Read and verify an lzo header, setting relevant block checksum options * and ignoring most everything else.// www .jav a2 s . c o m * @param in InputStream * @throws IOException if there is a error in lzo header */ protected void readHeader(InputStream in) throws IOException { readFully(in, buf, 0, 9); if (!Arrays.equals(buf, LzopCodec.LZO_MAGIC)) { throw new IOException("Invalid LZO header"); } Arrays.fill(buf, (byte) 0); Adler32 adler = new Adler32(); CRC32 crc32 = new CRC32(); int hitem = readHeaderItem(in, buf, 2, adler, crc32); // lzop version if (hitem > LzopCodec.LZOP_VERSION) { LOG.debug("Compressed with later version of lzop: " + Integer.toHexString(hitem) + " (expected 0x" + Integer.toHexString(LzopCodec.LZOP_VERSION) + ")"); } hitem = readHeaderItem(in, buf, 2, adler, crc32); // lzo library version if (hitem < LzoDecompressor.MINIMUM_LZO_VERSION) { throw new IOException("Compressed with incompatible lzo version: 0x" + Integer.toHexString(hitem) + " (expected at least 0x" + Integer.toHexString(LzoDecompressor.MINIMUM_LZO_VERSION) + ")"); } hitem = readHeaderItem(in, buf, 2, adler, crc32); // lzop extract version if (hitem > LzopCodec.LZOP_VERSION) { throw new IOException("Compressed with incompatible lzop version: 0x" + Integer.toHexString(hitem) + " (expected 0x" + Integer.toHexString(LzopCodec.LZOP_VERSION) + ")"); } hitem = readHeaderItem(in, buf, 1, adler, crc32); // method if (hitem < 1 || hitem > 3) { throw new IOException("Invalid strategy: " + Integer.toHexString(hitem)); } readHeaderItem(in, buf, 1, adler, crc32); // ignore level // flags hitem = readHeaderItem(in, buf, 4, adler, crc32); try { for (DChecksum f : dflags) { if (0 == (f.getHeaderMask() & hitem)) { dflags.remove(f); } else { dcheck.put(f, (int) f.getChecksumClass().newInstance().getValue()); } } for (CChecksum f : cflags) { if (0 == (f.getHeaderMask() & hitem)) { cflags.remove(f); } else { ccheck.put(f, (int) f.getChecksumClass().newInstance().getValue()); } } } catch (InstantiationException e) { throw new RuntimeException("Internal error", e); } catch (IllegalAccessException e) { throw new RuntimeException("Internal error", e); } ((LzopDecompressor) decompressor).initHeaderFlags(dflags, cflags); boolean useCRC32 = 0 != (hitem & 0x00001000); // F_H_CRC32 boolean extraField = 0 != (hitem & 0x00000040); // F_H_EXTRA_FIELD if (0 != (hitem & 0x400)) { // F_MULTIPART throw new IOException("Multipart lzop not supported"); } if (0 != (hitem & 0x800)) { // F_H_FILTER throw new IOException("lzop filter not supported"); } if (0 != (hitem & 0x000FC000)) { // F_RESERVED throw new IOException("Unknown flags in header"); } // known !F_H_FILTER, so no optional block readHeaderItem(in, buf, 4, adler, crc32); // ignore mode readHeaderItem(in, buf, 4, adler, crc32); // ignore mtime readHeaderItem(in, buf, 4, adler, crc32); // ignore gmtdiff hitem = readHeaderItem(in, buf, 1, adler, crc32); // fn len if (hitem > 0) { // skip filename int filenameLen = Math.max(4, hitem); // buffer must be at least 4 bytes for readHeaderItem to work. readHeaderItem(in, new byte[filenameLen], hitem, adler, crc32); } int checksum = (int) (useCRC32 ? crc32.getValue() : adler.getValue()); hitem = readHeaderItem(in, buf, 4, adler, crc32); // read checksum if (hitem != checksum) { throw new IOException("Invalid header checksum: " + Long.toHexString(checksum) + " (expected 0x" + Integer.toHexString(hitem) + ")"); } if (extraField) { // lzop 1.08 ultimately ignores this LOG.debug("Extra header field not processed"); adler.reset(); crc32.reset(); hitem = readHeaderItem(in, buf, 4, adler, crc32); readHeaderItem(in, new byte[hitem], hitem, adler, crc32); checksum = (int) (useCRC32 ? crc32.getValue() : adler.getValue()); if (checksum != readHeaderItem(in, buf, 4, adler, crc32)) { throw new IOException("Invalid checksum for extra header field"); } } }
From source file:ch.cyberduck.core.aquaticprime.DonationKey.java
/** * @return True if valid license key//from ww w .ja v a 2 s. c o m */ @Override public boolean verify() { if (null == dictionary) { return false; } final NSData signature = (NSData) dictionary.objectForKey("Signature"); if (null == signature) { log.warn(String.format("Missing key 'Signature' in dictionary %s", dictionary)); return false; } // Append all values StringBuilder values = new StringBuilder(); final ArrayList<String> keys = new ArrayList<>(dictionary.keySet()); // Sort lexicographically by key Collections.sort(keys, new NaturalOrderComparator()); for (String key : keys) { if ("Signature".equals(key)) { continue; } values.append(dictionary.objectForKey(key).toString()); } byte[] signaturebytes = signature.bytes(); byte[] plainbytes = values.toString().getBytes(Charset.forName("UTF-8")); final boolean valid; try { final BigInteger modulus = new BigInteger(StringUtils.removeStart(this.getPublicKey(), "0x"), 16); final BigInteger exponent = new BigInteger(Base64.decodeBase64("Aw==")); final KeySpec spec = new RSAPublicKeySpec(modulus, exponent); final PublicKey rsa = KeyFactory.getInstance("RSA").generatePublic(spec); final Cipher rsaCipher = Cipher.getInstance("RSA/ECB/PKCS1Padding"); rsaCipher.init(Cipher.DECRYPT_MODE, rsa); final MessageDigest sha1Digest = MessageDigest.getInstance("SHA1"); valid = Arrays.equals(rsaCipher.doFinal(signaturebytes), sha1Digest.digest(plainbytes)); } catch (NoSuchPaddingException | BadPaddingException | IllegalBlockSizeException | InvalidKeyException | InvalidKeySpecException | NoSuchAlgorithmException e) { log.warn(String.format("Signature verification failure for key %s", file)); return false; } if (valid) { if (log.isInfoEnabled()) { log.info(String.format("Valid key in %s", file)); } } else { log.warn(String.format("Not a valid key in %s", file)); } return valid; }
From source file:com.funambol.ctp.core.NotAuthenticated.java
/** * Compares <code>this</code> object with input object to establish if are * the same object.//ww w. jav a 2 s. c om * * @param obj the object to compare * @return true if the objects are equals, false otherwise */ public boolean deepequals(Object obj) { if (obj == null || (!obj.getClass().equals(this.getClass()))) { return false; } if (this == obj) { return true; } NotAuthenticated cmd = (NotAuthenticated) obj; if (this.getNonce() == null) { if (cmd.getNonce() != null) { return false; } } else { if (cmd.getNonce() == null) { return false; } if (!(Arrays.equals(this.getNonce(), cmd.getNonce()))) { return false; } } return true; }
From source file:org.killbill.billing.plugin.avatax.client.model.GetTaxResult.java
@Override public boolean equals(final Object o) { if (this == o) { return true; }/*from w w w. j a va 2 s . c om*/ if (o == null || getClass() != o.getClass()) { return false; } final GetTaxResult that = (GetTaxResult) o; if (Double.compare(that.TotalAmount, TotalAmount) != 0) { return false; } if (Double.compare(that.TotalDiscount, TotalDiscount) != 0) { return false; } if (Double.compare(that.TotalExemption, TotalExemption) != 0) { return false; } if (Double.compare(that.TotalTax, TotalTax) != 0) { return false; } if (Double.compare(that.TotalTaxCalculated, TotalTaxCalculated) != 0) { return false; } if (Double.compare(that.TotalTaxable, TotalTaxable) != 0) { return false; } if (DocCode != null ? !DocCode.equals(that.DocCode) : that.DocCode != null) { return false; } if (DocDate != null ? !DocDate.equals(that.DocDate) : that.DocDate != null) { return false; } if (!Arrays.equals(Messages, that.Messages)) { return false; } if (ResultCode != that.ResultCode) { return false; } if (!Arrays.equals(TaxAddresses, that.TaxAddresses)) { return false; } if (TaxDate != null ? !TaxDate.equals(that.TaxDate) : that.TaxDate != null) { return false; } if (!Arrays.equals(TaxLines, that.TaxLines)) { return false; } if (!Arrays.equals(TaxSummary, that.TaxSummary)) { return false; } if (Timestamp != null ? !Timestamp.equals(that.Timestamp) : that.Timestamp != null) { return false; } return true; }
From source file:com.buaa.cfs.nfs3.FileHandle.java
@Override public boolean equals(Object o) { if (this == o) { return true; }//from w w w. ja va 2 s. c o m if (!(o instanceof FileHandle)) { return false; } FileHandle h = (FileHandle) o; return Arrays.equals(handle, h.handle); }
From source file:com.milaboratory.core.alignment.AbstractAlignmentScoring.java
@Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; AbstractAlignmentScoring that = (AbstractAlignmentScoring) o; if (getAlphabet() != ((AbstractAlignmentScoring) o).getAlphabet()) return false; return Arrays.equals(subsMatrix, that.subsMatrix); }
From source file:com.couchbase.lite.AttachmentsTest.java
@SuppressWarnings("unchecked") public void testAttachments() throws Exception { String testAttachmentName = "test_attachment"; BlobStore attachments = database.getAttachments(); Assert.assertEquals(0, attachments.count()); Assert.assertEquals(new HashSet<Object>(), attachments.allKeys()); Status status = new Status(); Map<String, Object> rev1Properties = new HashMap<String, Object>(); rev1Properties.put("foo", 1); rev1Properties.put("bar", false); RevisionInternal rev1 = database.putRevision(new RevisionInternal(rev1Properties, database), null, false, status);/*from w w w. jav a2 s. c o m*/ Assert.assertEquals(Status.CREATED, status.getCode()); byte[] attach1 = "This is the body of attach1".getBytes(); database.insertAttachmentForSequenceWithNameAndType(new ByteArrayInputStream(attach1), rev1.getSequence(), testAttachmentName, "text/plain", rev1.getGeneration()); Assert.assertEquals(Status.CREATED, status.getCode()); //We must set the no_attachments column for the rev to false, as we are using an internal //private API call above (database.insertAttachmentForSequenceWithNameAndType) which does //not set the no_attachments column on revs table try { ContentValues args = new ContentValues(); args.put("no_attachments=", false); database.getDatabase().update("revs", args, "sequence=?", new String[] { String.valueOf(rev1.getSequence()) }); } catch (SQLException e) { Log.e(Database.TAG, "Error setting rev1 no_attachments to false", e); throw new CouchbaseLiteException(Status.INTERNAL_SERVER_ERROR); } Attachment attachment = database.getAttachmentForSequence(rev1.getSequence(), testAttachmentName); Assert.assertEquals("text/plain", attachment.getContentType()); InputStream is = attachment.getContent(); byte[] data = IOUtils.toByteArray(is); is.close(); Assert.assertTrue(Arrays.equals(attach1, data)); Map<String, Object> innerDict = new HashMap<String, Object>(); innerDict.put("content_type", "text/plain"); innerDict.put("digest", "sha1-gOHUOBmIMoDCrMuGyaLWzf1hQTE="); innerDict.put("length", 27); innerDict.put("stub", true); innerDict.put("revpos", 1); Map<String, Object> attachmentDict = new HashMap<String, Object>(); attachmentDict.put(testAttachmentName, innerDict); Map<String, Object> attachmentDictForSequence = database.getAttachmentsDictForSequenceWithContent( rev1.getSequence(), EnumSet.noneOf(Database.TDContentOptions.class)); Assert.assertEquals(attachmentDict, attachmentDictForSequence); RevisionInternal gotRev1 = database.getDocumentWithIDAndRev(rev1.getDocId(), rev1.getRevId(), EnumSet.noneOf(Database.TDContentOptions.class)); Map<String, Object> gotAttachmentDict = (Map<String, Object>) gotRev1.getProperties().get("_attachments"); Assert.assertEquals(attachmentDict, gotAttachmentDict); // Check the attachment dict, with attachments included: innerDict.remove("stub"); innerDict.put("data", Base64.encodeBytes(attach1)); attachmentDictForSequence = database.getAttachmentsDictForSequenceWithContent(rev1.getSequence(), EnumSet.of(Database.TDContentOptions.TDIncludeAttachments)); Assert.assertEquals(attachmentDict, attachmentDictForSequence); gotRev1 = database.getDocumentWithIDAndRev(rev1.getDocId(), rev1.getRevId(), EnumSet.of(Database.TDContentOptions.TDIncludeAttachments)); gotAttachmentDict = (Map<String, Object>) gotRev1.getProperties().get("_attachments"); Assert.assertEquals(attachmentDict, gotAttachmentDict); // Add a second revision that doesn't update the attachment: Map<String, Object> rev2Properties = new HashMap<String, Object>(); rev2Properties.put("_id", rev1.getDocId()); rev2Properties.put("foo", 2); rev2Properties.put("bazz", false); RevisionInternal rev2 = database.putRevision(new RevisionInternal(rev2Properties, database), rev1.getRevId(), false, status); Assert.assertEquals(Status.CREATED, status.getCode()); database.copyAttachmentNamedFromSequenceToSequence(testAttachmentName, rev1.getSequence(), rev2.getSequence()); // Add a third revision of the same document: Map<String, Object> rev3Properties = new HashMap<String, Object>(); rev3Properties.put("_id", rev2.getDocId()); rev3Properties.put("foo", 2); rev3Properties.put("bazz", false); RevisionInternal rev3 = database.putRevision(new RevisionInternal(rev3Properties, database), rev2.getRevId(), false, status); Assert.assertEquals(Status.CREATED, status.getCode()); byte[] attach2 = "<html>And this is attach2</html>".getBytes(); database.insertAttachmentForSequenceWithNameAndType(new ByteArrayInputStream(attach2), rev3.getSequence(), testAttachmentName, "text/html", rev2.getGeneration()); // Check the 2nd revision's attachment: Attachment attachment2 = database.getAttachmentForSequence(rev2.getSequence(), testAttachmentName); Assert.assertEquals("text/plain", attachment2.getContentType()); InputStream is2 = attachment2.getContent(); data = IOUtils.toByteArray(is2); is2.close(); Assert.assertTrue(Arrays.equals(attach1, data)); // Check the 3rd revision's attachment: Attachment attachment3 = database.getAttachmentForSequence(rev3.getSequence(), testAttachmentName); Assert.assertEquals("text/html", attachment3.getContentType()); InputStream is3 = attachment3.getContent(); data = IOUtils.toByteArray(is3); is3.close(); Assert.assertTrue(Arrays.equals(attach2, data)); Map<String, Object> attachmentDictForRev3 = (Map<String, Object>) database .getAttachmentsDictForSequenceWithContent(rev3.getSequence(), EnumSet.noneOf(Database.TDContentOptions.class)) .get(testAttachmentName); if (attachmentDictForRev3.containsKey("follows")) { if (((Boolean) attachmentDictForRev3.get("follows")).booleanValue() == true) { throw new RuntimeException("Did not expected attachment dict 'follows' key to be true"); } else { throw new RuntimeException("Did not expected attachment dict to have 'follows' key"); } } // Examine the attachment store: Assert.assertEquals(2, attachments.count()); Set<BlobKey> expected = new HashSet<BlobKey>(); expected.add(BlobStore.keyForBlob(attach1)); expected.add(BlobStore.keyForBlob(attach2)); Assert.assertEquals(expected, attachments.allKeys()); database.compact(); // This clears the body of the first revision Assert.assertEquals(1, attachments.count()); Set<BlobKey> expected2 = new HashSet<BlobKey>(); expected2.add(BlobStore.keyForBlob(attach2)); Assert.assertEquals(expected2, attachments.allKeys()); }
From source file:com.cloudera.impala.security.DelegationTokenTest.java
private void testTokenManager(boolean useZK) throws IOException { String userName = UserGroupInformation.getCurrentUser().getUserName(); Configuration config = new Configuration(); ZooKeeperSession zk = null;/*from w w w .j av a 2 s.c om*/ if (useZK) { config.set(ZooKeeperSession.ZOOKEEPER_CONNECTION_STRING_CONF, ZOOKEEPER_HOSTPORT); config.set(ZooKeeperSession.ZOOKEEPER_STORE_ACL_CONF, ZOOKEEPER_ACL); zk = new ZooKeeperSession(config, "test", 1, 1); } DelegationTokenManager mgr = new DelegationTokenManager(config, true, zk); // Create two tokens byte[] token1 = mgr.getToken(userName, userName, userName).token; byte[] token2 = mgr.getToken(userName, userName, null).token; // Retrieve the passwords by token. Although the token contains the // password, this retrieves it using just the identifier. byte[] password1 = mgr.getPasswordByToken(token1); byte[] password2 = mgr.getPasswordByToken(token2); // Make sure it matches the password in token and doesn't match the password for // the other token. Token<DelegationTokenIdentifier> t1 = new Token<DelegationTokenIdentifier>(); t1.decodeFromUrlString(new String(token1)); assertTrue(Arrays.equals(t1.getPassword(), password1)); assertFalse(Arrays.equals(t1.getPassword(), password2)); // Get the password from just the identifier. This does not contain the password // but the server stores it. DelegationTokenIdentifier id1 = new DelegationTokenIdentifier(); id1.readFields(new DataInputStream(new ByteArrayInputStream(t1.getIdentifier()))); byte[] serializedId1 = Base64.encodeBase64(id1.serialize()); assertTrue(serializedId1.length < token1.length); // Retrieve the password from the manager by serialized id. DelegationTokenManager.UserPassword userPw = mgr.retrieveUserPassword(new String(serializedId1)); assertTrue(Arrays.equals(password1, Base64.decodeBase64(userPw.password))); assertEquals(userName, userPw.user); // Cancel token2, token1 should continue to work fine. mgr.cancelToken(userName, token2); assertTrue(Arrays.equals(mgr.getPasswordByToken(token1), password1)); // Renew token1, should continue to work. mgr.renewToken(userName, token1); assertTrue(Arrays.equals(mgr.getPasswordByToken(token1), password1)); // Cancel token1, should fail to get password for it. mgr.cancelToken(userName, token1); boolean exceptionThrown = false; try { mgr.getPasswordByToken(token1); } catch (IOException e) { exceptionThrown = true; assertTrue(e.getMessage().contains("can't be found")); } catch (TokenStoreException e) { exceptionThrown = true; assertTrue(e.getMessage(), e.getMessage().contains("Token does not exist")); } assertTrue(exceptionThrown); // Try to renew. exceptionThrown = false; try { mgr.renewToken(userName, token1); } catch (IOException e) { exceptionThrown = true; assertTrue(e.getMessage().contains("Renewal request for unknown token")); } catch (TokenStoreException e) { exceptionThrown = true; assertTrue(e.getMessage(), e.getMessage().contains("Token does not exist")); } assertTrue(exceptionThrown); // Try to cancel. try { mgr.cancelToken(userName, token1); } catch (IOException e) { // Depending on the underlying store (ZK vs in mem), we will throw an exception // or silently fail. Having cancel be idempotent is reasonable and the ZK // behavior. assertTrue(e.getMessage().contains("Token not found")); } // Try a corrupt token. exceptionThrown = false; try { mgr.cancelToken(userName, new byte[100]); } catch (IOException e) { exceptionThrown = true; assertTrue(e.getMessage().contains("Token is corrupt.")); } assertTrue(exceptionThrown); }
From source file:com.senseidb.search.req.SenseiResult.java
private boolean senseiHitsAreEqual(SenseiHit[] a, SenseiHit[] b) { if (a == null) return b == null; if (a.length != b.length) return false; for (int i = 0; i < a.length; i++) { if (a[i].getUID() != b[i].getUID()) return false; if (a[i].getDocid() != b[i].getDocid()) return false; if (a[i].getScore() != b[i].getScore()) return false; if (a[i].getGroupValue() == null || b[i].getGroupValue() == null) { if (!(a[i].getGroupValue() == null && b[i].getGroupValue() == null)) return false; } else {//from www .ja v a 2 s . co m if (!a[i].getGroupValue().equals(b[i].getGroupValue())) return false; } if (a[i].getRawGroupValue() == null || b[i].getRawGroupValue() == null) { if (!(a[i].getRawGroupValue() == null && b[i].getRawGroupValue() == null)) return false; } else { if (a[i].getRawGroupValue() instanceof long[]) { if (!(b[i].getRawGroupValue() instanceof long[] && Arrays.equals((long[]) a[i].getRawGroupValue(), (long[]) b[i].getRawGroupValue()))) return false; } else if (!a[i].getRawGroupValue().equals(b[i].getRawGroupValue())) { return false; } } if (a[i].getGroupHitsCount() != b[i].getGroupHitsCount()) return false; if (!senseiHitsAreEqual(a[i].getSenseiGroupHits(), b[i].getSenseiGroupHits())) return false; if (!explanationsAreEqual(a[i].getExplanation(), b[i].getExplanation())) return false; if (!storedFieldsAreEqual(a[i].getStoredFields(), b[i].getStoredFields())) return false; if (!fieldValuesAreEqual(a[i].getFieldValues(), b[i].getFieldValues())) return false; if (!rawFieldValuesAreEqual(a[i].getRawFieldValues(), b[i].getRawFieldValues())) return false; } return true; }