Search in sources :

Example 16 with Block

use of org.apache.jena.tdb.base.block.Block in project jena by apache.

the class BlockAccessMapped method allocate.

@Override
public Block allocate(int blkSize) {
    if (blkSize > 0 && blkSize != this.blockSize)
        throw new FileException("Fixed blocksize only: request= " + blkSize + "fixed size=" + this.blockSize);
    int id = allocateId();
    ByteBuffer bb = getByteBuffer(id);
    bb.position(0);
    Block block = new Block(id, bb);
    return block;
}
Also used : Block(org.apache.jena.tdb.base.block.Block) ByteBuffer(java.nio.ByteBuffer) MappedByteBuffer(java.nio.MappedByteBuffer)

Example 17 with Block

use of org.apache.jena.tdb.base.block.Block in project jena by apache.

the class BlockAccessMem method allocate.

@Override
public Block allocate(int blkSize) {
    if (blkSize > 0 && blkSize != this.blockSize)
        throw new FileException("Fixed blocksize only: request= " + blkSize + " / fixed size=" + this.blockSize);
    int x = blocks.size();
    ByteBuffer bb = ByteBuffer.allocate(blkSize);
    Block block = new Block(x, bb);
    blocks.add(block);
    return block;
}
Also used : Block(org.apache.jena.tdb.base.block.Block) ByteBuffer(java.nio.ByteBuffer)

Example 18 with Block

use of org.apache.jena.tdb.base.block.Block in project jena by apache.

the class ObjectFileLogger method allocWrite.

@Override
public Block allocWrite(int maxBytes) {
    Block blk = other.allocWrite(maxBytes);
    info("allocWrite(" + maxBytes + ") -> " + blk.getId());
    return blk;
}
Also used : Block(org.apache.jena.tdb.base.block.Block)

Example 19 with Block

use of org.apache.jena.tdb.base.block.Block in project jena by apache.

the class ObjectFileStorage method allocWrite.

@Override
public Block allocWrite(int bytesSpace) {
    //log.info("AW("+bytesSpace+"):"+state()) ;
    if (inAllocWrite)
        Log.error(this, "In the middle of an alloc-write");
    // Include space for length.
    int spaceRequired = bytesSpace + SizeOfInt;
    // Find space.
    if (writeBuffer != null && spaceRequired > writeBuffer.remaining())
        flushOutputBuffer();
    if (writeBuffer == null || spaceRequired > writeBuffer.remaining()) {
        // Too big. Have flushed buffering if buffering.
        inAllocWrite = true;
        ByteBuffer bb = ByteBuffer.allocate(bytesSpace);
        allocBlock = new Block(filesize, bb);
        allocLocation = -1;
        //log.info("AW:"+state()+"-> ----") ;
        return allocBlock;
    }
    // Will fit.
    inAllocWrite = true;
    int start = writeBuffer.position();
    // Old values for restoration
    oldBufferPosn = start;
    oldBufferLimit = writeBuffer.limit();
    // id (but don't tell the caller yet).
    allocLocation = filesize + start;
    // Slice it.
    writeBuffer.putInt(bytesSpace);
    writeBuffer.position(start + SizeOfInt);
    writeBuffer.limit(start + spaceRequired);
    ByteBuffer bb = writeBuffer.slice();
    allocBlock = new Block(allocLocation, bb);
    if (logging)
        log("AW: %s->0x%X", state(), allocLocation);
    return allocBlock;
}
Also used : Block(org.apache.jena.tdb.base.block.Block) ByteBuffer(java.nio.ByteBuffer)

Example 20 with Block

use of org.apache.jena.tdb.base.block.Block in project jena by apache.

the class StringFile method write.

public long write(String str) {
    str = compress(str);
    Block block = file.allocWrite(4 * str.length());
    int len = Bytes.toByteBuffer(str, block.getByteBuffer());
    block.getByteBuffer().flip();
    file.completeWrite(block);
    return block.getId();
}
Also used : Block(org.apache.jena.tdb.base.block.Block)

Aggregations

Block (org.apache.jena.tdb.base.block.Block)42 ByteBuffer (java.nio.ByteBuffer)15 Test (org.junit.Test)11 BaseTest (org.apache.jena.atlas.junit.BaseTest)10 MappedByteBuffer (java.nio.MappedByteBuffer)2 TDBException (org.apache.jena.tdb.TDBException)2 Adler32 (java.util.zip.Adler32)1 BlockException (org.apache.jena.tdb.base.block.BlockException)1 BlockAccess (org.apache.jena.tdb.base.file.BlockAccess)1 ObjectFile (org.apache.jena.tdb.base.objectfile.ObjectFile)1 RecordBufferPage (org.apache.jena.tdb.base.recordbuffer.RecordBufferPage)1 FileRef (org.apache.jena.tdb.sys.FileRef)1