DataOutputStream HTTP Post rinse and segment the encoding problems

Hello

I'm finally back to the question that I had a few months ago, but I can't always solve this

I used this article to understand how to upload files into pieces of a server: http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800332/800431/How_To _...

Downloading is easy to implement, but I have problems with the download. I am trying to download a large file into smaller pieces. I tried different options. The one that works best is when I use DataOutputStream and write in there after each small party has been read from the file.

But when I used the flush() function then he threw OutOfMemoryException()! But only if the file is quite large.

An example of code:

InputStream    is = (StreamConnection)Connector.open(url , Connector.READ_WRITE, true);
HttpConnection c = (HttpsConnection)is;

//set connection parameters
c.setRequestMethod( HttpConnection.POST );
c.setRequestProperty( "User-Agent", "MyUserAgent/0.2" );

for( ;; )
{   if( done ) break;

   //i have removed some reading code to simlify example
   out.write( bytedata  , 0 , bytesRead );
   Thread.yield();
}

out.flush();     //<-- OutOfMemory exception here!

int result = c.getResponseCode();

out.close();

I found that I wasn't the only one to have this problem.

1: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4212479

2: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5026745

I usually have the same code, but only use HTTPConnection for this.

The solution was to use "Chunked" encoding of the header and appellant hunting every time data is written to the output stream.

However, it has not worked for me. If I use a stored block coding, I 'ConnectionClosedException' when flush() is used for the first time.

Here is a code example:

InputStream    is = (StreamConnection)Connector.open(url , Connector.READ_WRITE, true);
HttpConnection c = (HttpsConnection)is;

//set connection parameters
c.setRequestMethod( HttpConnection.POST );
c.setRequestProperty( "User-Agent", "MyUserAgent/0.2" );
c.setRequestProperty( HttpProtocolConstants.HEADER_TRANSFER_ENCODING, "chunked" );

for( ;; )
{
   if( done ) break;

   //i have removed some reading code to simlify example
   out.write( bytedata  , 0 , bytesRead );
   Thread.yield();
   out.flush();     //<-- ConnectionClosedException
}

int result = c.getResponseCode();

out.close();

Here is a screenshot of the at the time of the exception stack trace:

And here are the details of the exception:

Now, I honestly don't know what to do next. I tried all sorts of options and choices, but can not get this to work for some reason to download any.

Tried on BlackBerry JDE and Simulator 4.2.1

Help, please

Thank you.

Thank you, but I think that this was not related to this problem.

The solution is to use SocketConnection would work on writing data OutputStream and flush(). But only if the Content-Length is calculated with precision and this server application is also properly formatted.

If there are errors in the POST request, the server would send a message back and ConnectionClosedException appear.

The best way to resolve these issues is to get a sniffer package good as "Wireshark" and study all the packages with a lot of attention even a small typo can break everything.

I have another question, but the download itself works with the function flush() as expected on the device and emulator. So I think this can be considered fixed.

Tags: BlackBerry Developers

Similar Questions

  • I use Windows Live Hot Mail... and have the same problems as the previous person, asking a question on their e-mail. The only option I have to choose tools are on internet option. It's not correct my problem front of e-mail... suggestions?

    I use Windows Live Hot Mail... and have the same problems as the previous person, asking a question on their e-mail.  The only option I have to choose tools are on internet option.  This is not fix my problem before the email (to make changes to the police and have the new police to stay)... of suggestions?

    Hello, please send your application in the Windows Live Hotmail Forums.  Here is the link...

    http://answers.Microsoft.com/en-us/windowslive/default.aspx

    I hope that this information is beneficial.

    Thank you

    Aaron
    Microsoft Answers Support Engineer
    Visit our Microsoft answers feedback Forum and let us know what you think

  • The printer indicates that online, my laptop said that it is in offline mode, I've deleted and reinstalled the printer and still the same problem,

    The printer indicates that online, my laptop said that it is in offline mode, I've deleted and reinstalled the printer and still the same problem, please help

    You are not quite correct.  Some newer wireless printers have only a wireless connection.  No USB port and a standard Ethernet cable port.

  • I'm not on IE, I have Mozilla Firefox and have the same problem. I can only make temporary fix and it goes backward.

    We have Windows 7 with Windows Live Mail and Mozilla Firefox.  We are not receive mail and when I click on send and receive and window appears and says I am offline and asks if I want to go to the line, YES/NO, I select Yes the box back again and I select YES once more, then I get a dialog box that has a yellow triangle with our 2 addresses with a canceled address. When I click on the globe to go to the line, then click on send and reception, I recover the small box, I click Yes and back again and I click Yes once more and the great dialog box returns with only an address with a green check mark next to it.
    I'm went to the file in Mozilla and tried to change the button Off Line several times, as recommended.  It did not help.

    I'm not on IE, I have Mozilla Firefox and have the same problem

    Same thing as what? We cannot see what question you are referring.

    However, he is indifferent to any browser that you normally use. A third-party program interferes with the Windows Internet connection. The only way to fix this problem before the registry change is to deselect the work offline option in the file menu of Internet Explorer. (Internet Explorer is much more than a browser. Among other things, it offers connectivity Internet for Windows, used for example by all browsers and e-mail programs.

  • I deleted the bridge and ran the uninstall problem. Now, there seems to be no way to re-download it. How do I do that?

    I deleted the bridge and ran the uninstall problem. Now, there seems to be no way to re-download it. How do I do that? Can someone help me?

    Hi Amy,

    Please download the Bridge application from the link below:

    All updates of Adobe CC: Direct for Windows download links | ProDesignTools

    Kind regards

    Sheena

  • After Effects CS6: Cache and reload the film problem

    After Effects CS6: Cache and reload the film problem

    I have trouble to get my images to be updated in an AE project.

    In an existing project, there is a sequence of images in a publication.  I saved and closed AE, modified images (same size and quantity of images, only the pixel data changes) and then restarted AE and open the project.  Although I've changed the images, the old content still appears.

    To resolve this problem, I did the following:

    Edition > purge > all memory

    Edition > purge > picture Cache memory

    Edit > Preferences > media & Disk Cache > clear Disk Cache

    Edit > Preferences > media & Disk Cache > clean database & Cache

    In the project window, I selected all the sequences and selected Reload

    None of them got the images to update.  I could click the film twice in the project bin and scrub the playhead and the old footage was still displayed.

    Finally, I had to replace the film with himself and that solved the problem.

    If it is operator error, lack of understanding of the functions of cache, or something else, I would be grateful for some assistance. I don't remember this behavior in CS 5.5, so I think it's a change in SC6.

    Win 7 Pro 64-bit Service Pack 1

    Intel Xeon processor X 5450 @ 3 .00GHz 2.99 GHz

    20 GB OF RAM

    I think I found the solution or what the cause of the problem, at least in my case!

    I exported the image many in a single folder and later imported into AE sequence choose all together multiple sΘquence. I then created a model composition copied several times and tried to replace valid images dragging in their computer and replacing the model holding Alt. But it does not work. Everything I've done.

    SOLUTION: move footage in each separate folder (in Solution Explorer) and then imported one after the other and rest is all used!

    I hope I helped someone! See you soon!

  • HTTP POST will fail with the status code 400

    Hello

    I am trying to DISPLAY some data but my code still fails with code 400. I tried to change the URL and the method and adding different headers but I get the same answer. What I am doing wrong? My code is below.

    HttpConnection connection = null;
    DataOutputStream outputStream = null;
    
    try {
    connection = (HttpConnection) Connector.open(serverUrl);
                connection.setRequestMethod("POST");
                connection.setRequestProperty("Content-Type", "application/json;charset=UTF-8");            
    
                outputStream = connection.openDataOutputStream();
                outputStream.write(new String("test").getBytes());
    
                outputStream.flush();
                outputStream.close();                       
    
                if (connection.getResponseCode() == HttpConnection.HTTP_OK) {
                    isSuccess = true;
                } else {
                    failureMessage = "Error message " + connection.getResponseMessage();
                }
            } catch (IOException e) {
                failureMessage = "IOException: " + e.getMessage();
            } catch (Exception e) {
                failureMessage = e.getMessage();
            } finally {
                if (outputStream != null)
                    try {
                        outputStream.close();
                    } catch (IOException e) {
                        // Nothing to do
                    }
                if (connection != null)
                    try {
                        connection.close();
                    } catch (IOException e) {
                        // Nothing to do
                    }
            }
    

    In the end, the solution was to add "interface = wifi" at the end of the URL. I guess I'll have more problems when I switch to 3G, but for now it's ok.

    @Peter,

    I just wanted to say your responses in this forum have always been invaluable and led me to the right solutions. Your posts here and here were very useful to fix this that I had spent several hours on. So thanks a lot!

  • Outlook Express keeps trying to compact my messages. I'm unable to post messages and get the Error 0x800ccc0d code and I can not remove outlook Express

    Outlook Express keeps trying to shoot my messages several times per day.
    I'm unable to view messages in Outlook Express and get the code of Error 0x800ccc0d
    I'm unable to remove Outlook Express from my computer, I did not need it that I use Windows live mail.
    Any ideas on how to stop this nuisance.

    Windows Search is installed?

    You must tell Windows Search to stop indexing OE.

    In the control panel. Indexing Options. Change. Clear the check box for Outlook Express.

  • Acrobat 8 Professional can not repair acrobat for El Capitan on mac. If I click Cancel the program repairs her self and work. Once I turned off the computer and restart the same problem persists.

    Acrobat 8 Professional does not work when trying to open .pdf documents. Repair instructions does not work. I use OS X El Captain on my mac. However, if I click on the tab to cancel the program request to make changes to the my computer and when I give permission to the program corrections and to open documents (also the work of program OK after the corrections are installed). However, when the computer is turned off, the corrections are not preserved and I have the same problems whenever I start. How can I get a download to make permanent fixes?

    Post edited by: Alvin Strickland - Acrobat 8 Pro initiates changes automatically once I give permission for changes to the computer and does so in a few seconds, the document opens.

    Hi alvins52918593 ,

    Would like to inform that Acrobat 8 Pro is not compatible with this version of MAC OS.

    Please see this KB article for version requirement older:- Tech specs | Adobe Acrobat Pro XI

    Kind regards

    Christian

  • Had to uninstall first pro CS4 adobe and reinstall the original problem, I could get my edited project but when I sent it again he would burn no audio video now it's all messed up

    Need help with CS4 does not

    Need someone to help... more information please click below and provide the requested information

    -Premiere Pro video Editing information FAQ http://forums.adobe.com/message/4200840

  • Drag and drop the gambling problem

    Hi guys, im new to Flash and this forum and I really need help because im totally stuck for the last 3 days. I am train to create a simple drag / move the game in flash 5 dragable elements with 5 bins where they are supposed to be kept and bounce back on its initial position if they do not hit the correct location. The problem is that only 2 of the elements work as they are supposed to and also to return to their original position when you press the reset button and the rest 3 don't. The other 3 articles do not yet meet the reset button and that they do not end up where they are supposed to when you drag, they end up all the way to the right (in another tray) what have I done wrong? I can't find any errors in my code either! Ive put matching items for stores etc... so please if someone could just check if they see errors in my code because I think ive gone blind now.

    Gor ratt och fel osynliga symbolerna.

    right_mc. Visible = false;

    wrong_mc. Visible = false;

    //

    var orig1X:Number = item1_mc.x;

    var orig1Y:Number = item1_mc.y;

    var orig2X:Number = item2_mc.x;

    var orig2Y:Number = item2_mc.y;

    var orig3X:Number = item3_mc.x;

    var orig3Y:Number = item3_mc.y;

    var orig4X:Number = item4_mc.x;

    var orig4Y:Number = item4_mc.y;

    var orig5X:Number = item5_mc.x;

    var orig5Y:Number = item5_mc.y;

    item1_mc.addEventListener (MouseEvent.MOUSE_DOWN, dragTheObject);

    item1_mc.addEventListener (MouseEvent.MOUSE_UP, item1Release);

    item2_mc.addEventListener (MouseEvent.MOUSE_DOWN, dragTheObject);

    item2_mc.addEventListener (MouseEvent.MOUSE_UP, item2Release);

    item3_mc.addEventListener (MouseEvent.MOUSE_DOWN, dragTheObject);

    item3_mc.addEventListener (MouseEvent.MOUSE_UP, item3Release);

    item4_mc.addEventListener (MouseEvent.MOUSE_DOWN, dragTheObject);

    item4_mc.addEventListener (MouseEvent.MOUSE_UP, item4Release);

    item5_mc.addEventListener (MouseEvent.MOUSE_DOWN, dragTheObject);

    item5_mc.addEventListener (MouseEvent.MOUSE_UP, item5Release);

    skapar en liten hand nar man placerar musen over objects

    item1_mc.buttonMode = true;

    item2_mc.buttonMode = true;

    item3_mc.buttonMode = true;

    item4_mc.buttonMode = true;

    item5_mc.buttonMode = true;

    function dragTheObject(event:MouseEvent):void {}

    var item: MovieClip = MovieClip (event.target);

    item.startDrag ();

    var topPos:uint = this.numChildren - 1;

    this.setChildIndex (item, topPos);

    };

    function item1Release(event:MouseEvent):void {}

    var item: MovieClip = MovieClip (event.target);

    item.stopDrag ();

    If (avc_mc.hitTestPoint (item.x, item.y)) {}

    Item.x = avc_mc.x;

    Item.y = avc_mc.y;

    } else {}

    Item.x = orig1X;

    Item.y = orig1Y;

    }

    };

    function item2Release(event:MouseEvent):void {}

    var item: MovieClip = MovieClip (event.target);

    item.stopDrag ();

    If (miljo_mc.hitTestPoint (item.x, item.y)) {}

    Item.x = miljo_mc.x;

    Item.y = miljo_mc.y;

    } else {}

    Item.x = orig2X;

    Item.y = orig2Y;

    }

    };

    function item3Release(event:MouseEvent):void {}

    var item: MovieClip = MovieClip (event.target);

    item.stopDrag ();

    If (trashbag_mc.hitTestPoint (item.x, item.y)) {}

    Item.x = trashbag_mc.x;

    Item.y = trashbag_mc.y;

    } else {}

    Item.x = orig3X;

    Item.y = orig3Y;

    }

    };

    function item4Release(event:MouseEvent):void {}

    var item: MovieClip = MovieClip (event.target);

    item.stopDrag ();

    If (avs_mc.hitTestPoint (item.x, item.y)) {}

    Item.x = avs_mc.x;

    Item.y = avs_mc.y;

    } else {}

    Item.x = orig4X;

    Item.y = orig4Y;

    }

    };  function item5Release(event:MouseEvent):void {}

    var item: MovieClip = MovieClip (event.target);

    item.stopDrag ();

    If (apotek_mc.hitTestPoint (item.x, item.y)) {}

    Item.x = apotek_mc.x;

    Item.y = apotek_mc.y;

    } else {}

    Item.x = orig5X;

    Item.y = orig5Y;

    }

    answer_btn.addEventListener (MouseEvent.CLICK, checkAnswers);

    reset_btn.addEventListener (MouseEvent.CLICK, reset);

    };  function checkAnswers(event:MouseEvent):void {}

    If (avc_mc.hitTestPoint (item1_mc.x, item1_mc.y) & &)

    miljo_mc.hitTestPoint (item2_mc.x, item2_mc.y) & &

    trashbag_mc.hitTestPoint (item3_mc.x, item3_mc.y) & &

    avs_mc.hitTestPoint (item4_mc.x, item4_mc.y) & &

    {apotek_mc.hitTestPoint (item5_mc.x, item5_mc.y))}

    wrong_mc. Visible = false;

    right_mc. Visible = true;

    } else {}

    wrong_mc. Visible = true;

    right_mc. Visible = false;

    }

    } ; int reset(event:MouseEvent):void {}

    item1_mc.x = orig1X;

    item1_mc.y = orig1Y;

    item2_mc.x = orig2X;

    item2_mc.y = orig2Y;

    item3_mc.x = orig3X;

    item3_mc.y = orig3Y;

    item4_mc.x = orig4X;

    item4_mc.y = orig4Y;

    item5_mc.x = orig5X;

    item5_mc.y = orig5Y;

    right_mc. Visible = false;

    wrong_mc. Visible = false;

    }

    As far as your code goes, as a starting point, you could try is to use event.currentTarget event.target instead.  Event.Target can point to an object that lives inside the object with the assigned listener.  event.currentTarget pointing to the object that has the assigned listener.  See if that helps.

    I don't see why your reset function would not put everything back where it came from as long as you change frames and reassign the values origX/Y...

    For your own mental health better, you need to be more patient, when the hope of help - especially on a weekend.  One thing that you should avoid is to post a reply to your advertisement, you wonder why no one answers, because it adds the number of responses... 1 with 0 replies showing is what helps people to take notice of an announcement that did not have an answer.

  • Copy files to and from the PC problem

    No device

    When I Pug in the USB for PC cord, Win7 says that the device must be formatted first. The manual never mentions this possibility and the formatting from sounds pretty bad to me, unless there is a partition on the device, isolate this action.

    Can anyone help on this?

    Well, I spent $ 14.95 and enlisted the new, I think, support for WebOS. Last week I had live free chat service, but his week that they told me

    In any case, I was directed through telephone conversation to due a full erase and which leads to a re-formatting of TP.... with no harm to the BONE, and restore your apps, etc. the HP backup system handles it for you. That worked, as soon as I returned to the computer, the named player of the HP TouchPad appeared. He said that the car had a size of about 11.5 GB with only 141 MB used. The tech thought BONE was approximately 1 GB. the manual or something told me that you do not see the size of 16 GB. The technology also cited $385. package for service of the TP if necessary... HP is trying to re-coop some of their losses on this product?

    The conclusion is that the drive has been damaged in some way and not formatted for PC it would see. The full erase lead to a re - format the TP that was the way to emphasise with the PC.

    Thanks for your help, I will proceed to load CM - 9 at the next opportunity.

  • Http post: always answer with the value 1

    Hi all

    I have this code below. I always have the value "1″ in return; No files, or other values...

    This means that the value sent by 'POST' it always set to '1 '.

    Where is the error?

    Thank you very much!

    var myFile = new File("C:/APPS/Test/temp.jpg");
    var myLine = "";
    authorization of var = "";

    length of County

    boundaryContent = "-1234\n";
    boundaryContent += ' Content-Disposition: form-data; name = "upload"; filename = "'+ MyFile.Name +'" "+"\n";
    boundaryContent += "Content-Type:"+ "image/jpeg" + "\n"; '.
    boundaryContent += "\n";
    myFile.open ("r");
    myLine = myFile.read ();
    boundaryContent += myLine;
    myFile.close ();
    boundaryContent += "\n";
    boundaryContent += "- 1234 -" + "\n";

    Alert ("calculate file size:" + boundaryContent.length);

    County of end

    conn1 = new Socket;

    If (conn1.open ('127.0.0.1:8888', 'BINARY')) {}

    conn1. Timeout = 9000;

    conn1.writeln ("POST /Enterprise/config/plugins/NoWoodwing/servlet_temp.php HTTP/1.1");
    conn1.writeln ("Host: 127.0.0.1:8888");
    conn1.writeln ("Keep-Alive: 300");
    conn1.writeln ("Connection: keep-alive");
    conn1.writeln ("Content-Length:" + boundaryContent.length);

    conn1.writeln ("Expect: 100-continue");
    conn1.writeln ("Content-Type: multipart/form-data;") Boundary = 1234");
    conn1.writeln("");
    var boundaryContent1 = conn1.writeln("--1234");
    boundaryContent1 += conn1.writeln ('Content-Disposition: form-data: name = "upload"; filename = "'+ myFile.name +'" ');
    boundaryContent1 += conn1.writeln ("Content-Type:" + "image/jpeg");
    boundaryContent1 += conn1.writeln("");
    permission = conn1.readln ();
    Alert ("Autorizzazione:" + permission);
    If (permission == ' HTTP/1.1 100 continue') {}
    If (myFile.open ("r")) {}
    myLine = myFile.read ();
    Alert ("Nuova linea:" + myLine);
    boundaryContent1 += conn1.write (myLine);
    myFile.close ();
    }
    }
    boundaryContent1 += conn1.writeln("");
    boundaryContent1 += conn1.write("--1234--");

    Alert ("development of Post size file:" + boundaryContent1);

    /*
    var reply1 = ";
    {while(!conn1.) EOF)}
    reply1 += conn1.readln ();
    };
    Alert ("back:" + reply1);
    */

    conn1. Close();

    } else {alert ("error:" + conn1.error) ;}}

    It works if you run the upload of file with another tool, such as a browser?

    conn1 = new Socket;
    if (conn1.open ("127.0.0.1:8888", "BINARY")) {
        conn1.timeout=9000;
        conn1.writeln("POST /Enterprise/config/plugins/NoWoodwing/servlet_temp.php HTTP/1.1");
    

    Well, we certainly will be able to test that. Can you find an example of a server that is accessible to the public that accepts uploads and test against that?

  • Small office informed poster area and displays the current programs

    original title: shady on screen

    I have a small light colored oblong top left of my screen which shows whether the program is running.  Can someone tell me why he's here and how to get rid of.

    Thank you.

    Hi rosebo,

    If you do not already, all the troubleshooting steps that Mahesh listed in the previous post. In addition to these measures, if it is a recent issue, perform a System Restore. If there is a change in system caused this problem, restore the system should solve this problem for you by rolling the settings from your computer to a date when the problem occurred.

  • My third HP7500A all in one printer now and having the same problem: 0xc19a003. What to do?

    Anyone know how to solve the problem? I have already turned off the computer - and the new.

    Hi LisaB,

    You will need to contact support to get this replaced printer. Click on the following link for the number of contacts for technical support for your region.

    http://www.HP.com/cgi-bin/hpsupport/index.pl

Maybe you are looking for