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
Highlighted
Developer
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:

 

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

Transitional//EN&quot;

&quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;?&#5;-&#43;

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...

Developer
Posts: 19,633
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();
os.write(data);

 

with this:

 

OutputStream os = fconn.openOutputStream();
os.write(data);

 

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.