List of usage examples for java.util Arrays equals
public static boolean equals(Object[] a, Object[] a2)
From source file:com.bah.lucene.hdfs.BlurLockFactory.java
@Override public Lock makeLock(String lockName) { final Path lockPath = new Path(_dir, lockName); return new Lock() { private boolean _set; @Override//from w ww .j a v a 2 s . c om public boolean obtain() throws IOException { if (_set) { throw new IOException("Lock for [" + _baseLockKey + "] can only be set once."); } try { _lockKey = (_baseLockKey + "/" + System.currentTimeMillis()).getBytes(); FSDataOutputStream outputStream = _fileSystem.create(lockPath, true); outputStream.write(_lockKey); outputStream.close(); } finally { _set = true; } return true; } @Override public void release() throws IOException { _fileSystem.delete(lockPath, false); } @Override public boolean isLocked() throws IOException { if (!_set) { LOG.info("The lock has NOT been set."); return false; } if (!_fileSystem.exists(lockPath)) { LOG.info("The lock file has been removed."); return false; } FileStatus fileStatus = _fileSystem.getFileStatus(lockPath); long len = fileStatus.getLen(); if (len != _lockKey.length) { LOG.info("The lock file length has changed."); return false; } byte[] buf = new byte[_lockKey.length]; FSDataInputStream inputStream = _fileSystem.open(lockPath); inputStream.readFully(buf); inputStream.close(); if (Arrays.equals(_lockKey, buf)) { return true; } LOG.info("The lock information has been changed."); return false; } }; }
From source file:com.analog.lyric.dimple.solvers.core.parameterizedMessages.DirichletParameters.java
@Override public boolean objectEquals(@Nullable Object other) { if (other == this) { return true; }//from w ww . j av a 2 s. co m if (other instanceof DirichletParameters) { DirichletParameters that = (DirichletParameters) other; return super.objectEquals(other) && Arrays.equals(_alphaMinusOne, that._alphaMinusOne); } return false; }
From source file:org.springframework.social.facebook.web.SignedRequestDecoder.java
/** * Decodes a signed request, returning the payload of the signed request as a specified type. * @param signedRequest the value of the signed_request parameter sent by Facebook. * @param type the type to bind the signed_request to. * @param <T> the Java type to bind the signed_request to. * @return the payload of the signed request as an object * @throws SignedRequestException if there is an error decoding the signed request *///from w w w. java2s .co m public <T> T decodeSignedRequest(String signedRequest, Class<T> type) throws SignedRequestException { String[] split = signedRequest.split("\\."); String encodedSignature = split[0]; String payload = split[1]; String decoded = base64DecodeToString(payload); byte[] signature = base64DecodeToBytes(encodedSignature); try { T data = objectMapper.readValue(decoded, type); String algorithm = objectMapper.readTree(decoded).get("algorithm").textValue(); if (algorithm == null || !algorithm.equals("HMAC-SHA256")) { throw new SignedRequestException("Unknown encryption algorithm: " + algorithm); } byte[] expectedSignature = encrypt(payload, secret); if (!Arrays.equals(expectedSignature, signature)) { throw new SignedRequestException("Invalid signature."); } return data; } catch (IOException e) { throw new SignedRequestException("Error parsing payload.", e); } }
From source file:edu.stanford.muse.datacache.Blob.java
/** a blob is the same as another one if it has the same name, and the same content hash */ public boolean equals(Object o) { if (!(o instanceof Blob)) return false; Blob b = (Blob) o;/*from www . jav a 2 s .com*/ // return (b.filename != this.filename && Util.byteArrayToHexString(b.contentHash).equals(Util.byteArrayToHexString(this.contentHash)) && b.size == this.size); // return (b.filename != this.filename && b.size == this.size); if (this.contentHash == null || b.contentHash == null) return false; if (this.filename == null || b.filename == null) return false; if (!this.filename.equals(b.filename)) return false; return (Arrays.equals(b.contentHash, this.contentHash)); }
From source file:com.splicemachine.pipeline.constraint.ConstraintContext.java
@Override public boolean equals(Object o) { return (this == o) || (o instanceof ConstraintContext) && Arrays.equals(this.messageArgs, ((ConstraintContext) o).messageArgs); }
From source file:com.relicum.ipsum.Reflection.ReflectionUtil.java
/** * Gets a {@link Method} in a given {@link Class} object with the specified * arguments.//from w w w .j a va 2s . c o m * * @param clazz Class object * @param name Method name * @param args Arguments * @return The method, or null if none exists */ public static final Method getMethod(Class<?> clazz, String name, Class<?>... args) { Validate.notNull(clazz, "clazz cannot be null!"); Validate.notNull(name, "name cannot be null!"); if (args == null) args = new Class<?>[0]; for (Method method : clazz.getMethods()) { if (method.getName().equals(name) && Arrays.equals(args, method.getParameterTypes())) return method; } return null; }
From source file:com.github.aelstad.keccakj.fips202.KeccakDigestTestUtils.java
public void runTests(List<DigestTest> tests, AbstractKeccakMessageDigest messageDigest, int digestLength) throws Exception { for (DigestTest dt : tests) { messageDigest.reset();//from w ww .j a va 2 s . co m if ((dt.len & 7) == 0) messageDigest.update(dt.msg, 0, dt.len >> 3); else messageDigest.engineUpdateBits(dt.msg, 0, dt.len); System.out.println("Rate is now " + new String( Hex.encodeHex(messageDigest.getRateBits(0, Math.min(dt.len, messageDigest.getRateBits()))))); byte[] md = messageDigest.digest(); System.out.println("Testing length " + dt.len + ". Got " + new String(Hex.encodeHex(md))); Assert.assertTrue(digestLength == dt.digest.length); ; Assert.assertTrue(digestLength == md.length); ; org.junit.Assert.assertTrue(Arrays.equals(md, dt.digest)); } testPerformance(messageDigest); }
From source file:web.org.perfmon4j.restdatasource.data.Field.java
@Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; Field other = (Field) obj; if (!Arrays.equals(aggregationMethods, other.aggregationMethods)) return false; if (defaultAggregationMethod != other.defaultAggregationMethod) return false; if (name == null) { if (other.name != null) return false; } else if (!name.equals(other.name)) return false; if (primary != other.primary) return false; return true;/*from w ww . j a v a 2s. com*/ }
From source file:ly.count.android.api.CountlyStoreTests.java
public void testEvents_prefIsNull() { // the clear() call in setUp ensures the pref is not present assertTrue(Arrays.equals(new String[0], store.events())); }
From source file:org.opencastproject.remotetest.server.WorkingFileRepoRestEndpointTest.java
@Test public void testPutAndGetFile() throws Exception { // Store a file in the repository String mediapackageId = "123"; String elementId = "456"; byte[] bytesFromPost = IOUtils .toByteArray(getClass().getClassLoader().getResourceAsStream("opencast_header.gif")); InputStream in = getClass().getClassLoader().getResourceAsStream("opencast_header.gif"); String fileName = "our_logo.gif"; // Used to simulate a file upload MultipartEntity postEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE); postEntity.addPart("file", new InputStreamBody(in, fileName)); HttpPost post = new HttpPost(BASE_URL + "/files/mediapackage/" + mediapackageId + "/" + elementId); post.setEntity(postEntity);/*from w w w . j a va 2s. com*/ HttpResponse response = client.execute(post); HttpEntity responseEntity = response.getEntity(); String stringResponse = EntityUtils.toString(responseEntity); String expectedResponse = BASE_URL + "/files/mediapackage/" + mediapackageId + "/" + elementId + "/" + fileName; Assert.assertEquals(expectedResponse, stringResponse); // Get the file back from the repository HttpGet get = new HttpGet(BASE_URL + "/files/mediapackage/" + mediapackageId + "/" + elementId); HttpResponse getResponse = client.execute(get); byte[] bytesFromGet = IOUtils.toByteArray(getResponse.getEntity().getContent()); // Ensure that the bytes that we posted are the same we received Assert.assertTrue(Arrays.equals(bytesFromGet, bytesFromPost)); }