Package Parser

Examples of Parser.Parser


        fields.put("Accept", "text/html");
        fields.put("User-Agent", "Jetty");
        MetaData.Request metaData = new MetaData.Request("GET", HttpScheme.HTTP, new HostPortHttpField("localhost:8080"), "/path", HttpVersion.HTTP_2, fields);

        final List<HeadersFrame> frames = new ArrayList<>();
        Parser parser = new Parser(byteBufferPool, new Parser.Listener.Adapter()
        {
            @Override
            public boolean onHeaders(HeadersFrame frame)
            {
                frames.add(frame);
                return false;
            }
        }, 4096, 8192);

        // Iterate a few times to be sure generator and parser are properly reset.
        for (int i = 0; i < 2; ++i)
        {
            ByteBufferPool.Lease lease = new ByteBufferPool.Lease(byteBufferPool);
            generator.generateHeaders(lease, streamId, metaData, false);

            frames.clear();
            for (ByteBuffer buffer : lease.getByteBuffers())
            {
                while (buffer.hasRemaining())
                {
                    parser.parse(buffer);
                }
            }

            Assert.assertEquals(1, frames.size());
            HeadersFrame frame = frames.get(0);
View Full Code Here


    public void testGenerateParseOneByteAtATime() throws Exception
    {
        HeadersGenerator generator = new HeadersGenerator(new HeaderGenerator(), new HpackEncoder());

        final List<HeadersFrame> frames = new ArrayList<>();
        Parser parser = new Parser(byteBufferPool, new Parser.Listener.Adapter()
        {
            @Override
            public boolean onHeaders(HeadersFrame frame)
            {
                frames.add(frame);
                return false;
            }
        }, 4096, 8192);

        int streamId = 13;
        HttpFields fields = new HttpFields();
        fields.put("Accept", "text/html");
        fields.put("User-Agent", "Jetty");
        MetaData.Request metaData = new MetaData.Request("GET", HttpScheme.HTTP, new HostPortHttpField("localhost:8080"), "/path", HttpVersion.HTTP_2, fields);

        ByteBufferPool.Lease lease = new ByteBufferPool.Lease(byteBufferPool);
        generator.generateHeaders(lease, streamId, metaData, false);

        for (ByteBuffer buffer : lease.getByteBuffers())
        {
            while (buffer.hasRemaining())
            {
                parser.parse(ByteBuffer.wrap(new byte[]{buffer.get()}));
            }
        }

        Assert.assertEquals(1, frames.size());
        HeadersFrame frame = frames.get(0);
View Full Code Here

        @SuppressWarnings("unchecked")
        Promise<Session> promise = (Promise<Session>)context.get(SESSION_PROMISE_CONTEXT_KEY);

        Generator generator = new Generator(byteBufferPool, 4096);
        HTTP2ClientSession session = new HTTP2ClientSession(scheduler, endPoint, generator, listener, new HTTP2FlowControl(FlowControl.DEFAULT_WINDOW_SIZE));
        Parser parser = new Parser(byteBufferPool, session, 4096, 8192);
        return new HTTP2ClientConnection(client, byteBufferPool, executor, endPoint, parser, session, 8192, false, promise, listener);
    }
View Full Code Here

    public void testGenerateParse() throws Exception
    {
        GoAwayGenerator generator = new GoAwayGenerator(new HeaderGenerator());

        final List<GoAwayFrame> frames = new ArrayList<>();
        Parser parser = new Parser(byteBufferPool, new Parser.Listener.Adapter()
        {
            @Override
            public boolean onGoAway(GoAwayFrame frame)
            {
                frames.add(frame);
                return false;
            }
        }, 4096, 8192);

        int lastStreamId = 13;
        int error = 17;

        // Iterate a few times to be sure generator and parser are properly reset.
        for (int i = 0; i < 2; ++i)
        {
            ByteBufferPool.Lease lease = new ByteBufferPool.Lease(byteBufferPool);
            generator.generateGoAway(lease, lastStreamId, error, null);

            frames.clear();
            for (ByteBuffer buffer : lease.getByteBuffers())
            {
                while (buffer.hasRemaining())
                {
                    parser.parse(buffer);
                }
            }
        }

        Assert.assertEquals(1, frames.size());
View Full Code Here

    public void testGenerateParseOneByteAtATime() throws Exception
    {
        GoAwayGenerator generator = new GoAwayGenerator(new HeaderGenerator());

        final List<GoAwayFrame> frames = new ArrayList<>();
        Parser parser = new Parser(byteBufferPool, new Parser.Listener.Adapter()
        {
            @Override
            public boolean onGoAway(GoAwayFrame frame)
            {
                frames.add(frame);
                return false;
            }
        }, 4096, 8192);

        int lastStreamId = 13;
        int error = 17;
        byte[] payload = new byte[16];
        new Random().nextBytes(payload);

        ByteBufferPool.Lease lease = new ByteBufferPool.Lease(byteBufferPool);
        generator.generateGoAway(lease, lastStreamId, error, payload);

        for (ByteBuffer buffer : lease.getByteBuffers())
        {
            while (buffer.hasRemaining())
            {
                parser.parse(ByteBuffer.wrap(new byte[]{buffer.get()}));
            }
        }

        Assert.assertEquals(1, frames.size());
        GoAwayFrame frame = frames.get(0);
View Full Code Here

        long idleTimeout = endPoint.getIdleTimeout();
        if (idleTimeout > 0)
            idleTimeout /= 2;
        session.setStreamIdleTimeout(idleTimeout);

        Parser parser = newServerParser(connector.getByteBufferPool(), session);
        HTTP2Connection connection = new HTTP2ServerConnection(connector.getByteBufferPool(), connector.getExecutor(),
                        endPoint, parser, session, getInputBufferSize(), isDispatchIO(), listener);

        return configure(connection, connector, endPoint);
    }
View Full Code Here

  private void runtest(String src) {
    runtest(src, true);
  }

  private void runtest(String src, boolean succeed) {
    Parser parser = new Parser();
    try {
      parser.parse(new Lexer(new StringReader(src)));
      if(!succeed) {
        fail("Test was supposed to fail, but succeeded");
      }
    } catch (beaver.Parser.Exception e) {
      if(succeed) {
View Full Code Here

  private void runtest(String... srcs) {
    runtest(true, srcs);
  }

  private void runtest(boolean succeed, String... srcs) {
    Parser parser = new Parser();
    try {
      List<Module> modules = new List<Module>();
      for(String src : srcs)
        modules.add((Module)parser.parse(new Lexer(new StringReader(src))));
      Program prog = new Program(modules);
      prog.namecheck();
      if(!prog.hasErrors()) prog.typecheck();
      if(succeed) {
        if(prog.hasErrors()) {
View Full Code Here

   */
  private void runtest(String[] modules_src, String main_module, String main_function, Class<?>[] parm_types, Object[] args, Object expected) {
    try {
      List<Module> modules = new List<Module>();
      for(String module_src : modules_src) {
        Parser parser = new Parser();
        Module module = (Module)parser.parse(new Lexer(new StringReader(module_src)));
        modules.add(module);
      }
      Program prog = new Program(modules);
     
      prog.namecheck();
View Full Code Here

  public void testSum() throws LexicalException, Exception {
    ValueMap values = new ValueMap();
    values.put("val1", new BigDecimal(5));
    values.put("val2", new BigDecimal(10));
   
    Parser p = new Parser("val1+val2");
    BigDecimal value = p.eval(p.lexicalVerifier(), values);
    assertEquals(value.compareTo(new BigDecimal("15")), 0);
  }
View Full Code Here

TOP

Related Classes of Parser.Parser

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.