IAmGroot
IAmGroot

Reputation: 13865

JavaME Base64InputStream.decode() Limited to 64k string size

How can I overcome the string size limitation.

It seems that calling decode on Strings of size greater than 64k fails.

        is = con.openInputStream();
        String str = new String(IOUtilities.streamToBytes(is), "UTF-8");
        byte[] theArray = Base64InputStream.decode(str);  

Ive tried alsorts, including using

        Base64InputStream bs64 = new Base64InputStream(is);

And then trying to take from the bs64 stream.

It seems however, reading a large size leads to decode error. (Where it wouldnt error if size below 64k the origional way. I spent all day trying to figure this one..

Upvotes: 0

Views: 435

Answers (2)

mthakuri
mthakuri

Reputation: 1095

Trying breaking the string into chunks(By converting string to bytes). Encode each chunk(chunk of bytes) till u finish encoding full string. On the other side. Decoded each chunk and then combine to get the string back.

Note:Don't combine all chunk(chunk of bytes) and then try to decode it because I did that and got decode error.

Upvotes: 1

Rens Verhage
Rens Verhage

Reputation: 5857

You can decode your string in smaller chunks. Decode chunks of 3 bytes or a multitude of 3 bytes (1024 will do nicely) at a time.

Upvotes: 4

Related Questions