I want to decode a Base64 encoded file. I did a Google search and the easiest-to-use library seemed to be two Java classes, so I decided to do my app in Java.
I want to read a Outlook Express 4 mail file, where parts are encoded and others are not. I'm currently reading in the whole file, converting it to a string and searching for encoded blocks. Works great, finds the blocks correctly.
Now my problem: I end up with a String object named base64 which contains the encoded string. The decoding class is derived from FilterInputStream and expects an InputStream object passed to the constructor. But the only InputStream I can see that handles strings is StringInputString which is deprecated and saim the String directlyd to behave incorrectly. You should obviously use StringReader to read from strings.
My question: how can I get some kind of InputStream object, either fro or from StringReader?
For the time being I'll convert the String to a byte array and use a ByteArrayInputStream, but this is notoriously inefficient!
Thx in advance for any help.
All the buzzt CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
Unfortunately I can't help at the moment - if no-one replies before tomorrow I should be able to while I'm supposed to be working . My home PC is VERY bare at the moment after I wiped it - so I can't test anything.
If you still need help tomorrow I'd be glad to give you a hand.
I managed to get it to work, but it involves several unnecessary copies, so I'd be happy if someone would find a way that uses less copies.
Thanks.
Here's the final code.
All the buzzt CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
I've had a look through the java docs and through some of my own work. The only real way to do this is to use Byte Arrays.
The problem with the StringBufferInputStream is that it only uses the low 8-bits of the String. Therefore if you know your encoding its not a problem (8-bit obviously).
From all other examples I (and others) have used the Byte approach. The only advice is that you don't do the copying explicitly, just 'shove' it in the constructor for the Base64InputStream: