×

Discussion Board

Results 1 to 6 of 6
  1. #1
    Registered User
    Join Date
    Sep 2003
    Posts
    11

    Problems reading from Input Stream

    I am trying to read an input stream obtained by an http connection into an array, but I am not able to read it completely.

    The methods I have used are:


    --- int numBytes = disAux.read( arrayTotal );

    --- disAux.readFully( arrayTotal );

    --- disAux.read( arrayTotal, 0, dim);

    --- // Reading bytes:
    while( k<dim )
    {
    arrayTotal[k] = leerByte( disAux );
    k++;
    }

    private byte leerByte( DataInputStream disAux )
    throws Exception
    {
    byte b = 0;

    try
    {
    Integer numObjAux = new Integer( disAux.read() );
    b = numObjAux.byteValue();
    numObjAux = null;
    }
    catch( Exception e )
    {
    System.out.println("leerByte: ERROR");
    this.actualizarDisplayConexion("leerByte: ERROR:
    e.getClass():"+e.getClass()+"
    e.getMessage():"+e.getMessage());
    throw e; // lanza excepcion
    }
    return b;
    }


    In this function I obtain an IO Exception, and the message
    associated is:

    " 'chunk' not CALF terminated "


    Please, could anyone tell me something about this?

    Thanks in advance.

  2. #2
    Registered User
    Join Date
    Jul 2003
    Location
    Finland, Tampere
    Posts
    1,113
    hansolo_yo
    'chunk' not CRLF terminated probably.

    As far as I remember HTTP protocol, each line including the last one should end with CR LF combinations, i.e. chars with decimal codes 13 and 10 respectively.

    Your servlet or wherever you get data from probably doesn't follow the HTTP protocol

  3. #3
    Registered User
    Join Date
    Sep 2003
    Posts
    11
    Thanks for your reply.
    The servlet from which I obtain the stream does follow HTTP protocol.

    In fact, the exception does not occur always:

    - I obtain the error sometimes when I try to make a single request to the server and the length of the stream to be read is greater than aprox. 3000 bytes. The response is not read completely.

    -If I try to make several requests to retrieve the same amount of bytes, I obtain the exception after several responses have been read correctly.

  4. #4
    Super Contributor
    Join Date
    Jun 2003
    Location
    Cheshire, UK
    Posts
    7,395
    Does this happen using an emulator and local server, or just when using the real device OTA? WAP gateways impose a limit to the maximum chunk size they will permit... 3k sounds a bit small, I think that's about the smallest limit allowed by the specification. It would make sense that the CRLF pair would be missing from the chunk if it's been truncated by the gateway.

    Graham.

  5. #5
    Registered User
    Join Date
    Sep 2003
    Posts
    11

    New tests

    Thanks for your reply.

    The problem only happens in the real device. With the emulator, working with the same server, there are no problems.

    I am going to tell in more detail what is happening.

    The application tries to read from the server a stream containing a set of records, each of which corresponds to a simbol. Each of these records includes, among other things, the size of the record and an image.

    I have been making some additional tests and here are the results:

    --- First, I have tried to read all the records with a single http request and I have made tests with several sizes. Only in some cases I obtain an error. Yesterday the application could read without problems until 10kb, but that was not the case other days (as I mentioned, I have had problems with smaller sizes).
    The exception obtained here is "arrayIndexOutOfBounds".

    --- Afterwards, I tried to read the records with several http requests, limiting the maximum size of each of these requests. I have tried with several limits and stream sizes. The result is quite interesting: if I make "x" requests and I read "y" simbols on each request, I always obtain a "chunk not CRLF terminated " exception in the last simbol of each request!!!

    Please give me some idea.

  6. #6
    Registered User
    Join Date
    Sep 2003
    Posts
    11

    Partial solution and new problem

    I have added at the end of the last image of the stream an integer, to indicate its final and now aplication is able to read up to 12kb without the exception mentioned, but now I have another problem that I am going to write in another thread....

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •