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:jenkins.plugins.publish_over.helper.InputStreamMatcher.java

public boolean matches(final Object argument) {
    if (!(argument instanceof InputStream))
        return false;

    try {//from   w  w w  . j av a2 s.c  o  m
        final byte[] actual = IOUtils.toByteArray((InputStream) argument);
        if (LOG.isDebugEnabled()) {
            LOG.debug("Expected (md5) = " + DigestUtils.md5Hex(expectedContents));
            LOG.debug("Actual   (md5) = " + DigestUtils.md5Hex(actual));
        }
        return Arrays.equals(expectedContents, actual);
    } catch (IOException ioe) {
        throw new RuntimeException("Failed to read contents of InputStream", ioe);
    }
}

From source file:net.netheos.pcsapi.BytesIOTest.java

private void checkByteSource(ByteSource bs, byte[] expectedContent) throws IOException {
    assertEquals(70, bs.length());//from www  .j  a  v a  2s .  co m

    InputStream is = bs.openStream();
    byte[] b = IOUtils.toByteArray(is);
    assertTrue(Arrays.equals(expectedContent, b));
    is.close();

    // Create a range view of this byte source : 25 bytes starting at offset 5 :
    RangeByteSource rbs = new RangeByteSource(bs, 5, 25);
    assertEquals(25, rbs.length());
    is = rbs.openStream();

    try {
        b = new byte[1];
        is.read(b);
        assertEquals("1", new String(b, PcsUtils.UTF8));

        b = new byte[3];
        is.read(b);
        assertEquals("", new String(b, PcsUtils.UTF8));

        b = new byte[100];
        int len = is.read(b);
        assertEquals(21, len);
        final String actual = new String(b, 0, 21, PcsUtils.UTF8);
        assertEquals(" file is the test con", actual);

        b = new byte[100];
        len = is.read(b);
        assertEquals(0, len);

    } finally {
        IOUtils.closeQuietly(is);
    }

    // Now decorate again with a progress byte source
    StdoutProgressListener pl = new StdoutProgressListener();
    ProgressByteSource pbs = new ProgressByteSource(rbs, pl);
    assertEquals(rbs.length(), pbs.length());
    is = pbs.openStream();

    try {
        assertEquals(pbs.length(), pl.getTotal());
        assertEquals(0, pl.getCurrent());
        assertFalse(pl.isAborted());

        b = new byte[1];
        is.read(b);
        assertEquals(1, pl.getCurrent());

        b = new byte[10];
        is.read(b);
        assertEquals(11, pl.getCurrent());

        b = new byte[500];
        int len = is.read(b);
        assertEquals(14, len);
        assertEquals(25, pl.getCurrent());

    } finally {
        IOUtils.closeQuietly(is);
    }
}

From source file:com.lyncode.jtwig.render.stream.RenderIndex.java

@Override
public boolean equals(Object o) {
    if (this == o) {
        return true;
    }//ww  w  .  j  av a2  s  . c  o m
    if (o == null || getClass() != o.getClass()) {
        return false;
    }

    RenderIndex that = (RenderIndex) o;

    if (!Arrays.equals(mIndex, that.mIndex)) {
        return false;
    }

    return true;
}

From source file:libepg.util.bytearray.ByteArraySplitterTest.java

/**
 * Test of split method, of class ByteArraySplitter.
 *
 * @throws org.apache.commons.codec.DecoderException
 *//*from ww  w. j  ava  2 s  .  com*/
@Test
public void testSplit() throws DecoderException {
    LOG.debug("split");
    byte[] src = Hex.decodeHex("00112233445566778899aabbccddeeff".toCharArray());
    int size = 3;
    List<byte[]> expResult = new ArrayList<>();
    expResult.add(Hex.decodeHex("001122".toCharArray()));
    expResult.add(Hex.decodeHex("334455".toCharArray()));
    expResult.add(Hex.decodeHex("667788".toCharArray()));
    expResult.add(Hex.decodeHex("99aabb".toCharArray()));
    expResult.add(Hex.decodeHex("ccddee".toCharArray()));
    expResult.add(Hex.decodeHex("ff0000".toCharArray()));
    List result = ByteArraySplitter.split(src, size);

    Iterator<byte[]> it_result = result.iterator();
    Iterator<byte[]> it_expResult = expResult.iterator();
    while (it_result.hasNext() && it_expResult.hasNext()) {
        StringBuilder s = new StringBuilder();
        byte[] res = it_result.next();
        byte[] expRes = it_expResult.next();
        if (Arrays.equals(res, expRes) == false) {
            fail("???????");
        } else {
            s.append(Hex.encodeHexString(expRes));
            s.append(" = ");
            s.append(Hex.encodeHexString(res));
            LOG.debug(s.toString());
        }
    }
}

From source file:hd3gtv.embddb.network.DataBlock.java

/**
 * Import mode//from   ww  w .j a  va2s  .  co m
 */
DataBlock(Protocol protocol, byte[] request_raw_datas) throws IOException {
    if (log.isTraceEnabled()) {
        log.trace("Get raw datas" + Hexview.LINESEPARATOR + Hexview.tracelog(request_raw_datas));
    }

    ByteArrayInputStream inputstream_client_request = new ByteArrayInputStream(request_raw_datas);

    DataInputStream dis = new DataInputStream(inputstream_client_request);

    byte[] app_socket_header_tag = new byte[Protocol.APP_SOCKET_HEADER_TAG.length];
    dis.readFully(app_socket_header_tag, 0, Protocol.APP_SOCKET_HEADER_TAG.length);

    if (Arrays.equals(Protocol.APP_SOCKET_HEADER_TAG, app_socket_header_tag) == false) {
        throw new IOException("Protocol error with app_socket_header_tag");
    }

    int version = dis.readInt();
    if (version != Protocol.VERSION) {
        throw new IOException(
                "Protocol error with version, this = " + Protocol.VERSION + " and dest = " + version);
    }

    byte tag = dis.readByte();
    if (tag != 0) {
        throw new IOException("Protocol error, can't found request_name raw datas");
    }

    int size = dis.readInt();
    if (size < 1) {
        throw new IOException(
                "Protocol error, can't found request_name raw datas size is too short (" + size + ")");
    }

    byte[] request_name_raw = new byte[size];
    dis.read(request_name_raw);
    request_name = new String(request_name_raw, Protocol.UTF8);

    tag = dis.readByte();
    if (tag != 1) {
        throw new IOException("Protocol error, can't found zip raw datas");
    }

    entries = new ArrayList<>(1);

    ZipInputStream request_zip = new ZipInputStream(dis);

    ZipEntry entry;
    while ((entry = request_zip.getNextEntry()) != null) {
        entries.add(new RequestEntry(entry, request_zip));
    }
    request_zip.close();
}

From source file:io.confluent.kafkarest.entities.BinaryConsumerRecord.java

@Override
public boolean equals(Object o) {
    if (this == o) {
        return true;
    }//from  www .  j a  v a2 s  . com
    if (o == null || getClass() != o.getClass()) {
        return false;
    }
    BinaryConsumerRecord that = (BinaryConsumerRecord) o;
    return partition == that.partition && offset == that.offset && Objects.equals(topic, that.topic)
            && Arrays.equals(key, that.key) && Arrays.equals(value, that.value);
}

From source file:com.espertech.esper.epl.join.plan.TestQueryGraph.java

public void testFillEquivalency() {
    // test with just 3 streams
    queryGraph.addStrictEquals(0, "p00", null, 1, "p10", null);
    queryGraph.addStrictEquals(1, "p10", null, 2, "p20", null);

    assertFalse(queryGraph.isNavigableAtAll(0, 2));
    assertEquals(0, QueryGraphTestUtil.getStrictKeyProperties(queryGraph, 0, 2).length);
    assertEquals(0, QueryGraphTestUtil.getIndexProperties(queryGraph, 0, 2).length);

    QueryGraph.fillEquivalentNav(types, queryGraph);

    assertTrue(queryGraph.isNavigableAtAll(0, 2));
    String[] expectedOne = new String[] { "p00" };
    String[] expectedTwo = new String[] { "p20" };
    assertTrue(Arrays.equals(expectedOne, QueryGraphTestUtil.getStrictKeyProperties(queryGraph, 0, 2)));
    assertTrue(Arrays.equals(expectedTwo, QueryGraphTestUtil.getIndexProperties(queryGraph, 0, 2)));

    // test with 5 streams, connect all streams to all streams
    queryGraph = new QueryGraph(5);
    queryGraph.addStrictEquals(0, "p0", null, 1, "p1", null);
    queryGraph.addStrictEquals(3, "p3", null, 4, "p4", null);
    queryGraph.addStrictEquals(2, "p2", null, 3, "p3", null);
    queryGraph.addStrictEquals(1, "p1", null, 2, "p2", null);

    QueryGraph.fillEquivalentNav(types, queryGraph);

    for (int i = 0; i < 5; i++) {
        for (int j = 0; j < 5; j++) {
            if (i == j) {
                continue;
            }/*from ww w .  j a  v  a2 s. c  o m*/
            assertTrue("Not navigable: i=" + i + " j=" + j, queryGraph.isNavigableAtAll(i, j));
        }
    }
}

From source file:org.jtalks.common.model.entity.UserTest.java

@Test
public void testSetNormalAvatar() {
    byte[] testAvatar = new byte[] { 0, 1, 2 };

    sut.setAvatar(testAvatar);/*www  .  ja  va 2s . c  om*/

    assertTrue(Arrays.equals(sut.getAvatar(), testAvatar));
}

From source file:com.ca.dvs.app.dvs_servlet.misc.FileUtil.java

/**
 * A quick test to determine if uploaded file is a ZIP file
 * <p> //from   w  w w  . jav  a 2 s.  c  o m
 * @param file the file to interrogate for being a zip file 
 * @return true is the specified file is a zip file
 * @throws IOException
 */
public static boolean isZipFile(File file) throws IOException {

    boolean isZipFile = false;
    FileInputStream fileInputStream = null;

    try {

        fileInputStream = new FileInputStream(file);

        if (fileInputStream.available() > ZIP_SIGNATURE.length) {

            byte[] magic = new byte[ZIP_SIGNATURE.length];

            if (ZIP_SIGNATURE.length == fileInputStream.read(magic, 0, ZIP_SIGNATURE.length)) {

                isZipFile = Arrays.equals(magic, ZIP_SIGNATURE);

            }

        }

    } finally {

        if (null != fileInputStream) {
            fileInputStream.close();
        }

    }

    return isZipFile;
}

From source file:edu.oregonstate.eecs.mcplan.PhasedPolicy.java

@Override
public boolean equals(final Object obj) {
    if (obj == null || !(obj instanceof PhasedPolicy<?, ?>)) {
        return false;
    }/*w  w  w  .j  a  v  a2 s . c o  m*/
    final PhasedPolicy<?, ?> that = (PhasedPolicy<?, ?>) obj;
    return Pi_.equals(that.Pi_) && Arrays.equals(ts_, that.ts_);
}