/** * 获取文件名的扩展名部分(不包含.) * * @see {@link com.google.common.io.Files#getFileExtension} */ public static String getFileExtension(String fullName) { return com.google.common.io.Files.getFileExtension(fullName); } }
/** * 获取文件名的扩展名部分(不包含.) * * @see {@link com.google.common.io.Files#getFileExtension} */ public static String getFileExtension(File file) { return com.google.common.io.Files.getFileExtension(file.getName()); }
@Override public boolean accept(Path path) { return LogCopier.this.logFileExtensions.contains(Files.getFileExtension(path.getName())); } });
@Override public String getName() { final String ext = Files.getFileExtension(path); return Files.getNameWithoutExtension(path) + (Strings.isNullOrEmpty(ext) ? "" : ("." + ext)); }
@Override public boolean accept(Path path) { String fileName = path.getName(); String extension = Files.getFileExtension(fileName); return isStateMetaFile(fileName) || extension.equalsIgnoreCase("jst") || extension.equalsIgnoreCase("tst"); }
/** * 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(); }
/** * 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; }
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")); }
/** * 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; }
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; }
Files.getFileExtension(localFile.getName()), localFile.getName(), md5, 0, resourceId); } catch (final SQLException e) { final String msg = String
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); } } }
tmp.mkdirs(); String jarName = String.format( "%s-%d.%s", Files.getNameWithoutExtension( in.getName() ), num, Files.getFileExtension( in.getName() ) ); File out = new File( tmp, jarName );
outFileName += ".dex"; } else { String ext = Files.getFileExtension(fileName); if (!ext.isEmpty()) { outFileName += "." + ext;
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); } } }
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(); } }
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)); }
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; }
String ext = Files.getFileExtension(scriptFile.getName()); ScriptEngine seng = sem.getEngineByExtension(ext); logger.info("running {} with engine {}", scriptFile, seng);
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); }