Package org.jcoredb.fs

Examples of org.jcoredb.fs.Block


   
    BlockId blockId = new BlockId(containerId, segmentId, id);
   
    try
    {
      Block block = fs.read(blockId);
     
      JSONNode root = JSONHelper.createSuccessNode();
      JSONAttribute containerId = new JSONAttribute("containerId", ""+blockId.getContainerId(), AttrType.Number);
      JSONAttribute segmentId = new JSONAttribute("segmentId", ""+blockId.getSegmentId(), AttrType.Number);
      JSONAttribute id = new JSONAttribute("blockId", ""+blockId.getId(), AttrType.Number);
      JSONAttribute data = new JSONAttribute("data", Base64.encodeBase64String(block.getBytes()),AttrType.String);
      root.add(containerId);
      root.add(segmentId);
      root.add(id);
      root.add(data);
     
View Full Code Here


    String testStr = "<test> <content> Hello world! </content> </test>";
    byte[] content = testStr.getBytes();
   
    for (int i = 0; i < NUM_OF_BLOCKS_TO_APPEND; i++) {

      Block b = new Block(new BlockId(0));
      b.setBytes(content);     
      blocks[i] = b;
    }

    long startMs = System.currentTimeMillis();
   
View Full Code Here

    String testStr = "<test> <content> Hello world! </content> </test>";
    byte[] content = testStr.getBytes();
   
    for (int i = 0; i < NUM_OF_BLOCKS_TO_APPEND; i++) {

      Block b = new Block(new BlockId(0));
      b.setBytes(content);     
      blocks[i] = b;
    }

    long startMs = System.currentTimeMillis();
   
View Full Code Here

  public Block read(BlockId id) throws BlockReadErr, SegmentGetErr
  {
    IContainer c = containers.get(id.getContainerId());
    DataSegment seg = (DataSegment) c.getSegment(id.getSegmentId());

    Block b =  seg.readBlock(id.getId());
   
    if (b!=null) b.setId(id);
   
    return b;
  }
View Full Code Here

 
    IFileSystem fs = new FileSystem(Constants.ROOT_PATH);
    fs.create(0);
    fs.open();
   
    Block b = new Block(new BlockId(0));
    byte[] content = "<test> <content> Hello world! </content> </test>".getBytes();
    b.setBytes(content);
   
    Block b2 = new Block(new BlockId(0));
    b.setBytes(content);
   
    BlockId bid = fs.append(b, false);
    BlockId bid2 = fs.append(b2, false);
   
View Full Code Here

    ArrayList<Block> blocks = new ArrayList<Block>();
    ArrayList<BlockId> blockIds = new ArrayList<BlockId>();
   
    for (int i = 0; i < 200; i++) {

      Block b = new Block(new BlockId(0));
      byte[] content = "<test> <content> Hello world! </content> </test>".getBytes();
      b.setBytes(content);
     
      blocks.add(b);
     
      BlockId bid = fs.append(b, false);

      blockIds.add(bid);
    }

    BlockId toDelete = blockIds.get(100);
   
    fs.delete(toDelete, true);
   
    Block b = fs.read(toDelete);
   
    assertEquals(null, b);
   
    fs.close();
  }
View Full Code Here

      DataSegment seg = segments.get(blockId.getSegmentId());

      seg.getHeader().setFree(blockId.getId(), false);

      if (!soft) {
        Block emptyBlock = new Block(blockId);
        seg.writeBlock(emptyBlock);

        // Check if the segments runs empty and delete it
        if (seg.getHeader().isEmpty()) {
          segments.remove(seg);
View Full Code Here

    String testStr = "<test> <content> Hello world! </content> </test>";
    byte[] content = testStr.getBytes();
   
    for (int i = 0; i < 200; i++) {

      Block b = new Block(new BlockId(0));
      b.setBytes(content);
     
      blocks.add(b);
     
      BlockId bid = fs.append(b, false);

      blockIds.add(bid);
    }

       
    Block b = fs.read(new BlockId(0,0,111));
   
    assertEquals(testStr, new String(b.getBytes()).substring(0, testStr.length()));
   
    fs.close();
  }
View Full Code Here

    String testStr = "<test> <content> Hello world! </content> </test>";
    byte[] content = testStr.getBytes();
   
    for (int i = 0; i < 200; i++) {

      Block b = new Block(new BlockId(0));
      b.setBytes(content);
     
      blocks.add(b);
     
      BlockId bid = fs.append(b, false);

      blockIds.add(bid);
    }
   
    String newTestStr = "<test> <content> Hello world, again! </content> </test>";
    byte[] newContent = newTestStr.getBytes();
 
    Block b = new Block(blockIds.get(78));
    b.setBytes(newContent);
    fs.write(b);
   
   
    Block rB = fs.read(blockIds.get(78));
   
    assertEquals(newTestStr, new String(rB.getBytes()).substring(0, newTestStr.length()))
  }
View Full Code Here

  public void create() {
   
    IFileSystem fs = FileSystemRegistry.get(new FileSystemRegKey("localhost", Configs.getFSConfig().getRootDir()));
   
    BlockId blockId = new BlockId(containerId);
    Block block = new Block(blockId);
    block.setBytes(data);
   
    try
    {
      blockId = fs.append(block, only);
     
View Full Code Here

TOP

Related Classes of org.jcoredb.fs.Block

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.