List of usage examples for java.nio.file Path getFileName
Path getFileName();
From source file:ch.digitalfondue.jfiveparse.TreeConstructionTest.java
@Parameters(name = "{0}:{index}:{2}") public static List<Object[]> data() throws IOException { List<Object[]> data = new ArrayList<>(); try (DirectoryStream<Path> ds = Files .newDirectoryStream(Paths.get("src/test/resources/html5lib-tests/tree-construction"), "*.dat")) { for (Path p : ds) { String file = new String(Files.readAllBytes(p), StandardCharsets.UTF_8); String[] testsAsString = file.split("\n\n#data\n"); for (String t : testsAsString) { TreeConstruction treeTest = parse(t); if (treeTest.scriptingFlag == null) { data.add(new Object[] { p.getFileName().toString(), treeTest, false }); data.add(new Object[] { p.getFileName().toString(), treeTest, true }); } else if (treeTest.scriptingFlag) { data.add(new Object[] { p.getFileName().toString(), treeTest, true }); } else { data.add(new Object[] { p.getFileName().toString(), treeTest, false }); }/*from w w w . j a va 2s .com*/ } } } data.sort(new Comparator<Object[]>() { public int compare(Object[] o1, Object[] o2) { return new CompareToBuilder().append((String) o1[0], (String) o2[0]) .append((boolean) o1[2], (boolean) o2[2]).toComparison(); } }); return data; }
From source file:com.yqboots.fss.util.ZipUtils.java
/** * Compresses the specified directory to a zip file * * @param dir the directory to compress//from ww w .j a v a 2 s.com * @return the compressed file * @throws IOException */ public static Path compress(Path dir) throws IOException { Assert.isTrue(Files.exists(dir), "The directory does not exist: " + dir.toAbsolutePath()); Assert.isTrue(Files.isDirectory(dir), "Should be a directory: " + dir.toAbsolutePath()); Path result = Paths.get(dir.toAbsolutePath() + FileType.DOT_ZIP); try (final ZipOutputStream out = new ZipOutputStream( new BufferedOutputStream(new FileOutputStream(result.toFile())))) { // out.setMethod(ZipOutputStream.DEFLATED); final byte data[] = new byte[BUFFER]; // get a list of files from current directory Files.walkFileTree(dir, new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(final Path path, final BasicFileAttributes attrs) throws IOException { final File file = path.toFile(); // compress to relative directory, not absolute final String root = StringUtils.substringAfter(file.getParent(), dir.toString()); try (final BufferedInputStream origin = new BufferedInputStream(new FileInputStream(file), BUFFER)) { final ZipEntry entry = new ZipEntry(root + File.separator + path.getFileName()); out.putNextEntry(entry); int count; while ((count = origin.read(data, 0, BUFFER)) != -1) { out.write(data, 0, count); } } return FileVisitResult.CONTINUE; } }); } return result; }
From source file:nl.mpi.oai.harvester.control.FileSynchronization.java
public static void saveToHistoryFile(final Provider provider, final Path filePath, final Operation operation) { String dir = Main.config.getWorkingDirectory() + CMDI; File file = new File(dir + Util.toFileFormat(provider.getName()) + "_history.xml"); StringBuffer sb = new StringBuffer(); sb.append("<file ").append("harvestDate=\"").append(currentDate).append("\" ").append("name=\"") .append(filePath.getFileName()).append("\" ").append("operation=\"" + operation.name()) .append("\" ").append("/>\n"); writeToHistoryFile(file, sb.toString()); }
From source file:com.fizzed.blaze.util.Streamables.java
static public StreamableInput input(Path path) { Objects.requireNonNull(path, "path cannot be null"); if (!Files.exists(path)) { throw new FileNotFoundException("Path " + path + " not found"); }//from w ww . j a v a 2 s .c o m long size; try { size = Files.size(path); } catch (IOException e) { throw new BlazeException(e.getMessage(), e); } return new StreamableInput(new DeferredFileInputStream(path), path.getFileName().toString(), path, size); }
From source file:org.apache.taverna.databundle.DataBundles.java
protected static String filenameWithoutExtension(Path entry) { String fileName = entry.getFileName().toString(); int lastDot = fileName.lastIndexOf("."); if (lastDot < 0) return fileName.replace("/", ""); return fileName.substring(0, lastDot); }
From source file:org.apache.taverna.databundle.DataBundles.java
protected static Path withExtension(Path path, String extension) { String filename = path.getFileName().toString(); return path.resolveSibling(withExtensionFilename(filename, extension)); }
From source file:org.apache.taverna.databundle.DataBundles.java
private static Path anyExtension(Path path) throws IOException { return anyExtension(path.getParent(), path.getFileName().toString()); }
From source file:nl.coinsweb.sdk.FileManager.java
public static Path placeAttachment(String internalRef, Path attachment) { Path fileName = attachment.getFileName(); Path homePath = getTempZipPath().resolve(internalRef); Path attachmentPath = homePath.resolve(ATTACHMENT_PATH); Path absoluteTempPath = attachmentPath.resolve(fileName); try {/*from w w w.j ava 2 s. c o m*/ Files.copy(attachment, absoluteTempPath, StandardCopyOption.REPLACE_EXISTING); } catch (IOException e) { log.error(e.getMessage(), e); } return absoluteTempPath; }
From source file:at.tugraz.sss.serv.SSFileU.java
private static void formatAudioAndVideoFileName(final File file) throws Exception { final Path pathToFile = file.toPath(); String fileName = pathToFile.getFileName().toString().toLowerCase(); final SSFileExtE fileExt = SSFileExtE.ext(fileName); if (!SSFileExtE.isAudioOrVideoFileExt(fileExt)) { return;/* w w w . ja v a 2 s . co m*/ } fileName = SSStrU.replaceAllBlanksSpecialCharactersDoubleDots(fileName, SSStrU.underline); try { Files.move(pathToFile, pathToFile.resolveSibling(fileName)); } catch (FileAlreadyExistsException error) { System.out.println("file " + pathToFile.resolveSibling(fileName) + " already exists!"); } }
From source file:com.liferay.sync.engine.document.library.util.FileEventUtil.java
public static void updateFolder(Path filePath, long syncAccountId, SyncFile syncFile) { Map<String, Object> parameters = new HashMap<>(); parameters.put("description", syncFile.getDescription()); parameters.put("folderId", syncFile.getTypePK()); parameters.put("name", String.valueOf(filePath.getFileName())); parameters.put("syncFile", syncFile); UpdateFolderEvent updateFolderEvent = new UpdateFolderEvent(syncAccountId, parameters); updateFolderEvent.run();/*from w ww . j av a2 s .com*/ }