Example usage for com.google.common.io ByteSource contentEquals

List of usage examples for com.google.common.io ByteSource contentEquals

Introduction

In this page you can find the example usage for com.google.common.io ByteSource contentEquals.

Prototype

public boolean contentEquals(ByteSource other) throws IOException 

Source Link

Document

Checks that the contents of this byte source are equal to the contents of the given byte source.

Usage

From source file:com.tinspx.util.io.ChannelSource.java

@ByteUtils.ThreadLocalArray(8192)
static boolean contentEquals(ByteSource source, ByteSource other, boolean first) throws IOException {
    if (source instanceof BAChannelSource) {
        BAChannelSource o = (BAChannelSource) source;
        return contentEquals(other, o.buf, o.off, o.len);
    } else if (source instanceof ByteArrayChannelSource) {
        byte[] b = ((ByteArrayChannelSource) source).read();
        return contentEquals(other, b, 0, b.length);
    } else if (source instanceof BAOutputStream.BAOSChannelSource) {
        return source.contentEquals(other);
    } else if (source instanceof ByteBufferChannelSource) {
        ByteBuffer b = ((ByteBufferChannelSource) source).buf;
        if (b.hasArray()) {
            return contentEquals(other, b.array(), b.arrayOffset() + b.position(), b.remaining());
        }/*  w  w w  . ja  v a2s .c o m*/
    } else if (source instanceof MemoizeChannelSource) {
        return contentEquals(((MemoizeChannelSource) source).delegateThrow(), other, first);
    }
    if (first) {
        return contentEquals(other, source, false);
    } else {
        return ByteUtils.contentEqualsImpl(other, source);
    }
}