Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6359201
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T23:29:13+00:00 2026-05-24T23:29:13+00:00

I’m working on some code which POSTs large packets often over HTTP to a

  • 0

I’m working on some code which POSTs large packets often over HTTP to a REST server on IIS. I’m using the RIM/JavaME HTTPConnection class.

As far as I can tell HTTPConnection uses an internal buffer to “gather” up the output stream before sending the entire contents to the server. I’m not surprised, since this is how HttpURLConnect works by default as well. (I assume it does this so that the content-length is set correctly.) But in JavaSE I could override this behavior by using the method setFixedLengthStreamingMode so that when I call flush on the output stream it would send that “chunk” of the stream. On a phone this extra buffering is too expensive in terms of memory.

In Blackberry Java is there a way to do fixed-length streaming on a HTTP request, when you know the content-length in advance?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T23:29:14+00:00Added an answer on May 24, 2026 at 11:29 pm

    So, I never found a way to do this was the base API for HTTPConnection. So instead, I created a socket and wrapped it with my own simple HTTPClient, which did support chunking.

    Below is the prototype I used and tested on BB7.0.

    package mypackage;
    
    import java.io.IOException;
    import java.io.InputStreamReader;
    import java.io.OutputStreamWriter;
    import javax.microedition.io.Connector;
    import javax.microedition.io.SocketConnection;
    
    public class MySimpleHTTPClient{
    
        SocketConnection sc;
        String HttpHeader;
        OutputStreamWriter outWriter;
        InputStreamReader inReader;
    
        public void init(
                String Host, 
                String port, 
                String path, 
                int ContentLength, 
                String  ContentType ) throws IllegalArgumentException, IOException
        {
            String _host = (new StringBuffer())
                        .append("socket://")
                        .append(Host)
                        .append(":")
                        .append(port).toString();
            sc = (SocketConnection)Connector.open(_host );
            sc.setSocketOption(SocketConnection.LINGER, 5);
            StringBuffer _header = new StringBuffer();
            //Setup the HTTP Header.
            _header.append("POST ").append(path).append(" HTTP/1.1\r\n");
            _header.append("Host: ").append(Host).append("\r\n");
            _header.append("Content-Length: ").append(ContentLength).append("\r\n");
            _header.append("Content-Type: ").append(ContentType).append("\r\n");
            _header.append("Connection: Close\r\n\r\n");
            HttpHeader = _header.toString();
        }
    
        public void openOutputStream() throws IOException{
            if(outWriter != null) 
                return;
            outWriter = new OutputStreamWriter(sc.openOutputStream());
            outWriter.write( HttpHeader, 0 , HttpHeader.length() );
        }
    
        public void openInputStream() throws IOException{
            if(inReader != null) 
                return;
            inReader = new InputStreamReader(sc.openDataInputStream());
        }
    
        public void writeChunkToServer(String Chunk) throws Exception{
            if(outWriter == null){
                try {
                    openOutputStream();
                } catch (IOException e) {e.printStackTrace();}
            } 
            outWriter.write(Chunk, 0, Chunk.length());
        }
    
        public String readFromServer() throws IOException {
            if(inReader == null){
                try {
                    openInputStream();
                } catch (IOException e) {e.printStackTrace();}
            }
            StringBuffer sb = new StringBuffer();
            int data = inReader.read();
            //Note ::  This will also read the HTTP headers..
            // If you need to parse the headers, tokenize on \r\n for each 
            // header, the header section is done when you see \r\n\r\n
            while(data != -1){
                sb.append( (char)data  );
                data = inReader.read();
            }
            return sb.toString();
        }
    
        public void close(){
            if(outWriter != null){
                try {
                    outWriter.close();
                } catch (IOException e) {}
            }
            if(inReader != null){
                try {
                    inReader.close();
                } catch (IOException e) {}
            }
            if(sc != null){
                try {
                    sc.close();
                } catch (IOException e) {}
            }
        }
    }
    

    Here is example usage for it:

    MySimpleHTTPClient myConn = new MySimpleHTTPClient() ;
    String chunk1 = "ID=foo&data1=1234567890&chunk1=0|";
    String chunk2 = "ID=foo2&data2=123444344&chunk1=1";
    try {
        myConn.init(
                "pdxsniffe02.webtrends.corp", 
                "80",
                "TableAdd/234234234443?debug=1",
                chunk1.length() + chunk2.length(), 
                "application/x-www-form-urlencoded" 
        );
    
        myConn.writeChunkToServer(chunk1);
        //The frist chunk is already on it's way.
        myConn.writeChunkToServer(chunk2);
        System.out.println( myConn.readFromServer() );
    
    } catch (IllegalArgumentException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    }finally{
        myConn.close();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm making a simple page using Google Maps API 3. My first. One marker
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I have a bunch of posts stored in text files formatted in yaml/textile (from
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.