Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Contributor
khalandar
Posts: 41
Registered: ‎09-27-2010
My Device: Not Specified

decode using Base64InputStream, throwing IOException in curve 9300

I am using the following code to decode the data, I am getting IOExpection: Base64: decoding error in bb curve 9300 extended version to 6.0.

 

 

this code is working fine for small size data. but if data size around 300kb its getting failed

and its working fine in tourch 9800 and bold 9790 even for large size data. 

 

byte[] input = data.getBytes();
ByteArrayInputStream bis = new ByteArrayInputStream(input, 0, input.length);
Base64InputStream b64 = new Base64InputStream(bis);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
byte[] buff = new byte[512];

for (int len = b64.read(buff); len != -1; len = b64.read(buff)) {
bos.write(buff, 0, len);
}
byte[] bDecodedFile = bos.toByteArray();
return bDecodedFile;

Please use plain text.
Developer
peter_strange
Posts: 19,595
Registered: ‎07-14-2008
My Device: Not Specified

Re: decode using Base64InputStream, throwing IOException in curve 9300

I suspect this is the same problem as here:

http://supportforums.blackberry.com/t5/Java-Development/Limit-on-the-input-size-for-Base64InputStrea...

and I suggest the same procedure.  Look at the bytes you are trying to process at the time of the failure.  Let us determine if this is a communication issue rather than a Base64 decoding issue. 

Please use plain text.
Developer
peter_strange
Posts: 19,595
Registered: ‎07-14-2008
My Device: Not Specified

Re: decode using Base64InputStream, throwing IOException in curve 9300

 

In response to my post on the other Thread, which read:

 

First thing to do is to check that byte position and the surrounding few bytes in your 9300 and compare it with the same in your other devices.  Are they the same?

I suspect there is more likely to a problem in the input bytes than in the Base 64 decoding.

 

OP updated the other Thread with this message:

http://supportforums.blackberry.com/t5/Java-Development/Limit-on-the-input-size-for-Base64InputStrea...

which reads:

 

I checked in the other device Torch 9800 with  the same code, Its working fine. but it is getting failed in curve 9300. hence there is no issue with the bytes it seems.

In log I am getting "Bad Base64 input character at 18544: 5(decimal)".

 

This is my reply to that comment:

Personally I think if this code, works in one environment and does not work in another environment, then the most likely cause is a difference in the input data.  There is no point looking anywhere else until we have confirmed that the data is the same.

 

Anyway, we know on the 9300 that the processing has complained about some of the input.  Can you investigate the input bytes around position 18544 and tell us what they are? 

 

 

Please use plain text.
Contributor
khalandar
Posts: 41
Registered: ‎09-27-2010
My Device: Not Specified

Re: decode using Base64InputStream, throwing IOException in curve 9300

Hi Peter_strange,

 you are correct the problem is in input data only. but I am getting this input data from a file saved in phone memory(downloaded from email attachment, it can be of large size). I am parsing the file and getting the ecrypted data using the following code

 

String tempString = data.substring(data.indexOf(strtag));
tempString = tempString.substring(tempString.indexOf("value="));
tempString = tempString.substring(tempString.indexOf("\"") + 1);
String value = tempString.substring(0, tempString.indexOf("\""));

 

this "value" is the encoded input data to decode. I compared this with the attachment ecoded data.

Both are same for samll size of data, but for bigger size of data I observed some special charectors in middle(3 or 4 places based on size of the content) and few charectors are missing.

 

I tryed with other parsing technique(parse direct from byte array to get the encoded data) also, I observed same behavior.  But its working fine in other two devices I tested one Bold-9790 and one Torch-9800.

 

Please suggest some solution for this

Please use plain text.
Developer
peter_strange
Posts: 19,595
Registered: ‎07-14-2008
My Device: Not Specified

Re: decode using Base64InputStream, throwing IOException in curve 9300

Took me a while to work out what you were doing here.

 

I think I would have coded your extraction something like the following:

 

int startOfTag = data.indexOf(strtag);

int startOfAtrtibute = data.indexOf("value=",startOfTag + strtag.length());

int startOfValue = data.indexOf("\"",startOfAtrtibute+6) + 1;

int endOfValue = data.indexOf("\"",startOfValue);

String value = data.substring(startOfValue, endOfValue);

 

This saves creating and throwing away 4 String variables.  BTW, the code might not be correct, but you get the idea. 

 

You might like to try this code but I doubt it will solve your problem.

 

There is nothing obvious in the code you have given me that will cause the corruption that you see. 

 

So you will need to look at the processing that puts the attachment in the 'data' variable or look at the attachment itself - is it corrupted there?

 

Just to confirm, looking at this code, if the String value is corrupted, then the string data is almost certainly corrupted to.  So the cause of the corruption is earlier in your processing. 

 

Please use plain text.
Contributor
khalandar
Posts: 41
Registered: ‎09-27-2010
My Device: Not Specified

Re: decode using Base64InputStream, throwing IOException in curve 9300

You are right peter_strange, the downloaded attachment got currupted. But it is very stange, the attachment I downloaded manually from Messages application instead of downloading through my application, then also I observed the attachment got currupted after download.

There is no problem in attachment, because the same email account I configured in other phones(Torch and bold) and same mail attachment I downloaded and obseved no curruption in the file. I am able to decode it normally.

 

how is it possible, can we claim this?

Please use plain text.
Developer
peter_strange
Posts: 19,595
Registered: ‎07-14-2008
My Device: Not Specified

Re: decode using Base64InputStream, throwing IOException in curve 9300

Sorry, I have never attempted to process an email attachment so I don't know where you should start with doing this. 

 

I suggest you try to extract a sample case that demonstrates the problem, that you can give to RIM so that they can repeat the problem themselves. 

 

The other thing to look at is the OS level on the phone.  Perhaps it has a very old OS and if you upgraded it, the problem would go away.  What level of OS do you have on the phone?

Please use plain text.