Package org.jcoredb.fs

Examples of org.jcoredb.fs.BlockId


  {
    for (DataSegment seg : this.segments.values())
    {
      for (int i = 0; i < this.segmentSize; i++)
      {
        if (seg.getHeader().isFree(i)) return new BlockId(this.id, seg.getId(), i);
      }
    }
   
    return null;
  }
View Full Code Here


   
    int lastFree = lastSeg.getHeader().getLastFree();
   
    if (lastFree != -1)
    {
      return new BlockId(this.id, lastSeg.getId(), lastFree);
    }
    else
    {
      return null;
    }
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);
   
    assertEquals(0, bid.getContainerId());
    assertEquals(0, bid.getSegmentId());
    assertEquals(0, bid.getId());
   
    assertEquals(0, bid2.getContainerId());
    assertEquals(0, bid2.getSegmentId());
    assertEquals(1, bid2.getId());
       
    fs.close();
  }
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);
   
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>";
View Full Code Here

  @Override
  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);
     
      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);
      root.add(containerId);
      root.add(segmentId);
      root.add(id);
     
      out.println(root.toJSONString());
View Full Code Here

   * @return
   * @throws Exception
   */
  public Block readBlock(int idx) throws BlockReadErr
 
    BlockId blockId = new BlockId(this.container.getId(), this.id, idx);
   
    try
    {
      if (header.isFree(idx))
      {
View Full Code Here

  @Override
  public void create() {
   
    IFileSystem fs = FileSystemRegistry.get(new FileSystemRegKey(Constants.HOST, Configs.getFSConfig().getRootDir()));
   
    BlockId blockId = new BlockId(containerId, segmentId, id);
    Block block = new Block(blockId);
    block.setBytes(data);
   
    try
    {
View Full Code Here

  @Override
  public void create() {
   
    IFileSystem fs = FileSystemRegistry.get(new FileSystemRegKey(Constants.HOST, Configs.getFSConfig().getRootDir()));
   
    BlockId blockId = new BlockId(containerId, segmentId, id);
   
    try
    {
      fs.delete(blockId, soft);
     
View Full Code Here

TOP

Related Classes of org.jcoredb.fs.BlockId

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.