List of usage examples for java.nio.file Path getFileName
Path getFileName();
From source file:com.nwn.NwnFileHandler.java
/** * Get names of files in given directory * @param dir Path to directory for parsing * @return String of file names in directory */// ww w .j av a 2 s.c o m public static ArrayList<String> getFileNamesInDirectory(Path dir) throws NoSuchFileException, IOException { ArrayList<String> fileNamesInDir = new ArrayList<String>(); DirectoryStream<Path> dirStream = Files.newDirectoryStream(dir); for (Path file : dirStream) { fileNamesInDir.add(file.getFileName().toString()); } dirStream.close(); return fileNamesInDir; }
From source file:ec.edu.chyc.manejopersonal.managebean.util.BeansUtils.java
/*** * Abre un stream para descargar un archivo * @param direccionArchivoOrigen Archivo a descargar * @param nombreArchivoDescarga Nombre del archivo como se quiere descargar, puede ser diferente al nombre original * @return Stream de descarga/*from w ww . j a va 2 s . c o m*/ * @throws FileNotFoundException En caso de no encontrar el archivo */ public static StreamedContent streamParaDescarga(Path direccionArchivoOrigen, String nombreArchivoDescarga) throws FileNotFoundException { String nombreArchivoGuardado = direccionArchivoOrigen.getFileName().toString(); String extension = FilenameUtils.getExtension(nombreArchivoGuardado); String nuevoNombre = ServerUtils.convertirNombreArchivo(nombreArchivoDescarga, extension, 40); Path pathArchivo = direccionArchivoOrigen; InputStream stream = new BufferedInputStream(new FileInputStream(pathArchivo.toFile())); ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext(); StreamedContent streamParaDescarga = new DefaultStreamedContent(stream, externalContext.getMimeType(nuevoNombre), nuevoNombre); return streamParaDescarga; }
From source file:api.wiki.WikiGenerator.java
private static boolean isMarkdownFile(Path file) { return file.getFileName().toString().endsWith(MARKDOWN_FILE_EXTENSION); }
From source file:com.ibm.streamsx.topology.internal.context.remote.ZippedToolkitRemoteContext.java
private static void addAllToZippedArchive(Map<Path, String> starts, Path zipFilePath) throws IOException { try (ZipArchiveOutputStream zos = new ZipArchiveOutputStream(zipFilePath.toFile())) { for (Path start : starts.keySet()) { final String rootEntryName = starts.get(start); Files.walkFileTree(start, new SimpleFileVisitor<Path>() { public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { // Skip pyc files. if (file.getFileName().toString().endsWith(".pyc")) return FileVisitResult.CONTINUE; String entryName = rootEntryName; String relativePath = start.relativize(file).toString(); // If empty, file is the start file. if (!relativePath.isEmpty()) { entryName = entryName + "/" + relativePath; }// w ww. j a v a 2 s . co m // Zip uses forward slashes entryName = entryName.replace(File.separatorChar, '/'); ZipArchiveEntry entry = new ZipArchiveEntry(file.toFile(), entryName); if (Files.isExecutable(file)) entry.setUnixMode(0100770); else entry.setUnixMode(0100660); zos.putArchiveEntry(entry); Files.copy(file, zos); zos.closeArchiveEntry(); return FileVisitResult.CONTINUE; } public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException { final String dirName = dir.getFileName().toString(); // Don't include pyc files or .toolkit if (dirName.equals("__pycache__")) return FileVisitResult.SKIP_SUBTREE; ZipArchiveEntry dirEntry = new ZipArchiveEntry(dir.toFile(), rootEntryName + "/" + start.relativize(dir).toString().replace(File.separatorChar, '/') + "/"); zos.putArchiveEntry(dirEntry); zos.closeArchiveEntry(); return FileVisitResult.CONTINUE; } }); } } }
From source file:com.liferay.sync.engine.util.MSOfficeFileUtil.java
public static boolean isTempRenamedFile(Path sourceFilePath, Path targetFilePath) { String extension = FilenameUtils.getExtension(sourceFilePath.toString()); if (extension.equals("pub")) { String fileName = String.valueOf(targetFilePath.getFileName()); if (fileName.startsWith("pub") && fileName.endsWith(".tmp")) { return true; }/*from w w w .j av a 2s . c o m*/ } else if (hasExtension(extension, _excelExtensions) || hasExtension(extension, _powerpointExtensions)) { Matcher matcher = _tempRenamedFilePattern.matcher(String.valueOf(targetFilePath.getFileName())); if (matcher.matches()) { return true; } } else if (hasExtension(extension, _wordExtensions)) { String fileName = String.valueOf(targetFilePath.getFileName()); if (fileName.startsWith("~WR") && fileName.endsWith(".tmp")) { return true; } } return false; }
From source file:com.github.zhanhb.ckfinder.connector.utils.ImageUtils.java
/** * checks if file is image.//w w w. jav a 2s . c o m * * @param file file to check * @return true if file is image. */ public static boolean isImageExtension(Path file) { if (file != null) { String fileExt = FileUtils.getExtension(file.getFileName().toString()); return fileExt != null && ALLOWED_EXT.contains(fileExt.toLowerCase()); } else { return false; } }
From source file:com.textocat.textokit.commons.io.IoUtils.java
public static Path addExtension(Path srcPath, String newExt) { Preconditions.checkArgument(newExt != null, "extension is null"); if (srcPath.getNameCount() == 0) { return srcPath; }/*from ww w . j av a 2 s. c o m*/ String filename = srcPath.getFileName().toString(); return srcPath.resolveSibling(filename + "." + newExt); }
From source file:io.anserini.index.IndexClueWeb09b.java
static List<Path> discoverWarcFiles(Path p) { final List<Path> warcFiles = new ArrayList<>(); FileVisitor<Path> fv = new SimpleFileVisitor<Path>() { @Override/*w w w . j a va2s . co m*/ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { Path name = file.getFileName(); if (name != null && matcher.matches(name)) warcFiles.add(file); return FileVisitResult.CONTINUE; } }; try { Files.walkFileTree(p, fv); } catch (IOException e) { e.printStackTrace(); } return warcFiles; }
From source file:org.bonitasoft.web.designer.controller.utils.HttpFile.java
public static void writeFileInResponseForVisualization(HttpServletRequest request, HttpServletResponse response, Path filePath) throws IOException { if (!isExistingFilePath(response, filePath)) { response.sendError(HttpServletResponse.SC_NOT_FOUND); return;//from w ww.j a v a 2s . c om } String mimeType = request.getServletContext().getMimeType(filePath.getFileName().toString()); if (mimeType == null || !mimeType.contains("image")) { mimeType = MediaType.TEXT_PLAIN_VALUE; } writeFileInResponse(response, filePath, mimeType, "inline"); }
From source file:net.kemuri9.sling.filesystemprovider.impl.PersistenceHelper.java
/** retrieve the compression format from the specified file */ static JSONCompression compressionFromFile(Path file) { String fileName = file.getFileName().toString(); for (JSONCompression compression : JSONCompression.values()) { if (fileName.endsWith(compression.extension)) { return compression; }/* w w w . j a v a2 s.c o m*/ } // default to NONE return JSONCompression.NONE; }