Package org.apache.mina.core.buffer

Examples of org.apache.mina.core.buffer.IoBuffer


   */
  @Test
  public void testFragmented() throws CharacterCodingException {
    final int maxLen = 100;

    IoBuffer savedBuf = IoBuffer.allocate(maxLen);

    String origMsg = "<1>- - blah blam foo\n";
    IoBuffer buf1 = IoBuffer.wrap(
        origMsg.substring(0, 11).getBytes(Charsets.UTF_8));
    IoBuffer buf2 = IoBuffer.wrap(
        origMsg.substring(11, 16).getBytes(Charsets.UTF_8));
    IoBuffer buf3 = IoBuffer.wrap(
        origMsg.substring(16, 21).getBytes(Charsets.UTF_8));

    LineSplitter lineSplitter = new LineSplitter(maxLen);
    ParsedBuffer parsedLine = new ParsedBuffer();

View Full Code Here


    String dangerousChars = "þÿÀÁ";

    ///////////////////////////////////////////////////////
    // encode and send them through the message handler
    String msg;
    IoBuffer buf;
    Event evt;

    // valid ISO-8859-1 on the right (ISO-8859-1) port
    msg = header + dangerousChars + "\n";
    buf = IoBuffer.wrap(msg.getBytes(Charsets.ISO_8859_1));
View Full Code Here

        this.charset = charset;
        this.delimiter = delimiter;
       
        // Convert delimiter to ByteBuffer if not done yet.
        if (delimBuf == null) {
            IoBuffer tmp = IoBuffer.allocate(2).setAutoExpand(true);
           
            try{
                tmp.putString(delimiter.getValue(), charset.newEncoder());
            } catch (CharacterCodingException cce) {
               
            }
           
            tmp.flip();
            delimBuf = tmp;
        }
    }
View Full Code Here

                in.limit(oldLimit);
                in.position(pos);

                if (ctx.getOverflowPosition() == 0) {
                    IoBuffer buf = ctx.getBuffer();
                    buf.flip();
                    buf.limit(buf.limit() - matchCount);
                   
                    try {
                        writeText(session, buf.getString(ctx.getDecoder()), out);
                    } finally {
                        buf.clear();
                    }
                } else {
                    int overflowPosition = ctx.getOverflowPosition();
                    ctx.reset();
                    throw new RecoverableProtocolDecoderException(
View Full Code Here

                    in.limit(oldLimit);
                    in.position(pos);
                   
                    if (ctx.getOverflowPosition() == 0) {
                        IoBuffer buf = ctx.getBuffer();
                        buf.flip();
                        buf.limit(buf.limit() - matchCount);
                       
                        try {
                            writeText(session, buf.getString(ctx.getDecoder()), out);
                        } finally {
                            buf.clear();
                        }
                    } else {
                        int overflowPosition = ctx.getOverflowPosition();
                        ctx.reset();
                        throw new RecoverableProtocolDecoderException(
View Full Code Here

     * the request context into a BOSH requests.
     * @throws IOException
     * @throws SAXException
     */
    public void decode() throws IOException, SAXException {
        IoBuffer ioBuf = IoBuffer.allocate(1024);
        ioBuf.setAutoExpand(true);
        byte[] buf = new byte[1024];
        InputStream in = request.getInputStream();

        for (;;) {
            int i = in.read(buf);
            if (i == -1) {
                break;
            }
            ioBuf.put(buf, 0, i);
        }
        ioBuf.flip();
        reader.parse(ioBuf, CharsetUtil.UTF8_DECODER);
    }
View Full Code Here

  private XMLParticle decode(IoBuffer bb) throws Exception {
    return ParticleDecoder.decodeParticle(bb, CharsetUtil.UTF8_DECODER);
  }

  private List<XMLParticle> decodeAll(String xml) throws Exception {
    IoBuffer bb = wrap(xml);
    List<XMLParticle> particles = new ArrayList<XMLParticle>();
   
    XMLParticle particle = decode(bb);
    while(particle != null) {
      particles.add(particle);
View Full Code Here

    private static final CharsetEncoder CHARSET_ENCODER_UTF8 = CharsetUtil.UTF8_ENCODER;

    public void testDecoderSimple() throws Exception {
        XMLStreamTokenizer decoder = new XMLStreamTokenizer();
        MockIoSession session = new MockIoSession();
        IoBuffer firstByteBuffer = createByteBuffer();
        IoBuffer secondByteBuffer = createByteBuffer();
       
        String stanza = StanzaWriter.XML_PROLOG + "\n\r" +
                "<stream:stream to='example.com' xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' version='1.0'>" +
                "<trailing-stanza/>";

        firstByteBuffer.putString(stanza, CHARSET_ENCODER_UTF8).flip();
       
        MockProtocolDecoderOutput protocolDecoderOutput = new MockProtocolDecoderOutput();
        decoder.decode(session, firstByteBuffer, protocolDecoderOutput);
        assertEquals(4, protocolDecoderOutput.size());
       
        secondByteBuffer.putString("<next></next>", CHARSET_ENCODER_UTF8).flip();
       
        decoder.decode(session, secondByteBuffer, protocolDecoderOutput);
        assertEquals(5, protocolDecoderOutput.size());

        IoBuffer emptyBuffer = createByteBuffer().putString("eee", CHARSET_ENCODER_UTF8).flip();
        decoder.decode(session, emptyBuffer, protocolDecoderOutput);
        assertEquals("plain must be terminated by <", 5, protocolDecoderOutput.size());
       
        IoBuffer termBuffer = createByteBuffer().putString("<r>", CHARSET_ENCODER_UTF8).flip();
        decoder.decode(session, termBuffer, protocolDecoderOutput);
        // eee is now terminated, but r is not balanced yet
        assertEquals("plain termination", 6, protocolDecoderOutput.size());
       
    }
View Full Code Here

    }

    public void testDecoderPartial() throws Exception {
        XMLStreamTokenizer decoder = new XMLStreamTokenizer();
        MockIoSession session = new MockIoSession();
        IoBuffer firstByteBuffer = createByteBuffer();
        IoBuffer secondByteBuffer = createByteBuffer();
       
        String stanzaPart1 = "<stream:stream to='example.com' xmlns='jabber:client' xmlns:stream='ht";
        String stanzaPart2 = "tp://etherx.jabber.org/streams' version='1.0'>";

        MockProtocolDecoderOutput protocolDecoderOutput = new MockProtocolDecoderOutput();

        IoBuffer prolog = createByteBuffer();
        prolog.putString(StanzaWriter.XML_PROLOG + "\n\r", CHARSET_ENCODER_UTF8).flip();
        decoder.decode(session, prolog, protocolDecoderOutput);
        assertEquals(1, protocolDecoderOutput.size());
       
        firstByteBuffer.putString(stanzaPart1, CHARSET_ENCODER_UTF8).flip();
        decoder.decode(session, firstByteBuffer, protocolDecoderOutput);
View Full Code Here

    }

    public void testCRLFInElement() throws Exception {
        XMLStreamTokenizer decoder = new XMLStreamTokenizer();
        MockIoSession session = new MockIoSession();
        IoBuffer byteBuffer = createByteBuffer();
       
        String stanza =
        "<stream:stream\n" +
                "     from='juliet@example.com'\n" +
                "     to='example.com'\n" +
                "     version='1.0'\n" +
                "     xml:lang='en'\n" +
                "     xmlns='jabber:client'\n" +
                "     xmlns:stream='http://etherx.jabber.org/streams'>";
       
        MockProtocolDecoderOutput protocolDecoderOutput = new MockProtocolDecoderOutput();

        byteBuffer.putString(stanza, CHARSET_ENCODER_UTF8).flip();
        try {
            decoder.decode(session, byteBuffer, protocolDecoderOutput);
        } catch(Throwable th) {
            int lkjl = 0;
        }
View Full Code Here

TOP

Related Classes of org.apache.mina.core.buffer.IoBuffer

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.