Package net.sf.cindy

Examples of net.sf.cindy.Buffer


* @version $id$
*/
public class ByteArrayDecoder implements PacketDecoder {

    public Object decode(Session session, Packet packet) throws Exception {
        Buffer buffer = packet.getContent();
        byte[] content = new byte[buffer.remaining()];
        buffer.get(content);
        return content;
    }
View Full Code Here


* @version $id$
*/
public class BufferDecoder implements PacketDecoder {

    public Object decode(Session session, Packet packet) throws Exception {
        Buffer buffer = packet.getContent();
        return BufferFactory.allocate(buffer.remaining()).put(0, buffer);
    }
View Full Code Here

        chain.remove(decoder);
        return this;
    }

    public Object decode(Session session, Packet packet) throws Exception {
        Buffer content = packet.getContent();
        int position = content.position();
        int limit = content.limit();

        for (Iterator iter = chain.iterator(); iter.hasNext();) {
            PacketDecoder decoder = (PacketDecoder) iter.next();
            Object obj = decoder.decode(session, packet);
            if (obj != null)
                return obj;

            // not use slice to create new buffer, reduce memory cost
            content.limit(limit);
            content.position(position);
        }
        return null;
    }
View Full Code Here

    private void resize(int size) {
        if (buffer.remaining() < size) {
            int capacity = Math.max(buffer.position() + size, (buffer
                    .capacity() + 1) * 2);
            Buffer newBuffer = BufferFactory.allocate(capacity).put(
                    buffer.flip());
            buffer.release();
            buffer = newBuffer;
        }
    }
View Full Code Here

            buffer = newBuffer;
        }
    }

    public Buffer toBuffer() {
        Buffer result = BufferFactory.allocate(buffer.position());
        buffer.get(0, result);
        return result.flip();
    }
View Full Code Here

        return null;
    }

    protected byte _get(int index) {
        Entry entry = getEntry(index);
        Buffer buffer = entry.buffer;
        return buffer.get(buffer.position() + index - entry.position);
    }
View Full Code Here

        return buffer.get(buffer.position() + index - entry.position);
    }

    protected void _put(int index, byte b) {
        Entry entry = getEntry(index);
        Buffer buffer = entry.buffer;
        buffer.put(buffer.position() + index - entry.position, b);
    }
View Full Code Here

    protected Buffer batch(boolean get, int index, byte[] array, int offset,
            int length) {
        Entry entry = getEntry(index);
        int off = index - entry.position;
        do {
            Buffer buffer = entry.buffer;
            int len = Math.min(buffer.remaining() - off, length);

            if (get)
                buffer.get(buffer.position() + off, array, offset, len);
            else
                buffer.put(buffer.position() + off, array, offset, len);

            offset += len;
            length -= len;
            if (length <= 0)
                break;
View Full Code Here

    protected Buffer batch(boolean get, int index, ByteBuffer buffer, int length) {
        Entry entry = getEntry(index);
        int off = index - entry.position;
        do {
            Buffer content = entry.buffer;
            int len = Math.min(content.remaining() - off, length);

            if (get)
                content.get(content.position() + off, buffer, len);
            else {
                content.put(content.position() + off, buffer, len);
            }

            length -= len;
            if (length <= 0)
                break;
View Full Code Here

    protected Buffer batch(boolean get, int index, Buffer buffer, int length) {
        Entry entry = getEntry(index);
        int off = index - entry.position;
        do {
            Buffer content = entry.buffer;
            int len = Math.min(content.remaining() - off, length);

            if (get)
                content.get(content.position() + off, buffer, len);
            else
                content.put(content.position() + off, buffer, len);

            length -= len;
            if (length <= 0)
                break;
            off = 0;
View Full Code Here

TOP

Related Classes of net.sf.cindy.Buffer

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.