Examples of FastByteArrayOutputStream


Examples of xbird.util.io.FastByteArrayOutputStream

    }

    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

Examples of xbird.util.io.FastByteArrayOutputStream

    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

Examples of xbird.util.io.FastByteArrayOutputStream

* @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

Examples of xbird.util.io.FastByteArrayOutputStream

        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

Examples of xbird.util.io.FastByteArrayOutputStream

        return decoder;
    }

    private static void bulkOut(ObjectOutput out, Sequence<Item> entity, boolean remotePaing)
            throws IOException {
        final FastByteArrayOutputStream bufOut = new FastByteArrayOutputStream(16384);
        final ObjectOutputStream objOut = new ObjectOutputStream(bufOut);
        final XQEventEncoder encoder = new XQEventEncoder(objOut);
        if(remotePaing) {
            encoder.setRemotePaging(true);
        }
        try {
            encoder.emit(entity);
            objOut.flush();
        } catch (XQueryException xqe) {
            throw new IllegalStateException("failed encoding", xqe);
        } catch (Throwable e) {
            LOG.fatal(e);
            throw new IllegalStateException("failed encoding", e);
        }
        final byte[] buf = bufOut.toByteArray();
        bufOut.clear();
        final int buflen = buf.length;
        if(LOG.isDebugEnabled()) {
            LOG.debug("encoded sequence size: " + buflen);
        }
        out.writeInt(buflen);
View Full Code Here

Examples of xbird.util.io.FastByteArrayOutputStream

            final ObjectInputStream objInput = new NoHeaderObjectInputStream(inputBuf);
            this._decoder = new XQEventDecoder(objInput); // replace old Decoder with fresh Decoder
        }

        private void incrBulkOut(final ObjectOutput out) throws IOException {
            final FastByteArrayOutputStream bufOut = new FastByteArrayOutputStream(16384);
            final ObjectOutputStream objectOut = new ObjectOutputStream(bufOut);
            final XQEventDecoder decoder = _decoder;
            decoder.redirectTo(objectOut);
            decoder.close();
            objectOut.flush();
            final byte[] buf = bufOut.toByteArray();
            bufOut.clear();

            // Because input of decoder fully read, this section required for re-object serialization, etc.
            if(_reaccessable) {
                final FastByteArrayInputStream inputBuf = new FastByteArrayInputStream(buf);
                final ObjectInputStream objectInput = new ObjectInputStream(inputBuf);
View Full Code Here

Examples of xbird.util.io.FastByteArrayOutputStream

        return actualSequence.next(focus);
    }

    public synchronized void doEncode() throws IOException {
        if(encodedSequence != null) {
            final FastByteArrayOutputStream bufOut = new FastByteArrayOutputStream(16384);
            final ObjectOutputStream objOut = new ObjectOutputStream(bufOut);
            final XQEventEncoder encoder = new XQEventEncoder(objOut);
            try {
                encoder.emit(actualSequence);
                objOut.flush();
            } catch (XQueryException xqe) {
                throw new IOException(PrintUtils.prettyPrintStackTrace(xqe));
            } catch (Throwable e) {
                LOG.fatal(e);
                throw new IOException(PrintUtils.prettyPrintStackTrace(e));
            }
            this.encodedSequence = bufOut.toByteArray();
        }
    }
View Full Code Here

Examples of xbird.util.io.FastByteArrayOutputStream

        verify(Integer.MAX_VALUE - 1);
        verify(Integer.MAX_VALUE);
    }

    private static void verify(int i) throws IOException {
        FastByteArrayOutputStream os = new FastByteArrayOutputStream(256);
        VariableByteCodec.encodeInt(i, os);
        byte[] b1 = os.toByteArray();
        Assert.assertEquals(i, VariableByteCodec.decodeInt(b1));
    }
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.