List of usage examples for java.nio.file Path getFileName
Path getFileName();
From source file:cz.muni.fi.editor.typemanager.TypeServiceImpl.java
private void createBackup(Path target) throws IOException { if (Files.exists(target)) { String newName = getBaseName(target.getFileName().toString()) + "." + LocalDateTime.now().format(formatter) + ".xml"; Files.move(target, target.resolveSibling(newName)); Files.createFile(target); }/*from w w w . j av a2 s.c o m*/ }
From source file:com.zergiu.tvman.controllers.FSBrowseController.java
/** * @param children/* w w w .j av a 2s. c o m*/ * @param parent * @return * @throws IOException */ private void addChildFolders(Map<String, String> children, Path parent) throws IOException { try (DirectoryStream<Path> paths = Files.newDirectoryStream(parent)) { for (Path path : paths) { if (Files.isDirectory(path)) { Path name = path.getFileName(); children.put(path.toString(), name.toString()); } } } //try }
From source file:net.gvmtool.api.CandidateVersions.java
CandidateVersion determine(Context context, Path candidateDir, String versionName, GvmOptions options) { String candidateName = candidateDir.getFileName().toString(); if (options.isOffline()) { if (StringUtils.isNotBlank(versionName)) { if (context.candidateVersionInstalled(candidateDir, versionName)) { return version(context, candidateDir, versionName); } else { throw new RuntimeException("Not available offline"); }// w w w . j a va2s . c o m } else { if (context.candidateHasCurrentVersion(candidateDir)) { Path resolvedCurrentDir = context.candidateResolveCurrentDir(candidateDir); return version(context, candidateDir, resolvedCurrentDir.getFileName().toString()); } else { throw new RuntimeException("Not available offline"); } } } else { if (StringUtils.isBlank(versionName)) { Version defaultVersion; try { defaultVersion = context.getClient().getDefaultVersionFor(candidateName); } catch (GvmClientException e) { throw new RuntimeException("Error getting default version for " + candidateName, e); } return version(context, candidateDir, defaultVersion.getName()); } else { boolean versionValid; try { versionValid = context.getClient().validCandidateVersion(candidateName, versionName); } catch (GvmClientException e) { throw new RuntimeException("Error validating version " + versionName + " of " + candidateName, e); } if (versionValid) { return version(context, candidateDir, versionName); } if (context.candidateVersionIsSymlink(candidateDir, versionName)) { return version(context, candidateDir, versionName); } if (context.candidateVersionIsDir(candidateDir, versionName)) { return version(context, candidateDir, versionName); } throw new RuntimeException(versionName + " is not a valid " + candidateName + " version."); } } }
From source file:com.rptools.io.TableFileParser.java
private void setTableName(Path file, RPTable.Builder builder) { String filename = file.getFileName().toString().replace(EXT_TXT, "").replaceAll("^[0-9]*", ""); Matcher wordBreak = WORD_BREAK_PATTERN.matcher(filename); while (wordBreak.find()) { filename = filename.replace(wordBreak.group(0), wordBreak.group(1) + " " + wordBreak.group(2)); }// www . jav a2s. c om builder.setName(filename); }
From source file:uk.ac.ebi.eva.pipeline.jobs.steps.VariantLoaderStep.java
@Override public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception { ObjectMap variantOptions = jobOptions.getVariantOptions(); ObjectMap pipelineOptions = jobOptions.getPipelineOptions(); VariantStorageManager variantStorageManager = StorageManagerFactory.getVariantStorageManager();// TODO add mongo URI outdirUri = URLHelper.createUri(pipelineOptions.getString("output.dir")); URI nextFileUri = URLHelper.createUri(pipelineOptions.getString("input.vcf")); // URI pedigreeUri = pipelineOptions.getString("input.pedigree") != null ? createUri(pipelineOptions.getString("input.pedigree")) : null; Path output = Paths.get(outdirUri.getPath()); Path input = Paths.get(nextFileUri.getPath()); Path outputVariantJsonFile = output.resolve( input.getFileName().toString() + ".variants.json" + pipelineOptions.getString("compressExtension")); // outputFileJsonFile = output.resolve(input.getFileName().toString() + ".file.json" + config.compressExtension); URI transformedVariantsUri = outdirUri.resolve(outputVariantJsonFile.getFileName().toString()); logger.info("-- PreLoad variants -- {}", nextFileUri); variantStorageManager.preLoad(transformedVariantsUri, outdirUri, variantOptions); logger.info("-- Load variants -- {}", nextFileUri); variantStorageManager.load(transformedVariantsUri, variantOptions); // logger.info("-- PostLoad variants -- {}", nextFileUri); // variantStorageManager.postLoad(transformedVariantsUri, outdirUri, variantOptions); return RepeatStatus.FINISHED; }
From source file:controllers.ImageBrowser.java
@ModelAccess(AccessType.LISTED) public static void resolveFile(Path path, String mode, Project project, Float scale, Integer width, Integer height, Float brightness, Float contrast, Boolean histogram, Integer slice) throws IOException { if (!PermissionService.userCanAccessPath(Security.getUser(), path)) forbidden();//from w w w .j a v a 2 s . co m Boolean noWatermark = PermissionService.hasInheritedAccess(Security.getUser(), PathService.projectForPath(path), AccessType.NO_WATERMARK); if (params._contains("download")) response.setHeader("Content-Disposition", "attachment; filename=" + path.getFileName()); if (!PathService.isImage(path)) { renderBinary(path.toFile()); return; } String argumentString = PodbaseUtil.argumentString(path, mode, scale, width, height, brightness, contrast, histogram, slice, noWatermark); String argumentHash = PodbaseUtil.argumentHash(path, mode, scale, width, height, brightness, contrast, histogram, slice, noWatermark); Path cacheFolder = PathService.getApplicationPath().resolve("./tmp/cache"); Path cachedImagePath = PathService.calculateHashFolderPath(cacheFolder, argumentHash + ".png"); Path cacheMetadataPath = PathService.calculateHashFolderPath(cacheFolder, argumentHash + ".txt"); File cachedImageFile = cachedImagePath.toFile(); if (cacheMetadataPath.toFile().exists()) { String cachedArguments = FileUtils.readFileToString(cacheMetadataPath.toFile()); if (cachedArguments.equals(argumentString)) { //cache hit //System.out.println("Cache HIT"); BufferedImage bi = ImageIO.read(cachedImageFile); renderImage(bi); } } //System.out.println("cache miss"); //cache miss ImagePlus image = getImage(path); if (slice != null) { if (slice < 1 || slice > image.getStackSize()) throw new RuntimeException("Invalid slice! Found: " + slice + " max is " + image.getStackSize()); image.setSlice(slice); } if ("thumb".equals(mode)) { image = ImageService.scaleImageToFit(image, 200, 200); } else if ("fit".equals(mode) && width != null && height != null) { image = ImageService.scaleImageToFit(image, width, height); } else if (width != null && height != null) { image = ImageService.scaleImage(image, width, height); } else if (width != null || height != null) { image = ImageService.scaleImageToFit(image, width, height); } else if (scale != null) { image = ImageService.scaleImage(image, (int) (image.getWidth() * scale), (int) (image.getHeight() * scale)); } if (histogram == null) histogram = false; if (brightness == null) brightness = (float) 0; if (contrast == null) contrast = (float) 0; image = ImageService.adjustImage(image, brightness, contrast); if (histogram) { System.out.println("REIMPLEMENT ME!"); //BufferedImage hist = ImageService.makeHistogram(image, image.getWidth(), image.getWidth()/2); //image = ImageService.appendImages(image,hist); } BufferedImage imageOut = image.getBufferedImage(); if (!noWatermark) imageOut = ImageService.addWatermark(imageOut); try { if (!cachedImageFile.exists()) { cachedImageFile.getParentFile().mkdirs(); cachedImageFile.createNewFile(); cacheMetadataPath.toFile().createNewFile(); } ImageIO.write(imageOut, "png", cachedImageFile); FileUtils.write(cacheMetadataPath.toFile(), argumentString); } catch (IOException e) { System.err.println("Failed to write cached image"); e.printStackTrace(); } renderImage(imageOut); }
From source file:fr.cnrs.sharp.test.GenProvenanceForFile.java
@Test public void hello() throws FileNotFoundException, IOException { StopWatch sw = new StopWatch(); sw.start();/*from w ww . j a va2 s. co m*/ Path p = Paths.get("/Users/gaignard-a/Desktop/access.log-20150818"); String label = p.getFileName().toString(); System.out.println(); FileInputStream fis = new FileInputStream(p.toFile()); String sha512 = DigestUtils.sha512Hex(fis); System.out.println(""); System.out.println(sha512); System.out.println("SHA512 calculated in " + sw.getTime() + " ms."); StringBuffer sb = new StringBuffer(); sb.append("@base <http://fr.symetric> .\n" + "@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .\n" + "@prefix foaf: <http://xmlns.com/foaf/0.1/> .\n" + "@prefix sioc: <http://rdfs.org/sioc/ns#> .\n" + "@prefix prov: <http://www.w3.org/ns/prov#> .\n" + "@prefix sym: <http://fr.symetric/vocab#> .\n" + "@prefix dcterms: <http://purl.org/dc/terms/> .\n" + "@prefix tavernaprov: <http://ns.taverna.org.uk/2012/tavernaprov/> .\n" + "@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .\n"); sb.append("<#" + UUID.randomUUID().toString() + ">\n" + "\t a prov:Entity ;\n"); sb.append("\t rdfs:label \"" + label + "\"^^xsd:String ;\n"); sb.append("\t tavernaprov:sha512 \"" + sha512 + "\"^^xsd:String ."); System.out.println(""); System.out.println(""); System.out.println(sb.toString()); fis.close(); }
From source file:audiomanagershell.commands.FavCommand.java
@Override public void execute() throws CommandException { Path file = Paths.get(this.pathRef.toString(), this.arg); if (!Files.exists(file)) throw new FileNotFoundException(file.getFileName().toString()); if (!Files.isRegularFile(file)) throw new NotAFileException(file.getFileName().toString()); List<String> validExtensions = Arrays.asList("wav", "mp3", "flac", "mp4"); if (!validExtensions.contains(FilenameUtils.getExtension(file.toString()))) throw new NotAudioFileException(file.toString()); try (PrintWriter output = new PrintWriter(new FileWriter(favFile.toFile(), true)); Scanner input = new Scanner(new FileReader(favFile.toString()))) { while (input.hasNextLine()) { if (input.nextLine().equals(file.toString())) { System.out.printf("File \"%s\" is already added to favorite List!%n", file); return; }/*w ww . ja va2s. c o m*/ } System.out.printf("Added: \"%s\"%n", file); output.println(file); } catch (IOException ex) { throw new CommandException("Error related from I/O to file:" + favFile.toString()); } }
From source file:com.ignorelist.kassandra.steam.scraper.PathResolver.java
public Set<Path> findSharedConfig() throws IOException { Path base = findSteamBase().resolve("steam").resolve("userdata"); final Set<Path> paths = new HashSet<>(); Files.walkFileTree(base, new SimpleFileVisitor<Path>() { @Override/*from ww w . ja v a2 s. c o m*/ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { if ("sharedconfig.vdf".equals(file.getFileName().toString())) { paths.add(file); } return super.visitFile(file, attrs); } }); if (paths.isEmpty()) { throw new IllegalStateException("can't find sharedconfig.vdf"); } return paths; }
From source file:Helpers.HelpersCSV.java
public String getFileNameFromPath(String inputPath) { Path p = Paths.get(inputPath); return p.getFileName().toString(); }