本文整理汇总了Java中java.nio.file.Path.getFileName方法的典型用法代码示例。如果您正苦于以下问题:Java Path.getFileName方法的具体用法?Java Path.getFileName怎么用?Java Path.getFileName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.nio.file.Path
的用法示例。
在下文中一共展示了Path.getFileName方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: processStep
import java.nio.file.Path; //导入方法依赖的package包/类
@Override
public CleanupContext processStep(CleanupContext context) {
log.entry(context);
TranscodeFinishedEvent result = context.getTranscodeFinishedEvent();
if (isFailed(result)) return log.exit(context);
Path source = result.getTemporaryPath();
Path media = result.getMedia().getSourcePath();
Path target = createOutputDirectoryTree(media);
Path tempFile = source.getFileName();
Path finalPath = target.getParent().resolve(tempFile);
FileUtil.createParentDirectoriesFor(finalPath);
context.setOutputPath(moveAndReplaceExisting(source, finalPath, cleanupSettings.overwriteFiles()));
return log.exit(context);
}
示例2: createDescriptor
import java.nio.file.Path; //导入方法依赖的package包/类
private ToolDescriptor createDescriptor(String stringPath) {
ToolDescriptor toolDescriptor = new ToolDescriptor();
try {
Path path = Paths.get(stringPath);
if (path == null) {
throw new RuntimeException("Could not get file path.");
}
Path filePath = path.getFileName();
if (filePath == null) {
throw new RuntimeException("Could not get file path.");
}
String fileName = filePath.toString();
String content = new String(Files.readAllBytes(path), StandardCharsets.UTF_8);
toolDescriptor.setDescriptor(content);
toolDescriptor.setType(ToolDescriptor.TypeEnum.CWL);
// Temporarily setting the url to the filename, otherwise there's no way to pass it
toolDescriptor.setUrl(fileName);
} catch (IOException e) {
ExceptionHelper.errorMessage(LOGGER, "Could not read descriptor file" + e.getMessage(), ExceptionHelper.IO_ERROR);
}
return toolDescriptor;
}
示例3: zipfiles
import java.nio.file.Path; //导入方法依赖的package包/类
/**
* Zip all the files in our
* @param dest
* @throws IOException
*/
private void zipfiles(File dest) throws IOException
{
FileOutputStream fos = new FileOutputStream(dest);
ZipOutputStream zos = new ZipOutputStream(fos);
for (Path p : files) {
try {
Path file = p.getFileName();
if (file != null) {
zos.putNextEntry(new ZipEntry(file.toString()));
Files.copy(p, zos);
}
} catch (IOException ioe) {
log.warning("\bUnable to archive " + p);
}
zos.closeEntry();
}
zos.close();
fos.close();
}
示例4: implProbeContentType
import java.nio.file.Path; //导入方法依赖的package包/类
@Override
protected String implProbeContentType(Path path) {
Path fn = path.getFileName();
if (fn == null)
return null; // no file name
String ext = getExtension(fn.toString());
if (ext.isEmpty())
return null; // no extension
loadMimeTypes();
if (mimeTypeMap == null || mimeTypeMap.isEmpty())
return null;
// Case-sensitive search
String mimeType;
do {
mimeType = mimeTypeMap.get(ext);
if (mimeType == null)
ext = getExtension(ext);
} while (mimeType == null && !ext.isEmpty());
return mimeType;
}
示例5: createToolDockerfile
import java.nio.file.Path; //导入方法依赖的package包/类
private ToolDockerfile createToolDockerfile(String stringPath) {
ToolDockerfile toolDockerfile = new ToolDockerfile();
Path path = Paths.get(stringPath);
if (path == null) {
throw new RuntimeException("Could not get file path.");
}
Path filePath = path.getFileName();
if (filePath == null) {
throw new RuntimeException("Could not get file path.");
}
String fileName = filePath.toString();
try {
String content = new String(Files.readAllBytes(path), StandardCharsets.UTF_8);
toolDockerfile.setDockerfile(content);
// Temporarily setting the url to the filename
toolDockerfile.setUrl(fileName);
} catch (IOException e) {
ExceptionHelper.errorMessage(LOGGER, "Could not read dockerfile" + e.getMessage(), ExceptionHelper.IO_ERROR);
}
return toolDockerfile;
}
示例6: hasExtension
import java.nio.file.Path; //导入方法依赖的package包/类
protected static boolean hasExtension(Path path, String... extensions) {
final Path namePath = path.getFileName();
if (namePath == null) {
return false;
}
final String name = namePath.toString();
for (String ext : extensions) {
if (name.endsWith(ext)) {
return true;
}
}
return false;
}
示例7: postVisitDirectory
import java.nio.file.Path; //导入方法依赖的package包/类
@Override
public FileVisitResult postVisitDirectory(Path dir, IOException exc)
throws IOException
{
if (exc != null)
super.postVisitDirectory(dir, exc);
if (dir.getFileName() != null)
indent--;
return FileVisitResult.CONTINUE;
}
示例8: getFileName
import java.nio.file.Path; //导入方法依赖的package包/类
@Override
@FXThread
public @NotNull String getFileName() {
final Path editFile = getEditFile();
final Path fileName = editFile.getFileName();
return fileName.toString();
}
示例9: mv
import java.nio.file.Path; //导入方法依赖的package包/类
private static void mv(Path src, Path dest) throws MojoExecutionException {
try {
Files.move(src, dest);
} catch (IOException e) {
throw new MojoExecutionException("Failed to rename " + src.getFileName() + ": " + e.getMessage(), e);
}
}
示例10: implProbeContentType
import java.nio.file.Path; //导入方法依赖的package包/类
@Override
protected String implProbeContentType(Path path) throws IOException {
Path fn = path.getFileName();
if (fn == null)
return null; // no file name
String ext = getExtension(fn.toString());
if (ext.isEmpty())
return null; // no extension
return probe0(ext);
}
示例11: getNameWithoutExtension
import java.nio.file.Path; //导入方法依赖的package包/类
/**
* Returns the file name without its
* <a href="http://en.wikipedia.org/wiki/Filename_extension">file extension</a> or path. This is
* similar to the {@code basename} unix command. The result does not include the '{@code .}'.
*/
public static String getNameWithoutExtension(Path path) {
Path name = path.getFileName();
// null for empty paths and root-only paths
if (name == null) {
return "";
}
String fileName = name.toString();
int dotIndex = fileName.lastIndexOf('.');
return dotIndex == -1 ? fileName : fileName.substring(0, dotIndex);
}
示例12: normalizePath
import java.nio.file.Path; //导入方法依赖的package包/类
/**
* Returns a {@link Path} that can be tested, given a {@link Path}
* and the application of the {@code requireDirectory} and {@code
* basename} parameters passed to the constructor.
*
* <p>This method may return {@code null}.</p>
*
* @param path the {@link Path} to normalize; may be {@code null}
* in which case {@code null} will be returned
*
* @return a {@link Path} to be further tested; or {@code null}
*/
protected final Path normalizePath(final Path path) {
Path returnValue = path;
if (path != null) {
if (this.basename) {
returnValue = path.getFileName();
}
if (this.requireDirectory && !Files.isDirectory(path)) {
returnValue = null;
}
}
return returnValue;
}
示例13: getFileExtension
import java.nio.file.Path; //导入方法依赖的package包/类
/**
* Returns the <a href="http://en.wikipedia.org/wiki/Filename_extension">file extension</a> for
* the file at the given path, or the empty string if the file has no extension. The result does
* not include the '{@code .}'.
*
* <p><b>Note:</b> This method simply returns everything after the last '{@code .}' in the file's
* name as determined by {@link Path#getFileName}. It does not account for any filesystem-specific
* behavior that the {@link Path} API does not already account for. For example, on NTFS it will
* report {@code "txt"} as the extension for the filename {@code "foo.exe:.txt"} even though NTFS
* will drop the {@code ":.txt"} part of the name when the file is actually created on the
* filesystem due to NTFS's <a href="https://goo.gl/vTpJi4">Alternate Data Streams</a>.
*/
public static String getFileExtension(Path path) {
Path name = path.getFileName();
// null for empty paths and root-only paths
if (name == null) {
return "";
}
String fileName = name.toString();
int dotIndex = fileName.lastIndexOf('.');
return dotIndex == -1 ? "" : fileName.substring(dotIndex + 1);
}
示例14: getSuperfamilyIdentifier
import java.nio.file.Path; //导入方法依赖的package包/类
/**
* Reconstructs the superfamily identifier from the given {@link Path}.
*
* @param topSuperfamily The {@link Path} of the superfamily.
* @return The superfamily identifier.
*/
private static String getSuperfamilyIdentifier(Path topSuperfamily) {
return topSuperfamily.getParent().getParent().getParent() +
"_" +
topSuperfamily.getParent().getParent().getFileName() +
"_" +
topSuperfamily.getParent().getFileName() +
"_" +
topSuperfamily.getFileName();
}
示例15: test
import java.nio.file.Path; //导入方法依赖的package包/类
public void test() throws IOException {
String moduleName = "native_library";
Path classesDir = helper.generateModuleCompiledClasses(
helper.getJmodSrcDir(), helper.getJmodClassesDir(), moduleName);
Path libsDir = helper.getJmodDir().resolve("lib").resolve(moduleName);
Path configDir = helper.getJmodDir().resolve("config").resolve(moduleName);
Path cmdDir = helper.getJmodDir().resolve("cmd").resolve(moduleName);
Path config = writeFile(configDir.resolve("config.txt"), "AAAA\nBBBB");
Path cmd = writeFile(cmdDir.resolve("ls.sh"), "ls");
Path lib = writeFile(libsDir.resolve("native.so"), "native library");
JImageGenerator.getJModTask()
.addClassPath(classesDir)
.addNativeLibraries(libsDir)
.addCmds(cmdDir)
.addConfig(configDir)
.jmod(helper.createNewJmodFile(moduleName))
.create()
.assertSuccess();
String[] expectedFiles = new String[] {
"bin" + File.separator + cmd.getFileName(),
"conf" + File.separator + config.getFileName(),
"lib" + File.separator + lib.getFileName()
};
Path image = JImageGenerator.getJLinkTask()
.modulePath(helper.defaultModulePath())
.addMods(moduleName)
.output(helper.createNewImageDir(moduleName))
.call().assertSuccess();
helper.checkImage(image, moduleName, null, null, expectedFiles);
}