[antlr-interest] Re: Parse only <n> bytes from InputStream

andreasharth aharth at gmx.de
Wed Jul 7 09:30:15 PDT 2004


Hi Ric,

thanks for your reply.  I tried to extend CharBuffer.fill() with
	    
// n bytes are read (for http content-length)
_read += amount;

// read enough? close input
if (_read >= _contentLength) {
  input.close();
}

but that didn't do the trick, the connection is closed way to early. 
I presume that fill() is called more than once for every chunk of
input?  

A related question: when does the lexer stop reading in new characters
in the general case?  I'd like to just stop the lexer from reading new
data (or waiting for new data) when the content-length limit is
reached.  Then, leave the reader open and return to where the Parser
and Lexer were invoked to send a proper HTTP reply.

Thanks in advance for your time.

Regards,
Andreas.

--- In antlr-interest at yahoogroups.com, Ric Klaren <klaren at c...> wrote:
> On Tue, Jul 06, 2004 at 02:33:05PM -0000, andreasharth wrote:
> > I have written a small HTTP server in Java and like to parse input
> > from a HTTP PUT operation.  The length of the input in bytes is
> > specified using the content-length header.  I am able to parse the
> > stream that's coming in.  So far, so good.
> > 
> > Problem is that the parser should close the Reader after a number
of
> > bytes (the content-length) have been read.  I could first store
> > everything the HTTP server recieves, and then parse that, but
since I
> > want to process megabytes (and maybe gigabytes) caching things is
not
> > really an option.  I cannot specify and end of file symbol either
> > because that's not in the HTTP protocol.
> > 
> > Is there a way to make the parser stop after having read a given
> > number of bytes?
> 
> I'd implement a custom InputBuffer that would cut off after N bytes.
Then
> initialize the lexer with that one. Look at InputBuffer.java to see
what
> you have to do. You might also get some inspiration from
> lib/cpp/antlr/CharInputBuffer.hpp.
> 
> Cheers,
> 
> Ric



 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/antlr-interest/

<*> To unsubscribe from this group, send an email to:
    antlr-interest-unsubscribe at yahoogroups.com

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 



More information about the antlr-interest mailing list