Example usage for com.google.common.primitives UnsignedBytes MAX_VALUE

List of usage examples for com.google.common.primitives UnsignedBytes MAX_VALUE

Introduction

In this page you can find the example usage for com.google.common.primitives UnsignedBytes MAX_VALUE.

Prototype

byte MAX_VALUE

To view the source code for com.google.common.primitives UnsignedBytes MAX_VALUE.

Click Source Link

Document

The largest value that fits into an unsigned byte.

Usage

From source file:com.pingcap.tikv.codec.KeyUtils.java

/**
 * The next key for bytes domain It first plus one at LSB and if LSB overflows, a zero byte is
 * appended at the end Original bytes will be reused if possible
 *
 * @param key key to encode//from ww  w.java  2 s. c o  m
 * @return encoded results
 */
public static byte[] prefixNext(byte[] key) {
    int i;
    for (i = key.length - 1; i >= 0; i--) {
        if (key[i] != UnsignedBytes.MAX_VALUE) {
            key[i]++;
            break;
        }
    }
    if (i == -1) {
        return getNextKeyInByteOrder(key);
    }
    return key;
}

From source file:org.opendaylight.protocol.bgp.util.BinaryBGPDumpFileParser.java

/**
 * Extract BGP messages from binary file in MRT format.
 *
 * @param byteArray array of bytes with BGP messages in binary form.
 * @return list with byte arrays representing extracted messages.
 *//*  w  w w  .  j  a va 2s  .  c  o  m*/
public static List<byte[]> parseMessages(final byte[] byteArray) {

    final List<byte[]> messages = Lists.newLinkedList();
    // search for 16 FFs
    for (int i = 0; i < byteArray.length; i++) {
        final byte b = byteArray[i];

        // Marker start
        if (b == UnsignedBytes.MAX_VALUE) {
            final int start = i;
            int ffCount = 0;
            for (int j = i; j <= i + MARKER_LENGTH; j++) {
                // Check marker
                if (byteArray[j] == UnsignedBytes.MAX_VALUE) {
                    ffCount++;
                } else if (ffCount == MARKER_LENGTH) {
                    if (j == (i + MARKER_LENGTH)) {
                        // Parse length
                        final int length = ByteArray.bytesToInt(new byte[] { byteArray[j], byteArray[j + 1] });

                        Preconditions.checkArgument(length >= MINIMAL_LENGTH, "Invalid message at index "
                                + start + ", length atribute is lower than " + MINIMAL_LENGTH);

                        final byte[] message = Arrays.copyOfRange(byteArray, start, start + length);
                        messages.add(message);
                        j += length - MARKER_LENGTH;
                    }
                    i = j;
                    break;
                } else {
                    break;
                }
            }
        }

    }
    LOG.info("Succesfully extracted {} messages", messages.size());
    return messages;
}

From source file:org.anarres.dhcp.common.address.AddressUtils.java

/**
 * Performs an arbitrary-precision decrement of a byte array.
 *
 * @param in The array to decrement.//from  ww w  .j ava2 s  .  c o m
 * @return The same input array.
 */
@Nonnull
public static byte[] decrement(@Nonnull byte[] in) {
    for (int i = in.length - 1; i >= 0; i--) {
        if (UnsignedBytes.toInt(in[i]) > 0) {
            in[i]--;
            break;
        }
        in[i] = UnsignedBytes.MAX_VALUE;
    }

    return in;
}

From source file:com.torodb.mongowp.bson.netty.ParsingTools.java

/**
 * Translate a byte to the {@link BsonType} it represents, as specified on the
 * <a href="http://bsonspec.org/spec.html">BSON Spec</a>
 *
 * @param typeByte//from w  ww. j  a va 2s.  co  m
 * @return
 * @throws NettyBsonReaderException
 */
@Nonnull
protected static BsonType getBsonType(byte typeByte) throws NettyBsonReaderException {
    switch (typeByte) {
    case 0x01:
        return DOUBLE;
    case 0x02:
        return STRING;
    case 0x03:
        return DOCUMENT;
    case 0x04:
        return ARRAY;
    case 0x05:
        return BINARY;
    case 0x06:
        return UNDEFINED;
    case 0x07:
        return OBJECT_ID;
    case 0x08:
        return BOOLEAN;
    case 0x09:
        return DATETIME;
    case 0x0A:
        return NULL;
    case 0x0B:
        return REGEX;
    case 0x0C:
        return DB_POINTER;
    case 0x0D:
        return JAVA_SCRIPT;
    case 0x0E:
        return DEPRECATED;
    case 0x0F:
        return JAVA_SCRIPT_WITH_SCOPE;
    case 0x10:
        return INT32;
    case 0x11:
        return TIMESTAMP;
    case 0x12:
        return INT64;
    case 0x13:
        return DECIMAL128;
    case UnsignedBytes.MAX_VALUE:
        return MIN;
    case 0x7F:
        return MAX;
    default:
        throw new NettyBsonReaderException(
                "It is not defined the type associated with the byte " + UnsignedBytes.toString(typeByte, 16));
    }
}

From source file:com.eightkdata.mongowp.bson.netty.ParsingTools.java

/**
 * Translate a byte to the {@link BsonType} it represents, as specified on the
 * <a href="http://bsonspec.org/spec.html">BSON Spec</a>
 *
 * @param typeByte//from   w w w .j  av  a  2  s. co  m
 * @return
 * @throws NettyBsonReaderException
 */
@Nonnull
protected static BsonType getBsonType(byte typeByte) throws NettyBsonReaderException {
    switch (typeByte) {
    case 0x01:
        return DOUBLE;
    case 0x02:
        return STRING;
    case 0x03:
        return DOCUMENT;
    case 0x04:
        return ARRAY;
    case 0x05:
        return BINARY;
    case 0x06:
        return UNDEFINED;
    case 0x07:
        return OBJECT_ID;
    case 0x08:
        return BOOLEAN;
    case 0x09:
        return DATETIME;
    case 0x0A:
        return NULL;
    case 0x0B:
        return REGEX;
    case 0x0C:
        return DB_POINTER;
    case 0x0D:
        return JAVA_SCRIPT;
    case 0x0E:
        return DEPRECATED;
    case 0x0F:
        return JAVA_SCRIPT_WITH_SCOPE;
    case 0x10:
        return INT32;
    case 0x11:
        return TIMESTAMP;
    case 0x12:
        return INT64;
    case UnsignedBytes.MAX_VALUE:
        return MIN;
    case 0x7F:
        return MAX;
    default:
        throw new NettyBsonReaderException(
                "It is not defined the type associated with the byte " + UnsignedBytes.toString(typeByte, 16));
    }
}

From source file:com.torodb.mongowp.bson.netty.ParsingTools.java

protected static byte getByte(BsonType bsonType) throws NettyBsonReaderException {
    switch (bsonType) {
    case DOUBLE:/*from w  w  w .ja v  a  2  s  .com*/
        return 0x01;
    case STRING:
        return 0x02;
    case DOCUMENT:
        return 0x03;
    case ARRAY:
        return 0x04;
    case BINARY:
        return 0x05;
    case UNDEFINED:
        return 0x06;
    case OBJECT_ID:
        return 0x07;
    case BOOLEAN:
        return 0x08;
    case DATETIME:
        return 0x09;
    case NULL:
        return 0x0A;
    case REGEX:
        return 0x0B;
    case DB_POINTER:
        return 0x0C;
    case JAVA_SCRIPT:
        return 0x0D;
    case DEPRECATED:
        return 0x0E;
    case JAVA_SCRIPT_WITH_SCOPE:
        return 0x0F;
    case INT32:
        return 0x10;
    case TIMESTAMP:
        return 0x11;
    case INT64:
        return 0x12;
    case DECIMAL128:
        return 0x13;
    case MIN:
        return UnsignedBytes.MAX_VALUE;
    case MAX:
        return 0x7F;
    default:
        throw new NettyBsonReaderException("It is not defined the byte associated with the type " + bsonType);
    }
}

From source file:com.eightkdata.mongowp.bson.netty.ParsingTools.java

protected static byte getByte(BsonType bsonType) throws NettyBsonReaderException {
    switch (bsonType) {
    case DOUBLE:/* ww w .j  a v a2s .  co m*/
        return 0x01;
    case STRING:
        return 0x02;
    case DOCUMENT:
        return 0x03;
    case ARRAY:
        return 0x04;
    case BINARY:
        return 0x05;
    case UNDEFINED:
        return 0x06;
    case OBJECT_ID:
        return 0x07;
    case BOOLEAN:
        return 0x08;
    case DATETIME:
        return 0x09;
    case NULL:
        return 0x0A;
    case REGEX:
        return 0x0B;
    case DB_POINTER:
        return 0x0C;
    case JAVA_SCRIPT:
        return 0x0D;
    case DEPRECATED:
        return 0x0E;
    case JAVA_SCRIPT_WITH_SCOPE:
        return 0x0F;
    case INT32:
        return 0x10;
    case TIMESTAMP:
        return 0x11;
    case INT64:
        return 0x12;
    case MIN:
        return UnsignedBytes.MAX_VALUE;
    case MAX:
        return 0x7F;
    default:
        throw new NettyBsonReaderException("It is not defined the byte associated with the type " + bsonType);
    }
}

From source file:org.anarres.dhcp.common.address.AddressUtils.java

@Nonnull
public static byte[] toBroadcastAddress(@Nonnull byte[] in, @Nonnegative int netmask) {
    int idx = netmask / Byte.SIZE;
    if (idx < in.length) {
        int mask = toByteMask(netmask);
        in[idx] &= mask;/*w w  w.  j av  a2s .c o m*/
        in[idx] |= ~mask;
        Arrays.fill(in, idx + 1, in.length, UnsignedBytes.MAX_VALUE);
    }
    return in;
}

From source file:org.apache.beam.runners.dataflow.util.RandomAccessData.java

/**
 * Returns a RandomAccessData that is the smallest value of same length which
 * is strictly greater than this. Note that if this is empty or is all 0xFF then
 * a token value of positive infinity is returned.
 *
 * <p>The {@link UnsignedLexicographicalComparator} supports comparing {@link RandomAccessData}
 * with support for positive infinitiy./*from  w w w  .  j  a v  a  2s .  c om*/
 */
public RandomAccessData increment() throws IOException {
    RandomAccessData copy = copy();
    for (int i = copy.size - 1; i >= 0; --i) {
        if (copy.buffer[i] != UnsignedBytes.MAX_VALUE) {
            copy.buffer[i] = UnsignedBytes.checkedCast(UnsignedBytes.toInt(copy.buffer[i]) + 1);
            return copy;
        }
    }
    return POSITIVE_INFINITY;
}

From source file:org.anarres.dhcp.common.address.AddressUtils.java

/**
 * Constructs an address suitable for use as a mask.
 *
 * The return value is a big-endian byte array of the specified length.
 * The high <code>netmask</code> bits will be 1 and the remaining low bits will be 0.
 * For example, the address may be of the form 255.255.240.0 or ff:ff:fc:....
 *///w w  w.  j a  v  a 2  s.  com
@Nonnull
public static byte[] toNetworkMask(@Nonnegative int addressLength, @Nonnegative int netmask) {
    byte[] out = new byte[addressLength];
    int idx = netmask / Byte.SIZE;
    if (idx < addressLength) {
        Arrays.fill(out, 0, idx, UnsignedBytes.MAX_VALUE);
        out[idx] = (byte) toByteMask(netmask);
    } else {
        Arrays.fill(out, UnsignedBytes.MAX_VALUE);
    }
    return out;
}