Help - extension for the binary download java

I was wondering if someone could look over what follows and say if I made a simple mistake somewhere in the java code. I wrote an extension to allow me to download a binary file by passing a URL to a web server and a destination file for storage on Board on the BB device.

She does not return errors in javascript, but it is not also download the file to the device.

I call from javascript.

csiFileIO.binImageLoader (imgName, filePath3);

where imgName is the complete URL to the file png on my Web server, and the filePath3 is the location of the file on the device.

And, Yes, the image is in the file config.xml in whitelist

Thanks in advance

package widgetpackage;

import org.w3c.dom.Document;

import net.rim.device.api.browser.field2.BrowserField;
import net.rim.device.api.script.ScriptEngine;
import net.rim.device.api.web.WidgetConfig;
import net.rim.device.api.web.WidgetExtension;

public final class csiFileIO implements WidgetExtension {

    public String[] getFeatureList() {

        String[] result = new String[1];
        result[0] = "csiFileIO";
        return result;
    }

    public void loadFeature(String feature, String version, Document doc,
            ScriptEngine scriptEngine) throws Exception {

        if (feature == "csiFileIO") {
            scriptEngine.addExtension("csiFileIO.binImageLoader", new binImageLoader());
            }

    }

    public void register(WidgetConfig arg0, BrowserField arg1) {
        // TODO Auto-generated method stub

    }

    public void unloadFeatures(Document arg0) {
        // TODO Auto-generated method stub

    }

}
package widgetpackage;

import net.rim.device.api.script.Scriptable;

public final class UpdateImage extends Scriptable { 

    public static final String FIELD_CHANGEICON = "binimageloader";
    private binImageLoader changer;

    public UpdateImage(){
        this.changer = new binImageLoader();
    }

    public Object getField(String name) throws Exception {                  

        if (name.equals(FIELD_CHANGEICON))
        {
            return this.changer;
        }

            return super.getField(name);
    }

}
package widgetpackage;

import java.io.*;

import javax.microedition.io.Connector;
import javax.microedition.io.file.*;
import javax.microedition.io.HttpConnection;

import java.io.IOException;
import net.rim.device.api.io.File;
import net.rim.device.api.script.ScriptableFunction;

public class binImageLoader extends ScriptableFunction {
    String url;
    String fdest;
    public Object invoke(Object obj, Object[] args) throws Exception {
        if (args.length == 2) {
            url   = ((String)args[0]).toString();
            fdest = ((String)args[1]).toString();
            }
    if (url != null ) {
      HttpConnection c = null;
      InputStream is = null;
      int rc;

      try {
          c = (HttpConnection)Connector.open(url);

          // Getting the response code will open the connection,
          // send the request, and read the HTTP response headers.
          // The headers are stored until requested.
          rc = c.getResponseCode();
          if (rc != HttpConnection.HTTP_OK) {
              throw new IOException("HTTP response code: " + rc);
          }

          is = c.openInputStream();

          // Get the length and process the data
          int len = (int)c.getLength();
          if (len > 0) {
               int actual = 0;
               int bytesread = 0 ;
               byte[] data = new byte[len];
               while ((bytesread != len) && (actual != -1)) {
                  actual = is.read(data, bytesread, len - bytesread);
                  bytesread += actual;
               }

               try {
                     FileConnection fconn = (FileConnection)Connector.open(fdest);
                     if (!fconn.exists()) {
                         fconn.create();  // create the file if it doesn't exist
                         DataOutputStream outstream;
                         outstream =fconn.openDataOutputStream();
                         outstream.write(data);
                         outstream.flush();
                         outstream.close();
                     }
                         fconn.close();
                 }
                 catch (IOException ioe) {
                 }

          }
      } catch (Throwable t)
        {
        }
      return UNDEFINED;
      }
    return obj;
    }
  }

Hey thanks for the suggestions. Using what described you I put in some return statements in error (catch blocks) handlers and has managed to reduce it to a my source web server 404 error.

I was able to run unmodified included code and with the method call as I had in the first post on a second web server, and it succeeds.

Thanks again for the pointer and I bought your book - look before you read.

Tags: BlackBerry Developers

Similar Questions

  • Types of bad operand for the binary operator '! =' error

    Hello

    I get the following compilation error:

    types of bad operand for the binary operator '! =';  Firstly, type: oracle.jbo.domain.Date;  Second: null type >

    When I try to compare a Date with null object, for example:

        public static Calendar jboDateToCalendar(Date d) {
            if (d != null && d.getValue() != null) {
                Calendar c = Calendar.getInstance();
                c.setTime(d.getValue());
                return c;
            }
            return null;
        }
    

    I use JDev 12.1.3. running with Java 1.7.0_75.

    Does anyone have an idea? Ever seen this error before.

    Media do not help btw.

    Thank you

    Johannes

    I found the solution. I used only the 'Oracle BC4J areas' library to import the Houston to date data types.

    After adding "Oracle JDBC" such as the library, the errors disappeared.

  • What developer support options are available for the development of Java for the BlackBerry Smartphone?

    What developer support options are available for the development of Java for the BlackBerry Smartphone?

    What plans are available?

    Who can I contact with to register a support plan?

    One of the evangelists 'Developer' RIM working outside South Africa, I think, so there should be someone local you can talk too.  If you message Mark Sohm (the RIM name you will see a lot on the forum - MSohm), with your e-mail address and it ask to put you in contact with the Developer Evangelist in SA, which should help.  You can tell Mark to ask me if he needs clarification.  Do not promise anything either but I hope that something will happen.

  • where the requirements for the current download? This used to be posted prominently.

    where the requirements for the current download? This used to be posted prominently.

    See:

    You can find the full version of the latest version of Firefox 24.0 in all languages and for all systems operating here:

  • Need help now for the live installation

    Need help now for the live installation

    Hello

    As described in the question, I understand that you need help. I will definitely help you however, I would be grateful if you could help me with more information to better understand the problem and resolving it.

    1. What is the problem you are experiencing during installation?

    2. That you install? Any software or operating system?

    3. How you try to install the software/Os/application?

    If you need live support from Microsoft then you can click on the link given below and check if it helps.

    https://support.Microsoft.com/en-us/contactus/

    Hope that this help, please write us back for any further assistance on this point, we will be happy to help you further.

  • Can I register for the automatic download of Adobe Flash Player

    Can I register for the automatic download of Adobe Flash Player, and how do I do this?

    Hello Kenneth

    Adobe Flash Player is a free application, you can download Adobe Flash Player install for all versions

    Thank you

    Varun

  • Hello, I just pay for membership on the cloud creative adobe but I see that I have only a trial for the programs download, do I have to buy each program separately?

    Hello, I just pay for membership on the cloud creative adobe but I see that I have only a trial for the programs download, do I have to buy each program separately?

    Hello Maria,.

    As I checked the details of your account with the e-mail given on the forums you bought subscription Creative Cloud STE and if it is to give you the trial please follow the steps listed below:

    Connect and disconnect activate Cloud Creative applications

    It will be useful.

    Concerning

    Bianka Attre

  • What is the technology used for the integration of java with Flex application?

    How we integrate java into a Flex application or how to build flex applications that use Java as a backend?

    BlazeDs is currently used in businesses to serve the above purpose?

    Or is there a better technology that is used in businesses for the integration of Java with Flex application?

    What is the latest version of BlazeDs?

    Also, please give me a few important article links which shows a sample application in Flex using Java development as a backend.

    Thank you in advance.

    BlazeDS is the way to go. Just google BlazeDS and you will find many examples of link Java to Flex via Remoting and BlazeDS.

  • How can I make my default program for the Adobe Downloads?

    How can I make my default program for the Adobe Downloads?

    Set up the default program depends on the type of file you download, Ex:-PDF file open in Adobe Reader or Acrobat.

    The downloaded file is opened in the default program set on your computer for this file type.

    The steps may vary for Windows and Mac.

    Windows

    Right click on any file with the file type that you want to change the default program Ex:-Pdf,.

    Select 'open with '.

    and from the list select your application that you want to set default Ex: Acrobat

    Check the option on the bottom, "always choose this application to open this file type.

    Mac

    CTRL + click on any file with the file type

    Go to 'Get Info '.

    Modify the Application in the 'open with '.

    Select 'change everything '.

    Close window 'Get info '.

  • With the firefox extension do you recommend for the secure download Youtube music

    Looking for a Youtube Downloader without danger. I don't have confidence these on Google search and menu/extensions for Firefox, there are several to choose. Would like the recommendation of firefox.

    All the Add-ons are safe, if you download "addons.mozilla.org".

    In my opinion, I use the below mentioned Add-ons

  • posing for the path to java.exe in sqldeveloper 2.1.0.62.61

    Hello

    When I try to run the release early adopter of the sqldeveloper 2 (2.1.0.62.61), I wonder the path to java.exe. Should what path I use.

    Thank you
    Oliver

    Hi John,.

    It was a known issue before releasing.
    We didn't want to delay the release of all others so that this issue has been described in the release notes.
    http://www.Oracle.com/technology/products/database/sql_developer/files/relnotes_v2.1.html#sec1

    Downloaded Zip files - ask java.exe+.
    For windows, you have the choice to download the zip without the JDK included. It's not different from previous versions. You need access to the JDK and point SQL Developer for the java.exe on commissioning initial. If you download the zip file that includes the JDK in the early adopter release, you will be asked for the java.exe. You can search for and locate this file in the \sqldeveloper\jdk\jre\bin\ folder.

    For we all non Americans 'dog kicking '.
    http://football.about.com/cs/football101/g/gl_poochkick.htm

    I have initially if it refers to harm us animals ;)

    Hope this helps
    Kind regards
    Dermot
    SQL development team

  • Help me for the drivers XP for HP G50-123NR

    Hello, I recently haven't bought this model no HP G50-123NR notebook and I was wondering where I could get the XP drivers for it? Any help would be appreciated. Thank you

    Your model should ICH9 sata driver sliptreamed in the installer CD of XP.

    Use Nlite to sliptream ICH9 sata driver.
    A good guide for driver sata sliptream, here

    Note: do NOT use this guide sata driver, your sata driver is below ICH9.

    ICH9 sata driver,

    The pilot lies in iaAHCI.inf and is called ICH9M-E/M SATA AHCI Controller, here

    Download nLite, here

    _____

    Drivers XP for G50-123NR (Intel processor + Intel 4500MHD graphics card)

    Intel chipset (install and reboot before other drivers), here

    MS - UAA (required a reboot before Intel video-HDMI, Audio drivers and modem), here

    Intel Graphics Media Accelerator 4500MHD (with HDMI audio driver), here

    Conexant SmartAudio 221 (problem of fixed microphone by forum user) here

    or try the new driver of toshiba modded here (smartaudio works best in the new driver)

    How to install:

    Relax in a folder.run installation program.

    If it errors use Device Manager.
    In Device Manager, right click "Audio Device on HD", choose Update driver,
    Not to connect, install from a list or specific location,

    Select don't search, I will choose the driver to install.
    For the hardware Type select 'show all devices '.
    Remove control "Show compatible hardware" and click on 'disk '.
    Next... Navigate to the unzipped folder and choose the "WiSVHe5.inf".
    Ignore XP when it complains.
    Reset.

    Conexant HDAUDIO Soft Data Fax Modem Driver SmartCP, here

    If you Broadcom Wireless, here

    If you have Intel PRO/Wireless Driver here

    If you have Atheros Wireless driver, here

    or if it doesn't work try here

    RealTek RTL8101E Family PCI - E Fast Ethernet NIC Driver, here

    If you have Realtek usb 2.0 card reader, here

    Synaptics Touchpad Driver, here

    .NET framework (required before HP Quick Launch Buttons), here

    HP Quick Lauch Buttons, here

    If you had for 7 unknown devices (buttons drivers), here

    Do a manual installation

    Go to Device Manager, right click on the unknown device,

    Choose update driver, not to communicate.

    Choose the install from a list or a specific location, not search, have-disk,

    Navigate to the location of machine.inf.

    Do it for the rest of the unknown devices

    Good luck

  • What is the file extension for the files saved with my headers and footers?

    I moved to a new PC and I pray my headers and footers have been moved but I need help looking for files and the file extension would be easier!

    I found my answer

    C:\Users\#username#\AppData\Roaming\Adobe\Acrobat\2015\Preferences\HeaderFooter

  • After the computer crash and reinstall CS, can't reinstall Captivate, for which I pay via a separate subscription.  Go to my account, I see Captivate, but no place for the re - download!

    Could not find a way to download Captivate, even if I have to pay for the subscription.  I can't find any link or how to find the software online.  Help, please.

    I don't use this program so don't know if it is included in the links below, but all I have to offer

    http://www.Adobe.com/downloads/other-downloads.html can help

    -or kglad links in response #1 here https://forums.adobe.com/thread/1930162

  • Error is the installer of the product for the trial downloads

    Hello - I tried to download the evaluation version of Creative Suite Design Premium last night. WHEREAS the two + hours for the process, and at the end, I got the message "error exracting setup of the product (error 101). Check the available disk space on your system and try to download the product again. "Because he was so late, I left there and came back to it today. I assumed that the CS was too big for my system, I decided to just install the two products that I really want, the Photoshop Extended and Illustrator CS, separately. Unfortunately, I got the same error messages. Tried troubleshooting without result. My computer has plenty of available disk space (of 1.34 TB of free space - quite clearly!). All the other tips can you offer me?

    I found my answer in a previous thread on the Forum - it worked for me.

    Here it is:

    41. November 8, 2011 06:50 (in response to stevedolan)

    Re: CS5.5 error Wizard 101 download

    OK, the problem is solved!

    Go to: http://prodesigntools.com/adobe-cs5-5-direct-download-links.html.  There is a direct link that downloads a file Adobe CS5.5 without the help of the software Adobe Download Assistant.  Read and follow the load exactly on this site.  Very Important:  MAKE SURE to SIGN IN or CREATE A FREE ADOBE ID if YOU don't have it ALREADY FACT SO.  If not, you will receive a message saying "access denied" or 'resume your download' and thus preventing the connection.

    Once the files are downloaded (a total of 2 files), extract the files to your desktop.

    After the extraction process is completed, click on the Setup file 'Setup bootstrapping application' in the extracted folder and should manually open the installation screen.  Just follow the installation instructions, and everything should work!  Good luck!

Maybe you are looking for