public BinaryValue convertTo(BinaryValueType binaryValueType) throws XPathException {
//TODO temporary approach, consider implementing a TranscodingBinaryValueFromBinaryString(BinaryValueFromBinaryString) class
//that only does the transncoding lazily
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
FilterOutputStream fos = null;
try {
//transcode
fos = binaryValueType.getEncoder(baos);
streamBinaryTo(fos);
} catch(final IOException ioe) {
throw new XPathException(ioe);
} finally {
if(fos != null) {
try {
fos.close();
} catch(final IOException ioe) {
LOG.error("Unable to close stream: " + ioe.getMessage(), ioe);
}
}