Пример #1
0
  @Override
  public void deleteBook(String fileName) {
    this.helper.delete(fileName);

    // Only delete files we manage
    if (fileName.startsWith(config.getLibraryFolder())) {
      File bookFile = new File(fileName);
      File parentFolder = bookFile.getParentFile();

      bookFile.delete();

      while (parentFolder.list() == null || parentFolder.list().length == 0) {
        parentFolder.delete();
        parentFolder = parentFolder.getParentFile();
      }
    }
  }
Пример #2
0
  private File copyToLibrary(String fileName, String author, String title) throws IOException {

    File baseFile = new File(fileName);

    File targetFolder =
        new File(config.getLibraryFolder() + "/" + cleanUp(author) + "/" + cleanUp(title));

    targetFolder.mkdirs();

    FileChannel source = null;
    FileChannel destination = null;

    File targetFile = new File(targetFolder, baseFile.getName());

    if (baseFile.equals(targetFile)) {
      return baseFile;
    }

    LOG.debug("Copying to file: " + targetFile.getAbsolutePath());

    targetFile.createNewFile();

    try {
      source = new FileInputStream(baseFile).getChannel();
      destination = new FileOutputStream(targetFile).getChannel();
      destination.transferFrom(source, 0, source.size());
    } finally {
      if (source != null) {
        source.close();
      }
      if (destination != null) {
        destination.close();
      }
    }

    return targetFile;
  }
Пример #3
0
 @Override
 public void loadText(Spanned text) {
   this.text = text;
   this.pageNum = 0;
   this.pageOffsets = getPageOffsets(text, config.isShowPageNumbers());
 }