Examples of IoBuffer


Examples of com.google.code.hs4j.network.buffer.IoBuffer

  @Test
  public void testEncodeDecode() {
    assertNull(this.cmd.getIoBuffer());
    this.cmd.encode();
    IoBuffer buf = this.cmd.getIoBuffer();
    assertNotNull(buf);
    assertEquals(0, buf.position());
    assertTrue(buf.limit() > 0);

    assertEquals("P\t1\tmytest\tuser\tINDEX_1\tid,name,password\n",
        new String(buf.array(), 0, buf.limit()));

    IoBuffer buffer = IoBuffer.allocate(4);
    buffer.put("0\t1\n".getBytes());
    buffer.flip();

    assertEquals(1, this.cmd.getLatch().getCount());
    assertTrue(this.cmd.decode(null, buffer));
    assertEquals(0, this.cmd.getResponseStatus());
    assertEquals(1, this.cmd.getNumColumns());
View Full Code Here

Examples of com.google.code.yanf4j.buffer.IoBuffer

    }


    @Test
    public void testGetPrefixedString() throws Exception {
        IoBuffer buf = IoBuffer.allocate(16);
        CharsetEncoder encoder;
        CharsetDecoder decoder;
        encoder = Charset.forName("ISO-8859-1").newEncoder();
        decoder = Charset.forName("ISO-8859-1").newDecoder();

        buf.putShort((short) 3);
        buf.putString("ABCD", encoder);
        buf.clear();
        assertEquals("ABC", buf.getPrefixedString(decoder));
    }
View Full Code Here

Examples of com.google.opengse.iobuffer.IOBuffer

      encodeData(output_buf, true);

      // prepend response headers if they haven't already been committed
      if (!isCommitted()) {
        // prepend response headers to response body
        IOBuffer headers = prepareHeaders(keepAlive, true);
        output_buf.prepend(headers);
      }

      LOGGER.log(Level.FINEST, "request finished ("
          + output_buf.availableBytes() + " bytes)", output_buf);
View Full Code Here

Examples of com.taobao.gecko.core.buffer.IoBuffer

    }


    @Test
    public void testMakeHead() throws Exception {
        final IoBuffer head = this.fileMessageSet.makeHead(-1999, 100);
        assertEquals(0, head.position());
        assertTrue(head.hasRemaining());
        assertEquals("value 100 -1999\r\n", new String(head.array()));
    }
View Full Code Here

Examples of net.rubyeye.xmemcached.buffer.IoBuffer

  }

  public abstract void createBufferAllocator();

  public void testEmptyBuffer() {
    IoBuffer emptyBuffer = this.allocator.allocate(0);

    assertNotNull(emptyBuffer);
    assertEquals(0, emptyBuffer.capacity());
    assertEquals(0, emptyBuffer.position());
    assertEquals(0, emptyBuffer.limit());

    try {
      emptyBuffer.put((byte) 0);
      fail();
    } catch (BufferOverflowException e) {
      assertTrue(true);
    }
View Full Code Here

Examples of org.apache.mina.codec.IoBuffer

    @Test
    public void testTruncatedValues() {
        for (int value : new int[] { 0, 1, 127, 128, 65536, 198649, Integer.MAX_VALUE }) {

            IoBuffer buffer = IoBuffer.wrap(encoder.encode(value));

            for (int i = 0; i < buffer.remaining(); i++) {
                IoBuffer partialBuffer = buffer.slice();
                partialBuffer.limit(partialBuffer.position() + i);
                try {
                    assertNull(decoder.decode(partialBuffer));
                } catch (ProtocolDecoderException e) {
                    fail("Should not throw exception");
                }
View Full Code Here

Examples of org.apache.mina.codec.IoBuffer

            ByteBuffer buffer = encoder.encode(value);

            for (int i = 1; i < 5; i++) {
                int size = buffer.remaining() + i;
                IoBuffer extendedBuffer = IoBuffer.wrap(ByteBuffer.allocate(size));
                int start = extendedBuffer.position();
                extendedBuffer.put(buffer.slice());
                extendedBuffer.position(start);
                extendedBuffer.limit(start + size);

                try {
                    decoder.decode(extendedBuffer);
                    assertEquals(i, extendedBuffer.remaining());
                } catch (ProtocolDecoderException e) {
                    fail("Should not throw exception");
                }
            }
        }
View Full Code Here

Examples of org.apache.mina.codec.IoBuffer

        if (nextBlockSize.getValue() == null) {
            nextBlockSize.setValue(sizeDecoder.decode(input));
        }

        if (nextBlockSize.isDefined() && (input.remaining() >= nextBlockSize.getValue())) {
            IoBuffer buffer = input.slice();
            buffer.limit(buffer.position() + nextBlockSize.getValue());

            output = payloadDecoder.decode(buffer);
            nextBlockSize.reset();
        }
View Full Code Here

Examples of org.apache.mina.common.IoBuffer

        if (n == -1 && off == 0) {
            return null;
        }

        IoBuffer buffer = IoBuffer.wrap(bytes, 0, off);

        return buffer;
    }
View Full Code Here

Examples of org.apache.mina.common.IoBuffer

            return null;
        }
       
        // Allocate the buffer for reading from the file
        final int bufferSize = (int) Math.min(getWriteBufferSize(), fileRegion.getRemainingBytes());
        IoBuffer buffer = IoBuffer.allocate(bufferSize);

        // Read from the file
        int bytesRead = fileRegion.getFileChannel().read(buffer.buf(),
                fileRegion.getPosition());
        fileRegion.update(bytesRead);

        // return the buffer
        buffer.flip();
        return buffer;
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.