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

Ric Klaren klaren at cs.utwente.nl
Tue Jul 6 07:47:08 PDT 2004


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
-- 
-----+++++*****************************************************+++++++++-------
    ---- Ric Klaren ----- j.klaren at utwente.nl ----- +31 53 4893755  ----
-----+++++*****************************************************+++++++++-------
  Xander: "Buffy, we need to do something *now*"
  Angel: "We need a distraction."
  Buffy: "Right."
  Angel: "What are you going to do?"
  Buffy: "I'm going to kill them all. That oughtta distract 'em..."



 
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