下面列出了java.nio.ByteBuffer#compareTo ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
boolean compareInputStreamToConfigFile(InputStream inputStream) throws IOException {
logger.debug("Checking if change is different");
AtomicReference<ByteBuffer> currentConfigFileReference = configurationFileHolder.getConfigFileReference();
ByteBuffer currentConfigFile = currentConfigFileReference.get();
ByteBuffer byteBuffer = ByteBuffer.allocate(currentConfigFile.limit());
DataInputStream dataInputStream = new DataInputStream(inputStream);
try {
dataInputStream.readFully(byteBuffer.array());
} catch (EOFException e) {
logger.debug("New config is shorter than the current. Must be different.");
return true;
}
logger.debug("Read the input");
if (dataInputStream.available() != 0) {
return true;
} else {
return byteBuffer.compareTo(currentConfigFile) != 0;
}
}
@Override
public int compareTo(Object o) {
if (this.equals(o)) {
return 0;
}
if (o instanceof BgpFsDestinationPrefix) {
BgpFsDestinationPrefix that = (BgpFsDestinationPrefix) o;
if (this.ipPrefix().prefixLength() == that.ipPrefix().prefixLength()) {
ByteBuffer value1 = ByteBuffer.wrap(this.ipPrefix.address().toOctets());
ByteBuffer value2 = ByteBuffer.wrap(that.ipPrefix.address().toOctets());
return value1.compareTo(value2);
}
if (this.ipPrefix().prefixLength() > that.ipPrefix().prefixLength()) {
return 1;
} else if (this.ipPrefix().prefixLength() < that.ipPrefix().prefixLength()) {
return -1;
}
}
return 1;
}
@Override
public int compareTo(Object o) {
if (this.equals(o)) {
return 0;
}
if (o instanceof BgpFsSourcePrefix) {
BgpFsSourcePrefix that = (BgpFsSourcePrefix) o;
if (this.ipPrefix().prefixLength() == that.ipPrefix().prefixLength()) {
ByteBuffer value1 = ByteBuffer.wrap(this.ipPrefix.address().toOctets());
ByteBuffer value2 = ByteBuffer.wrap(that.ipPrefix.address().toOctets());
return value1.compareTo(value2);
}
if (this.ipPrefix().prefixLength() > that.ipPrefix().prefixLength()) {
return 1;
} else if (this.ipPrefix().prefixLength() < that.ipPrefix().prefixLength()) {
return -1;
}
}
return 1;
}
private boolean byteBuffersEqual(ByteBuffer bb1, ByteBuffer bb2) {
bb1.position(0);
bb2.position(0);
boolean res = (bb1.compareTo(bb2) == 0);
bb1.position(0);
bb2.position(0);
return res;
}
public int compare(ByteBuffer o1, ByteBuffer o2)
{
if (!o1.hasRemaining() || !o2.hasRemaining())
return o1.hasRemaining() ? 1 : o2.hasRemaining() ? -1 : 0;
int res = compareTimestampBytes(o1, o2);
if (res != 0)
return res;
return o1.compareTo(o2);
}
@Override
public int compareTo(Object o) {
if (this.equals(o)) {
return 0;
}
ByteBuffer value1 = ByteBuffer.wrap(this.ipPrefix);
ByteBuffer value2 = ByteBuffer.wrap(((IPReachabilityInformationTlv) o).ipPrefix);
return value1.compareTo(value2);
}
@Override
public int compareTo(Object o) {
if (this.equals(o)) {
return 0;
}
ByteBuffer value1 = ByteBuffer.wrap(this.isoNodeID);
ByteBuffer value2 = ByteBuffer.wrap(((IsIsNonPseudonode) o).isoNodeID);
return value1.compareTo(value2);
}
@Override
public int compareTo(Object o) {
if (this.equals(o)) {
return 0;
}
ByteBuffer value1 = ByteBuffer.wrap(this.isoNodeID);
ByteBuffer value2 = ByteBuffer.wrap(((IsIsPseudonode) o).isoNodeID);
if (value1.compareTo(value2) != 0) {
return value1.compareTo(value2);
}
return ((Byte) (this.psnIdentifier)).compareTo((Byte) (((IsIsPseudonode) o).psnIdentifier));
}
@Override
public int compare(byte[] b1, int s1, int l1, byte[] b2, int s2, int l2) {
//wrapping is done so that it would throw exceptions on wrong lengths
ByteBuffer bb1 = ByteBuffer.wrap(b1, s1, l1);
ByteBuffer bb2 = ByteBuffer.wrap(b2, s2, l2);
return bb1.compareTo(bb2);
}
@Override
//Not a valid comparison, but just to check byte boundaries
public int compare(byte[] b1, int s1, int l1, byte[] b2, int s2, int l2) {
Preconditions.checkArgument(l2 > 0 && l1 > 0, "l2=" + l2 + ",l1=" + l1);
ByteBuffer bb1 = ByteBuffer.wrap(b1, s1, l1);
ByteBuffer bb2 = ByteBuffer.wrap(b2, s2, l2);
return bb1.compareTo(bb2);
}
public boolean isNew(ByteBuffer inputBuffer) {
AtomicReference<ByteBuffer> currentConfigFileReference = configurationFileHolder.getConfigFileReference();
ByteBuffer currentConfigFile = currentConfigFileReference.get();
return inputBuffer.compareTo(currentConfigFile) != 0;
}