/** * Decodes the given base 16 encoded bytes. */ public static byte[] decode(byte[] b16) { return b16 == null || b16.length == 0 ? b16 : codec.decode(b16, b16.length); } }
/** * Returns a base 16 encoded byte array of the given bytes. */ public static byte[] encode(byte[] bytes) { return bytes == null || bytes.length == 0 ? bytes : codec.encode(bytes); }
@Override public byte[] decode(byte[] src, final int length) { if (length % 2 != 0) { throw new IllegalArgumentException( "Input is expected to be encoded in multiple of 2 bytes but found: " + length ); } final byte[] dest = new byte[length / 2]; for (int i=0, j=0; j < dest.length; j++) { dest[j] = (byte) ( pos(src[i++]) << 4 | pos(src[i++]) ) ; } return dest; }
/** * Returns a base 16 encoded byte array of the given bytes. */ public static byte[] encode(byte[] bytes) { return bytes == null || bytes.length == 0 ? bytes : codec.encode(bytes); }
/** * Decodes the given base 16 encoded bytes. */ public static byte[] decode(byte[] b16) { return b16 == null || b16.length == 0 ? b16 : codec.decode(b16, b16.length); } }
@Override public byte[] decode(byte[] src, final int length) { if (length % 2 != 0) { throw new IllegalArgumentException( "Input is expected to be encoded in multiple of 2 bytes but found: " + length); } final byte[] dest = new byte[length / 2]; for (int i = 0, j = 0; j < dest.length; j++) { dest[j] = (byte) ( pos(src[i++]) << BITS_4 | pos(src[i++]) ); } return dest; }
/** * Returns a base 16 encoded string (in upper case) of the given bytes. */ public static String encodeAsString(byte ... bytes) { if (bytes == null) return null; return bytes.length == 0 ? "" : CodecUtils.toStringDirect(codec.encode(bytes)); }
/** * Decodes the given base 16 encoded string, * skipping carriage returns, line feeds and spaces as needed. */ public static byte[] decode(String b16) { if (b16 == null) return null; if (b16.length() == 0) return new byte[0]; byte[] buf = new byte[b16.length()]; int len = CodecUtils.sanitize(b16, buf); return codec.decode(buf, len); }
@Override public byte[] decode(byte[] src, final int length) { if (length % 2 != 0) { throw new IllegalArgumentException( "Input is expected to be encoded in multiple of 2 bytes but found: " + length ); } final byte[] dest = new byte[length / 2]; for (int i=0, j=0; j < dest.length; j++) { dest[j] = (byte) ( pos(src[i++]) << 4 | pos(src[i++]) ) ; } return dest; }
/** * Returns a base 16 encoded string (in lower case) of the given bytes. */ public static String encodeAsString(byte ... bytes) { if (bytes == null) return null; return bytes.length == 0 ? "" : CodecUtils.toStringDirect(codec.encode(bytes)); }
/** * Decodes the given base 16 encoded string, * skipping carriage returns, line feeds and spaces as needed. */ public static byte[] decode(String b16) { if (b16 == null) return null; if (b16.length() == 0) return new byte[0]; byte[] buf = new byte[b16.length()]; int len = CodecUtils.sanitize(b16, buf); return codec.decode(buf, len); }
@Override public byte[] decode(byte[] src, final int length) { if (length % 2 != 0) { throw new IllegalArgumentException( "Input is expected to be encoded in multiple of 2 bytes but found: " + length); } final byte[] dest = new byte[length / 2]; for (int i = 0, j = 0; j < dest.length; j++) { dest[j] = (byte) ( pos(src[i++]) << BITS_4 | pos(src[i++]) ); } return dest; }
/** * Returns a base 16 encoded byte array of the given bytes. */ public static byte[] encode(byte[] bytes) { return bytes == null || bytes.length == 0 ? bytes : codec.encode(bytes); }
/** * Decodes the given base 16 encoded bytes. * @param b16 the byte[] to decode. * @return the decoded result. */ public static byte[] decode(byte[] b16) { return b16 == null || b16.length == 0 ? b16 : CODEC.decode(b16, b16.length); } }
@Override public byte[] decode(byte[] src, final int length) { if (length % 2 != 0) { throw new IllegalArgumentException( "Input is expected to be encoded in multiple of 2 bytes but found: " + length); } final byte[] dest = new byte[length / 2]; for (int i = 0, j = 0; j < dest.length; j++) { dest[j] = (byte) ( pos(src[i++]) << BITS_4 | pos(src[i++]) ); } return dest; }
/** * @param bytes the bytes. * @return a 16 encoded byte array of the given bytes. */ public static byte[] encode(byte[] bytes) { return bytes == null || bytes.length == 0 ? bytes : CODEC.encode(bytes); }
/** * Decodes the given base 16 encoded bytes. */ public static byte[] decode(byte[] b16) { return b16 == null || b16.length == 0 ? b16 : codec.decode(b16, b16.length); } }
@Override public byte[] decode(byte[] src, final int length) { if (length % 2 != 0) { throw new IllegalArgumentException( "Input is expected to be encoded in multiple of 2 bytes but found: " + length ); } final byte[] dest = new byte[length / 2]; for (int i=0, j=0; j < dest.length; j++) { dest[j] = (byte) ( pos(src[i++]) << 4 | pos(src[i++]) ) ; } return dest; }
/** * Returns a base 16 encoded byte array of the given bytes. */ public static byte[] encode(byte[] bytes) { return bytes == null || bytes.length == 0 ? bytes : codec.encode(bytes); }
/** * Decodes the given base 16 encoded bytes. */ public static byte[] decode(byte[] b16) { return b16 == null || b16.length == 0 ? b16 : codec.decode(b16, b16.length); } }