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

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

Introduction

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

Prototype

@Beta
@CheckReturnValue
public static String toString(byte x, int radix) 

Source Link

Document

Returns a string representation of x for the given radix, where x is treated as unsigned.

Usage

From source file:se.sics.caracaldb.utils.ByteArrayFormatter.java

public static String toHexString(byte[] bytes) {
    if (bytes == null) {
        return "(null)";
    }/*  w w w . j av  a  2  s.co m*/
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < bytes.length; i++) {
        String bStr = UnsignedBytes.toString(bytes[i], 16);
        if (bStr.length() == 1) {
            sb.append('0');
        }
        sb.append(bStr.toUpperCase());
    }
    return sb.toString();
}

From source file:org.opendaylight.vpnservice.mdsalutil.NWUtil.java

public static String toStringIpAddress(byte[] ipAddress) {
    if (ipAddress == null) {
        return "";
    }/*  www  .j ava  2s  .  co m*/

    StringBuilder sb = new StringBuilder(18);

    for (int i = 0; i < ipAddress.length; i++) {
        sb.append(UnsignedBytes.toString(ipAddress[i], 10));
        sb.append(".");
    }

    sb.setLength(17);
    return sb.toString();
}

From source file:org.opendaylight.vpnservice.mdsalutil.NWUtil.java

public static String toStringMacAddress(byte[] macAddress) {
    if (macAddress == null) {
        return "";
    }//from   ww  w.ja  va2s.  c o m

    StringBuilder sb = new StringBuilder(18);

    for (int i = 0; i < macAddress.length; i++) {
        String tmp = UnsignedBytes.toString(macAddress[i], 16).toUpperCase();
        if (tmp.length() == 1 || macAddress[i] == (byte) 0) {
            sb.append("0");
        }
        sb.append(tmp);
        sb.append(":");
    }

    sb.setLength(17);
    return sb.toString();
}

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//ww  w  .ja v a2s  .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 ww . ja  va2  s.  c om*/
 * @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:org.opendaylight.vpnservice.alivenessmonitor.internal.AlivenessMonitorUtil.java

public static String toStringMacAddress(byte[] macAddress) {
    if (macAddress == null) {
        return "";
    }/*www .  j  av  a 2  s  . c om*/

    StringBuilder sb = new StringBuilder(18);

    for (int i = 0; i < macAddress.length; i++) {
        sb.append(UnsignedBytes.toString(macAddress[i], 16).toUpperCase());
        sb.append(":");
    }

    sb.setLength(17);
    return sb.toString();
}

From source file:org.opendaylight.genius.mdsalutil.NWUtil.java

public static String toStringMacAddress(byte[] macAddress) {
    if (macAddress == null) {
        return "";
    }/*from  www .  ja v  a 2 s  .  c  om*/

    StringBuilder sb = new StringBuilder(18);

    for (byte macAddres : macAddress) {
        String tmp = UnsignedBytes.toString(macAddres, 16).toUpperCase();
        if (tmp.length() == 1 || macAddres == (byte) 0) {
            sb.append("0");
        }
        sb.append(tmp);
        sb.append(NwConstants.MACADDR_SEP);
    }

    sb.setLength(17);
    return sb.toString();
}

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

protected static BinarySubtype getBinarySubtype(byte readByte) {
    switch (readByte) {
    case 0x00://from w  w  w.j av a2 s  . com
        return BinarySubtype.GENERIC;
    case 0x01:
        return BinarySubtype.FUNCTION;
    case 0x02:
        return BinarySubtype.OLD_BINARY;
    case 0x03:
        return BinarySubtype.OLD_UUID;
    case 0x04:
        return BinarySubtype.UUID;
    case 0x05:
        return BinarySubtype.MD5;
    default: {
        if (UnsignedBytes.compare(readByte, FIRST_USER_DEFINED) >= 0) {
            return BinarySubtype.USER_DEFINED;
        } else {
            throw new AssertionError("Unrecognized binary type 0x" + UnsignedBytes.toString(readByte, 16));
        }
    }
    }
}

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

@Override
BsonBoolean readBoolean(@Loose @ModifiesIndexes ByteBuf byteBuf) throws NettyBsonReaderException {
    byte readByte = byteBuf.readByte();
    if (readByte == 0x00) {
        return FalseBsonBoolean.getInstance();
    }//from www . j  av  a  2s. c  o  m
    if (readByte == 0x01) {
        return TrueBsonBoolean.getInstance();
    }
    throw new NettyBsonReaderException("Unexpected boolean byte. 0x00 or " + "0x01 was expected, but 0x"
            + UnsignedBytes.toString(readByte, 16) + " was read");
}