Refine search
@Override public FileVisitResult visitFile(final Path file, final BasicFileAttributes attrs) throws IOException { String extension = FilenameUtils.getExtension(file.toString()); if ("jar".equalsIgnoreCase(extension)) { fileVisitor.visitFile(file, attrs); } return FileVisitResult.CONTINUE; } };
/** Maps paths to classes. */ private static Stream<Class<?>> getClasses(URL url, String packageName) throws IOException, URISyntaxException { return getPathsInDir(url) .stream() .filter(path -> "class".equalsIgnoreCase(FilenameUtils.getExtension(path.toString()))) .<Class<?>>map(path -> { try { return Class.forName(packageName + "." + FilenameUtils.getBaseName(path.getFileName().toString())); } catch (ClassNotFoundException e) { e.printStackTrace(); return null; } }) .filter(Objects::nonNull); }
@DataBoundConstructor public FileParameterValue(String name, FileItem file) { this(name, file, FilenameUtils.getName(file.getName())); }
/** * Converts all separators to the system separator. * * @param path the path to be changed, null ignored * @return the updated path */ public static String separatorsToSystem(final String path) { if (path == null) { return null; } if (isSystemWindows()) { return separatorsToWindows(path); } else { return separatorsToUnix(path); } }
/** * Gets the base name, minus the full path and extension, from a full filename. * <p> * This method will handle a file in either Unix or Windows format. * The text after the last forward or backslash and before the last dot is returned. * <pre> * a/b/c.txt --> c * a.txt --> a * a/b/c --> c * a/b/c/ --> "" * </pre> * <p> * The output will be the same irrespective of the machine that the code is running on. * * @param filename the filename to query, null returns null * @return the name of the file without the path, or an empty string if none exists. Null bytes inside string * will be removed */ public static String getBaseName(final String filename) { return removeExtension(getName(filename)); }
public String getFullViewPath() { if (StringUtils.isBlank(assetRoot)) { return viewPath; } int positionOfQueryParamStart = viewPath.indexOf('?'); String viewPathWithoutQueryParams = positionOfQueryParamStart == -1 ? viewPath : viewPath.substring(0, positionOfQueryParamStart); String queryParams = positionOfQueryParamStart == -1 ? "" : viewPath.substring(positionOfQueryParamStart); return URI.create(FilenameUtils.separatorsToUnix(Paths.get(assetRoot, viewPathWithoutQueryParams).toString()) + queryParams).normalize().toString(); }
public static MimeType fromURI(URI uri) { try { return fromFilename(Paths.get(uri).toString()); } catch (FileSystemNotFoundException e) { // For non-file URIs, try to guess the MIME type from the URL path, if possible return fromExtension(FilenameUtils.getExtension(uri.toString())); } }
public void init(String bundleParam) { if (bundleParam != null) { Path fullPath = Paths.get(bundleParam); File bundleFile = fullPath.toFile(); if (bundleFile.exists()) { bundlePath = bundleFile.toPath().getParent(); bundleName = FilenameUtils.getBaseName(bundleFile.getName()); } else { LOG.error("Invalid bundle '" + bundleParam + "': file doesn't exist"); } } }
private static File relativePathForProject(File workspaceDir, MavenProject project, String localPathToSrc) throws MojoExecutionException { Path rootPath = workspaceDir.toPath().normalize(); Path path = Paths.get(project.getBuild().getDirectory() + localPathToSrc); Path relativePath = rootPath.relativize(path); String relativePathString = FilenameUtils.separatorsToUnix(relativePath.toString()); if (relativePathString.isEmpty()) { throw new MojoExecutionException("Cannot handle project because not relative path to root workspace could be build"); } return new File(relativePathString); } }
Collection<File> childrenFiles = org.apache.commons.io.FileUtils.listFiles(sourceDirectory, null, true); relativePath = FilenameUtils.separatorsToUnix(relativePath); childrenFiles = org.apache.commons.io.FileUtils.listFiles(chaincodeMetaInf, null, true); final String relativePath = Paths.get("META-INF", metabase.relativize(childFile.toURI()).getPath()).toString();
int prefix = FilenameUtils.getPrefixLength(name); if (prefix > -1) { name = name.substring(prefix); name = FilenameUtils.normalize(FilenameUtils.getName(name)); Path outputFile = outputDir.resolve(name); if (Files.exists(outputFile)) { outputFile = outputDir.resolve(UUID.randomUUID().toString()+"-"+name); Files.createDirectories(outputFile.getParent()); Files.copy(stream, outputFile);
String tempFileSuffix = tika ? null : "." + FilenameUtils.getExtension(fileName); String tempFilePrefix = UUID.randomUUID().toString(); Path tempFile = Files.createTempFile(tempFilePrefix, tempFileSuffix); try { InputStream in = new PushbackInputStream(new BufferedInputStream(inputStream)); try (OutputStream out = new FileOutputStream(tempFile.toFile())) { IOUtils.copyLarge(in, out); String contentType = Files.probeContentType(tempFile); if (contentType == null) { if (LOGGER.isLoggable(Level.WARNING)) { if (FilenameUtils.wildcardMatch(contentType.toLowerCase(), accept)) { accepted = true; if (LOGGER.isLoggable(Level.FINE)) { Files.delete(tempFile); tempFile.toAbsolutePath()), ex); try { tempFile.toFile().deleteOnExit();
private String getRuleClassSourceFilepath(String ruleClass) throws IOException { final String relativeSourceFilename = ruleClass.replaceAll("\\.", Matcher.quoteReplacement(File.separator)) + ".java"; final List<Path> foundPathResult = new LinkedList<>(); Files.walkFileTree(root, new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { String path = file.toString(); if (path.contains("src") && path.endsWith(relativeSourceFilename)) { foundPathResult.add(file); return FileVisitResult.TERMINATE; } return super.visitFile(file, attrs); } }); if (!foundPathResult.isEmpty()) { Path foundPath = foundPathResult.get(0); foundPath = root.relativize(foundPath); return FilenameUtils.normalize(foundPath.toString(), true); } return FilenameUtils.normalize(relativeSourceFilename, true); } }
(InternalConfigurationPersistenceService) getConfigurationPersistenceService(); if (zipFileName != null) { Path tempDir = Files.createTempDirectory("temp"); Path exportedDir = tempDir.resolve("cluster_config"); Path zipFile = tempDir.resolve(FilenameUtils.getName(zipFileName)); try { for (Configuration config : configPersistenceService.getEntireConfiguration().values()) { configPersistenceService.writeConfigToFile(config, exportedDir.toFile()); logger.error("unable to export configuration.", e); } finally { FileUtils.deleteQuietly(tempDir.toFile());
/** * Similar to {@link Path#relativize(Path)} except that: * <ul> * <li>null is returned if file is not a child of dir * <li>the resulting path is converted to use Unix separators * </ul> * @since 6.0 */ @CheckForNull public String relativePath(Path dir, Path file) { Path baseDir = dir.normalize(); Path path = file.normalize(); if (!path.startsWith(baseDir)) { return null; } try { Path relativized = baseDir.relativize(path); return FilenameUtils.separatorsToUnix(relativized.toString()); } catch (IllegalArgumentException e) { return null; } }
public SerializedFileReader(Path file) throws IOException { String fileName = file.getFileName().toString(); String fileExt = FilenameUtils.getExtension(fileName); // load audio buffer if existing readResourceStream(file.resolveSibling(fileName + ".streamingResourceImage")); readResourceStream(file.resolveSibling(fileName + ".resS")); // join split serialized files before loading if (fileExt.startsWith("split")) { L.fine("Found split serialized file"); fileName = FilenameUtils.removeExtension(fileName); List<Path> parts = new ArrayList<>(); int splitIndex = 0; // collect all files with .split0 to .splitN extension while (true) { String splitName = String.format("%s.split%d", fileName, splitIndex); Path part = file.resolveSibling(splitName); if (Files.notExists(part)) { break; } L.log(Level.FINE, "Adding splinter {0}", part.getFileName()); splitIndex++; parts.add(part); } // load all parts to one byte buffer in = DataReaders.forByteBuffer(ByteBufferUtils.load(parts)); } else { in = DataReaders.forFile(file, READ); } }
@Override public Attachment visitAttachmentFile(final Path attachmentFile) { final RandomUidContext context = configuration.requireContext(RandomUidContext.class); return attachments.computeIfAbsent(attachmentFile, file -> { final String uid = context.getValue().get(); final String realType = probeContentType(file); final String extension = Optional.of(getExtension(file.toString())) .filter(s -> !s.isEmpty()) .map(s -> "." + s) .orElseGet(() -> getExtensionByMimeType(realType)); final String source = uid + (extension.isEmpty() ? "" : extension); final Long size = getFileSizeSafe(file); return new Attachment() .setUid(uid) .setName(file.getFileName().toString()) .setSource(source) .setType(realType) .setSize(size); }); }
private static Set<String> readChangedFilesFromSource(String filePath) throws IOException { String normalizedPath = FilenameUtils.normalize(filePath); if (!get(normalizedPath).isAbsolute()) { throw new RuntimeException(MESSAGE_ERROR_LOADING_SMART_MODE_CONFIG_FILE + " Path[" + normalizedPath + "] is not an absolute path."); } if (!isRegularFile(get(normalizedPath), NOFOLLOW_LINKS)) { throw new RuntimeException(MESSAGE_ERROR_LOADING_SMART_MODE_CONFIG_FILE + " Path[" + normalizedPath + "] does not lead to a regular file."); } return ArgumentProcessorUtils.loadChangedItems(normalizedPath); }
private boolean process( final Path root, final Path file ) String relative = root.relativize( file ).toString(); if( !"json".equals( FilenameUtils.getExtension( file.toString() ) ) || relative.startsWith( "_" ) ) String name = FilenameUtils.removeExtension( relative ).replaceAll( "\\\\", "/" ); ResourceLocation key = new ResourceLocation( this.ctx.getModId(), name ); try reader = Files.newBufferedReader( file ); JsonObject json = JsonUtils.fromJson( GSON, reader, JsonObject.class ); if( json.has( "conditions" ) && !CraftingHelper.processConditions( JsonUtils.getJsonArray( json, "conditions" ), this.ctx ) )