Package org.apache.lucene.util
Class PagedBytes
- java.lang.Object
-
- org.apache.lucene.util.PagedBytes
-
- All Implemented Interfaces:
Accountable
public final class PagedBytes extends java.lang.Object implements Accountable
Represents a logical byte[] as a series of pages. You can write-once into the logical byte[] (append only), using copy, and then retrieve slices (BytesRef) into it using fill.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description classPagedBytes.PagedBytesDataInputclassPagedBytes.PagedBytesDataOutputstatic classPagedBytes.ReaderProvides methods to read BytesRefs from a frozen PagedBytes.
-
Field Summary
Fields Modifier and Type Field Description private static longBASE_RAM_BYTES_USEDprivate intblockBitsprivate intblockMaskprivate byte[][]blocksprivate intblockSizeprivate longbytesUsedPerBlockprivate byte[]currentBlockprivate booleandidSkipBytesprivate static byte[]EMPTY_BYTESprivate booleanfrozenprivate intnumBlocksprivate intupto-
Fields inherited from interface org.apache.lucene.util.Accountable
NULL_ACCOUNTABLE
-
-
Constructor Summary
Constructors Constructor Description PagedBytes(int blockBits)1<<blockBits must be bigger than biggest single BytesRef slice that will be pulled
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private voidaddBlock(byte[] block)voidcopy(IndexInput in, long byteCount)Read this many bytes from invoidcopy(BytesRef bytes, BytesRef out)Copy BytesRef in, setting BytesRef out to the result.longcopyUsingLengthPrefix(BytesRef bytes)Copy bytes in, writing the length as a 1 or 2 byte vInt prefix.PagedBytes.Readerfreeze(boolean trim)Commits final byte[], trimming it if necessary and if trim=truePagedBytes.PagedBytesDataInputgetDataInput()Returns a DataInput to read values from this PagedBytes instance.PagedBytes.PagedBytesDataOutputgetDataOutput()Returns a DataOutput that you may use to write into this PagedBytes instance.longgetPointer()longramBytesUsed()Return the memory usage of this object in bytes.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.apache.lucene.util.Accountable
getChildResources
-
-
-
-
Field Detail
-
BASE_RAM_BYTES_USED
private static final long BASE_RAM_BYTES_USED
-
blocks
private byte[][] blocks
-
numBlocks
private int numBlocks
-
blockSize
private final int blockSize
-
blockBits
private final int blockBits
-
blockMask
private final int blockMask
-
didSkipBytes
private boolean didSkipBytes
-
frozen
private boolean frozen
-
upto
private int upto
-
currentBlock
private byte[] currentBlock
-
bytesUsedPerBlock
private final long bytesUsedPerBlock
-
EMPTY_BYTES
private static final byte[] EMPTY_BYTES
-
-
Method Detail
-
addBlock
private void addBlock(byte[] block)
-
copy
public void copy(IndexInput in, long byteCount) throws java.io.IOException
Read this many bytes from in- Throws:
java.io.IOException
-
copy
public void copy(BytesRef bytes, BytesRef out)
Copy BytesRef in, setting BytesRef out to the result. Do not use this if you will use freeze(true). This only supports bytes.length <= blockSize
-
freeze
public PagedBytes.Reader freeze(boolean trim)
Commits final byte[], trimming it if necessary and if trim=true
-
getPointer
public long getPointer()
-
ramBytesUsed
public long ramBytesUsed()
Description copied from interface:AccountableReturn the memory usage of this object in bytes. Negative values are illegal.- Specified by:
ramBytesUsedin interfaceAccountable
-
copyUsingLengthPrefix
public long copyUsingLengthPrefix(BytesRef bytes)
Copy bytes in, writing the length as a 1 or 2 byte vInt prefix.
-
getDataInput
public PagedBytes.PagedBytesDataInput getDataInput()
Returns a DataInput to read values from this PagedBytes instance.
-
getDataOutput
public PagedBytes.PagedBytesDataOutput getDataOutput()
Returns a DataOutput that you may use to write into this PagedBytes instance. If you do this, you should not call the other writing methods (eg, copy); results are undefined.
-
-