03-05-2012 11:27 PM
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>   text/html????j ????=????? vDOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitiona
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...
03-06-2012 04:39 AM
SInce you do not need to to be a DataOutputStream, can I suggest you replace this:
DataOutputStream os = fconn.openDataOutputStream();
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.