本文整理了Java中org.apache.commons.io.FilenameUtils.getBaseName()
方法的一些代码示例,展示了FilenameUtils.getBaseName()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。FilenameUtils.getBaseName()
方法的具体详情如下:
包路径:org.apache.commons.io.FilenameUtils
类名称:FilenameUtils
方法名:getBaseName
[英]Gets the base name, minus the full path and extension, from a full filename.
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.
a/b/c.txt --> c
a.txt --> a
a/b/c --> c
a/b/c/ --> ""
The output will be the same irrespective of the machine that the code is running on.
[中]从完整文件名中获取基名称,减去完整路径和扩展名。
此方法将处理Unix或Windows格式的文件。最后一个正斜杠或反斜杠之后,返回最后一个点之前的文本。
a/b/c.txt --> c
a.txt --> a
a/b/c --> c
a/b/c/ --> ""
无论代码在哪台机器上运行,输出都是相同的。
代码示例来源:origin: jenkinsci/jenkins
static String computeShortName(Manifest manifest, String fileName) {
// use the name captured in the manifest, as often plugins
// depend on the specific short name in its URLs.
String n = manifest.getMainAttributes().getValue("Short-Name");
if(n!=null) return n;
// maven seems to put this automatically, so good fallback to check.
n = manifest.getMainAttributes().getValue("Extension-Name");
if(n!=null) return n;
// otherwise infer from the file name, since older plugins don't have
// this entry.
return getBaseName(fileName);
}
代码示例来源:origin: jenkinsci/jenkins
protected String identifyPluginShortName(File t) {
try {
JarFile j = new JarFile(t);
try {
String name = j.getManifest().getMainAttributes().getValue("Short-Name");
if (name!=null) return name;
} finally {
j.close();
}
} catch (IOException e) {
LOGGER.log(WARNING, "Failed to identify the short name from "+t,e);
}
return FilenameUtils.getBaseName(t.getName()); // fall back to the base name of what's uploaded
}
代码示例来源:origin: kiegroup/optaplanner
public String getInputId() {
return FilenameUtils.getBaseName(inputFile.getPath());
}
}
代码示例来源:origin: kiegroup/optaplanner
@Override
public String getProblemName() {
return FilenameUtils.getBaseName(problemFile.getName());
}
代码示例来源:origin: kiegroup/optaplanner
public String getInputId() {
return FilenameUtils.getBaseName(inputFile.getPath());
}
代码示例来源:origin: kiegroup/optaplanner
@Override
public String getInputId() {
return FilenameUtils.getBaseName(inputFile.getParentFile().getPath());
}
代码示例来源:origin: kiegroup/optaplanner
@Override
public String getInputId() {
return FilenameUtils.getBaseName(inputFile.getParentFile().getPath());
}
代码示例来源:origin: Meituan-Dianping/walle
private void generateChannelApk(final File inputFile, final File outputDir, final String channel) {
final String name = FilenameUtils.getBaseName(inputFile.getName());
final String extension = FilenameUtils.getExtension(inputFile.getName());
final String newName = name + "_" + channel + "." + extension;
final File channelApk = new File(outputDir, newName);
try {
FileUtils.copyFile(inputFile, channelApk);
ChannelWriter.put(channelApk, channel, extraInfo);
} catch (IOException | SignatureNotFoundException e) {
e.printStackTrace();
}
}
}
代码示例来源:origin: Meituan-Dianping/walle
private void generateChannelApk(final File inputFile, final File outputDir, final String channel, final String alias, final Map<String, String> extraInfo) {
final String channelName = alias == null ? channel : alias;
final String name = FilenameUtils.getBaseName(inputFile.getName());
final String extension = FilenameUtils.getExtension(inputFile.getName());
final String newName = name + "_" + channelName + "." + extension;
final File channelApk = new File(outputDir, newName);
try {
FileUtils.copyFile(inputFile, channelApk);
ChannelWriter.put(channelApk, channel, extraInfo);
} catch (IOException | SignatureNotFoundException e) {
e.printStackTrace();
}
}
}
代码示例来源:origin: pmd/pmd
public static String getRuleSetFilename(String rulesetFileName) {
return FilenameUtils.getBaseName(StringUtils.chomp(rulesetFileName));
}
代码示例来源:origin: apache/incubator-gobblin
/**
* Construct filename for a late file. If the file does not exists in the output dir, retain the original name.
* Otherwise, append a LATE_COMPONENT{RandomInteger} to the original file name.
* For example, if file "part1.123.avro" exists in dir "/a/b/", the returned path will be "/a/b/part1.123.late12345.avro".
*/
public Path constructLateFilePath(String originalFilename, FileSystem fs, Path outputDir) throws IOException {
if (!fs.exists(new Path(outputDir, originalFilename))) {
return new Path(outputDir, originalFilename);
}
return constructLateFilePath(FilenameUtils.getBaseName(originalFilename) + LATE_COMPONENT
+ new Random().nextInt(Integer.MAX_VALUE) + SEPARATOR + FilenameUtils.getExtension(originalFilename), fs,
outputDir);
}
代码示例来源:origin: pmd/pmd
/** 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);
}
代码示例来源:origin: uber/NullAway
public static Result run(String inPaths, String pkgName)
throws IOException, ClassHierarchyException, IllegalArgumentException {
String outPath = "";
String firstInPath = inPaths.split(",")[0];
if (firstInPath.endsWith(".jar") || firstInPath.endsWith(".aar")) {
outPath =
FilenameUtils.getFullPath(firstInPath)
+ FilenameUtils.getBaseName(firstInPath)
+ MODEL_JAR_SUFFIX;
} else if (new File(firstInPath).exists()) {
outPath = FilenameUtils.getFullPath(firstInPath) + DEFAULT_ASTUBX_LOCATION;
}
return run(inPaths, pkgName, outPath, DEBUG, VERBOSE);
}
/**
代码示例来源:origin: commons-io/commons-io
@Test
public void testGetBaseName() {
assertEquals(null, FilenameUtils.getBaseName(null));
assertEquals("noseperator", FilenameUtils.getBaseName("noseperator.inthispath"));
assertEquals("c", FilenameUtils.getBaseName("a/b/c.txt"));
assertEquals("c", FilenameUtils.getBaseName("a/b/c"));
assertEquals("", FilenameUtils.getBaseName("a/b/c/"));
assertEquals("c", FilenameUtils.getBaseName("a\\b\\c"));
assertEquals("file.txt", FilenameUtils.getBaseName("file.txt.bak"));
}
代码示例来源:origin: gocd/gocd
@Override
protected void handleFile(File file, int depth, Collection results) {
String fileName = file.getName();
if (!FilenameUtils.getExtension(fileName).equalsIgnoreCase(XML_EXTENSION)) {
return;
}
String xmlContentOfFie = safeReadFileToString(file);
if (xmlContentOfFie == null || !file.canRead()) {
serverHealthService.update(ServerHealthState.warning("Command Repository", "Failed to access command snippet XML file located in Go Server Directory at " + file.getPath() +
". Go does not have sufficient permissions to access it.", HealthStateType.commandRepositoryAccessibilityIssue(), systemEnvironment.getCommandRepoWarningTimeout()));
LOGGER.warn("[Command Repository] Failed to access command snippet XML file located in Go Server Directory at {}. Go does not have sufficient permissions to access it.", file.getAbsolutePath());
return;
}
try {
String relativeFilePath = FileUtil.removeLeadingPath(commandRepositoryBaseDirectory.get(), file.getAbsolutePath());
results.add(commandSnippetXmlParser.parse(xmlContentOfFie, FilenameUtils.getBaseName(fileName), relativeFilePath));
} catch (Exception e) {
LOGGER.warn("Failed loading command snippet from {}", file.getAbsolutePath());
LOGGER.debug(null, e);
}
}
代码示例来源:origin: skylot/jadx
@Override
public void init(RootNode root) {
List<DexNode> dexNodes = root.getDexNodes();
if (dexNodes.isEmpty()) {
return;
}
InputFile firstInputFile = dexNodes.get(0).getDexFile().getInputFile();
String firstInputFileName = firstInputFile.getFile().getAbsolutePath();
String inputPath = FilenameUtils.getFullPathNoEndSeparator(firstInputFileName);
String inputName = FilenameUtils.getBaseName(firstInputFileName);
File deobfMapFile = new File(inputPath, inputName + ".jobf");
JadxArgs args = root.getArgs();
deobfuscator = new Deobfuscator(args, dexNodes, deobfMapFile);
boolean deobfuscationOn = args.isDeobfuscationOn();
if (deobfuscationOn) {
deobfuscator.execute();
}
boolean isCaseSensitive = FileUtils.isCaseSensitiveFS(new File(inputPath)); // args.getOutDir() - not set in gui
checkClasses(root, isCaseSensitive);
}
代码示例来源:origin: commons-io/commons-io
@Test
public void testGetBaseName_with_nullByte() {
try {
assertEquals("file.txt", FilenameUtils.getBaseName("fil\u0000e.txt.bak"));
} catch (final IllegalArgumentException ignore) {
}
}
代码示例来源:origin: kiegroup/optaplanner
@Override
public TspSolution readSolution() throws IOException {
tspSolution = new TspSolution();
tspSolution.setId(0L);
tspSolution.setName(FilenameUtils.getBaseName(inputFile.getName()));
floydSteinbergDithering();
createVisitList();
BigInteger possibleSolutionSize = factorial(tspSolution.getLocationList().size() - 1);
logger.info("TspSolution {} has {} locations with a search space of {}.",
getInputId(),
tspSolution.getLocationList().size(),
getFlooredPossibleSolutionSize(possibleSolutionSize));
return tspSolution;
}
代码示例来源:origin: spring-projects/spring-batch
@BeforeStep
public void createOutputNameFromInput(StepExecution stepExecution) {
ExecutionContext executionContext = stepExecution.getExecutionContext();
String inputName = stepExecution.getStepName().replace(":", "-");
if (executionContext.containsKey(inputKeyName)) {
inputName = executionContext.getString(inputKeyName);
}
if (!executionContext.containsKey(outputKeyName)) {
executionContext.putString(outputKeyName, path + FilenameUtils.getBaseName(inputName)
+ ".csv");
}
}
代码示例来源:origin: geoserver/geoserver
/** Keys for overriding default layer properties */
public static class StyleProperty<T> {
T get(Map<StyleProperty, Object> map, T def) {
return map != null && map.containsKey(this) ? (T) map.get(this) : def;
}
public static StyleProperty<String> FORMAT = new StyleProperty<String>();
public static StyleProperty<Version> FORMAT_VERSION = new StyleProperty<Version>();
public static StyleProperty<LegendInfo> LEGEND_INFO = new StyleProperty<LegendInfo>();
}
内容来源于网络,如有侵权,请联系作者删除!