コード例 #1
0
 /** Запись в файл. Thread-safe операция. */
 public synchronized void writeToFile(String content) throws IOException {
   logger.debug("[{}]: writeToFile({})", Thread.currentThread().getName(), content);
   try (BufferedWriter bufferedWriter = fileFactory.getBufferedWriter()) {
     bufferedWriter.write(content, 0, content.length());
     bufferedWriter.flush();
   }
 }
コード例 #2
0
  @Override
  public AbstractFile getRoot() {
    FileURL rootURL = (FileURL) getURL().clone();
    String rootPath = getRootPath();
    rootURL.setPath("/" + vmIdentifier + "/" + rootPath);

    return FileFactory.getFile(rootURL);
  }
コード例 #3
0
ファイル: FTPFile.java プロジェクト: solitaryreaper/IRODS
  /**
   * Copies this file to another file. This object is the source file. The destination file is given
   * as the argument. If the destination file, does not exist a new one will be created. Otherwise
   * the source file will be appended to the destination file. Directories will be copied
   * recursively.
   *
   * @param file The file to receive the data.
   * @throws NullPointerException If file is null.
   * @throws IOException If an IOException occurs.
   */
  public void copyTo(GeneralFile file, boolean forceOverwrite) throws IOException {
    if (file == null) {
      throw new NullPointerException();
    }

    if (isDirectory()) {
      // recursive copy
      GeneralFile[] fileList = listFiles();

      file.mkdir();
      if (fileList != null) {
        for (int i = 0; i < fileList.length; i++) {
          fileList[i].copyTo(
              FileFactory.newFile(
                  file.getFileSystem(), file.getAbsolutePath(), fileList[i].getName()),
              forceOverwrite);
        }
      }
    } else {
      if (file.isDirectory()) {
        // change the destination from a directory to a file
        file = FileFactory.newFile(file, getName());
      }
      try {
        if (file instanceof LocalFile) {
          ftpClient.get(getPath(), ((LocalFile) file).getFile());
        } else if (file instanceof FTPFile) {
          ftpClient.transfer(
              getPath(), ((FTPFile) file).getFTPClient(), file.getPath(), !forceOverwrite, null);
        } else {
          super.copyTo(file);
        }
      } catch (FTPException e) {
        IOException io = new IOException();
        io.initCause(e);
        throw io;
      }
    }
  }
コード例 #4
0
ファイル: FTPFile.java プロジェクト: solitaryreaper/IRODS
  /**
   * Copies this file to another file. This object is the source file. The destination file is given
   * as the argument. If the destination file, does not exist a new one will be created. Otherwise
   * the source file will be appended to the destination file. Directories will be copied
   * recursively.
   *
   * @param file The file to receive the data.
   * @throws NullPointerException If file is null.
   * @throws IOException If an IOException occurs.
   */
  public void copyFrom(GeneralFile file, boolean forceOverwrite) throws IOException {
    if (file == null) {
      throw new NullPointerException();
    }

    if (file.isDirectory()) {
      // recursive copy
      GeneralFile[] fileList = file.listFiles();

      mkdir();
      if (fileList != null) {
        for (int i = 0; i < fileList.length; i++) {
          FileFactory.newFile(this, fileList[i].getName()).copyFrom(fileList[i], forceOverwrite);
        }
      }
    } else {
      if (isDirectory()) {
        // change the destination from a directory to a file
        GeneralFile subFile = FileFactory.newFile(this, file.getName());
        subFile.copyFrom(file);
        return;
      }
      try {
        if (file instanceof LocalFile) {
          ftpClient.put(((LocalFile) file).getFile(), getPath(), !forceOverwrite);
        } else if (file instanceof FTPFile) {
          ftpClient.transfer(file.getPath(), ftpClient, getPath(), !forceOverwrite, null);
        } else {
          super.copyTo(file);
        }
      } catch (FTPException e) {
        IOException io = new IOException();
        io.initCause(e);
        throw io;
      }
    }
  }
コード例 #5
0
ファイル: CopyJob.java プロジェクト: nuCommander/nuCommander
  @Override
  protected void jobCompleted() {
    super.jobCompleted();

    // If the destination files are located inside an archive, optimize the archive file
    AbstractArchiveFile archiveFile = baseDestFolder.getParentArchive();
    if (archiveFile != null && archiveFile.isArchive() && archiveFile.isWritable())
      optimizeArchive((AbstractRWArchiveFile) archiveFile);

    // If this job correponds to a 'local copy' of a single file and in the same directory,
    // select the copied file in the active table after this job has finished (and hasn't been
    // cancelled)
    if (files.size() == 1
        && newName != null
        && baseDestFolder.equalsCanonical(files.elementAt(0).getParent())) {
      // Resolve new file instance now that it exists: some remote files do not immediately update
      // file attributes
      // after creation, we need to get an instance that reflects the newly created file attributes
      selectFileWhenFinished(FileFactory.getFile(baseDestFolder.getAbsolutePath(true) + newName));
    }
  }
コード例 #6
0
ファイル: Main.java プロジェクト: GuilhermeHideki/b1lp2
  public static void run(Folder f) {
    System.out.println("+" + f.path);

    for (Extension x : f.allowedExtensions) {
      System.out.println(x.toString());
    }

    f.getFilePaths();

    for (String path : f.files) {
      File file = FileFactory.Create(path);
      System.out.println(file.getPath());
      file.read();

      file.getWords().forEach((k, v) -> words.merge(k, v, (v1, v2) -> v1 + v2));
    }

    int times =
        Integer.parseInt(
            JOptionPane.showInputDialog("Qual o mínimo de repetições a serem mostradas"));
    File.ListWords(words, times);
  }