List of usage examples for java.util Arrays equals
public static boolean equals(Object[] a, Object[] a2)
From source file:net.bluehornreader.model.User.java
public boolean checkPassword(String password) { try {// ww w . j a va 2s. c o m byte[] hash = computeHashedPassword(password, salt); return Arrays.equals(hash, this.password); } catch (Exception e) { LOG.error("Error checking password", e); } return false; }
From source file:com.opopov.cloud.image.DecodeImageTest.java
@Test public void testLoadImage() throws Exception { ImageStitchingConfiguration config = new ImageStitchingConfiguration(); config.setRowCount(3);/* w w w . jav a2 s . c om*/ config.setColumnCount(3); config.setSourceHeight(256); config.setSourceWidth(256); String[][] imageUrls = new String[][] { //rows left to right, top to bottom { "z15/9/x9650/5/y5596", "z15/9/x9650/5/y5597", "z15/9/x9650/5/y5598" }, { "z15/9/x9651/5/y5596", "z15/9/x9651/5/y5597", "z15/9/x9651/5/y5598" }, { "z15/9/x9652/5/y5596", "z15/9/x9652/5/y5597", "z15/9/x9652/5/y5598" } }; String pattern = "http://www.opopov.com/osmtopo1/%s.png"; for (String[] row : imageUrls) { for (String cell : row) { config.getUrlList().add(String.format(pattern, cell)); } } final AtomicReference<byte[]> buffer = new AtomicReference<>(); DeferredResult<ResponseEntity<?>> result = service.getStitchedImage(config); result.setResultHandler(new DeferredResult.DeferredResultHandler() { @Override public void handleResult(Object result) { ResponseEntity<byte[]> responseEntity = (ResponseEntity<byte[]>) result; buffer.set(responseEntity.getBody()); } }); Thread.sleep(TIMEOUT_MILLIS); InputStream is = getClass().getResourceAsStream("/horizontal-stitched-test-1-frame.png"); byte[] expectedBytes = IOUtils.toByteArray(is); // Uncomment the lines below to see the generated stitched image // FileOutputStream fos = new FileOutputStream("/tmp/horizontal-stitched-test-1-frame.png"); // IOUtils.write(buffer.get(), fos); // fos.close(); Assert.assertTrue("Image data of stitched PNG image", Arrays.equals(expectedBytes, buffer.get())); }
From source file:com.example.marcieltorres.nfcproject_serverapp.cardreader.LoyaltyCardReader.java
/** * Callback when a new tag is discovered by the system. * * <p>Communication with the card should take place here. * * @param tag Discovered tag//from ww w.ja v a 2 s . com */ @Override public void onTagDiscovered(Tag tag) { //Log.i(TAG, "New tag discovered"); // Android's Host-based Card Emulation (HCE) feature implements the ISO-DEP (ISO 14443-4) // protocol. // // In order to communicate with a device using HCE, the discovered tag should be processed // using the IsoDep class. IsoDep isoDep = IsoDep.get(tag); if (isoDep != null) { try { // Connect to the remote NFC device isoDep.connect(); // Build SELECT AID command for our loyalty card service. // This command tells the remote device which service we wish to communicate with. //Log.i(TAG, "Requesting remote AID: " + SAMPLE_LOYALTY_CARD_AID); byte[] command = BuildSelectApdu(SAMPLE_LOYALTY_CARD_AID); // Send command to remote device //Log.i(TAG, "Sending: " + ByteArrayToHexString(command)); byte[] result = isoDep.transceive(command); // If AID is successfully selected, 0x9000 is returned as the status word (last 2 // bytes of the result) by convention. Everything before the status word is // optional payload, which is used here to hold the account number. int resultLength = result.length; byte[] statusWord = { result[resultLength - 2], result[resultLength - 1] }; byte[] payload = Arrays.copyOf(result, resultLength - 2); if (Arrays.equals(SELECT_OK_SW, statusWord)) { // The remote NFC device will immediately respond with its stored account number String accountNumber = new String(payload, "UTF-8"); //Log.i(TAG, "Received: " + accountNumber); // Inform CardReaderFragment of received account number mAccountCallback.get().onAccountReceived(accountNumber); mAccountCallback.get().onAccountReceived(accountNumber); } } catch (IOException e) { //Log.e(TAG, "Error communicating with card: " + e.toString()); } } }
From source file:hudson.remoting.BinarySafeStreamTest.java
private void _testRoundtrip(boolean flush) throws IOException { byte[] dataSet = getDataSet(65536); Random r = new Random(0); for (int i = 0; i < 16; i++) { if (dump) System.out.println("test started"); ByteArrayOutputStream buf = new ByteArrayOutputStream(); randomCopy(r, new ByteArrayInputStream(dataSet), BinarySafeStream.wrap(buf), flush); decodeByMaster(buf.toString(), dataSet); if (dump) System.out.println("------"); ByteArrayOutputStream dst = new ByteArrayOutputStream(); randomCopy(r, BinarySafeStream.wrap(new ByteArrayInputStream(buf.toByteArray())), dst, flush); byte[] result = dst.toByteArray(); if (!Arrays.equals(dataSet, result)) { String msg = print(result, 0, result.length); for (int j = 0; j < result.length; j++) assertEquals("offset " + j + " at " + msg, result[j], dataSet[j]); fail(msg);/*w ww. ja v a 2s . c o m*/ } if (dump) System.out.println("------"); } }
From source file:org.bpmscript.correlation.CorrelationSupportTest.java
/** * Test method for {@link org.bpmscript.correlation.CorrelationSupport#getBytes(java.lang.Object)}. * @throws IOException //from w w w .ja v a 2 s . com * @throws ClassNotFoundException */ public void testGetBytes() throws IOException, ClassNotFoundException { CorrelationSupport correlationSupport = new CorrelationSupport(); Object[] values = new Object[3]; values[0] = 10; values[1] = "test"; values[2] = "randomblahblah"; byte[] bytes = correlationSupport.getBytes(values); Object[] storedValue = (Object[]) correlationSupport.getObject(bytes); assertTrue(Arrays.equals(values, storedValue)); }
From source file:com.opengamma.analytics.financial.model.volatility.smile.function.SABRFormulaData.java
@Override public boolean equals(final Object obj) { if (this == obj) { return true; }/*from w w w . j av a 2 s .co m*/ if (obj == null) { return false; } if (getClass() != obj.getClass()) { return false; } final SABRFormulaData other = (SABRFormulaData) obj; if (!Arrays.equals(_parameters, other._parameters)) { return false; } return true; }
From source file:cc.arduino.plugins.wifi101.flashers.java.NinaFlasher.java
@Override public void updateFirmware(String port) throws Exception { FlasherSerialClient client = null;/*from www.jav a 2 s. c om*/ try { file = openFirmwareFile(); progress(10, "Connecting to programmer..."); client = new FlasherSerialClient(); client.open(port, this.baudrate); client.hello(); int maxPayload = client.getMaximumPayload(); byte[] fwData = this.getData(); int size = fwData.length; int address = 0x00000000; int written = 0; progress(20, "Erasing target..."); client.eraseFlash(address, size); while (written < size) { progress(20 + written * 40 / size, "Programming " + size + " bytes ..."); int len = maxPayload; if (written + len > size) { len = size - written; } client.writeFlash(address, Arrays.copyOfRange(fwData, written, written + len)); written += len; address += len; } progress(55, "Verifying..."); md5Checksum = getMD5Checksum(fwData); address = 0x00000000; byte[] md5rec = client.md5Flash(address, size); progress(75, "Verifying..."); if (Arrays.equals(md5rec, md5Checksum)) { progress(100, "Done!"); } else { throw new Exception("Error validating flashed firmware"); } } finally { if (client != null) { client.close(); } } }
From source file:cc.redberry.core.combinatorics.IntPriorityPermutationsGeneratorTest.java
private void addPriority(IntPriorityPermutationsGenerator generator, int[] permutation) { int[] p;//from w w w . ja v a2s .c o m while ((p = generator.take()) != null) if (Arrays.equals(p, permutation)) { generator.nice(); return; } throw new RuntimeException(); }
From source file:edu.oregonstate.eecs.mcplan.SequencePolicy.java
@Override public boolean equals(final Object obj) { if (!(obj instanceof SequencePolicy<?, ?>)) { return false; }/*from w w w .ja va 2 s . c om*/ @SuppressWarnings("unchecked") final SequencePolicy<S, A> that = (SequencePolicy<S, A>) obj; return policies.equals(that.policies) && Arrays.equals(switch_times, that.switch_times); }
From source file:com.github.aelstad.keccakj.fips202.KeccackDigestTestUtils.java
public void runTests(List<DigestTest> tests, KeccackSponge sponge) { for (DigestTest dt : tests) { sponge.reset();//from w w w. j a va 2 s .co m sponge.getAbsorbStream().writeBits(dt.msg, 0, dt.len); System.out.println("Rate is now " + new String(Hex.encodeHex(sponge.getRateBits(0, Math.min(dt.len, sponge.getRateBits()))))); byte[] rv = new byte[dt.digest.length]; sponge.getSqueezeStream().read(rv); Assert.assertTrue(rv.length == dt.digest.length); ; org.junit.Assert.assertTrue(Arrays.equals(rv, dt.digest)); } testPerformance(sponge); }