List of usage examples for java.util Arrays equals
public static boolean equals(Object[] a, Object[] a2)
From source file:org.hibernate.ogm.datastore.redis.impl.Base64ByteArrayTypeDescriptor.java
@Override public boolean areEqual(byte[] one, byte[] another) { return one == another || (one != null && another != null && Arrays.equals(one, another)); }
From source file:acmi.l2.clientmod.l2_version_switcher.Util.java
public static boolean hashEquals(File file, String hashString) throws IOException { try {// w w w. j a va 2 s. c om MessageDigest md = MessageDigest.getInstance("sha-1"); try (FileInputStream hashBytes = new FileInputStream(file)) { DigestInputStream dis = new DigestInputStream(hashBytes, md); IOUtils.copy(dis, NullOutputStream.NULL_OUTPUT_STREAM); } byte[] hash = md.digest(); return Arrays.equals(hash, parseHexBinary(hashString)); } catch (NoSuchAlgorithmException e) { throw new RuntimeException(e); } }
From source file:com.joyent.manta.http.entity.DigestedEntityTest.java
public void testWriteToProducesReliableDigest() throws Exception { String content = STRING_GENERATOR.generate(100); DigestedEntity entity = new DigestedEntity(new ExposedStringEntity(content, StandardCharsets.UTF_8), new FastMD5Digest()); ByteArrayOutputStream out = new ByteArrayOutputStream(); entity.writeTo(out);//w w w .ja v a2 s .com byte[] initialDigest = entity.getDigest(); // connection reset, httpclient performs a retry reusing the same entity out.reset(); entity.writeTo(out); byte[] retryDigest = entity.getDigest(); Assert.assertTrue(Arrays.equals(initialDigest, retryDigest), "Reuse of DigestedEntity produced differing digest for first retry"); // connection reset again out.reset(); entity.writeTo(out); byte[] extraRetryDigest = entity.getDigest(); Assert.assertTrue(Arrays.equals(initialDigest, extraRetryDigest), "Reuse of DigestedEntity produced differing digest for second retry"); }
From source file:Main.java
@TargetApi(Build.VERSION_CODES.GINGERBREAD) public static void setBestPreviewFPS(Camera.Parameters parameters, int minFPS, int maxFPS) { List<int[]> supportedPreviewFpsRanges = parameters.getSupportedPreviewFpsRange(); Log.i(TAG, "Supported FPS ranges: " + toString(supportedPreviewFpsRanges)); if (supportedPreviewFpsRanges != null && !supportedPreviewFpsRanges.isEmpty()) { int[] suitableFPSRange = null; for (int[] fpsRange : supportedPreviewFpsRanges) { int thisMin = fpsRange[Camera.Parameters.PREVIEW_FPS_MIN_INDEX]; int thisMax = fpsRange[Camera.Parameters.PREVIEW_FPS_MAX_INDEX]; if (thisMin >= minFPS * 1000 && thisMax <= maxFPS * 1000) { suitableFPSRange = fpsRange; break; }/* www .j a v a 2s .c o m*/ } if (suitableFPSRange == null) { Log.i(TAG, "No suitable FPS range?"); } else { int[] currentFpsRange = new int[2]; parameters.getPreviewFpsRange(currentFpsRange); if (Arrays.equals(currentFpsRange, suitableFPSRange)) { Log.i(TAG, "FPS range already set to " + Arrays.toString(suitableFPSRange)); } else { Log.i(TAG, "Setting FPS range to " + Arrays.toString(suitableFPSRange)); parameters.setPreviewFpsRange(suitableFPSRange[Camera.Parameters.PREVIEW_FPS_MIN_INDEX], suitableFPSRange[Camera.Parameters.PREVIEW_FPS_MAX_INDEX]); } } } }
From source file:com.yahoo.gondola.container.impl.ZookeeperConfigProviderTest.java
@Test public void testGetConfigFile() throws Exception { File configFile = configProvider.getConfigFile(); assertTrue(Arrays.equals(IOUtils.toByteArray(configFile.toURI()), IOUtils.toByteArray(file))); }
From source file:ru.mystamps.web.validation.jsr303.ImageFileValidator.java
private static boolean doesItLookLikePng(byte[] bytes) { return Arrays.equals(bytes, PNG_FIRST_PART_SIGNATURE); }
From source file:legendarena.api.fanciful.ArrayWrapper.java
/** * Determines if this object has a value equivalent to another object. * @see Arrays#equals(Object[], Object[]) *//*ww w .ja v a 2 s. c om*/ @SuppressWarnings("rawtypes") @Override public boolean equals(Object other) { return other instanceof ArrayWrapper && Arrays.equals(_array, ((ArrayWrapper) other)._array); }
From source file:com.talis.storage.s3.ExternalizableS3ObjectTest.java
public static void assertObjectsEqual(S3Object first, S3Object second) { try {/*from www . j a v a 2 s . c o m*/ ByteArrayOutputStream b0 = new ByteArrayOutputStream(); IOUtils.copy(first.getDataInputStream(), b0); ByteArrayOutputStream b1 = new ByteArrayOutputStream(); IOUtils.copy(first.getDataInputStream(), b1); assertTrue(Arrays.equals(b0.toByteArray(), b1.toByteArray())); } catch (Exception e) { fail("Caught an Exception when reading entity bytes"); } assertEquals(first.getContentType(), second.getContentType()); assertEquals(first.getKey(), second.getKey()); assertEquals(first.getBucketName(), second.getBucketName()); assertEquals(first.getAcl(), second.getAcl()); assertEquals(first.isMetadataComplete(), second.isMetadataComplete()); assertEquals(first.getMetadataMap(), second.getMetadataMap()); }
From source file:com.amazonaws.services.s3.internal.MD5DigestCalculatingInputStreamTest.java
@Test public void test() throws Exception { byte[] data = "0123456789abcdefghijklmnopqrstuvwxyz!@#$%^&*()_+-=".getBytes(StringUtils.UTF8); byte[] md5Expected = Md5Utils.computeMD5Hash(data); byte[] baExpected; {/*from w ww . j a v a2 s .c om*/ MD5DigestCalculatingInputStream is = new MD5DigestCalculatingInputStream( new ByteArrayInputStream(data)); baExpected = IOUtils.toByteArray(is); byte[] md5 = is.getMd5Digest(); assertTrue(Arrays.equals(md5Expected, md5)); } { MD5DigestCalculatingInputStream is = new MD5DigestCalculatingInputStream( new ByteArrayInputStream(data)); is.mark(-1); baExpected = IOUtils.toByteArray(is); byte[] md5 = is.getMd5Digest(); assertTrue(Arrays.equals(md5Expected, md5)); is.reset(); byte[] ba = IOUtils.toByteArray(is); byte[] md5_2 = is.getMd5Digest(); assertTrue(Arrays.equals(md5Expected, md5_2)); assertTrue(Arrays.equals(baExpected, ba)); } { MD5DigestCalculatingInputStream is = new MD5DigestCalculatingInputStream( new ByteArrayInputStream(data)); is.mark(-1); is.read(new byte[10]); is.reset(); byte[] ba = IOUtils.toByteArray(is); if (DEBUG) System.out.println("ba.length: " + ba.length); assertTrue(Arrays.equals(baExpected, ba)); byte[] md5 = is.getMd5Digest(); assertTrue(Arrays.equals(md5Expected, md5)); } { MD5DigestCalculatingInputStream is = new MD5DigestCalculatingInputStream( new ByteArrayInputStream(data)); is.mark(-1); is.read(new byte[10]); is.mark(-1); is.read(new byte[10]); is.reset(); byte[] ba = IOUtils.toByteArray(is); if (DEBUG) System.out.println("ba.length: " + ba.length); assertFalse(Arrays.equals(baExpected, ba)); byte[] md5 = is.getMd5Digest(); assertTrue(Arrays.equals(md5Expected, md5)); } { MD5DigestCalculatingInputStream is = new MD5DigestCalculatingInputStream( new ByteArrayInputStream(data)); is.read(new byte[10]); is.mark(-1); is.read(new byte[10]); is.reset(); is.read(new byte[10]); is.mark(-1); is.read(); is.reset(); byte[] ba = IOUtils.toByteArray(is); if (DEBUG) System.out.println("ba.length: " + ba.length); assertFalse(Arrays.equals(baExpected, ba)); byte[] md5 = is.getMd5Digest(); assertTrue(Arrays.equals(md5Expected, md5)); } }
From source file:com.delphix.session.impl.frame.SessionHandle.java
@Override public boolean equals(Object obj) { if (obj == null) { return false; }//from w ww .j a va 2 s .c o m if (!(obj instanceof SessionHandle)) { return false; } SessionHandle handle = (SessionHandle) obj; return Arrays.equals(this.handle, handle.handle); }