Example usage for org.apache.lucene.store DataInput readBytes

List of usage examples for org.apache.lucene.store DataInput readBytes

Introduction

In this page you can find the example usage for org.apache.lucene.store DataInput readBytes.

Prototype

public void readBytes(byte[] b, int offset, int len, boolean useBuffer) throws IOException 

Source Link

Document

Reads a specified number of bytes into an array at the specified offset with control over whether the read should be buffered (callers who have their own buffer should pass in "false" for useBuffer).

Usage

From source file:org.apache.ignite.internal.processors.query.h2.opt.GridLuceneOutputStream.java

License:Apache License

/** {@inheritDoc} */
@Override/*  www  .  ja  v  a  2s.c  o  m*/
public void copyBytes(DataInput input, long numBytes) throws IOException {
    assert numBytes >= 0 : "numBytes=" + numBytes;

    GridLuceneInputStream gridInput = input instanceof GridLuceneInputStream ? (GridLuceneInputStream) input
            : null;

    while (numBytes > 0) {
        if (bufPosition == bufLength) {
            currBufIdx++;

            switchCurrentBuffer();
        }

        int toCp = BUFFER_SIZE - bufPosition;

        if (numBytes < toCp)
            toCp = (int) numBytes;

        if (gridInput != null)
            gridInput.readBytes(currBuf + bufPosition, toCp);
        else {
            byte[] buff = new byte[toCp];

            input.readBytes(buff, 0, toCp, false);

            mem.writeBytes(currBuf + bufPosition, buff);
        }

        numBytes -= toCp;
        bufPosition += toCp;
    }
}

From source file:org.elasticsearch.common.compress.CompressedIndexOutput.java

License:Apache License

@Override
public void copyBytes(DataInput input, long length) throws IOException {
    final int BUFFER_LEN = uncompressedLength;

    // simple case first: buffering only (for trivially short writes)
    int free = BUFFER_LEN - position;
    if (free >= length) {
        input.readBytes(uncompressed, position, (int) length, false);
        position += length;//from  w  w w. j a  v a2s  .com
        uncompressedPosition += length;
        return;
    }
    // fill partial input as much as possible and flush
    if (position > 0) {
        input.readBytes(uncompressed, position, free, false);
        position += free;
        uncompressedPosition += free;
        flushBuffer();
        length -= free;
    }

    // then write intermediate full block, if any, without copying:

    // Note, if we supported flushing buffers not on "chunkSize", then
    // we could have flushed up to the rest of non compressed data in the input
    // and then copy compressed segments. This means though that we need to
    // store the compressed sizes of each segment on top of the offsets, and
    // CompressedIndexInput#seek would be more costly, since it can't do (pos / chunk)
    // to get the index...

    while (length >= BUFFER_LEN) {
        offsets.add(out.getFilePointer());
        input.readBytes(uncompressed, 0, BUFFER_LEN);
        compress(uncompressed, 0, BUFFER_LEN, out);
        length -= BUFFER_LEN;
        uncompressedPosition += BUFFER_LEN;
    }

    // and finally, copy leftovers in input, if any
    if (length > 0) {
        input.readBytes(uncompressed, 0, (int) length, false);
    }
    position = (int) length;
    uncompressedPosition += length;
}