com.google.common.io.Files.getFileExtension()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(10.6k)|赞(0)|评价(0)|浏览(362)

本文整理了Java中com.google.common.io.Files.getFileExtension()方法的一些代码示例,展示了Files.getFileExtension()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Files.getFileExtension()方法的具体详情如下:
包路径:com.google.common.io.Files
类名称:Files
方法名:getFileExtension

Files.getFileExtension介绍

[英]Returns the file extension for the given file name, or the empty string if the file has no extension. The result does not include the ' .'.

Note: This method simply returns everything after the last ' .' in the file's name as determined by File#getName. It does not account for any filesystem-specific behavior that the File API does not already account for. For example, on NTFS it will report "txt" as the extension for the filename "foo.exe:.txt" even though NTFS will drop the ":.txt" part of the name when the file is actually created on the filesystem due to NTFS's Alternate Data Streams.
[中]返回给定文件名的{$0$},如果文件没有扩展名,则返回空字符串。结果不包括“.”。
注意:此方法仅返回最后一个“.”之后的所有内容由文件#getName确定的文件名。它不考虑文件API尚未考虑的任何特定于文件系统的行为。例如,在NTFS上,它将报告“txt”作为文件名“foo.exe:.txt”的扩展名,即使由于NTFS的Alternate Data Streams而在文件系统上实际创建文件时,NTFS将删除名称的“:.txt”部分。

代码示例

代码示例来源:origin: springside/springside4

/**
   * 获取文件名的扩展名部分(不包含.)
   * 
   * @see {@link com.google.common.io.Files#getFileExtension}
   */
  public static String getFileExtension(String fullName) {
    return com.google.common.io.Files.getFileExtension(fullName);
  }
}

代码示例来源:origin: springside/springside4

/**
 * 获取文件名的扩展名部分(不包含.)
 * 
 * @see {@link com.google.common.io.Files#getFileExtension}
 */
public static String getFileExtension(File file) {
  return com.google.common.io.Files.getFileExtension(file.getName());
}

代码示例来源:origin: apache/incubator-gobblin

@Override
 public boolean accept(Path path) {
  return LogCopier.this.logFileExtensions.contains(Files.getFileExtension(path.getName()));
 }
});

代码示例来源:origin: apache/incubator-druid

@Override
public String getName()
{
 final String ext = Files.getFileExtension(path);
 return Files.getNameWithoutExtension(path) + (Strings.isNullOrEmpty(ext) ? "" : ("." + ext));
}

代码示例来源:origin: apache/incubator-gobblin

@Override
public boolean accept(Path path) {
 String fileName = path.getName();
 String extension = Files.getFileExtension(fileName);
 return isStateMetaFile(fileName) || extension.equalsIgnoreCase("jst") || extension.equalsIgnoreCase("tst");
}

代码示例来源:origin: apache/incubator-gobblin

/**
 * Construct a new file path by appending record count to the filename of the given file path, separated by SEPARATOR.
 * For example, given path: "/a/b/c/file.avro" and record count: 123,
 * the new path returned will be: "/a/b/c/file.123.avro"
 */
public static String constructFilePath(String oldFilePath, long recordCounts) {
 return new Path(new Path(oldFilePath).getParent(), Files.getNameWithoutExtension(oldFilePath).toString() + SEPARATOR
   + recordCounts + SEPARATOR + Files.getFileExtension(oldFilePath)).toString();
}

代码示例来源:origin: apache/incubator-gobblin

/**
  * check whether the file has the proper naming and hierarchy
  * @param configFilePath the relative path from the repo root
  * @return false if the file does not conform
  */
private boolean checkConfigFilePath(String configFilePath) {
 // The config needs to stored at configDir/flowGroup/flowName.(pull|job|json|conf)
 Path configFile = new Path(configFilePath);
 String fileExtension = Files.getFileExtension(configFile.getName());
 if (configFile.depth() != CONFIG_FILE_DEPTH
   || !configFile.getParent().getParent().getName().equals(folderName)
   || !(PullFileLoader.DEFAULT_JAVA_PROPS_PULL_FILE_EXTENSIONS.contains(fileExtension)
   || PullFileLoader.DEFAULT_JAVA_PROPS_PULL_FILE_EXTENSIONS.contains(fileExtension))) {
  log.warn("Changed file does not conform to directory structure and file name format, skipping: "
    + configFilePath);
  return false;
 }
 return true;
}

代码示例来源:origin: google/guava

public void testGetFileExtension() {
 assertEquals("txt", Files.getFileExtension(".txt"));
 assertEquals("txt", Files.getFileExtension("blah.txt"));
 assertEquals("txt", Files.getFileExtension("blah..txt"));
 assertEquals("txt", Files.getFileExtension(".blah.txt"));
 assertEquals("txt", Files.getFileExtension("/tmp/blah.txt"));
 assertEquals("gz", Files.getFileExtension("blah.tar.gz"));
 assertEquals("", Files.getFileExtension("/"));
 assertEquals("", Files.getFileExtension("."));
 assertEquals("", Files.getFileExtension(".."));
 assertEquals("", Files.getFileExtension("..."));
 assertEquals("", Files.getFileExtension("blah"));
 assertEquals("", Files.getFileExtension("blah."));
 assertEquals("", Files.getFileExtension(".blah."));
 assertEquals("", Files.getFileExtension("/foo.bar/blah"));
 assertEquals("", Files.getFileExtension("/foo/.bar/blah"));
}

代码示例来源:origin: apache/incubator-gobblin

/**
 * check whether the file has the proper naming and hierarchy
 * @param file the relative path from the repo root
 * @return false if the file does not conform
 */
private boolean checkFilePath(String file, int depth) {
 // The file is either a node file or an edge file and needs to be stored at either:
 // flowGraphDir/nodeName/nodeName.properties (if it is a node file), or
 // flowGraphDir/nodeName/nodeName/edgeName.properties (if it is an edge file)
 Path filePath = new Path(file);
 String fileExtension = Files.getFileExtension(filePath.getName());
 if (filePath.depth() != depth || !checkFileLevelRelativeToRoot(filePath, depth)
   || !(this.javaPropsExtensions.contains(fileExtension))) {
  log.warn("Changed file does not conform to directory structure and file name format, skipping: "
    + filePath);
  return false;
 }
 return true;
}

代码示例来源:origin: dreamhead/moco

public MediaType getContentType() {
  Optional<MediaType> optionalType = toContentType(Files.getFileExtension(filename));
  Optional<Charset> targetCharset = toCharset(optionalType);
  MediaType type = optionalType.or(DEFAULT_CONTENT_TYPE_WITH_CHARSET);
  if (targetCharset.isPresent() && !type.charset().equals(targetCharset)) {
    return type.withCharset(targetCharset.get());
  }
  return type;
}

代码示例来源:origin: azkaban/azkaban

Files.getFileExtension(localFile.getName()), localFile.getName(), md5, 0, resourceId);
} catch (final SQLException e) {
 final String msg = String

代码示例来源:origin: Sable/soot

private List<File> allSourcesFromFile(File dexSource) throws IOException {
 if (dexSource.isDirectory()) {
  List<File> dexFiles = getAllDexFilesInDirectory(dexSource);
  if (dexFiles.size() > 1 && !Options.v().process_multiple_dex()) {
   File file = dexFiles.get(0);
   logger.warn("Multiple dex files detected, only processing '" + file.getCanonicalPath()
     + "'. Use '-process-multiple-dex' option to process them all.");
   return Collections.singletonList(file);
  } else {
   return dexFiles;
  }
 } else {
  String ext = com.google.common.io.Files.getFileExtension(dexSource.getName()).toLowerCase();
  if ((ext.equals("jar") || ext.equals("zip")) && !Options.v().search_dex_in_archives()) {
   return Collections.EMPTY_LIST;
  } else {
   return Collections.singletonList(dexSource);
  }
 }
}

代码示例来源:origin: simpligility/android-maven-plugin

tmp.mkdirs();
String jarName = String.format( "%s-%d.%s",
  Files.getNameWithoutExtension( in.getName() ), num, Files.getFileExtension( in.getName() ) );
File out = new File( tmp, jarName );

代码示例来源:origin: CalebFenton/simplify

outFileName += ".dex";
} else {
  String ext = Files.getFileExtension(fileName);
  if (!ext.isEmpty()) {
    outFileName += "." + ext;

代码示例来源:origin: lenskit/lenskit

public static void main(String[] args) throws IOException, ScriptException {
    File scriptFile = new File(args[0]);
    ScriptEngineManager sem = new ScriptEngineManager();
    String ext = Files.getFileExtension(scriptFile.getName());
    ScriptEngine engine = sem.getEngineByExtension(ext);
    engine.put("cmdArgs", Arrays.asList(args).subList(1, args.length));
    try (Reader reader = Files.newReader(scriptFile, Charsets.UTF_8)) {
      engine.eval(reader);
    }
  }
}

代码示例来源:origin: google/bundletool

private static Optional<FileReference.Type> getFileType(String resFilePath) {
 switch (Files.getFileExtension(resFilePath).toLowerCase()) {
  case "png":
   return Optional.of(FileReference.Type.PNG);
  case "xml":
   return Optional.of(FileReference.Type.PROTO_XML);
  default:
   return Optional.empty();
 }
}

代码示例来源:origin: google/bundletool

private Path writeTestDataToFile(String testDataPath) throws Exception {
 checkArgument(testDataPath.contains("."));
 String extension = com.google.common.io.Files.getFileExtension(testDataPath);
 return Files.write(
   Files.createTempFile(tmpDir, getClass().getSimpleName(), "." + extension),
   TestData.readBytes(testDataPath));
}

代码示例来源:origin: HubSpot/Singularity

private List<LogrotateAdditionalFile> getAllExtraFiles() {
 final List<SingularityExecutorLogrotateAdditionalFile> original = configuration.getLogrotateAdditionalFiles();
 final List<LogrotateAdditionalFile> transformed = new ArrayList<>(original.size());
 for (SingularityExecutorLogrotateAdditionalFile additionalFile : original) {
  String dateformat;
  if (additionalFile.getDateformat().isPresent()) {
   dateformat = additionalFile.getDateformat().get().startsWith("-") ? additionalFile.getDateformat().get().substring(1) : additionalFile.getDateformat().get();
  } else {
   dateformat = configuration.getLogrotateExtrasDateformat().startsWith("-") ? configuration.getLogrotateExtrasDateformat().substring(1) : configuration.getLogrotateExtrasDateformat();
  }
  transformed.add(
    new LogrotateAdditionalFile(
      taskDefinition.getTaskDirectoryPath().resolve(additionalFile.getFilename()).toString(),
      additionalFile.getExtension().or(Strings.emptyToNull(Files.getFileExtension(additionalFile.getFilename()))),
      dateformat,
      additionalFile.getLogrotateFrequencyOverride()
    ));
 }
 return transformed;
}

代码示例来源:origin: lenskit/lenskit

String ext = Files.getFileExtension(scriptFile.getName());
ScriptEngine seng = sem.getEngineByExtension(ext);
logger.info("running {} with engine {}", scriptFile, seng);

代码示例来源:origin: HubSpot/Singularity

public SingularityExecutorTask buildTask(String taskId, ExecutorDriver driver, TaskInfo taskInfo, Logger log) {
 SingularityTaskExecutorData taskExecutorData = readExecutorData(jsonObjectMapper, taskInfo);
 SingularityExecutorTaskDefinition taskDefinition = new SingularityExecutorTaskDefinition(taskId, taskExecutorData, MesosUtils.getTaskDirectoryPath(taskId).toString(), executorPid,
   taskExecutorData.getServiceLog(), Files.getFileExtension(taskExecutorData.getServiceLog()), taskExecutorData.getServiceFinishedTailLog(), executorConfiguration.getTaskAppDirectory(),
   executorConfiguration.getExecutorBashLog(), executorConfiguration.getLogrotateStateFile(), executorConfiguration.getSignatureVerifyOut());
 jsonObjectFileHelper.writeObject(taskDefinition, executorConfiguration.getTaskDefinitionPath(taskId), log);
 return new SingularityExecutorTask(driver, executorUtils, baseConfiguration, executorConfiguration, taskDefinition, executorPid, artifactFetcher, taskInfo, templateManager, log, jsonObjectFileHelper, dockerUtils, s3Configuration, jsonObjectMapper);
}

相关文章