How to convert a byte Array to Base64 String in Blackberry
The following code block shows how to convert a byte array in to base64 string
private String encodeBase64( byte[] toEncode, int offset, int length ) {
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(length);
Base64OutputStream base64OutputStream = new Base64OutputStream( byteArrayOutputStream );
try{
base64OutputStream.write( toEncode, offset, length );
base64OutputStream.flush();
base64OutputStream.close();
}
catch (IOException ioe){
System.out.println("Error in encodeBase64() : "+ioe.toString());
return null;
}
return byteArrayOutputStream.toString();
}//fn encodeBase64
The following code shows how how to convert base64 encoded string to bytes
byte[] decoded = Base64InputStream.decode(base64str);