Package net.sf.cindy.buffer

Examples of net.sf.cindy.buffer.BufferBuilder


*/
public class SerialEncoder implements PacketEncoder {

    public Packet encode(Session session, Object obj) throws Exception {
        if (obj instanceof Serializable) {
            final BufferBuilder builder = new BufferBuilder();
            try {
                ObjectOutputStream oos = new ObjectOutputStream(
                        new OutputStream() {

                            public void write(int b) {
                                builder.append((byte) b);
                            }

                            public void write(byte[] b, int off, int len) {
                                builder.append(ByteBuffer.wrap(b, off, len));
                            }
                        });
                oos.writeUnshared(obj);
                oos.close();
                return new DefaultPacket(builder.toBuffer());
            } finally {
                builder.release();
            }
        }
        return null;

    }
View Full Code Here

TOP

Related Classes of net.sf.cindy.buffer.BufferBuilder

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.