List of usage examples for java.nio.file Path resolveSibling
default Path resolveSibling(String other)
From source file:com.github.cbismuth.fdupes.io.PathOrganizer.java
private void onNoTimestampPath(final Path destination, final PathElement pathElement, final AtomicInteger counter) { final Path path = pathElement.getPath(); final String baseName = FilenameUtils.getBaseName(path.toString()); final int count = counter.getAndIncrement(); final String extension = FilenameUtils.getExtension(path.toString()); final String newName = String.format("%s-%d.%s", baseName, count, extension); final Path sibling = path.resolveSibling(newName); try {//from ww w.ja v a 2s . com FileUtils.moveFile(path.toFile(), sibling.toFile()); FileUtils.moveFileToDirectory(sibling.toFile(), Paths.get(destination.toString(), "misc").toFile(), true); } catch (final IOException e) { LOGGER.error(e.getMessage()); } }
From source file:io.github.swagger2markup.markup.builder.internal.AbstractMarkupDocBuilder.java
@Override public Path addFileExtension(Path file) { return file.resolveSibling(addFileExtension(file.getFileName().toString())); }
From source file:io.github.swagger2markup.markup.builder.internal.AbstractMarkupDocBuilder.java
@Override public void writeToFile(Path file, Charset charset, OpenOption... options) { writeToFileWithoutExtension(file.resolveSibling(addFileExtension(file.getFileName().toString())), charset, options);//from w w w.java2 s. c om }
From source file:com.aol.advertising.qiao.injector.file.watcher.QiaoFileManager.java
private Path resolveNewFilePath(Path sourceFilePath, long checksum) { String fname = sourceFilePath.getFileName().toString() + "." + checksum; return sourceFilePath.resolveSibling(fname); }
From source file:com.aol.advertising.qiao.injector.file.watcher.QiaoFileManager.java
private Path renameToTmpFilePath(Path sourceFilePath) throws IOException { String tmp_name = UUID.randomUUID() + "_" + sourceFilePath.getFileName().toString(); Path new_path = sourceFilePath.resolveSibling(tmp_name); Files.move(sourceFilePath, new_path, StandardCopyOption.ATOMIC_MOVE); return new_path; }
From source file:licorice.gui.MainPanel.java
private void processBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_processBtnActionPerformed SwingUtilities.invokeLater(() -> { try {//from ww w. ja va 2 s.c o m minQual = Integer.parseInt(minQualField.getText()); processBtn.setEnabled(false); //progressBar = new JProgressBar(); progressBar.setMinimum(0); progressBar.setMaximum(100); Path genomePath = Paths.get(prop.getProperty("genome.path")); prop.setProperty("input.default_dir", fc.getCurrentDirectory().getAbsolutePath()); prop.setProperty("minimum.quality", minQual.toString()); prop.setProperty("maximum.nocall.rate", maxNC.toString()); prop.store(new FileOutputStream("licorice.properties"), null); Path inputPath = Paths.get(fileNameField.getText()); if (!inputPath.toFile().exists()) { JOptionPane.showMessageDialog(null, "Input file does not exist"); appendLog("Input file '" + inputPath + "' does not exist"); return; } Path outputPath = inputPath .resolveSibling(FilenameUtils.getBaseName(inputPath.getFileName().toString()) + ".txt"); appendLog("Output in: '" + outputPath.getParent() + "'\n"); appendLog("Analysis Started...\n"); processBtn.setText("Processing..."); SimpleGenomeRef genome = new SimpleGenomeRef(genomePath); GenomeRef.ValidationResult validation = genome.validate(); if (!validation.isValid()) { appendLog("Reference Error: '" + validation.getErrors() + "'\n"); return; } Path effectivePath = ZipUtil.directoryfy(inputPath); Map<String, String> samples = VCFUtils.makeSamplesDictionary(VCFUtils.listVCFFiles(effectivePath)); appendLog("==================================\n"); appendLog("Samples List\n"); appendLog("==================================\n"); appendLog("Sample\tFile"); samples.forEach((k, v) -> appendLog(String.format("%s\t%s\n", k, v))); appendLog("==================================\n"); Path samplesPath = inputPath.resolveSibling( FilenameUtils.getBaseName(inputPath.getFileName().toString()) + ".samples.txt"); appendLog("Samples List in: '" + samplesPath.getParent() + "'\n"); try (PrintStream out = new PrintStream(new FileOutputStream(samplesPath.toFile()))) { out.println("Sample\tFile"); samples.forEach((k, v) -> out.println(String.format("%s\t%s", k, v))); } analysis = new Analysis(genome, minQual, maxNC, false, outputPath, VCFUtils.listVCFFiles(effectivePath)); analysis.progressListener(progress -> progressBar.setValue(progress)); analysis.onFinish(() -> { log.info("Callback called"); appendLog("Analysis Finished.\n"); fileNameField.setText(""); processBtn.setText("Process"); processBtn.setEnabled(true); processBtn.repaint(); this.repaint(); return null; }); analysis.onException((Thread t, Throwable ex) -> { appendLog(ex.getMessage()); appendLog("Analysis Failed!!!"); JOptionPane.showMessageDialog(null, "Analysis Failed!!!"); processBtn.setText("Process"); processBtn.setEnabled(true); processBtn.repaint(); }); } catch (IOException ex) { appendLog(ex.getMessage() + "\n"); log.error(ex.getMessage()); JOptionPane.showMessageDialog(null, "Analysis Failed!!!"); ex.printStackTrace(); } analysis.start(); //progressBar. }); }
From source file:com.searchcode.app.jobs.repository.IndexBaseRepoJob.java
/** * Logs to the logs directory a formatted CSV of the supplied list strings *///from w w w .j a v a2s . co m private void logIndexed(String repoName, List<String[]> reportList) { try { CSVWriter writer = new CSVWriter( new FileWriter(Singleton.getHelpers().getLogPath() + repoName + ".csv.tmp")); writer.writeAll(reportList); writer.flush(); writer.close(); Path source = Paths.get(Singleton.getHelpers().getLogPath() + repoName + ".csv.tmp"); Files.move(source, source.resolveSibling(repoName + ".csv"), StandardCopyOption.REPLACE_EXISTING); } catch (IOException ex) { Singleton.getLogger().warning("ERROR - caught a " + ex.getClass() + " in " + this.getClass() + " logIndexed for " + repoName + "\n with message: " + ex.getMessage()); } }
From source file:at.tfr.securefs.client.SecurefsFileServiceClient.java
public void run() { DateTime start = new DateTime(); try {// w w w . j a va2 s . c om FileService svc = new FileService(new URL(fileServiceUrl)); BindingProvider binding = (BindingProvider) svc.getFileServicePort(); binding.getRequestContext().put(BindingProvider.USERNAME_PROPERTY, username); binding.getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, password); for (Path path : files) { if (write) { if (!path.toFile().exists()) { System.err.println(Thread.currentThread() + ": NoSuchFile: " + path + " currentWorkdir=" + Paths.get("./").toAbsolutePath()); continue; } System.out.println(Thread.currentThread() + ": Sending file: " + start + " : " + path); svc.getFileServicePort().write(path.toString(), IOUtils.toByteArray(Files.newInputStream(path))); } Path out = path.resolveSibling( path.getFileName() + (asyncTest ? "." + Thread.currentThread().getId() : "") + ".out"); if (read) { System.out.println(Thread.currentThread() + ": Reading file: " + new DateTime() + " : " + out); if (out.getParent() != null) { Files.createDirectories(out.getParent()); } byte[] arr = svc.getFileServicePort().read(path.toString()); IOUtils.write(arr, Files.newOutputStream(out)); } if (write && read) { long inputChk = FileUtils.checksumCRC32(path.toFile()); long outputChk = FileUtils.checksumCRC32(out.toFile()); if (inputChk != outputChk) { throw new IOException(Thread.currentThread() + ": Checksum Failed: failure to write/read: in=" + path + ", out=" + out); } System.out.println(Thread.currentThread() + ": Checked Checksums: " + new DateTime() + " : " + inputChk + " / " + outputChk); } if (delete) { boolean deleted = svc.getFileServicePort().delete(path.toString()); if (!deleted) { throw new IOException( Thread.currentThread() + ": Delete Failed: failure to delete: in=" + path); } else { System.out.println(Thread.currentThread() + ": Deleted File: in=" + path); } } } } catch (Throwable t) { t.printStackTrace(); throw new RuntimeException(t); } }
From source file:uk.org.openeyes.diagnostics.AbstractFieldProcessor.java
/** * * @param metaData/*from www .j av a 2s .c om*/ * @param report * @param file * @return */ protected void moveFile(HumphreyFieldMetaData metaData, FieldReport report, File file) throws IOException { session = HibernateUtil.getSessionFactory().getCurrentSession(); session.getTransaction().begin(); session.update(report); for (Iterator<FieldErrorReport> it = report.getFieldErrorReports().iterator(); it.hasNext();) { session.update(it.next()); } if (!report.getFieldErrorReports().isEmpty()) { log.log(Level.FINE, "Errors detected in {0}:", file.getName()); } for (Iterator<FieldErrorReport> it = report.getFieldErrorReports().iterator(); it.hasNext();) { FieldErrorReport fer = it.next(); log.log(Level.FINE, "\t{0} {1}", new Object[] { fer.getFieldError().getId(), fer.getFieldError().getDescription() }); } session.getTransaction().commit(); // in the case of an invalid file reference, we treat a non-existent image as existing: if (!this.errorReportContains(report.getFieldErrorReports(), DbUtils.ERROR_INVALID_FILE_REFERENCE)) { // then the image file exists - move this too: File imageFile = new File(this.dir, metaData.getFileReference()); File fileToMove = new File(this.errDir, metaData.getFileReference()); Path source = imageFile.toPath(); try { Files.move(source, source.resolveSibling(fileToMove.getAbsolutePath())); } catch (IOException e) { e.printStackTrace(); throw new IOException( "Unable to rename " + imageFile.getAbsolutePath() + " to " + fileToMove.getAbsolutePath()); } // if (!imageFile.renameTo(fileToMove)) { // throw new IOException("Unable to rename " + imageFile.getAbsolutePath() // + " to " + fileToMove.getAbsolutePath()); // } if (!fileToMove.exists()) { throw new IOException("Unable to move " + imageFile.getAbsolutePath()); } } else if (this.errorReportContains(report.getFieldErrorReports(), DbUtils.ERROR_INVALID_FILE_REFERENCE)) { // the file might exist but the reference might be duff - check anyway: String basename = FilenameUtils.getBaseName(file.getName()); File imageFile = new File(file.getParentFile(), basename + ".tif"); if (imageFile.exists()) { imageFile.renameTo(new File(this.errDir, imageFile.getName())); } } File fileToMoveTo = new File(this.errDir, file.getName()); file.renameTo(fileToMoveTo); if (!fileToMoveTo.exists()) { throw new IOException("Unable to move " + file.getAbsolutePath()); } }
From source file:codes.thischwa.c5c.impl.LocalConnector.java
@Override public boolean rename(String oldBackendPath, String sanitizedName) throws C5CException { Path src = buildRealPath(oldBackendPath); boolean isDirectory = Files.isDirectory(src); if (!Files.exists(src)) { logger.error("Source file not found: {}", src.toString()); FilemanagerException.Key key = (isDirectory) ? FilemanagerException.Key.DirectoryNotExist : FilemanagerException.Key.FileNotExists; throw new FilemanagerException(FilemanagerAction.RENAME, key, FilenameUtils.getName(oldBackendPath)); }//from www. j av a2s . c o m Path dest = src.resolveSibling(sanitizedName); try { Files.move(src, dest); } catch (SecurityException | IOException e) { logger.warn(String.format("Error while renaming [%s] to [%s]", src.getFileName().toString(), dest.getFileName().toString()), e); FilemanagerException.Key key = (Files.isDirectory(src)) ? FilemanagerException.Key.ErrorRenamingDirectory : FilemanagerException.Key.ErrorRenamingFile; throw new FilemanagerException(FilemanagerAction.RENAME, key, FilenameUtils.getName(oldBackendPath), sanitizedName); } catch (FileSystemAlreadyExistsException e) { logger.warn("Destination file already exists: {}", dest.toAbsolutePath()); FilemanagerException.Key key = (Files.isDirectory(dest)) ? FilemanagerException.Key.DirectoryAlreadyExists : FilemanagerException.Key.FileAlreadyExists; throw new FilemanagerException(FilemanagerAction.RENAME, key, sanitizedName); } return isDirectory; }