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.netscape.cmstools.profile.ProfileEditCLI.java

public void execute(String[] args) throws Exception {
    // Always check for "--help" prior to parsing
    if (Arrays.asList(args).contains("--help")) {
        printHelp();//from   w  w  w . java2  s  .  c  o  m
        return;
    }

    CommandLine cmd = parser.parse(options, args);

    String[] cmdArgs = cmd.getArgs();

    if (cmdArgs.length < 1) {
        throw new Exception("No Profile ID specified.");
    }

    String profileId = cmdArgs[0];

    ProfileClient profileClient = profileCLI.getProfileClient();

    // read profile into temporary file
    byte[] orig = profileClient.retrieveProfileRaw(profileId);
    ProfileCLI.checkConfiguration(orig, false /* requireProfileId */, true /* requireDisabled */);
    Path tempFile = Files.createTempFile("pki", ".cfg");

    try {
        Files.write(tempFile, orig);

        // invoke editor on temporary file
        String editor = System.getenv("EDITOR");
        String[] command;
        if (editor == null || editor.trim().isEmpty()) {
            command = new String[] { "/usr/bin/env", "vi", tempFile.toString() };
        } else {
            command = new String[] { editor.trim(), tempFile.toString() };
        }
        ProcessBuilder pb = new ProcessBuilder(command);
        pb.inheritIO();
        int exitCode = pb.start().waitFor();
        if (exitCode != 0) {
            throw new Exception("Exited abnormally.");
        }

        // read data from temporary file and modify if changed
        byte[] cur = ProfileCLI.readRawProfileFromFile(tempFile);
        if (!Arrays.equals(cur, orig)) {
            profileClient.modifyProfileRaw(profileId, cur);
        }
        System.out.write(cur);
    } finally {
        Files.delete(tempFile);
    }
}

From source file:com.jivesoftware.os.jive.utils.id.ImmutableByteArray.java

@Override
public boolean equals(Object _object) {
    if (_object == this) {
        return true;
    }//www. j  a v a  2s  . c om
    byte[] b = null;
    if (_object instanceof byte[]) {
        b = (byte[]) _object;
    } else if (_object instanceof ImmutableByteArray) {
        b = ((ImmutableByteArray) _object).bytes;
    }
    if (b == null) {
        return false;
    }
    byte[] a = bytes;
    return Arrays.equals(a, b);
}

From source file:com.limegroup.gnutella.metadata.MP3DataEditor.java

/**
 * Actually writes the ID3 tags out to the ID3V3 section of the mp3 file
 *///from   w  w  w. ja v a2s  .  c  o m
private int writeID3V2DataToDisk(File file) throws IOException, ID3v2Exception {
    ID3v2 id3Handler = new ID3v2(file);
    Vector frames = null;
    try {
        frames = (Vector) id3Handler.getFrames().clone();
    } catch (NoID3v2TagException ex) {//there are no ID3v2 tags in the file
        //fall thro' we'll deal with it later -- frames will be null
    }

    List framesToUpdate = new ArrayList();
    addAllNeededFrames(framesToUpdate);
    if (framesToUpdate.size() == 0) //we have nothing to update
        return LimeXMLReplyCollection.NORMAL;
    if (frames != null) { //old frames present, update the differnt ones 
        for (Iterator iter = frames.iterator(); iter.hasNext();) {
            ID3v2Frame oldFrame = (ID3v2Frame) iter.next();
            //note: equality of ID3v2Frame based on value of id
            int index = framesToUpdate.indexOf(oldFrame);
            ID3v2Frame newFrame = null;
            if (index >= 0) {
                newFrame = (ID3v2Frame) framesToUpdate.remove(index);
                if (Arrays.equals(oldFrame.getContent(), newFrame.getContent()))
                    continue;//no need to update, skip this frame
            }
            //we are either going to replace it if it was changed, or remove
            //it since there is no equivalent frame in the ones we need to
            //update, this means the user probably removed it
            id3Handler.removeFrame(oldFrame);
            if (newFrame != null)
                id3Handler.addFrame(newFrame);
        }
    }
    //now we are left with the ones we need to add only, if there were no
    //old tags this will be all the frames that need to get updated
    for (Iterator iter = framesToUpdate.iterator(); iter.hasNext();) {
        ID3v2Frame frame = (ID3v2Frame) iter.next();
        id3Handler.addFrame(frame);
    }

    id3Handler.update();
    //No Exceptions? We are home
    return LimeXMLReplyCollection.NORMAL;
}

From source file:com.navercorp.pinpoint.common.buffer.FixedBufferTest.java

@Test
public void testPadBytes() throws Exception {
    int TOTAL_LENGTH = 20;
    int TEST_SIZE = 10;
    Buffer buffer = new FixedBuffer(32);
    byte[] test = new byte[10];

    random.nextBytes(test);//  ww  w .jav a 2 s .  c  om

    buffer.putPadBytes(test, TOTAL_LENGTH);

    byte[] result = buffer.getBuffer();
    Assert.assertEquals(result.length, TOTAL_LENGTH);
    Assert.assertTrue("check data",
            Arrays.equals(Arrays.copyOfRange(test, 0, TEST_SIZE), Arrays.copyOfRange(result, 0, TEST_SIZE)));
    byte[] padBytes = new byte[TOTAL_LENGTH - TEST_SIZE];
    Assert.assertTrue("check pad", Arrays.equals(Arrays.copyOfRange(padBytes, 0, TEST_SIZE),
            Arrays.copyOfRange(result, TEST_SIZE, TOTAL_LENGTH)));

}

From source file:no.digipost.api.interceptors.steps.ReferenceValidatorStep.java

private void validate(final Reference expected, final Reference actual) {
    if (!expected.getDigestMethod().getAlgorithm().equals(actual.getDigestMethod().getAlgorithm())) {
        throw new RuntimeException(
                "Unexpected digest method. Expected:" + expected.getDigestMethod().getAlgorithm() + " Actual:"
                        + actual.getDigestMethod().getAlgorithm());
    }/* www  .  j a  v  a  2s. c om*/
    if (!Arrays.equals(expected.getDigestValue(), actual.getDigestValue())) {
        throw new RuntimeException(
                "Unexpected digest value. Expected:" + Base64.encode(expected.getDigestValue()) + " Actual:"
                        + Base64.encode(actual.getDigestValue()));
    }
    validateTransforms(expected, actual);
}

From source file:org.jasig.cas.support.spnego.authentication.principal.SpnegoCredentials.java

public boolean equals(final Object obj) {
    if (obj == null || !obj.getClass().equals(this.getClass())) {
        return false;
    }/*from  w w  w .  j  a v  a  2  s  . c om*/

    final SpnegoCredentials c = (SpnegoCredentials) obj;

    return Arrays.equals(this.initToken, c.getInitToken()) && this.principal.equals(c.getPrincipal())
            && Arrays.equals(this.nextToken, c.getNextToken());
}

From source file:com.android.im.imps.ImpsPresenceUtils.java

/**
 * Builds a list of PrimitiveElement need be sent to the server to update
 * the user's presence./*from  ww w  . j  ava2 s  . co  m*/
 *
 * @param oldPresence
 * @param newPresence
 * @return
 */
public static ArrayList<PrimitiveElement> buildUpdatePresenceElems(Presence oldPresence, Presence newPresence,
        PresenceMapping mapping) {
    int status = newPresence.getStatus();
    ArrayList<PrimitiveElement> elems = new ArrayList<PrimitiveElement>();

    boolean newOnlineStatus = mapping.getOnlineStatus(status);
    PrimitiveElement onlineElem = new PrimitiveElement(ImpsTags.OnlineStatus);
    onlineElem.addChild(ImpsTags.Qualifier, true);
    onlineElem.addChild(ImpsTags.PresenceValue, newOnlineStatus);
    elems.add(onlineElem);

    String newUserAvailablity = mapping.getUserAvaibility(status);
    PrimitiveElement availElem = new PrimitiveElement(ImpsTags.UserAvailability);
    availElem.addChild(ImpsTags.Qualifier, true);
    availElem.addChild(ImpsTags.PresenceValue, newUserAvailablity);
    elems.add(availElem);
    Map<String, Object> extra = mapping.getExtra(status);
    if (extra != null) {
        mapToPrimitives(extra, elems);
    }
    String statusText = newPresence.getStatusText();
    if (statusText == null) {
        statusText = "";
    }
    if (!statusText.equals(oldPresence.getStatusText())) {
        PrimitiveElement statusElem = new PrimitiveElement(ImpsTags.StatusText);
        statusElem.addChild(ImpsTags.Qualifier, true);
        statusElem.addChild(ImpsTags.PresenceValue, statusText);
        elems.add(statusElem);
    }

    byte[] avatar = newPresence.getAvatarData();
    if (avatar != null && !Arrays.equals(avatar, oldPresence.getAvatarData())) {
        String base64Avatar = new String(Base64.encodeBase64(avatar));
        PrimitiveElement statusContent = new PrimitiveElement(ImpsTags.StatusContent);
        statusContent.addChild(ImpsTags.Qualifier, true);
        statusContent.addChild(ImpsTags.DirectContent, base64Avatar);
        statusContent.addChild(ImpsTags.ContentType, newPresence.getAvatarType());
        elems.add(statusContent);
    }

    return elems;
}

From source file:edu.oregonstate.eecs.mcplan.domains.voyager.policies.ExpansionPolicy.java

@Override
public boolean equals(final Object obj) {
    if (obj == null || !(obj instanceof ExpansionPolicy)) {
        return false;
    }//www  .  j av a  2s . c  om
    final ExpansionPolicy that = (ExpansionPolicy) obj;
    return player_ == that.player_ && Arrays.equals(priority_list_, that.priority_list_)
            && garrison_ == that.garrison_;
}

From source file:eu.europa.ec.markt.dss.validation.OCSPRef.java

/**
 * /*from  ww  w . j av a2  s .  c om*/
 * @param ocspResp
 * @return
 */
public boolean match(BasicOCSPResp ocspResp) {
    try {
        MessageDigest digest = MessageDigest.getInstance(algorithm);
        if (matchOnlyBasicOCSPResponse) {
            digest.update(ocspResp.getEncoded());
        } else {
            digest.update(OCSPUtils.fromBasicToResp(ocspResp).getEncoded());
        }
        byte[] computedValue = digest.digest();
        LOG.info("Compare " + Hex.encodeHexString(digestValue) + " to computed value "
                + Hex.encodeHexString(computedValue) + " of BasicOCSPResp produced at "
                + ocspResp.getProducedAt());
        return Arrays.equals(digestValue, computedValue);
    } catch (NoSuchAlgorithmException ex) {
        throw new RuntimeException("Maybe BouncyCastle provider is not installed ?", ex);
    } catch (IOException ex) {
        throw new RuntimeException(ex);
    }
}

From source file:edu.umn.msi.tropix.common.test.FileDisposableResourceFactoryTest.java

@SuppressWarnings("unchecked")
@Test(groups = "unit", timeOut = 1000)
public void fromByteWithTempFileSupplier() throws IOException {
    final Supplier<File> mockSupplier = EasyMock.createMock(Supplier.class);
    final File file = File.createTempFile("tpxtest", "");
    EasyMock.expect(mockSupplier.get()).andReturn(file);
    EasyMock.replay(mockSupplier);/*from www  .j  av  a 2 s.  c  o  m*/
    final byte[] bytes = new byte[10];
    RANDOM.nextBytes(bytes);
    final DisposableResource resource = FileDisposableResourceFactory.getByteFunction(mockSupplier)
            .apply(bytes);
    EasyMock.verify(mockSupplier);
    assert resource.getFile().equals(file);
    assert file.exists();
    assert Arrays.equals(bytes, FileUtils.readFileToByteArray(file));
    resource.dispose();
    assert !file.exists();
}