Package xbird.util.io

Examples of xbird.util.io.FastByteArrayOutputStream


        this._exprBytes = b;
    }

    public static byte[] toBytes(final BindingVariable bindingVar, final XQExpression bodyExpr) {
        final FastByteArrayOutputStream bos = new FastByteArrayOutputStream(8192);
        try {
            final ObjectOutputStream oos = new ObjectOutputStream(bos);
            oos.writeObject(bodyExpr);
            oos.writeObject(bindingVar);
            oos.flush();
        } catch (IOException e) {
            LOG.error(e.getMessage(), e);
            throw new IllegalStateException(e);
        }
        return bos.toByteArray();
    }
View Full Code Here


* @author Makoto YUI (yuin405+xbird@gmail.com)
*/
public class SerializationTest extends TestCase {

    public void test1() throws IOException, ClassNotFoundException {
        FastByteArrayOutputStream f = new FastByteArrayOutputStream();

        ObjectOutputStream out = new ObjectOutputStream(f);
        Student student1 = new Student("Chris", "Giroir", "111111", "elkfjwe", "wifjew");
        out.writeObject(student1);
        out.writeInt(5);
        out.close();

        out = new NoHeaderObjectOutputStream(f);
        Student student2 = new Student("Chris2", "Giroir2", "elkfjwe", "111111");
        out.writeObject(student2);
        out.close();

        final byte[] b = f.toByteArray();

        FastByteArrayInputStream in = new FastByteArrayInputStream(b);
        ObjectInputStream oin = new ObjectInputStream(in);

        Assert.assertEquals(student1, oin.readObject());
View Full Code Here

        oin.close();
    }

    public void test2() throws IOException, ClassNotFoundException {
        FastByteArrayOutputStream f = new FastByteArrayOutputStream();

        ObjectOutputStream out = new ObjectOutputStream(f);
        Student student1 = new Student("Chris", "Giroir", "111111", "elkfjwe", "wifjew");
        out.writeObject(student1);
        out.writeInt(5);

        FastByteArrayOutputStream out2 = new FastByteArrayOutputStream();
        ObjectOutputStream oos2 = new ObjectOutputStream(out2);
        Student student2 = new Student("Chris2", "Giroir2", "elkfjwe", "111111");
        Student student3 = new Student("dsfsfsd", "sasa", "DSsd", "sds");
        oos2.writeObject(student2);
        oos2.writeObject(student3);

        byte[] b2 = out2.toByteArray();
        out.writeInt(b2.length);
        out.write(b2);

        FastByteArrayInputStream bis3 = new FastByteArrayInputStream(b2);
        ObjectInputStream ois3 = new ObjectInputStream(bis3);
View Full Code Here

        oin.close();
    }

    public void testPlaceHolder1() throws IOException, ClassNotFoundException {
        FastByteArrayOutputStream f = new FastByteArrayOutputStream();
        ObjectOutputStream out = new ObjectOutputStream(f);
        PlaceHolder holder1 = new PlaceHolder();
        out.writeObject(holder1);
        out.flush();

        FastByteArrayInputStream bis = new FastByteArrayInputStream(f.getInternalArray(), 0, f.size());
        ObjectInputStream ois = new ObjectInputStream(bis);
        Assert.assertEquals(holder1, ois.readObject());
    }
View Full Code Here

        }

        private byte[] ser() throws IOException {
            student2 = new Student("Chris2", "Giroir2", "elkfjwe", "111111");
            student3 = new Student("dsfsfsd", "sasa", "DSsd", "sds");
            FastByteArrayOutputStream out2 = new FastByteArrayOutputStream();
            ObjectOutputStream oos2 = new ObjectOutputStream(out2);
            oos2.writeObject(student2);
            oos2.writeObject(student3);
            return out2.toByteArray();
        }
View Full Code Here

    public static byte[] compress(final char[] input) {
        int n = input.length;
        int bitwidth = estimateAdequateBitWidth(input, n);
        CompressedSegment segment = new CompressedSegment(bitwidth);
        compress(input, n, segment);
        FastByteArrayOutputStream bos = new FastByteArrayOutputStream(4096);
        DataOutputStream dos = new DataOutputStream(bos);
        try {
            segment.writeTo(dos);
            dos.flush();
        } catch (IOException e) {
            throw new IllegalStateException(e);
        }
        byte[] b = bos.toByteArray();
        return b;
    }
View Full Code Here

    }

    public static byte[] compress(final char[] input, final int bitwidth) {
        CompressedSegment segment = new CompressedSegment(bitwidth);
        compress(input, input.length, segment);
        FastByteArrayOutputStream bos = new FastByteArrayOutputStream(4096);
        DataOutputStream dos = new DataOutputStream(bos);
        try {
            segment.writeTo(dos);
            dos.flush();
        } catch (IOException e) {
            throw new IllegalStateException(e);
        }
        byte[] b = bos.toByteArray();
        return b;
    }
View Full Code Here

    public Value[] getValues() {
        return values;
    }

    private static byte[] merge(Value[] values) {
        final FastByteArrayOutputStream bos = new FastByteArrayOutputStream(2048);
        final int size = values.length;
        try {
            IOUtils.writeInt(size, bos);
            for(Value v : values) {
                IOUtils.writeInt(v.getLength(), bos);
                v.writeTo(bos);
            }
        } catch (IOException e) {
            LOG.error(PrintUtils.prettyPrintStackTrace(e));
            throw new IllegalStateException(e);
        }
        return bos.toByteArray();
    }
View Full Code Here

* @author Makoto YUI (yuin405+xbird@gmail.com)
*/
public class ContinousInflaterInputStreamTest extends TestCase {

    public void testContinuous() throws IOException {
        FastByteArrayOutputStream out = new FastByteArrayOutputStream(8192);
        DeflaterOutputStream def1 = new DeflaterOutputStream(out, new Deflater(Deflater.DEFAULT_COMPRESSION, false), 100);
        IOUtils.writeString("1", def1);
        IOUtils.writeInt(2, def1);
        def1.close();
        DeflaterOutputStream def2 = new DeflaterOutputStream(out, new Deflater(Deflater.DEFAULT_COMPRESSION, false), 100);
        IOUtils.writeString("3", def2);
        IOUtils.writeString("4", def2);
        def2.close();
        DeflaterOutputStream def3 = new DeflaterOutputStream(out, new Deflater(Deflater.DEFAULT_COMPRESSION, false), 100);
        IOUtils.writeString("5", def3);
        IOUtils.writeString("6", def3);
        def3.close();

        byte[] b = out.toByteArray();
        FastByteArrayInputStream in = new FastByteArrayInputStream(b);
        ContinousInflaterInputStream inf1 = new ContinousInflaterInputStream(in, new Inflater(false), 8192);
        Assert.assertEquals("1", IOUtils.readString(inf1));
        Assert.assertEquals(2, IOUtils.readInt(inf1));
        Assert.assertEquals("3", IOUtils.readString(inf1));
View Full Code Here

        Assert.assertEquals(-1, inf1.read());
        Assert.assertEquals(0, inf1.available());
    }

    public void testNonContinuous() throws IOException {
        FastByteArrayOutputStream out = new FastByteArrayOutputStream(8192);
        DeflaterOutputStream def1 = new DeflaterOutputStream(out, new Deflater(Deflater.DEFAULT_COMPRESSION, false), 100);
        IOUtils.writeString("1", def1);
        IOUtils.writeInt(2, def1);
        IOUtils.writeString("3", def1);
        IOUtils.writeString("4", def1);
        IOUtils.writeString("5", def1);
        IOUtils.writeString("6", def1);
        def1.close();

        byte[] b = out.toByteArray();
        FastByteArrayInputStream in = new FastByteArrayInputStream(b);
        InflaterInputStream inf1 = new InflaterInputStream(in, new Inflater(false), 8192);
        Assert.assertEquals("1", IOUtils.readString(inf1));
        Assert.assertEquals(2, IOUtils.readInt(inf1));
        Assert.assertEquals("3", IOUtils.readString(inf1));
View Full Code Here

TOP

Related Classes of xbird.util.io.FastByteArrayOutputStream

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.