Example usage for java.util Arrays equals

List of usage examples for java.util Arrays equals

Introduction

In this page you can find the example usage for java.util Arrays equals.

Prototype

public static boolean equals(Object[] a, Object[] a2) 

Source Link

Document

Returns true if the two specified arrays of Objects are equal to one another.

Usage

From source file:com.docd.purefm.test.JavaFileTest.java

private static void testAgainstJavaIoFile(final JavaFile genericFile, final File javaFile) throws Throwable {
    assertEquals(javaFile, genericFile.toFile());
    assertEquals(javaFile.getName(), genericFile.getName());
    assertEquals(javaFile.getAbsolutePath(), genericFile.getAbsolutePath());
    assertEquals(javaFile.canRead(), genericFile.canRead());
    assertEquals(javaFile.canWrite(), genericFile.canWrite());
    assertEquals(javaFile.canExecute(), genericFile.canExecute());
    assertEquals(javaFile.exists(), genericFile.exists());
    assertEquals(javaFile.getPath(), genericFile.getPath());
    assertEquals(javaFile.getParent(), genericFile.getParent());
    assertEquals(javaFile.length(), genericFile.length());
    final File parentFile;
    final GenericFile genericParentFile = genericFile.getParentFile();
    if (genericParentFile == null) {
        parentFile = null;/*from www  . j  a va  2 s .  c om*/
    } else {
        parentFile = genericParentFile.toFile();
    }
    assertEquals(javaFile.getParentFile(), parentFile);
    assertEquals(javaFile.length(), genericFile.length());
    try {
        assertEquals(FileUtils.isSymlink(javaFile), genericFile.isSymlink());
    } catch (IOException e) {
        e.printStackTrace();
    }
    try {
        assertEquals(javaFile.getCanonicalPath(), genericFile.getCanonicalPath());
    } catch (IOException e) {
        e.printStackTrace();
    }
    assertEquals(javaFile.length(), genericFile.length());
    assertEquals(javaFile.lastModified(), genericFile.lastModified());
    assertEquals(javaFile.isDirectory(), genericFile.isDirectory());
    assertTrue(Arrays.equals(javaFile.list(), genericFile.list()));
    assertTrue(Arrays.equals(javaFile.listFiles(), genericFile.listFiles()));
}

From source file:org.alloy.site.resource.GeneratedResource.java

@Override
public boolean equals(Object res) {
    if (res == null) {
        return false;
    }//from  w  w w . j a v a2 s.  c o m
    if (!getClass().isAssignableFrom(res.getClass())) {
        return false;
    }

    return Arrays.equals(source, ((GeneratedResource) res).source);
}

From source file:com.alfaariss.oa.authentication.password.AbstractDigestorResourceHandler.java

/**
 * @see IResourceHandler#authenticate(java.lang.String, java.lang.String)
 *///from  www  . ja  v  a 2 s . c om
public boolean authenticate(String password, String username) throws UserException, OAException {
    // Retrieve stores password from backend.
    // Create digest of user entered password.
    byte[] userEnteredPasswd = _digest.digest(password, _sResourceRealm, constructUsername(username));
    byte[] userEncodedPassword = _encoder.getBytes(userEnteredPasswd);

    byte[] storedPassword = getData(_sResourceRealm, constructUsername(username));

    // Compare
    if (_logger.isDebugEnabled()) {
        _logger.debug("User supplied password: " + new String(userEncodedPassword));
        _logger.debug("Stored password: " + new String(storedPassword));
    }
    return Arrays.equals(userEncodedPassword, storedPassword);
}

From source file:com.opengamma.maths.lowlevelapi.datatypes.primitive.PackedMatrixTest.java

@Test
public void testBandedWithZeroRowBothSideZerosAllowedConstructor() {
    double[] expectedData = { 1, 2, 0, 0, 0, 3, 4, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 7, 8, 0, 0, 0, 9, 10 };
    PackedMatrix M = new PackedMatrix(_bandedwithzerorow, allowZerosOn.bothSides, 5, 5);
    assertTrue(Arrays.equals(M.getData(), expectedData));
}

From source file:de.psdev.energylogger.parser.EnergyLoggerDataParserImpl.java

@Override
public List<LogEntry> parseFileContents(InputStream input) throws IOException {
    if (!(input instanceof BufferedInputStream)) {
        input = new BufferedInputStream(input);
    }//from   w  ww .  j  a va 2 s  . c o  m
    final List<LogEntry> logEntries = new ArrayList<LogEntry>();

    final byte[] data = IOUtils.toByteArray(input);
    int counter = 0;
    final Calendar currentDate = GregorianCalendar.getInstance();
    FileType fileType = FileType.UNKNOWN;

    while (counter < data.length) {
        if (fileType == FileType.DATA) {
            if (Arrays.equals(Arrays.copyOfRange(data, counter, counter + START_CODE.length), START_CODE)) {
                counter += START_CODE.length;
                currentDate.setTime(
                        parseDate(Arrays.copyOfRange(data, counter, counter + START_DATE_BYTES_LENGTH)));
                counter += START_DATE_BYTES_LENGTH;
            } else if (Arrays.equals(Arrays.copyOfRange(data, counter, counter + EOF_CODE.length), EOF_CODE)) {
                break;
            } else {
                final byte[] dataBytes = Arrays.copyOfRange(data, counter, counter + DATA_BYTES_LENGTH);
                final double avgVoltage = parseDouble(dataBytes[0], dataBytes[1]) / 10;
                final double avgCurrent = parseDouble(dataBytes[2], dataBytes[3]) / 1000;
                final double avgPowerFactor = parseDouble(dataBytes[4]) / 100;
                final LogEntry logEntry = new LogEntryImpl();
                logEntry.setVoltage(avgVoltage);
                logEntry.setCurrent(avgCurrent);
                logEntry.setPowerfactor(avgPowerFactor);
                logEntry.setTimestamp(currentDate.getTime());
                logEntries.add(logEntry);
                currentDate.add(Calendar.MINUTE, 1);
                counter += DATA_BYTES_LENGTH;
            }

        } else if (fileType == FileType.INFO) {
            LOG.warn("got INFO file - ignoring because of invalid data");
            break;
        } else if (fileType == FileType.UNKNOWN) {
            if (Arrays.equals(Arrays.copyOfRange(data, counter, counter + INFO_FILE_START_CODE.length),
                    INFO_FILE_START_CODE)) { // INFO FILE
                fileType = FileType.INFO;
            } else if (Arrays.equals(Arrays.copyOfRange(data, counter, counter + START_CODE.length),
                    START_CODE)) {
                fileType = FileType.DATA;
            } else {
                throw new RuntimeException("Unknown Filetype");
            }

        }
    }
    return logEntries;
}

From source file:mitm.common.security.cms.SignerIdentifierImpl.java

@Override
public boolean match(X509Certificate certificate) throws IOException {
    if (certificate == null) {
        return false;
    }/*ww  w .jav a 2 s. c o  m*/

    if (issuer != null && !issuer.equals(certificate.getIssuerX500Principal())) {
        return false;
    }

    if (serialNumber != null && !serialNumber.equals(certificate.getSerialNumber())) {
        return false;
    }

    if (subjectKeyIdentifier != null && !Arrays.equals(subjectKeyIdentifier,
            X509CertificateInspector.getSubjectKeyIdentifier(certificate))) {
        return false;
    }

    return true;
}

From source file:com.antsdb.saltedfish.server.mysql.packet.AuthPacket.java

/**
 * Check if response is version 41//  w  w w.  jav  a 2s  .  c  o m
 * @param in
 * @return
 */
private boolean checkResponseVer41(ByteBuf in) {
    // response V41 has at least 32 bytes
    if (packetLength >= 32) {
        in.markReaderIndex();
        byte[] reserved = new byte[23];

        // 23 bytes from index 9 (+4 head offset) are all zero for V41
        in.getBytes(9 + 4, reserved, 0, 23);
        in.resetReaderIndex();
        if (Arrays.equals(reserved, new byte[23])) {
            return true;
        }

    }
    return false;
}

From source file:org.brekka.phalanx.core.services.impl.PasswordBasedCryptoServiceImpl.java

@Override
@Transactional(propagation = Propagation.SUPPORTS, noRollbackFor = { PhalanxException.class })
public <T> T decrypt(PasswordedCryptoData cryptoData, String password, Class<T> expectedType) {
    cryptoData = (PasswordedCryptoData) cryptoDataDAO.retrieveById(cryptoData.getId());

    byte[] cipherText = cryptoData.getData();
    byte[] salt = cryptoData.getSalt();
    Integer iterations = cryptoData.getIterations();
    byte[] key = toKey(password);

    CryptoProfile cryptoProfile = cryptoProfileService.retrieveProfile(cryptoData.getProfile());
    DerivedKey derivedKey = phoenixDerived.apply(key, salt, iterations, cryptoProfile);
    SymmetricCryptoSpec symmetricCryptoSpec = phoenixSymmetric.toSymmetricCryptoSpec(derivedKey);

    byte[] result;
    try {/* w  ww  . j a  va2 s .  c  o m*/
        result = phoenixSymmetric.decrypt(cipherText, symmetricCryptoSpec);
    } catch (PhoenixException e) {
        if (e.getCause() instanceof BadPaddingException) {
            throw new PhalanxException(PhalanxErrorCode.CP302, "The password is incorrect");
        }
        throw e;
    }
    int digestLength = phoenixDigest.getDigestLength(cryptoProfile);

    byte[] digest = ArrayUtils.subarray(result, 0, digestLength);
    byte[] data = ArrayUtils.subarray(result, digestLength, result.length);
    DigestResult digestResult = phoenixDigest.digest(data, cryptoProfile);

    if (!Arrays.equals(digest, digestResult.getDigest())) {
        throw new PhalanxException(PhalanxErrorCode.CP302, "The password is incorrect");
    }
    return toType(data, expectedType, cryptoData.getId(), cryptoProfile);
}

From source file:com.springsource.greenhouse.account.GreenhousePasswordEncoder.java

private boolean matches(byte[] expected, byte[] actual) {
    return Arrays.equals(expected, actual);
}

From source file:com.yahoo.parsec.clients.ParsecEqualsUtil.java

/**
 * Ning Part equals.//from  www . j a  va2s .c  om
 *
 * @param lhs lhs
 * @param rhs rhs
 *
 * @return true when two Ning Part are equal by value
 */
static boolean partEquals(final Part lhs, final Part rhs) {
    if (!lhs.equals(rhs)) {
        if (lhs.getClass() != rhs.getClass()) {
            return false;
        }

        if (!new EqualsBuilder().append(lhs.getCharset(), rhs.getCharset())
                .append(lhs.getContentId(), rhs.getContentId())
                .append(lhs.getContentType(), rhs.getContentType())
                .append(lhs.getDispositionType(), rhs.getDispositionType()).append(lhs.getName(), rhs.getName())
                .append(lhs.getTransferEncoding(), rhs.getTransferEncoding()).isEquals()) {
            return false;
        }

        switch (lhs.getClass().getSimpleName()) {
        case "ByteArrayPart":
            if (!Arrays.equals(((ByteArrayPart) lhs).getBytes(), ((ByteArrayPart) rhs).getBytes())) {
                return false;
            }
            break;
        case "FilePart":
            if (!((FilePart) lhs).getFile().equals(((FilePart) rhs).getFile())) {
                return false;
            }
            break;
        case "StringPart":
            if (!((StringPart) lhs).getValue().equals(((StringPart) rhs).getValue())) {
                return false;
            }
            break;
        default:
            return false;
        }
    }
    return true;
}