@Override public boolean equals(Object obj) { if (obj instanceof UnsignedByte) { return num == ((UnsignedByte) obj).getSignedValue(); } return false; }
/** * Returns a hex string. * * @param bytes Bytes array. * @return Bytes in hex. */ public static String bytesToHexString(byte[] bytes) { checkNotNull(bytes, "Argument [bytes] may not be null"); StringBuilder buffer = new StringBuilder(); for (int i = 0; i < bytes.length; i++) { buffer.append(UnsignedByte.toHexString(bytes[i])); if (i < bytes.length - 1) { buffer.append(" "); } } return buffer.toString(); }
/** * Returns a hex string. * * @param bytes Bytes array. * @return Bytes in hex. */ public static String bytesToHexString(byte[] bytes) { checkNotNull(bytes, "Argument [bytes] may not be null"); StringBuilder buffer = new StringBuilder(); for (int i = 0; i < bytes.length; i++) { buffer.append(UnsignedByte.toHexString(bytes[i])); if (i < bytes.length - 1) { buffer.append(" "); } } return buffer.toString(); }
@Override public boolean equals(Object obj) { if (obj instanceof UnsignedByte) { return num == ((UnsignedByte) obj).getSignedValue(); } return false; }
/** * Gets hex string of a byte. * * @param b byte * @return Byte as Hex string. */ public static String toHexString(byte b) { return Integer.toHexString(toInt(b)); }
/** * Gets hex string of a byte. * * @param b byte * @return Byte as Hex string. */ public static String toHexString(byte b) { return Integer.toHexString(toInt(b)); }
/** * Returns a log message. * * @param bytes Bytes array. * @param size data length in bytes array. * @param type Message type. * @return Log message. */ public static String build(byte[] bytes, final int size, MsgType type) { checkNotNull(bytes, "Argument [bytes] may not be null"); checkNotNull(type, "Argument [type] may not be null"); StringBuilder debugMsg = new StringBuilder(); switch (type) { case RECEIVE: debugMsg.append("Received: "); break; case SEND: debugMsg.append("Sent: "); break; default: break; } for (int i = 0; i < size; i++) { int x = UnsignedByte.toInt(bytes[i]); debugMsg.append(Integer.toHexString(x)).append(" "); } return debugMsg.toString(); }
/** * Returns a log message. * * @param bytes Bytes array. * @param size data length in bytes array. * @param type Message type. * @return Log message. */ public static String build(byte[] bytes, final int size, MsgType type) { checkNotNull(bytes, "Argument [bytes] may not be null"); checkNotNull(type, "Argument [type] may not be null"); StringBuilder debugMsg = new StringBuilder(); switch (type) { case RECEIVE: debugMsg.append("Received: "); break; case SEND: debugMsg.append("Sent: "); break; default: break; } for (int i = 0; i < size; i++) { int x = UnsignedByte.toInt(bytes[i]); debugMsg.append(Integer.toHexString(x)).append(" "); } return debugMsg.toString(); }
addressBytes = new byte[4]; System.arraycopy(receivedData, 4, addressBytes, 0, addressBytes.length); int a = UnsignedByte.toInt(addressBytes[0]); int b = UnsignedByte.toInt(addressBytes[1]); int c = UnsignedByte.toInt(addressBytes[2]); int d = UnsignedByte.toInt(addressBytes[3]); portBytes[0] = receivedData[8]; portBytes[1] = receivedData[9]; (UnsignedByte.toInt(portBytes[0]) << 8) | (UnsignedByte.toInt(portBytes[1]))); portBytes[1] = receivedData[5 + size]; logger.debug("Server replied:Address as host:{}, port:{}", new String(addressBytes), (UnsignedByte.toInt(portBytes[0]) << 8) | (UnsignedByte.toInt(portBytes[1]))); } else if (receivedData[3] == AddressType.IPV6) { int size = receivedData[4];
addressBytes = new byte[4]; System.arraycopy(receivedData, 4, addressBytes, 0, addressBytes.length); int a = UnsignedByte.toInt(addressBytes[0]); int b = UnsignedByte.toInt(addressBytes[1]); int c = UnsignedByte.toInt(addressBytes[2]); int d = UnsignedByte.toInt(addressBytes[3]); portBytes[0] = receivedData[8]; portBytes[1] = receivedData[9]; (UnsignedByte.toInt(portBytes[0]) << 8) | (UnsignedByte.toInt(portBytes[1]))); portBytes[1] = receivedData[5 + size]; logger.debug("Server replied:Address as host:{}, port:{}", new String(addressBytes), (UnsignedByte.toInt(portBytes[0]) << 8) | (UnsignedByte.toInt(portBytes[1]))); } else if (receivedData[3] == AddressType.IPV6) { int size = receivedData[4];