List of usage examples for java.util Arrays equals
public static boolean equals(Object[] a, Object[] a2)
From source file:com.gliffy.restunit.comparator.StrictMatchComparator.java
/** Compares the two bodies, requiring an exact match. * @param expectedBody the body expected, may be null * @param expectedContentType the content type expected by the test, or null if it wasn't specified * @param receivedBody the body received, may be null * @param receivedContentType the content type received in the response, or null if it wasn't specified * @return a successful match if both bodies are byte-for-byte matches. a null body * and an empty body (0-length array) are considered equal. Note that if the content type expected is a text-based * type the message included in the ComparisonResult will attempt to render both bits of data as strings, for purposes of * indicating the difference. This will be done using the encoding's specified, or the default encoding if none is specified. *///from w w w . j a va2 s. co m protected ComparisonResult compareBodies(byte[] expectedBody, ContentType expectedContentType, byte[] receivedBody, ContentType receivedContentType) { if (Arrays.equals(normalize(expectedBody), normalize(receivedBody))) { return ComparisonResult.MATCHES; } else { String diffMessage = createDiffMessage(normalize(expectedBody), expectedContentType, normalize(receivedBody), receivedContentType); return new ComparisonResult(false, diffMessage); } }
From source file:edu.wisc.doit.tcrypt.BouncyCastleTokenDecrypter.java
@Override public String decrypt(String ciphertext) throws InvalidCipherTextException { final Matcher tokenMatcher = TOKEN_PATTERN.matcher(ciphertext); if (tokenMatcher.matches()) { ciphertext = tokenMatcher.group(1); } else {//from w w w.j a va2s.c om final Matcher base64Matcher = BASE64_PATTERN.matcher(ciphertext); if (!base64Matcher.matches()) { throw new IllegalArgumentException("Specified ciphertext is not valid"); } } //Decode the cipher text final byte[] encryptedTokenWithHash = Base64.decodeBase64(ciphertext); final AsymmetricBlockCipher e = getDecryptCipher(); final byte[] tokenWithHashBytes = e.processBlock(encryptedTokenWithHash, 0, encryptedTokenWithHash.length); //Split the decrypted text into the password and the hash final String tokenWithHash = new String(tokenWithHashBytes, BouncyCastleTokenEncrypter.CHARSET); final int seperatorIndex = tokenWithHash.lastIndexOf(BouncyCastleTokenEncrypter.SEPARATOR); if (seperatorIndex < 0) { throw new IllegalArgumentException( "token/hash string doesn't contain seperator: " + BouncyCastleTokenEncrypter.SEPARATOR); } final byte[] passwordBytes = tokenWithHash.substring(0, seperatorIndex) .getBytes(BouncyCastleTokenEncrypter.CHARSET); final byte[] passwordHashBytes = Base64.decodeBase64( tokenWithHash.substring(seperatorIndex + 1).getBytes(BouncyCastleTokenEncrypter.CHARSET)); //Generate hash of the decrypted password final GeneralDigest digest = this.createDigester(); digest.update(passwordBytes, 0, passwordBytes.length); final byte[] expectedHashBytes = new byte[digest.getDigestSize()]; digest.doFinal(expectedHashBytes, 0); //Verify the generated hash against the decrypted hash if (!Arrays.equals(expectedHashBytes, passwordHashBytes)) { throw new IllegalArgumentException("Hash of the decrypted token does not match the decrypted hash"); } return new String(passwordBytes, BouncyCastleTokenEncrypter.CHARSET); }
From source file:com.opengamma.analytics.math.interpolation.data.RadialBasisFunctionInterpolatorDataBundle.java
@Override public boolean equals(final Object obj) { if (this == obj) { return true; }/* w w w . j a v a 2 s . c om*/ if (!super.equals(obj)) { return false; } if (!(obj instanceof RadialBasisFunctionInterpolatorDataBundle)) { return false; } final RadialBasisFunctionInterpolatorDataBundle other = (RadialBasisFunctionInterpolatorDataBundle) obj; if (_useNormalized != other._useNormalized) { return false; } if (!Arrays.equals(_weights, other._weights)) { return false; } if (!ObjectUtils.equals(_basisFunction, other._basisFunction)) { return false; } if (!ObjectUtils.equals(_decomp, other._decomp)) { return false; } if (!ObjectUtils.equals(_decompRes, other._decompRes)) { return false; } return true; }
From source file:com.opengamma.analytics.financial.interestrate.swaption.derivative.SwaptionBermudaFixedIbor.java
@Override public boolean equals(Object obj) { if (this == obj) { return true; }/*from ww w .j a va 2s . c om*/ if (obj == null) { return false; } if (getClass() != obj.getClass()) { return false; } SwaptionBermudaFixedIbor other = (SwaptionBermudaFixedIbor) obj; if (!Arrays.equals(_expiryTime, other._expiryTime)) { return false; } if (_isLong != other._isLong) { return false; } if (!Arrays.equals(_settlementTime, other._settlementTime)) { return false; } if (!Arrays.equals(_underlyingSwap, other._underlyingSwap)) { return false; } return true; }
From source file:com.projity.util.ArrayUtils.java
/** * Tests two double arrays for equality. * /* w w w. j a v a 2 s .c o m*/ * @param array1 the first array. * @param array2 the second arrray. * * @return A boolean. */ public static boolean equal(final double[][] array1, final double[][] array2) { if (array1 == null) { return (array2 == null); } if (array2 == null) { return false; } if (array1.length != array2.length) { return false; } for (int i = 0; i < array1.length; i++) { if (!Arrays.equals(array1[i], array2[i])) { return false; } } return true; }
From source file:com.github.rholder.esthree.command.GetMultipart.java
@Override public Integer call() throws Exception { ObjectMetadata om = amazonS3Client.getObjectMetadata(bucket, key); contentLength = om.getContentLength(); // this is the most up to date digest, it's initialized here but later holds the most up to date valid digest currentDigest = MessageDigest.getInstance("MD5"); chunkSize = chunkSize == null ? DEFAULT_CHUNK_SIZE : chunkSize; fileParts = Parts.among(contentLength, chunkSize); for (Part fp : fileParts) { /*//from www .j a va2 s . c o m * We'll need to compute the digest on the full incoming stream for * each valid chunk that comes in. Invalid chunks will need to be * recomputed and fed through a copy of the MD5 that was valid up * until the latest chunk. */ currentDigest = retryingGetWithRange(fp.start, fp.end); } // TODO fix total content length progress bar if (progressListener != null) { progressListener.progressChanged(new ProgressEvent(ProgressEventType.TRANSFER_STARTED_EVENT)); } String fullETag = om.getETag(); if (!fullETag.contains("-")) { byte[] expected = BinaryUtils.fromHex(fullETag); byte[] current = currentDigest.digest(); if (!Arrays.equals(expected, current)) { throw new AmazonClientException("Unable to verify integrity of data download. " + "Client calculated content hash didn't match hash calculated by Amazon S3. " + "The data may be corrupt."); } } else { // TODO log warning that we can't validate the MD5 if (verbose) { System.err.println("\nMD5 does not exist on AWS for file, calculated value: " + BinaryUtils.toHex(currentDigest.digest())); } } // TODO add ability to resume from previously downloaded chunks // TODO add rate limiter return 0; }
From source file:org.opensafety.hishare.managers.implementation.http.ParcelManagerImpl.java
public boolean verifyParcelAvailable(String parcelId, String parcelPassword) { if (parcelDao.verifyParcelAvailable(parcelId)) { Parcel parcel = parcelDao.getById(parcelId); if (parcel == null) { return false; }//from w w w.j a v a 2 s . c o m if (notExpired(parcel)) { try { byte[] hashedPassword = encryption.hashPassword(parcelPassword, parcel.getSalt()); return Arrays.equals(hashedPassword, parcel.getHashedPassword()); } catch (CryptographyException e) { log.error("Password Matching Threw Exception!", e); return false; } } } return false; }
From source file:com.netflix.imfutility.itunes.image.ImageValidator.java
private static boolean checkBytes(File file, byte[] start, byte[] end) throws IOException { RandomAccessFile randomAccessFile = new RandomAccessFile(file, "r"); byte[] destStart = new byte[start.length]; if (start.length != 0) { int res = randomAccessFile.read(destStart, 0, start.length); if (res == -1) { return false; }/* w ww . j a va2s.c o m*/ } byte[] destEnd = new byte[end.length]; if (end.length != 0) { randomAccessFile.seek(file.length() - end.length); int res = randomAccessFile.read(destEnd, 0, end.length); if (res == -1) { return false; } } return Arrays.equals(start, destStart) && Arrays.equals(end, destEnd); }
From source file:com.palantir.atlasdb.keyvalue.impl.RowResults.java
public static <T> RowResult<T> merge(RowResult<T> base, RowResult<T> overwrite) { Validate.isTrue(Arrays.equals(base.getRowName(), overwrite.getRowName())); Builder<byte[], T> colBuilder = ImmutableSortedMap.orderedBy(UnsignedBytes.lexicographicalComparator()); colBuilder.putAll(overwrite.getColumns()); colBuilder.putAll(Maps.difference(base.getColumns(), overwrite.getColumns()).entriesOnlyOnLeft()); return RowResult.create(base.getRowName(), colBuilder.build()); }
From source file:com.tresys.jalop.utils.jnltest.Config.ConfigTest.java
@Test public void createFromJsonReturnsValidConfigWithPublisher() throws Exception { jsonCfg.put("publisher", pub); Config cfg = Config.createFromJson("path/to/nothing", jsonCfg); assertNotNull(cfg);//from www . jav a2s.c o m assertEquals("path/to/nothing", cfg.getSource()); assertTrue(Arrays.equals(new byte[] { 127, 0, 0, 1 }, cfg.getAddress().getAddress())); assertEquals(-1, cfg.getPendingDigestMax()); assertEquals(-1, cfg.getPendingDigestTimeout()); assertEquals(1234, cfg.getPort()); assertNotNull(cfg.getPeerConfigs()); assertTrue(cfg.getPeerConfigs().isEmpty()); assertEquals(new File("./input").getPath(), cfg.getInputPath().getPath()); assertEquals(new SimpleDateFormat("hh:mm:ss").parse("00:00:00"), cfg.getSessionTimeout()); }