public SmppProcessingException(int errorCode, String msg) { super("SMPP processing error [0x" + HexUtil.toHexString(errorCode) + "]" + (msg == null ? "" : " message [" + msg + "]")); this.errorCode = errorCode; }
public byte[] hexStringToByteArray(String s) { return HexUtil.toByteArray(s); }
/** * Appends 16 characters to a StringBuilder with the long in a "Big Endian" * hexidecimal format. For example, a long 0xAABBCCDDEE123456 will be appended as a * String in format "AABBCCDDEE123456". A long of value 0 will be appended as "0000000000000000". * @param buffer The StringBuilder the long value in hexidecimal format * will be appended to. If the buffer is null, this method will throw * a NullPointerException. * @param value The long value that will be converted to a hexidecimal String. */ static public void appendHexString(StringBuilder buffer, long value) { appendHexString(buffer, (int)((value & 0xFFFFFFFF00000000L) >>> 32)); appendHexString(buffer, (int)(value & 0x00000000FFFFFFFFL)); }
/** * Appends a byte array to a StringBuilder with each byte in a "Big Endian" * hexidecimal format. For example, a byte 0x34 will be appended as a * String in format "34". A byte array of { 0x34, 035 } would append "3435". * @param buffer The StringBuilder the byte array in hexidecimal format * will be appended to. If the buffer is null, this method will throw * a NullPointerException. * @param bytes The byte array that will be converted to a hexidecimal String. * If the byte array is null, this method will append nothing (a noop) */ public static void appendHexString(StringBuilder buffer, byte[] bytes) { assertNotNull(buffer); if (bytes == null) { return; // do nothing (a noop) } appendHexString(buffer, bytes, 0, bytes.length); }
/** * Creates a String from a byte array with each byte in a "Big Endian" * hexidecimal format. For example, a byte 0x34 will return a * String "34". A byte array of { 0x34, 035 } would return "3435". * @param buffer The StringBuilder the byte array in hexidecimal format * will be appended to. If the buffer is null, this method will throw * a NullPointerException. * @param bytes The byte array that will be converted to a hexidecimal String. * If the byte array is null, this method will append nothing (a noop) * @param offset The offset in the byte array to start from. If the offset * or length combination is invalid, this method will throw an IllegalArgumentException. * @param length The length (from the offset) to conver the bytes. If the offset * or length combination is invalid, this method will throw an IllegalArgumentException. */ public static String toHexString(byte[] bytes, int offset, int length) { if (bytes == null) { return ""; } assertOffsetLengthValid(offset, length, bytes.length); // each byte is 2 chars in string StringBuilder buffer = new StringBuilder(length * 2); appendHexString(buffer, bytes, offset, length); return buffer.toString(); }
/** * Appends a byte array to a StringBuilder with each byte in a "Big Endian" * hexidecimal format. For example, a byte 0x34 will be appended as a * String in format "34". A byte array of { 0x34, 035 } would append "3435". * @param buffer The StringBuilder the byte array in hexidecimal format * will be appended to. If the buffer is null, this method will throw * a NullPointerException. * @param bytes The byte array that will be converted to a hexidecimal String. * If the byte array is null, this method will append nothing (a noop) * @param offset The offset in the byte array to start from. If the offset * or length combination is invalid, this method will throw an IllegalArgumentException. * @param length The length (from the offset) to conver the bytes. If the offset * or length combination is invalid, this method will throw an IllegalArgumentException. */ static public void appendHexString(StringBuilder buffer, byte[] bytes, int offset, int length) { assertNotNull(buffer); if (bytes == null) { return; // do nothing (a noop) } assertOffsetLengthValid(offset, length, bytes.length); int end = offset + length; for (int i = offset; i < end; i++) { int nibble1 = (bytes[i] & 0xF0) >>> 4; int nibble0 = (bytes[i] & 0x0F); buffer.append(HEX_TABLE[nibble1]); buffer.append(HEX_TABLE[nibble0]); } }
@Override public String toString() { StringBuilder buffer = new StringBuilder(40); if (tagName != null) { buffer.append(this.tagName); } else { buffer.append("tlv"); } buffer.append(": 0x"); buffer.append(HexUtil.toHexString(this.tag)); buffer.append(" 0x"); buffer.append(HexUtil.toHexString((short)getUnsignedLength())); buffer.append(" ["); HexUtil.appendHexString(buffer, this.value); buffer.append("]"); return buffer.toString(); }
return null; assertOffsetLengthValid(offset, length, hexString.length()); int highNibble = hexCharToIntValue(hexString.charAt(i)); int lowNibble = hexCharToIntValue(hexString.charAt(i+1)); bytes[j++] = (byte)(((highNibble << 4) & 0xF0) | (lowNibble & 0x0F));
/** * Appends 2 characters to a StringBuilder with the byte in a "Big Endian" * hexidecimal format. For example, a byte 0x34 will be appended as a * String in format "34". A byte of value 0 will be appended as "00". * @param buffer The StringBuilder the byte value in hexidecimal format * will be appended to. If the buffer is null, this method will throw * a NullPointerException. * @param value The byte value that will be converted to a hexidecimal String. */ static public void appendHexString(StringBuilder buffer, byte value) { assertNotNull(buffer); int nibble = (value & 0xF0) >>> 4; buffer.append(HEX_TABLE[nibble]); nibble = (value & 0x0F); buffer.append(HEX_TABLE[nibble]); }
@Override public String toString() { StringBuilder buffer = new StringBuilder(40); if (tagName != null) { buffer.append(this.tagName); } else { buffer.append("tlv"); } buffer.append(": 0x"); buffer.append(HexUtil.toHexString(this.tag)); buffer.append(" 0x"); buffer.append(HexUtil.toHexString((short)getUnsignedLength())); buffer.append(" ["); HexUtil.appendHexString(buffer, this.value); buffer.append("]"); return buffer.toString(); }
/** * Appends a byte array to a StringBuilder with each byte in a "Big Endian" * hexidecimal format. For example, a byte 0x34 will be appended as a * String in format "34". A byte array of { 0x34, 035 } would append "3435". * @param buffer The StringBuilder the byte array in hexidecimal format * will be appended to. If the buffer is null, this method will throw * a NullPointerException. * @param bytes The byte array that will be converted to a hexidecimal String. * If the byte array is null, this method will append nothing (a noop) */ public static void appendHexString(StringBuilder buffer, byte[] bytes) { assertNotNull(buffer); if (bytes == null) { return; // do nothing (a noop) } appendHexString(buffer, bytes, 0, bytes.length); }
/** * Creates a String from a byte array with each byte in a "Big Endian" * hexidecimal format. For example, a byte 0x34 will return a * String "34". A byte array of { 0x34, 035 } would return "3435". * @param buffer The StringBuilder the byte array in hexidecimal format * will be appended to. If the buffer is null, this method will throw * a NullPointerException. * @param bytes The byte array that will be converted to a hexidecimal String. * If the byte array is null, this method will append nothing (a noop) * @param offset The offset in the byte array to start from. If the offset * or length combination is invalid, this method will throw an IllegalArgumentException. * @param length The length (from the offset) to conver the bytes. If the offset * or length combination is invalid, this method will throw an IllegalArgumentException. */ public static String toHexString(byte[] bytes, int offset, int length) { if (bytes == null) { return ""; } assertOffsetLengthValid(offset, length, bytes.length); // each byte is 2 chars in string StringBuilder buffer = new StringBuilder(length * 2); appendHexString(buffer, bytes, offset, length); return buffer.toString(); }
/** * Appends a byte array to a StringBuilder with each byte in a "Big Endian" * hexidecimal format. For example, a byte 0x34 will be appended as a * String in format "34". A byte array of { 0x34, 035 } would append "3435". * @param buffer The StringBuilder the byte array in hexidecimal format * will be appended to. If the buffer is null, this method will throw * a NullPointerException. * @param bytes The byte array that will be converted to a hexidecimal String. * If the byte array is null, this method will append nothing (a noop) * @param offset The offset in the byte array to start from. If the offset * or length combination is invalid, this method will throw an IllegalArgumentException. * @param length The length (from the offset) to conver the bytes. If the offset * or length combination is invalid, this method will throw an IllegalArgumentException. */ static public void appendHexString(StringBuilder buffer, byte[] bytes, int offset, int length) { assertNotNull(buffer); if (bytes == null) { return; // do nothing (a noop) } assertOffsetLengthValid(offset, length, bytes.length); int end = offset + length; for (int i = offset; i < end; i++) { int nibble1 = (bytes[i] & 0xF0) >>> 4; int nibble0 = (bytes[i] & 0x0F); buffer.append(HEX_TABLE[nibble1]); buffer.append(HEX_TABLE[nibble0]); } }
return null; assertOffsetLengthValid(offset, length, hexString.length()); int highNibble = hexCharToIntValue(hexString.charAt(i)); int lowNibble = hexCharToIntValue(hexString.charAt(i+1)); bytes[j++] = (byte)(((highNibble << 4) & 0xF0) | (lowNibble & 0x0F));
/** * Appends 2 characters to a StringBuilder with the byte in a "Big Endian" * hexidecimal format. For example, a byte 0x34 will be appended as a * String in format "34". A byte of value 0 will be appended as "00". * @param buffer The StringBuilder the byte value in hexidecimal format * will be appended to. If the buffer is null, this method will throw * a NullPointerException. * @param value The byte value that will be converted to a hexidecimal String. */ static public void appendHexString(StringBuilder buffer, byte value) { assertNotNull(buffer); int nibble = (value & 0xF0) >>> 4; buffer.append(HEX_TABLE[nibble]); nibble = (value & 0x0F); buffer.append(HEX_TABLE[nibble]); }
public SmppProcessingException(int errorCode, String msg) { super("SMPP processing error [0x" + HexUtil.toHexString(errorCode) + "]" + (msg == null ? "" : " message [" + msg + "]")); this.errorCode = errorCode; }
@Override public String toString() { StringBuilder buffer = new StringBuilder(40); if (tagName != null) { buffer.append(this.tagName); } else { buffer.append("tlv"); } buffer.append(": 0x"); buffer.append(HexUtil.toHexString(this.tag)); buffer.append(" 0x"); buffer.append(HexUtil.toHexString((short)getUnsignedLength())); buffer.append(" ["); HexUtil.appendHexString(buffer, this.value); buffer.append("]"); return buffer.toString(); }
/** * @deprecated Please use new utility class HexUtil * @see HexUtil#toByteArray(java.lang.CharSequence, int, int) */ @Deprecated public static byte[] toHexByte(String hexString, int offset, int length) { return HexUtil.toByteArray(hexString, offset, length); }
/** * Appends 16 characters to a StringBuilder with the long in a "Big Endian" * hexidecimal format. For example, a long 0xAABBCCDDEE123456 will be appended as a * String in format "AABBCCDDEE123456". A long of value 0 will be appended as "0000000000000000". * @param buffer The StringBuilder the long value in hexidecimal format * will be appended to. If the buffer is null, this method will throw * a NullPointerException. * @param value The long value that will be converted to a hexidecimal String. */ static public void appendHexString(StringBuilder buffer, long value) { appendHexString(buffer, (int)((value & 0xFFFFFFFF00000000L) >>> 32)); appendHexString(buffer, (int)(value & 0x00000000FFFFFFFFL)); }
/** * Appends 4 characters to a StringBuilder with the short in a "Big Endian" * hexidecimal format. For example, a short 0x1234 will be appended as a * String in format "1234". A short of value 0 will be appended as "0000". * @param buffer The StringBuilder the short value in hexidecimal format * will be appended to. If the buffer is null, this method will throw * a NullPointerException. * @param value The short value that will be converted to a hexidecimal String. */ static public void appendHexString(StringBuilder buffer, short value) { assertNotNull(buffer); int nibble = (value & 0xF000) >>> 12; buffer.append(HEX_TABLE[nibble]); nibble = (value & 0x0F00) >>> 8; buffer.append(HEX_TABLE[nibble]); nibble = (value & 0x00F0) >>> 4; buffer.append(HEX_TABLE[nibble]); nibble = (value & 0x000F); buffer.append(HEX_TABLE[nibble]); }