コード例 #1
0
  public void removeBlock(long blockId) {
    transactionIds.remove(blockId);
    headerIds.remove(blockId);

    BitCoopFile fileToDelete = getFileForId(blockId);
    if (fileToDelete != null) {
      fileToDelete.delete();
    }
  }
コード例 #2
0
  /*junit*/ long getUsedSpace(BitCoopFile rootFile) {
    if (rootFile.isFile()) return rootFile.length();

    long size = 0;
    BitCoopFile[] files = rootFile.listFiles();
    if (files == null) return 0;
    for (BitCoopFile file : files) {
      size += getUsedSpace(file);
    }
    return size;
  }
コード例 #3
0
 private void deleteTree(BitCoopFile root) {
   BitCoopFile childs[] = root.listFiles();
   if (childs != null) {
     for (BitCoopFile child : childs) {
       deleteTree(child);
     }
   }
   if (root.delete() == false) {
     Logger.getLogger(this.getClass()).error("Delete failed for file " + root);
   }
 }
コード例 #4
0
  /**
   * @param repositoryManager
   * @param peerName
   * @throws FileNotFoundException
   */
  public FSBlockRepository(FSRepositoryManager repositoryManager, String directoryPath) {
    super(repositoryManager);

    if (directoryPath == null) {
      throw new RuntimeException("DirectoryPath cannot be null");
    }
    this.directoryPath = directoryPath;
    this.usedSpace = getUsedSpace();
    try {
      BitCoopFile dirFile = new BitCoopFile(directoryPath);
      dirFile.mkdirs();
      openIndex();
    } catch (Exception e) {
      e.printStackTrace();
      throw new RuntimeException(e);
    }
  }
コード例 #5
0
 /*junit*/ BitCoopFile getFileForId(long blockId) {
   BitCoopFile parent = new BitCoopFile(getFilePath(blockId));
   parent.mkdirs();
   return new BitCoopFile(parent, "data");
 }