@Override InternalBinaryStringEncoder getEncoder() { return new AbstractBouncyCastleInternalBinaryStringEncoder(new HexEncoder(), BLOCK_SIZE, CHAR_SIZE) { @Override public boolean isValidEncoding(byte b) { return ((b >= 0x2f && b <= 0x39) || (b >= 0x41 && b <= 0x46) || (b >= 0x61 && b <= 0x66)); } }; } }
public HexEncoder() { initialiseDecodingTable(); }
/** {@inheritDoc} */ protected void writeEncoded( final byte[] data, final int offset, final int length) throws IOException { encoder.encode(data, offset, length, out); } }
/** {@inheritDoc} */ protected void fillBuffer() throws IOException { position = 0; decodeBuffer.reset(); final int count = in.read(byteBuffer); if (count > 0) { encoder.decode(byteBuffer, 0, count, decodeBuffer); } } }
/** {@inheritDoc} */ public byte[] toBytes(final String input) { if (delimitBytesFlag) { final ByteArrayOutputStream out = new ByteArrayOutputStream(); final String[] hexBytes = splitPattern.split(input); for (String hexByte : hexBytes) { try { encoder.decode(hexByte, out); } catch (IOException e) { throw new IllegalArgumentException(e.getMessage()); } } return out.toByteArray(); } else { return super.toBytes(input); } }
@Override InternalBinaryStringEncoder getEncoder() { return new AbstractBouncyCastleInternalBinaryStringEncoder(new HexEncoder(), BLOCK_SIZE, CHAR_SIZE) { @Override public boolean isValidEncoding(byte b) { return ((b >= 0x2f && b <= 0x39) || (b >= 0x41 && b <= 0x46) || (b >= 0x61 && b <= 0x66)); } }; } }
public HexEncoder() { initialiseDecodingTable(); }
/** {@inheritDoc} */ public String fromBytes( final byte[] input, final int offset, final int length) { if (delimitBytesFlag) { final byte[] delimBytes = byteDelimiter.getBytes(); final ByteArrayOutputStream out = new ByteArrayOutputStream(); for (int i = offset; i < length; i++) { try { if (i > offset) { out.write(delimBytes); } encoder.encode(input, offset + i, 1, out); } catch (IOException e) { throw new IllegalArgumentException(e.getMessage()); } } // Use the default character set since the delimiter likely comes // from platform character set, which could possibly be outside ASCII return out.toString().toUpperCase(); } else { return super.fromBytes(input, offset, length); } }