Package xbird.util.io

Examples of xbird.util.io.FastMultiByteArrayOutputStream


        }
        return (T) obj;
    }

    public static byte[] toBytes(final Object obj) {
        final FastMultiByteArrayOutputStream bos = new FastMultiByteArrayOutputStream();
        toStream(obj, bos);
        return bos.toByteArray_clear();
    }
View Full Code Here


        toStream(obj, bos);
        return bos.toByteArray_clear();
    }

    public static byte[] toBytes(final Object obj, final int estimatedLen) {
        final FastMultiByteArrayOutputStream bos = new FastMultiByteArrayOutputStream(estimatedLen * 2);
        toStream(obj, bos);
        return bos.toByteArray_clear();
    }
View Full Code Here

        toStream(obj, bos);
        return bos.toByteArray_clear();
    }

    public static byte[] toGzipCompressedBytes(final Object obj) {
        final FastMultiByteArrayOutputStream bos = new FastMultiByteArrayOutputStream();
        final GZIPOutputStream gos;
        try {
            gos = new GZIPOutputStream(bos);
        } catch (IOException e) {
            throw new IllegalStateException(e);
        }
        toStream(obj, gos);
        return bos.toByteArray_clear();
    }
View Full Code Here

    public void test2() {
        probe("asasdfdfagfffffaerawefgsgsdffffgvsdfgsgfsgfgweffvsregsrevsdfsagghhawdfd".getBytes());
    }

    public void testRand1000() throws IOException {
        FastMultiByteArrayOutputStream out = new FastMultiByteArrayOutputStream(4096);
        DataOutputStream data = new DataOutputStream(out);
        Random rand = new Random(22222);
        for(int times = 0; times < 3; times++) {
            for(int i = 0; i < 1000; i++) {
                data.writeInt(rand.nextInt());
            }
            probe(out.toByteArray_clear());
        }
    }
View Full Code Here

    }

    private final int pageOutSegments(final FixedSegments paged, final int beginPage, boolean toend)
            throws IOException {
        final int[][] blockRef = _block;
        final FastMultiByteArrayOutputStream buf = new FastMultiByteArrayOutputStream(DEFAULT_EXTENT_SIZE);
        final long lp = (_blockPtr >> PAGE_SHIFT) + 1;
        if(lp > 0x7fffffffL) {
            throw new IllegalStateException("Illegal page number: " + lp);
        }
        final int usedPages = (int) lp;
        int cnt = 0;
        for(int i = beginPage; i <= usedPages; i += DEFAULT_EXTENT_THRESHOLD) {
            final int pages;
            if((i + DEFAULT_EXTENT_THRESHOLD) > usedPages) {
                if(!toend) {
                    break;
                }
                pages = usedPages - i;
            } else {
                pages = DEFAULT_EXTENT_THRESHOLD;
            }
            int addr = i;
            final int limit = Math.min(i + pages, blockRef.length);
            for(int p = i; p < limit; p++) {
                final int[] ref = blockRef[p];
                if(ref == null) {
                    if(buf.size() > 0) {
                        final byte[] b = buf.toByteArray();
                        buf.reset();
                        paged.bulkWrite(addr, b);
                    }
                } else {
                    if(buf.size() == 0) {
                        addr = p;
                    }
                    buf.writeInts(ref, 0, ref.length);
                    blockRef[p] = null;
                    ++cnt;
                }
            }
            if(buf.size() > 0) {
                final byte[] b = buf.toByteArray();
                buf.reset();
                paged.bulkWrite(addr, b);
            }
        }
        buf.close();
        paged.flush(false);
        if(LOG.isInfoEnabled()) {
            LOG.info("paged out docuemnt table seqment(" + beginPage + " - " + (beginPage + cnt)
                    + ") to disk: " + paged.getFile().getAbsolutePath());
        }
View Full Code Here

    protected abstract void setFlag(final long at, final int flag);

    @Override
    public String toString() {
        final DocumentTableModel dtm = new DocumentTableModel(this);
        final FastMultiByteArrayOutputStream baos = new FastMultiByteArrayOutputStream();
        final SAXWriter writer = new SAXWriter(baos);
        final SAXSerializer ser = new SAXSerializer(writer);
        try {
            dtm.export(0, ser);
        } catch (XQueryException e) {
            PrintUtils.prettyPrintStackTrace(e, new PrintStream(baos));
        }
        return baos.toString();
    }
View Full Code Here

        }

        private void pageOutSegments(final FixedSegments paged, final int beginPage, final int endPage)
                throws IOException {
            final int[][] blockRef = _block;
            final FastMultiByteArrayOutputStream buf = new FastMultiByteArrayOutputStream(DEFAULT_EXTENT_SIZE);
            for(int i = beginPage; i <= endPage; i += DEFAULT_EXTENT_THRESHOLD) {
                final int pages;
                if((i + DEFAULT_EXTENT_THRESHOLD - 1) > endPage) {
                    break;
                } else {
                    pages = DEFAULT_EXTENT_THRESHOLD;
                }
                int addr = i;
                final int limit = Math.min(i + pages, blockRef.length - 1);
                for(int p = i; p < limit; p++) {
                    final int[] ref = blockRef[p];
                    if(ref == null) {
                        if(buf.size() > 0) {
                            final byte[] b = buf.toByteArray();
                            buf.reset();
                            paged.bulkWrite(addr, b);
                        }
                    } else {
                        if(buf.size() == 0) {
                            addr = p;
                        }
                        buf.writeInts(ref, 0, ref.length);
                        blockRef[p] = null;
                    }
                }
                if(buf.size() > 0) {
                    final byte[] b = buf.toByteArray();
                    buf.reset();
                    paged.bulkWrite(i, b);
                }
            }
            buf.close();
            paged.flush(false);
            if(LOG.isInfoEnabled()) {
                LOG.info("paged out docuemnt table seqment(" + beginPage + " - " + endPage
                        + ") to disk: " + paged.getFile().getAbsolutePath());
            }
View Full Code Here

    }

    private final int pageOutSegments(final FixedSegments paged, final int beginPage, boolean toend)
            throws IOException {
        final long[][] blockRef = _block;
        final FastMultiByteArrayOutputStream buf = new FastMultiByteArrayOutputStream(DEFAULT_EXTENT_SIZE);
        final long lp = (_blockPtr >> PAGE_SHIFT) + 1;
        if(lp > 0x7fffffffL) {
            throw new IllegalStateException("Illegal page number: " + lp);
        }
        final int usedPages = (int) lp;
        int cnt = 0;
        for(int i = beginPage; i <= usedPages; i += DEFAULT_EXTENT_THRESHOLD) {
            final int pages;
            if((i + DEFAULT_EXTENT_THRESHOLD) > usedPages) {
                if(!toend) {
                    break;
                }
                pages = usedPages - i;
            } else {
                pages = DEFAULT_EXTENT_THRESHOLD;
            }
            int addr = i;
            final int limit = Math.min(i + pages, blockRef.length);
            for(int p = i; p < limit; p++) {
                final long[] ref = blockRef[p];
                if(ref == null) {
                    if(buf.size() > 0) {
                        final byte[] b = buf.toByteArray();
                        buf.reset();
                        paged.bulkWrite(addr, b);
                    }
                } else {
                    if(buf.size() == 0) {
                        addr = p;
                    }
                    buf.writeLongs(ref, 0, ref.length);
                    blockRef[p] = null;
                    ++cnt;
                }
            }
            if(buf.size() > 0) {
                final byte[] b = buf.toByteArray();
                buf.reset();
                paged.bulkWrite(addr, b);
            }
        }
        buf.close();
        paged.flush(false);
        if(LOG.isInfoEnabled()) {
            LOG.info("paged out docuemnt table seqment(" + beginPage + " - " + (beginPage + cnt)
                    + ") to disk: " + paged.getFile().getAbsolutePath());
        }
View Full Code Here

            return seq;
        }
    }

    private static XQEventDecoder pipedIn(ObjectInput in, boolean reaccessable) throws IOException {
        final FastMultiByteArrayOutputStream bufOut = new FastMultiByteArrayOutputStream(BUFFERING_BLOCK_SIZE);
        final ObjectOutputStream objectOut = new ObjectOutputStream(bufOut);
        final XQEventDecoder decoder = new XQEventDecoder(in);
        decoder.redirectTo(objectOut);
        objectOut.flush();

        final byte[][] buf = bufOut.toMultiByteArray();
        final int totalBufSize = bufOut.size();
        bufOut.clear();

        // Because input of decoder fully read, this section required for re-object serialization, etc.
        final FastMultiByteArrayInputStream inputBuf = new FastMultiByteArrayInputStream(buf, BUFFERING_BLOCK_SIZE, totalBufSize);
        if(!reaccessable) {
            inputBuf.setCleanable(true);
View Full Code Here

        final StopWatch sw = new StopWatch("[Xbird_file] " + queryFilePath);
        final XQueryProcessor processor = new XQueryProcessor();
        // parse
        XQueryModule mod = processor.parse(queryStr, new File(queryFilePath).toURI());
        // execute              
        FastMultiByteArrayOutputStream out = new FastMultiByteArrayOutputStream();
        SAXWriter writer = new SAXWriter(out, "UTF-8");
        final Serializer ser = new SAXSerializer(writer);
        Sequence<? extends Item> result = processor.execute(mod);
        ser.emit(result);
        writer.flush();

        System.err.println(sw);
        return out.toString();
    }
View Full Code Here

TOP

Related Classes of xbird.util.io.FastMultiByteArrayOutputStream

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.