I am trying to pull a .jpg image off of a server, and display it as and EncodedImage
in a ZoomScreen
. Because this .jpg could be very large I want to save the .jpg to a file and read it from there so i don't have the whole thing sitting in memory.
The problem I'm facing is that Connector.open("http.url.com/file.jpg") is either throwing an IOException
with the message "Bad Socket Id", or it is throwing a ClassCastException
when i attempt to open a FileConnection
to the URL. Here is an example of what i've tried:
try {
FileConnection fileIn = (FileConnection)Connector.open(fileURL);
FileConnection fileOut = (FileConnection)Connector.open(fileDest);
if(!fileOut.exists())
fileOut.create();
InputStream is = fileIn.openInputStream();
OutputStream os = fileOut.openOutputStream();
while(fileIn.canRead() && fileOut.canWrite()){
os.write(is.read());
}
is.close();
os.close();
fileIn.close();
fileOut.close();
EncodedImage image = EncodedImage.getEncodedImageResource(fileDest);
UiApplication.getUiApplication().pushScreen(new ZoomScreen(image));
} catch (Exception e) {
e.printStackTrace();
}
I'm getting most of this from RIM, but I'm missing something. I know the url is correct because i use the same format when i stream audio from the same server. The exception is being thrown on the first line, when i attempt to connect to the server.
Does anyone have experience with this?