Download the image via httpConnection very slowly

I've been wroted a function to get a picture from the internet, the size of the image always in 50x50px, very small, but I have to waste a lot of time for reveiving given, here is my code:

package code;

import java.io.IOException;
import java.io.InputStream;

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

import net.rim.device.api.io.IOCancelledException;
import net.rim.device.api.io.IOUtilities;
import net.rim.device.api.ui.UiApplication;

public class HttpUtility
{
    private static byte[] _imageData;
    private static String _url;

    public static byte[] getInternetImage(String url, boolean waiting)
    {
        _url=url;
        _imageData=null;

        Runnable run=new Runnable()
        {
            public void run()
            {
                byte[] data=null;

                try {
                    HttpConnection httpConnection=(HttpConnection) Connector.open(_url+Function.updateConnectionSuffix());
                    InputStream inputStream=httpConnection.openInputStream();

                    if(inputStream.available()>0)
                    {
                        data=IOUtilities.streamToBytes(inputStream);
                        inputStream.read(data);

                        _imageData=data;
                    }
                } catch(IOCancelledException e2) {Function.errorDialog(e2.toString());}
                  catch (IOException e) {Function.errorDialog(e.toString());}
            }
        };

        if(waiting)
        {
            UiApplication.getUiApplication().invokeAndWait(run);
        } else {
            UiApplication.getUiApplication().invokeLater(run);
        }

        return _imageData;
    }
}

The updateConnectionSuffix() to determine the network environment and choose a better way for httpConnection.

Is there a problem in my code? I have no idea

invokelater executes on the thread of the event, and not on a separate thread.
currently you block your UI until data is available.

See
http://supportforums.BlackBerry.com/T5/Java-development/what-is-the-event-thread/Ta-p/446865

Take a look at the httpdemo to see how you could do it better.

Tags: BlackBerry Developers

Similar Questions

  • I took a video on my Android phone that is currently playing in Windows Media Player 90 to the horizontal. on VLC player, but the image quality is very poor on this player.

    original title: video orientation

    I took a video on my Android phone that is currently playing in Windows Media Player 90 to the horizontal. I tried to watch the videos on VLC Player, but the image quality is very poor on this player. I have Windows XP Home Edition so the moviemaker product will not work. Are there other options available to get my videos to play properly?

    You can rotate the video to display in VLC media player:

    Open an it... then video and pause go to...
    Tools / effects and filters / video effects tab / geometry tab.
    Select the check box turn / slide the circle / close / play.

    If you want the video permanently turned... Movie Maker
    worth a try, but you will need to convert the video to the
    . Before importing WMV format.

    There are many converters available on the net... some
    free... some detail.

    The following freeware converter is just one example:

    (FWIW... it's always a good idea to create a system)
    Restore point before installing software or updates)

    Format Factory (freeware)
    http://www.videohelp.com/tools/Format_Factory
    (the 'direct link' is faster download)
    (the file you want to download is: > FFSetup280.zip<>
    (FWIW... installation..., you can uncheck
    ('all' boxes on the final screens)
    (Windows XP / Vista / 7)

    First, you will need to decompress the file or just open the
    Drag FFSetup280.exe out of the folder
    and drop it on your desktop. To install left click.

    Next, after the download and installation of Format
    Factory... you can open the program and
    left click on the toolbar, the "Option" button and
    "Select an output folder to" / apply / OK.
    (this is where you find your files after they)
    are converted)

    Drag and drop your video clips on the main screen...

    Select "all to WMV" / OK...

    Click on... Beginning... in the toolbar...

    That should do it...

    Good luck...

  • Loading/downloading the images from the camera

    I downloaded the images from the camera to the computer, then accidentally deleted from the memory card.  Move them back to the memory card?

    I downloaded the images from the camera to the computer, then accidentally deleted from the memory card.  Move them back to the memory card?

    =====================================================
    FWIW... this task is easier to do than to explain.

    (1) connect the camera via a USB cable and turn it on... or insert the memory card in
    your Media Player.

    (2) go to... Start / my computer... your camera should be attached to a drive letter.
    The reader should be recognized as one or several removable disks... it can
    have several drive letters.

    Removable disk (e :))
    Removable drive (g)
    Removable disk (h :))

    Left 3) click on drive letters... When you identify the drive letter for the camera or
    Media Player... (it will be one that does not launch a dialog box indicating:)
    Please insert a disc in the drive?) ...

    Follow these steps...

    4) navigate to the folder in which the photos are... Open it and go... Edition/select all... good
    Click the group selected (highlighted), then from the menu choose... Send to /.
    Removable disk?

    Only a limited number of files can be copied to the root directory of the card... if you
    Transfer lots of pictures... they must be in one or more folders.

    If these files have been changed in any way, rename, rotate, changing the brightness...
    No matter what... the camera will recognize them is no longer, but they will always be on the map
    If you want to use as a backup. You can click on the left to see what is on the drive letter
    the map.

    Volunteer - MS - MVP - Digital Media Experience J - Notice_This is not tech support_I'm volunteer - Solutions that work for me may not work for you - * proceed at your own risk *.

  • Download the image blob field

    Hello experts,

    I am trying to download an image via the input file to convert it to a blob field and then save it in the database.

    So I linked the value of the input file to create the blob through bean, I found on the internet.

    My Page binding components:

    < af:inputFile id = value = "#{UploadBean.file}" / 'inputImage' >

    < af:button text = 'Upload' id = 'btnUpload' action = "#{UploadBean.uploadImage}" / >


    My Bean:


    private BlobDomain img;

    private UploadedFile inasmuch;

    public UploadBean() {}

    Super();

    }

    public UploadedFile getFile() {}

    return inasmuch;

    }

    {} public void next (file UploadedFile)

    Inasmuch = file;

    }

    public void uploadImage() {}

    UploadedFile myfile = (UploadedFile) this.getFile ();

    IMG = createBlobDomain (myfile);

    System.out.println (IMG);

    }

    Private BlobDomain createBlobDomain (file UploadedFile) {}

    InputStream in = null;

    BlobDomain blobDomain = null;

    OutputStream out = null;

    try {}

    in = file.getInputStream ();

    blobDomain = new BlobDomain();

    out = blobDomain.getBinaryOutputStream ();

    ubyte [] buffer = new byte [8192];

    int bytesRead = 0;

    While ((bytesRead = in.read (buffer, 0, 8192))! = - 1) {}

    out. Write (buffer, 0, bytesRead);

    }

    in. Close();

    } catch (IOException e) {}

    e.printStackTrace ();

    } catch (SQLException e) {}

    e.fillInStackTrace ();

    }

    Return blobDomain;

    }

    But it seems to me that the file is still set to null after choosing an image, because it throws the following error message:

    <oracle.adf.common> <AdfDiagnosticsJarsVersionDumpImpl> <executeDump> <Pfad für den Dump der JAR-Version :C:\Users\user\AppData\Roaming\JDeveloper\system12.1.3.0.41.140521.1008\DefaultDomain\servers\DefaultServer\adr\diag\ofm\defaultdomain\defaultserver\incident\incdir_45/adf_DiagnosticsJarsVersionDump42_i45.txt>

    < oracle.dfw.impl.incident.DiagnosticsDataExtractorImpl > < DiagnosticsDataExtractorImpl > < createADRIncident > < 46 event mit Problemschlussel 'ADFC-00032 [ADFc]' is >

    < oracle.adf.view > < RichExceptionHandler > < _logUnhandledException > < ADF_FACES - 60098:Faces - empfangt nicht behandelte Exceptions in Phase INVOKE_APPLICATION 5 cases >

    javax.faces.FacesException: #{UploadBean.uploadImage}: //C:/Users/user/AppData/Roaming/JDeveloper/system12.1.3.0.41.140521.1008/o.j2ee/drs/REA/ViewPflegeWebApp.war/de/test/viewpflege/pages/UploadPage.jsff @13,85 action = "#{UploadBean.uploadImage}": java.lang.NullPointerException "

    ...

    What I'm missing or doing wrong?

    Uusing JDeveloper 12.1.3

    Thank you!

    Hello

    Make sure that the UsesUpload of the property in your page jspx is true.

    also, for more information check this: https://tompeez.wordpress.com/2011/11/26/jdev11-1-2-1-0-handling-imagesfiles-in-adf-part-1/

    Kind regards

    Habib

  • What is downloaded the image url?

    I created the script to download the image to the server. After downloading images are located in the directory D:/uploads/logo. What is the url of the image to view it in the browser?

    My web.xml:

    < context-param >
    < description > fileuploads Parent directory location < / description >
    < param-name > APP. FILE_UPLOADS_DIR < / param-name >
    < param-value >/uploads/logo < / param-value >
    < / context-param >

    < filter >
    < filter-name > adfFaces < / filter-name >
    > class filter < oracle.adf.view.rich.webapp.AdfFacesFilter < / class filter >
    < / filter >

    < filter mapping >
    < filter-name > adfFaces < / filter-name >
    < name servlet - > Faces Servlet < / servlet-name >
    < / filter-mapping >

    < servlet >
    < name servlet - > Faces Servlet < / servlet-name >
    > the servlet class < javax.faces.webapp.FacesServlet < / servlet-class >
    < load-on-startup > 1 < / load-on-startup >
    < / servlet >

    < servlet-mapping >
    < name servlet - > Faces Servlet < / servlet-name >
    < url-pattern > /visages / * < / url-pattern >
    < / servlet-mapping >

    Alex,

    There will be no default URL that allows you to view the downloaded images. You will need to do something yourself to make the image visible via a URL; some suggestions would be:

    (1) on the Web/Application Server, create a virtual directory to d:/uploads/logo map
    (2) write your own servlet that can (according to certain parameters you offers in the URL) read the file from the image of the directory and the return flow to the browser

    John

  • How to download the image of the device using javascript

    Hi all

    I developed the web application. In I want to download the image in the folder in my possible device.if blackberry please give the code for me. Thanks in advance...

    Kind regards

    Marimuthu_P

    I did it with PhoneGap and their API FileTransfer long ago.

    I think he uses XHR - here's a great article on how to do several things with XHR and HTML5: http://www.html5rocks.com/en/tutorials/file/xhr2/

  • How to download the image to the server

    Hi all
    1. work on the version of BB storm (9500/9530 Simulator) is v4.7.0.75
    2 opportunity BB JDE v4.7

    3. the request is:

    In my application I have to download the image to the server.

    How to upload photos to my Simulator server.
    For the download, I need to write script server-side?

    any body can help me on this.

    Thanks in advance

    Abreu - Bureddy

    See this article.

    http://supportforums.BlackBerry.com/Rim/Board/message?board.ID=java_dev&thread.ID=17169&view=by_date...

  • Do I need to buy a license, even if I am registered for the promotion of 10 free images? If this isn't the case, then how the hell do you want to download the images?

    Do I need to buy a license, even if I am registered for the promotion of 10 free images? If this isn't the case, then how the hell do you want to download the images?

    Go to your license history and you will see the license key. By clicking above opens a dialog where you can buy an extended license, simply select scope from the menu drop down.

  • I just bought two images, but there are so many link or anywhere for me to download the images. How can I download these?

    I just bought two images, but there are so many link or anywhere for me to download the images. How can I download these?

    Just follow these steps: I downloaded my 10 free images and they all have the Adobe watermark on them, so I can't use them. Why do they have a watermark on them?

  • Is there a shortcut key for "Flatten Image"?  I just upgraded to CC and again it is not a shortcut for IT... Ugh.  Someone knows something to flatten the Image via the keyboard?

    Is there a shortcut key for "Flatten Image"?  I just upgraded to CC and again it is not a shortcut for IT... Ugh.  Someone knows something to flatten the Image via the keyboard?

    I've been using Ctrl + Alt + Shift + F for years, don't know if it's a default shortcut, or if I assigned.

    You can create your own sets of shortcuts - Edition > keyboard shortcuts.

  • try to download the software: via the link provided in the email, I get an error page «» Then I tried via my account by clicking on the link 'Download' screen 'my order. " Then, I get a message saying "you have no download. I'm almost ready to fi

    Hi, I just bought first elements. I paid online via Paypal. I got the Adobe confirmation email a few hours later. I then try to download the software: via the link provided in the email, I get an error page «» Then I tried via my account by clicking on the link 'Download' screen 'my order. " Then, I get a message saying "you have no download. I'm almost ready to file a complaint with Paypal for fraudulent online sales. What should I do?

    Hi H D,

    Tell us the name of the product you have purchased.

    Please visit: http://www.adobe.com/downloads/other-downloads.html

    Let me know if it helps.

    Concerning

    Megha Rawat

  • How to download the image of the BLOB, inline in new browser tab or window

    APEX V4.2.3

    I have an interactive relationship with a column of type blob download which is the inline value.  When I click on the link 'Download' the image automatically appears in the same window as the application of the APEX.  How do I download the image in a new tab in the browser?  I need to shake "target ="_blank"' somewhere but I don't know where that link structure is hidden."

    Here is the code for my download section in the interactive report.

    Select

    ....,

    decode (nvl (dbms_lob.getlength (BLOB_CONTENT), 0), 0, null,)

    "< img style =" border: 4px solid #CCC; " -moz-border-radius: 4px; -webkit - border-radius: 4px; » '||

    "src =" "|

    apex_util.get_blob_file_src ('P98_BLOB_CONTENT', image_id) |

    "' '" height = "100" width = "100" alt = "'. Name of FILE: ' "" title = "'. FILE name | " » / >")

    as detail_img,

    ....

    of ' #OWNER # '. " TIS_ATTACHMENTS ".

    ...

    Thanks in advance

    PaulP

    I suggest you

    SELECT ID, NAME,CASE WHEN NVL(dbms_lob.getlength(document),0) = 0
      THEN NULL
      ELSE CASE WHEN attach_mimetype like 'image%'
      THEN ''
      ELSE
      'Download'
      end
      END new_img
      FROM TEST_WITH_BLOB
    
  • I don't know why I can't download the image of my student during the proof of eligibility card?

    I am trying to download the image of my student card for proof that I'm amstudent, but when the presentation starts the image disappear. It is a jpeg image. How can we not

    How can I do?

    Please try using another web browser for you to bid.

    Moved to this discussion in the forum student and Teacher Edition Information.

  • can we get the name of the image before you download the image?

    Hi all

    I have image download in my application.

    Problem is that the user can download the image with the same name several times.

    Can we get the name of the image before upload? I think that we cannot name before downloading.

    I have here a way to get the name of the image before upload?

    Chavigny hi...

    In some cases of fileReferance you can get the name.

    link will help you.

    http://livedocs.Adobe.com/Flex/3/langref/Flash/NET/FileReference.html#propertySummary

    Thank you

    Vikram

  • Download the image file from the server

    Hi I want to download the image file of the server.

    When you download a file save dialogue comes. I don't want this dialog box.

    There will be a specific location where this file is saved.

    Can someone help me?

    Thank you

    CK

    You can not download the file without saving dialog file - it is a security restriction.

Maybe you are looking for