/** Запись в файл. 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(); } }
@Override public AbstractFile getRoot() { FileURL rootURL = (FileURL) getURL().clone(); String rootPath = getRootPath(); rootURL.setPath("/" + vmIdentifier + "/" + rootPath); return FileFactory.getFile(rootURL); }
/** * 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; } } }
/** * 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; } } }
@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)); } }
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); }