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

Posts: 34
Registered: ‎08-11-2011
My Device: BlackBerry Bold
My Carrier: Axis

Issue in Saving HTML Web Page with Content-Type: application/vnd.rim.html

Hi, I have an issue when saving a html web page on a BlackBerry device. I'm using the code below to save the InputConnection returned by the BrowserFieldProtocolController's handleResourceRequest(request) method.


InputStream is = ic.openInputStream();
byte[] data = IOUtilities.streamToBytes(is);

FileConnection fconn = FileConnectionUtils.createFileConnectionToNewFile(directoryURI, fileName); // Custom method.

DataOutputStream os = fconn.openDataOutputStream(); os.write(data);

When I try to open the html file on the BlackBerry simulator, the HTML page opens fine. But when I save the web page on a BlackBerry device and reopen the html file on my computer the file becomes filled with weird characters like this:


<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
&#16;&#8;&#1; &#2;&#1;&#4; text/html&#3;&#5;????j&#7; ????=????&#1;? vDOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0



Does anyone know why this happened?


P.S. The Content-Type of the HTTP response on the simulator is "text/ html", but on the device it's "application/vnd.rim.html". Weird...

Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Issue in Saving HTML Web Page with Content-Type: application/vnd.rim.html

SInce you do not need to to be a DataOutputStream, can I suggest you replace this:


DataOutputStream os = fconn.openDataOutputStream();


with this:


OutputStream os = fconn.openOutputStream();


I don't think it will, but using DataOutputStream always raises a concern with me about it trying to be clever with data when in fact we just want the raw bytes from the connection.


The other thing to do is to debug the process, view the bytes that you get in your "data" array and see what they say.  Compare that with what you see on the PC. 


You might find that the 'editor' you are using to view the data from the BlackBerry is converting the data.