title: How do you save images to a Blackberry device via HttpConnection?
body: <p>My script fetches xml via httpConnection and saves to persistent store. No problems there.
  Then I loop through the saved data to compose a list of image url's to fetch via queue.</p>
  
  <p>Each of these requests calls the httpConnection thread as so</p>
  
  <p>...</p>
  
  <pre><code>public synchronized void run()
   { 
           HttpConnection connection = (HttpConnection)Connector.open("http://www.somedomain.com/image1.jpg");
           connection.setRequestMethod("GET");
           String contentType = connection.getHeaderField("Content-type");
  
           InputStream responseData = connection.openInputStream();
           connection.close();
  
           outputFinal(responseData, contentType);
  }
  
  public synchronized void outputFinal(InputStream result, String contentType) throws SAXException, ParserConfigurationException, IOException
   {
  
    if(contentType.startsWith("text/"))
    {
         // bunch of xml save code that works fine
  
    }
    else if(contentType.equals("image/png") || contentType.equals("image/jpeg") || contentType.equals("image/gif"))
    {
     // how to save images here?
    }
    else
    {
     //default
    }
   }
  </code></pre>
  
  <p>What I can't find any good documentation on is how one would take the response data and save it to an image stored on the device.</p>
  
  <p>Maybe I just overlooked something very obvious. Any help is very appreciated.
  Thanks</p>
  
  <hr>
  
  <p>I tried following this advise and found the same thing I always find when looking up BB specific issues: nothing.</p>
  
  <p>The problem is that every example or post assumes you know everything about the platform. 
  Here's a simple question: What line of code writes the read output stream to the blackberry device? What path? How do I retrieve it later?</p>
  
  <p>I have this code, which I do not know if it does anything because I don't know where it is supposedly writing to or if that's even what it is doing at all:</p>
  
  <p>** filename is determined on a loop based on the url called.</p>
  
  <pre><code>FileOutputStream fos = null;
  try
  {
      fos = new FileOutputStream( File.FILESYSTEM_PATRIOT, filename );
  
      byte [] buffer = new byte [262144];
      int byteRead;
      while ((byteRead = result.read (buffer ))!=- 1)
      {
          fos.write (buffer, 0, byteRead);
      }
  
      fos.flush();
      fos.close();   
  }
  catch(IOException ieo)
  { 
  }
  finally
  {
      if(fos != null)
      {
          fos.close();
      }
  }
  </code></pre>
  
  <p>The idea is that I have some 600 images pulled from a server. I need to loop the xml and save each image to the device so that when an entity is called, I can pull the associated image - entity_id.png - from the internal storage.</p>
  
  <p>The documentation from RIM does not specify this, nor does it make it easy to begin figuring it out.
  This issue does not seem to be addressed on this forum, or others I have searched.</p>
  
  <p>Thanks</p>