List of usage examples for java.util Arrays equals
public static boolean equals(Object[] a, Object[] a2)
From source file:com.navercorp.pinpoint.profiler.sender.UdpDataSender.java
public boolean isNetworkAvailable() { final NetworkAvailabilityCheckPacket dto = new NetworkAvailabilityCheckPacket(); try {//from w w w . j av a 2s . co m final byte[] interBufferData = serialize(serializer, dto); final int interBufferSize = serializer.getInterBufferSize(); reusePacket.setData(interBufferData, 0, interBufferSize); udpSocket.send(reusePacket); if (logger.isInfoEnabled()) { logger.info("Data sent. {}", dto); } final byte[] receiveData = new byte[NetworkAvailabilityCheckPacket.DATA_OK.length]; final DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length); udpSocket.receive(receivePacket); if (logger.isInfoEnabled()) { logger.info("Data received. {}", Arrays.toString(receivePacket.getData())); } return Arrays.equals(NetworkAvailabilityCheckPacket.DATA_OK, receiveData); } catch (IOException e) { logger.warn("packet send error {}", dto, e); return false; } }
From source file:com.mastfrog.acteur.util.PasswordHasher.java
License:asdf
/** * Check an unhashed password against a stored, hashed one * * @param unhashed The unhashed password * @param hashed//ww w.ja v a 2 s .c o m * @return */ public boolean checkPassword(String unhashed, String hashed) { try { String[] saltAndPassAndAlgorithm = findSalt(hashed); if (saltAndPassAndAlgorithm.length == 1) { // Backward compatibility byte[] bytes = hash(unhashed, algorithm); byte[] check = org.apache.commons.codec.binary.Base64.decodeBase64(hashed); // byte[] check = Base64.getDecoder().decode(hashed); return Arrays.equals(bytes, check); } if (saltAndPassAndAlgorithm.length != 3) { // Ensure a failed attempt takes the same amount of time encryptPassword("DaCuBYLAlxBbT6lTyatauRp2iXCsf9WGDi8a2SyWeFVsoxGBk3Y3l1l9IHie" + "+aVuOGQBD8mZlrhj8yGjl1ghjw==", "3J5pgcx0", algorithm); return false; } String enc = encryptPassword(unhashed, saltAndPassAndAlgorithm[1], decodeAlgorithm(saltAndPassAndAlgorithm[0])); return slowEquals(enc, hashed); } catch (NoSuchAlgorithmException ex) { return Exceptions.chuck(ex); } }
From source file:com.opengamma.analytics.math.linearalgebra.TridiagonalMatrix.java
@Override public boolean equals(final Object obj) { if (this == obj) { return true; }//from w ww . j a v a 2 s .co m if (obj == null) { return false; } if (getClass() != obj.getClass()) { return false; } final TridiagonalMatrix other = (TridiagonalMatrix) obj; if (!Arrays.equals(_a, other._a)) { return false; } if (!Arrays.equals(_b, other._b)) { return false; } if (!Arrays.equals(_c, other._c)) { return false; } return true; }
From source file:com.bitbreeds.webrtc.common.SignalUtilTest.java
@Test public void findIntegrity() throws DecoderException { String bytes = "000100502112a442e9dec49e8038338d00f9a79c0006001162323064306166343a623230643061663400000000250000002400046e7f00ff802a00081eb6ff2cf7589cd700080014020b27ff78fbd931427c9f4518b9f40d5415562e8028000473cf7c86"; String noFinger2 = "000100482112a442e9dec49e8038338d00f9a79c0006001162323064306166343a623230643061663400000000250000002400046e7f00ff802a00081eb6ff2cf7589cd7"; byte[] msg = Hex.decodeHex(noFinger2.toCharArray()); byte[] mac = Hex.decodeHex("020b27ff78fbd931427c9f4518b9f40d5415562e".toCharArray()); String password = "230f754083a9070aff5bd1ced7654a9c"; byte[] compMac = SignalUtil.hmacSha1(msg, password.getBytes()); System.out.println(Hex.encodeHexString(mac) + " " + Hex.encodeHexString(compMac)); assertTrue(Arrays.equals(mac, compMac)); }
From source file:com.couchbase.touchdb.testapp.tests.HeavyAttachments.java
@SuppressWarnings("unchecked") public void buildAttachments(boolean heavyAttachments, boolean pushAttachments) throws Exception { TDBlobStore attachments = database.getAttachments(); Assert.assertEquals(0, attachments.count()); Assert.assertEquals(new HashSet<Object>(), attachments.allKeys()); TDStatus status = new TDStatus(); Map<String, Object> rev1Properties = new HashMap<String, Object>(); rev1Properties.put("foo", 1); rev1Properties.put("bar", false); TDRevision rev1 = database.putRevision(new TDRevision(rev1Properties), null, false, status); Assert.assertEquals(TDStatus.CREATED, status.getCode()); byte[] attach1 = "This is the body of attach1".getBytes(); status = database.insertAttachmentForSequenceWithNameAndType(new ByteArrayInputStream(attach1), rev1.getSequence(), "attach", "text/plain", rev1.getGeneration()); Assert.assertEquals(TDStatus.CREATED, status.getCode()); TDAttachment attachment = database.getAttachmentForSequence(rev1.getSequence(), "attach", status); Assert.assertEquals(TDStatus.OK, status.getCode()); Assert.assertEquals("text/plain", attachment.getContentType()); byte[] data = IOUtils.toByteArray(attachment.getContentStream()); 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("attach", innerDict); Map<String, Object> attachmentDictForSequence = database .getAttachmentsDictForSequenceWithContent(rev1.getSequence(), false); Assert.assertEquals(attachmentDict, attachmentDictForSequence); TDRevision gotRev1 = database.getDocumentWithIDAndRev(rev1.getDocId(), rev1.getRevId(), EnumSet.noneOf(TDDatabase.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(), true); Assert.assertEquals(attachmentDict, attachmentDictForSequence); gotRev1 = database.getDocumentWithIDAndRev(rev1.getDocId(), rev1.getRevId(), EnumSet.of(TDDatabase.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); TDRevision rev2 = database.putRevision(new TDRevision(rev2Properties), rev1.getRevId(), false, status); Assert.assertEquals(TDStatus.CREATED, status.getCode()); status = database.copyAttachmentNamedFromSequenceToSequence("attach", rev1.getSequence(), rev2.getSequence());/*from w ww .jav a 2s . co m*/ Assert.assertEquals(TDStatus.OK, status.getCode()); // 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); TDRevision rev3 = database.putRevision(new TDRevision(rev3Properties), rev2.getRevId(), false, status); Assert.assertEquals(TDStatus.CREATED, status.getCode()); byte[] attach2 = "<html>And this is attach2</html>".getBytes(); status = database.insertAttachmentForSequenceWithNameAndType(new ByteArrayInputStream(attach2), rev3.getSequence(), "attach", "text/html", rev2.getGeneration()); Assert.assertEquals(TDStatus.CREATED, status.getCode()); // Check the 2nd revision's attachment: TDAttachment attachment2 = database.getAttachmentForSequence(rev2.getSequence(), "attach", status); Assert.assertEquals(TDStatus.OK, status.getCode()); Assert.assertEquals("text/plain", attachment2.getContentType()); data = IOUtils.toByteArray(attachment2.getContentStream()); Assert.assertTrue(Arrays.equals(attach1, data)); // Check the 3rd revision's attachment: TDAttachment attachment3 = database.getAttachmentForSequence(rev3.getSequence(), "attach", status); Assert.assertEquals(TDStatus.OK, status.getCode()); Assert.assertEquals("text/html", attachment3.getContentType()); data = IOUtils.toByteArray(attachment3.getContentStream()); Assert.assertTrue(Arrays.equals(attach2, data)); // Examine the attachment store: Assert.assertEquals(2, attachments.count()); Set<TDBlobKey> expected = new HashSet<TDBlobKey>(); expected.add(TDBlobStore.keyForBlob(attach1)); expected.add(TDBlobStore.keyForBlob(attach2)); Assert.assertEquals(expected, attachments.allKeys()); status = database.compact(); // This clears the body of the first revision Assert.assertEquals(TDStatus.OK, status.getCode()); Assert.assertEquals(1, attachments.count()); Set<TDBlobKey> expected2 = new HashSet<TDBlobKey>(); expected2.add(TDBlobStore.keyForBlob(attach2)); Assert.assertEquals(expected2, attachments.allKeys()); TDRevision lastRev = rev3; if (heavyAttachments) { int numberOfImagesOkayOn512Ram = 4; int numberOfImagesOkayOn768Ram = 6; int numberOfImagesOkayOn1024Ram = 8; lastRev = attachImages(numberOfImagesOkayOn1024Ram, rev3); /* query the db for that doc */ TDRevision largerRev = database.getDocumentWithIDAndRev(lastRev.getDocId(), lastRev.getRevId(), EnumSet.noneOf(TDDatabase.TDContentOptions.class)); attachmentDict = (Map<String, Object>) largerRev.getProperties().get("_attachments"); Assert.assertNotNull(attachmentDict); } if (pushAttachments) { URL remote = getReplicationURL(); deleteRemoteDB(remote); final TDReplicator repl = database.getReplicator(remote, true, false, server.getWorkExecutor()); ((TDPusher) repl).setCreateTarget(true); try { runTestOnUiThread(new Runnable() { @Override public void run() { // Push them to the remote: repl.start(); Assert.assertTrue(repl.isRunning()); } }); } catch (Throwable e) { e.printStackTrace(); } while (repl.isRunning()) { Log.i(TAG, "Waiting for replicator to finish"); Thread.sleep(1000); } /* Ensure that the last version of the doc is the last thing replicated. */ Assert.assertTrue(lastRev.getRevId().startsWith(repl.getLastSequence())); } }
From source file:com.google.dart.server.generated.types.TypeHierarchyItem.java
@Override public boolean equals(Object obj) { if (obj instanceof TypeHierarchyItem) { TypeHierarchyItem other = (TypeHierarchyItem) obj; return ObjectUtilities.equals(other.classElement, classElement) && ObjectUtilities.equals(other.displayName, displayName) && ObjectUtilities.equals(other.memberElement, memberElement) && ObjectUtilities.equals(other.superclass, superclass) && Arrays.equals(other.interfaces, interfaces) && Arrays.equals(other.mixins, mixins) && Arrays.equals(other.subclasses, subclasses); }// w w w . j a v a 2s. co m return false; }
From source file:io.kodokojo.service.redis.RedisUserStore.java
@Override public boolean addUser(User user) { if (user == null) { throw new IllegalArgumentException("user must be defined."); }/*from w w w. j a v a 2 s .com*/ ByteArrayOutputStream byteArray = new ByteArrayOutputStream(); try (ObjectOutputStream out = new ObjectOutputStream(byteArray); Jedis jedis = pool.getResource()) { if (jedis.get(RedisUtils.aggregateKey(USERNAME_PREFIX, user.getUsername())) == null) { byte[] previous = jedis.get(RedisUtils.aggregateKey(NEW_ID_PREFIX, user.getIdentifier())); if (Arrays.equals(previous, NEW_USER_CONTENT) && !jedis.exists(RedisUtils.aggregateKey(USER_PREFIX, user.getIdentifier()))) { byte[] password = RSAUtils.encryptWithAES(key, user.getPassword()); UserValue userValue = new UserValue(user, password); out.writeObject(userValue); jedis.set(RedisUtils.aggregateKey(USER_PREFIX, user.getIdentifier()), byteArray.toByteArray()); jedis.set(USERNAME_PREFIX + user.getUsername(), user.getIdentifier()); jedis.del((NEW_ID_PREFIX + user.getIdentifier()).getBytes()); return true; } } } catch (IOException e) { throw new RuntimeException("Unable to serialized UserValue.", e); } return false; }
From source file:io.uploader.drive.config.ConfigTest.java
@Test public void shouldUpdateHttpProxy() throws IOException { verifyProxy(Configuration.INSTANCE.getHttpProxySettings(), false, "host-http", 9000, "user-http", "password-http"); byte[] initFileContents = FileUtils.readFileToByteArray(configSettingFile); boolean activated = true; String host = "host.of.the.new.proxy"; String password = "the*new_password"; String username = "the new user name"; int port = 8567; Proxy newProxy = new Proxy.Builder("http").setActivated(activated).setHost(host).setPassword(password) .setUsername(username).setPort(port).build(); Configuration.INSTANCE.updateProxy(newProxy); verifyProxy(Configuration.INSTANCE.getHttpProxySettings(), activated, host, port, username, password); byte[] updatedFileContents = FileUtils.readFileToByteArray(configSettingFile); assertFalse(Arrays.equals(updatedFileContents, initFileContents)); }
From source file:com.microsoft.tfs.client.common.ui.compare.TFSItemContentComparator.java
/** * * @param hash1/*from w w w .j a v a 2 s.co m*/ * @param hash2 * @return */ private ContentComparisonResult compareByHash(final byte[] hash1, final byte[] hash2) { if (hash1 == null || hash2 == null) { return ContentComparisonResult.UNKNOWN; } return Arrays.equals(hash1, hash2) ? ContentComparisonResult.EQUAL : ContentComparisonResult.NOT_EQUAL; }
From source file:com.vmware.identity.saml.PrincipalAttribute.java
@Override public boolean equals(Object obj) { if (this == obj) { return true; }/* www . j a v a2s. com*/ if (obj == null || this.getClass() != obj.getClass()) { return false; } PrincipalAttribute other = (PrincipalAttribute) obj; return attributeDefinition.equals(other.getAttributeDefinition()) && ((values == null && other.values == null) || Arrays.equals(values, other.values)); }