Package xbird.util.io

Examples of xbird.util.io.FastMultiByteArrayOutputStream


        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


        final StopWatch sw = new StopWatch("[Xbird_collection] " + 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);
        //processor.execute(mod, ser);
        writer.flush();

        System.err.println(sw);
        return out.toString();
    }
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 initPattern(byte[] p) {
        final IntStack typeStack = new IntStack(12);
        final ArrayList<byte[]> patternStack = new ArrayList<byte[]>();
        final FastMultiByteArrayOutputStream pending = new FastMultiByteArrayOutputStream(32);
        final int ptnlen = p.length;
        for(int i = 0; i < ptnlen; i++) {
            byte c = p[i];
            if(c == anyPattern) {
                if(!typeStack.isEmpty()) {
                    int lastType = typeStack.peek();
                    if(lastType == anyPattern) {
                        continue;
                    }
                }
                if(pending.size() > 0) {
                    typeStack.push(MATCH);
                    patternStack.add(pending.toByteArray());
                    pending.reset();
                }
                typeStack.push(ANY);
                patternStack.add(null);
            } else {
                pending.write(c);
            }
        }
        if(pending.size() > 0) {
            typeStack.push(MATCH);
            patternStack.add(pending.toByteArray());
        }
        this._patterns = patternStack.toArray(new byte[patternStack.size()][]);
        this._types = typeStack.toArray();
    }
View Full Code Here

            }
            if(LOG.isTraceEnabled()) {
                LOG.trace((ph.getStatus() == LEAF ? "Leaf " : "Branch ") + "Node#"
                        + page.getPageNum() + " - " + Arrays.toString(keys));
            }
            final FastMultiByteArrayOutputStream bos = new FastMultiByteArrayOutputStream(_fileHeader.getWorkSize());
            final DataOutputStream os = new DataOutputStream(bos);

            // write out the prefix
            final short prefixlen = ph.getPrefixLength();
            if(prefixlen > 0) {
                prefix.writeTo(os);
            }
            // Write out the Values
            Value prevKey = null;
            for(int i = 0; i < keys.length; i++) {
                final Value v = keys[i];
                if(v == prevKey) {
                    os.writeInt(-1);
                } else {
                    final int len = v.getLength();
                    final int size = len - prefixlen;
                    os.writeInt(size);
                    if(size > 0) {
                        v.writeTo(os, prefixlen, size);
                    }
                }
                prevKey = v;
            }
            // Write out the pointers
            for(int i = 0; i < ptrs.length; i++) {
                VariableByteCodec.encodeLong(ptrs[i], os);
            }
            // Write out link if current node is a leaf
            if(ph.getStatus() == LEAF) {
                os.writeLong(_prev);
                os.writeLong(_next);
            }

            writeValue(page, new Value(bos.toByteArray()));
            setDirty(false);
        }
View Full Code Here

     * @param page The starting Page
     * @return The Value
     */
    public final Value readValue(Page page) throws DbException {
        PageHeader sph = page.getPageHeader();
        FastMultiByteArrayOutputStream bos = new FastMultiByteArrayOutputStream(sph.getRecordLength());

        // Loop until we've read all the pages into memory
        Page p = page;
        while(true) {
            // Add the contents of the page onto the stream
            try {
                p.writeData(bos);
            } catch (IOException e) {
                throw new DbException(e);
            }
            // Continue following the list of pages until we get to the end
            PageHeader ph = p.getPageHeader();
            long nextPage = ph.getNextPage();
            if(nextPage == NO_PAGE) {
                break;
            }
            p = getPage(nextPage);
        }
        // Return a Value with the collected contents of all pages
        return new Value(bos.toByteArray());
    }
View Full Code Here

        /**
         * @link http://java.sun.com/javase/technologies/core/basic/serializationFAQ.jsp#appendSerialStream
         */
        private void incrPipedOutReaccessable(final ObjectOutputStream out) throws IOException {
            assert (_reaccessable);
            final FastMultiByteArrayOutputStream bufOut = new FastMultiByteArrayOutputStream(BUFFERING_BLOCK_SIZE);
            final TeeOutputStream tee = new TeeOutputStream(out, bufOut);
            final ObjectOutputStream objectOut = new AppendingObjectOutputStream(tee);
            final XQEventDecoder decoder = _decoder;
            decoder.redirectTo(objectOut);
            decoder.close();
            objectOut.flush();

            // Because input of decoder fully read, this section required for re-object serialization, etc.
            final byte[][] buf = bufOut.toMultiByteArray();
            final int bufTotalSize = bufOut.size();
            bufOut.clear();
            final FastMultiByteArrayInputStream inputBuf = new FastMultiByteArrayInputStream(buf, BUFFERING_BLOCK_SIZE, bufTotalSize);
            if(!_reaccessable) {
                inputBuf.setCleanable(true);
            }
            final ObjectInputStream objInput = new AppendedObjectInputStream(inputBuf);
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

        }

        private void pageOutSegments(final FixedSegments paged, final int beginPage, final int endPage)
                throws IOException {
            final long[][] 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 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;
                    }
                }
                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 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

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.