Search in sources :

Example 11 with Block

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

the class AbstractTestBlockAccessFixedSize method fileaccess_02.

@Test
public void fileaccess_02() {
    Block b = data(file, blkSize);
    file.write(b);
}
Also used : Block(org.apache.jena.tdb.base.block.Block) BaseTest(org.apache.jena.atlas.junit.BaseTest) Test(org.junit.Test)

Example 12 with Block

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

the class AbstractTestObjectFile method objectfile_02.

@Test
public void objectfile_02() {
    Block block = file.allocWrite(10);
    fill(block.getByteBuffer());
    file.completeWrite(block);
    long x1 = block.getId();
    assertEquals(0, x1);
    ByteBuffer bb = file.read(x1);
    // position
    assertTrue(sameValue(block.getByteBuffer(), bb));
}
Also used : Block(org.apache.jena.tdb.base.block.Block) ByteBuffer(java.nio.ByteBuffer) BaseTest(org.apache.jena.atlas.junit.BaseTest) Test(org.junit.Test)

Example 13 with Block

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

the class BlockAccessByteArray method allocate.

@Override
public Block allocate(int size) {
    long addr = alloc;
    ByteBuffer bb = ByteBuffer.allocate(size);
    alloc += (size + SizeOfInt);
    return new Block((int) addr, bb);
}
Also used : Block(org.apache.jena.tdb.base.block.Block) ByteBuffer(java.nio.ByteBuffer)

Example 14 with Block

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

the class BlockAccessByteArray method read.

@Override
public Block read(long id) {
    // Variable length blocks.
    if (id < 0 || id >= length || id >= bytes.capacity())
        throw new FileException("Bad id (read): " + id);
    bytes.position((int) id);
    int len = bytes.getInt();
    ByteBuffer bb = ByteBuffer.allocate(len);
    // Copy out the bytes - copy for safety.
    bytes.get(bb.array(), 0, len);
    return new Block(id, bb);
}
Also used : Block(org.apache.jena.tdb.base.block.Block) ByteBuffer(java.nio.ByteBuffer)

Example 15 with Block

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

the class BlockAccessMapped method read.

@Override
public Block read(long id) {
    check(id);
    checkIfClosed();
    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)

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