APISonar


com.google.common.io.Files.getFileExtension

> com > google > common > io > Files > getFileExtension
com APIs google APIs common APIs io APIs Files APIs getFileExtension APIs

Example 1
static String getContentType(String fileName) {
    return EXTENSION_TO_CONTENT_TYPE.getOrDefault(
        Files.getFileExtension(fileName), DEFAULT_CONTENT_TYPE);
  }
Example 2
private String getFileName(String originalFilename) {
        return String.format("%s-%s.%s",
            Files.getNameWithoutExtension(originalFilename),
            FILE_DATE_FORMAT.format(new Date()),
            Files.getFileExtension(originalFilename));
    }
Example 3
static InputStream getFileInputStream(File file) throws IOException {
    InputStream is = new FileInputStream(file);
    String name = file.getName();
    if ("gz".equalsIgnoreCase(Files.getFileExtension(name.toLowerCase()))) {
      return new GZIPInputStream(is);
    } else if ("zip".equalsIgnoreCase(Files.getFileExtension(name.toLowerCase()))) {
      return new ZipInputStream(is);
    } else {
      return is;
    }
  }
Example 4
public MediaType getContentType() {
        Optional<MediaType> optionalType = toContentType(Files.getFileExtension(filename));
        Optional<Charset> targetCharset = toCharset(optionalType.orElse(null));

        MediaType type = optionalType.orElse(DEFAULT_CONTENT_TYPE_WITH_CHARSET);
        if (targetCharset.isPresent() && !type.charset().equals(targetCharset)) {
            return type.withCharset(targetCharset.get());
        }

        return type;
    }
Example 5
static String getUniqueContentName(File classpathElement, String contentHash) {
    String fileName = Files.getNameWithoutExtension(classpathElement.getAbsolutePath());
    String fileExtension = Files.getFileExtension(classpathElement.getAbsolutePath());
    if (classpathElement.isDirectory()) {
      return fileName + "-" + contentHash + ".jar";
    } else if (fileExtension.isEmpty()) {
      return fileName + "-" + contentHash;
    }
    return fileName + "-" + contentHash + "." + fileExtension;
  }
Example 6
public String getShortName() {
    Optional<CxxSource.Type> type = CxxSource.Type.fromExtension(
        Files.getFileExtension(input.getFileName().toString()));
    String fileType;
    if (type.isPresent()) {
      fileType = type.get().getLanguage();
    } else {
      fileType = "unknown";
    }
    return fileType + " " + operation.toString().toLowerCase();
  }
Example 7
public static Predicate<File> withExtension(@NonNull final String extension) {
        checkArgument(extension.charAt(0) != '.', "Extension should not start with a dot.");

        return new Predicate<File>() {
            @Override
            public boolean apply(File input) {
                return Files.getFileExtension(input.getName()).equals(extension);
            }
        };
    }
Example 8
public MimeRule getMimeRuleForExtension(String extension) {
    while (!extension.isEmpty()) {
      if (extensions.containsKey(extension)) {
        return extensions.get(extension);
      }
      extension = Files.getFileExtension(extension);
    }
    return null;
  }
Example 9
public void toFile(File file) throws IOException {
    String extension = Files.getFileExtension(file.getCanonicalPath());
    DataWriter<?> dataWriter = registry.getWriterForExtension(extension);
    dataWriter.write(table, new Destination(file));
  }
Example 10
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);
        }
    }
Example 11
private static boolean isPossibleResourceName(String fileOrDirName) {
    if (NON_ASSET_FILENAMES.contains(fileOrDirName.toLowerCase())) {
      return false;
    }
    if (fileOrDirName.charAt(fileOrDirName.length() - 1) == '~') {
      return false;
    }
    if (MiniAapt.IGNORED_FILE_EXTENSIONS.contains(Files.getFileExtension(fileOrDirName))) {
      return false;
    }
    return true;
  }
Example 12
public static boolean isVersionedDataModel(AppleWrapperResourceArg arg) {
    return VERSIONED_CORE_DATA_MODEL_EXTENSION.equals(
        Files.getFileExtension(arg.path.getFileName().toString()));
  }
Example 13
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;
  }
Example 14
public Table file(File file) throws IOException {
    String extension = Files.getFileExtension(file.getCanonicalPath());
    Optional<DataReader<?>> reader = registry.getReaderForExtension(extension);
    if (reader.isPresent()) {
      return reader.get().read(new Source(file));
    }
    throw new IllegalArgumentException("No reader registered for extension " + extension);
  }
Example 15
private static Path getPathInSymlinkTree(
      SourcePathResolver resolver, Path goPackageName, SourcePath ruleOutput) {
    Path output = resolver.getRelativePath(ruleOutput);

    String extension = Files.getFileExtension(output.toString());
    return Paths.get(goPackageName.toString() + (extension.equals("") ? "" : "." + extension));
  }
Example 16
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();
  }
Example 17
public FrameworkType getFrameworkType(Function<SourcePath, Path> resolver) {
    Path fileName = getFileName(resolver);
    Optional<FrameworkType> frameworkType = FrameworkType.fromExtension(
        Files.getFileExtension(fileName.toString()));

    if (!frameworkType.isPresent()) {
      throw new HumanReadableException("Unsupported framework file name: " + fileName);
    }

    return frameworkType.get();
  }
Example 18
public void ctorFileDoesntExistException() throws Exception {
    PowerMockito.when(Files.getFileExtension(anyString()))
      .thenThrow(new IllegalStateException("Boo!"));
    final QueryLimitOverride limits = new QueryLimitOverride(tsdb);
    verify(file, times(1)).exists();
    assertEquals(42, limits.getDefaultByteLimit());
    assertEquals(24, limits.getDefaultDataPointsLimit());
    assertEquals(0, limits.getLimits().size());
    verify(timer, times(1))
      .newTimeout(any(TimerTask.class), anyLong(), any(TimeUnit.class));
  }
Example 19
private static String getCOutputName(String name) {
    String base = Files.getNameWithoutExtension(name);
    String ext = Files.getFileExtension(name);
    Preconditions.checkArgument(OCamlCompilables.SOURCE_EXTENSIONS.contains(ext));
    return base + ".o";
  }
Example 20
protected AssetUri getUri(String moduleId, Path relativePath) {
        if (relativePath.getNameCount() > 1) {
            Path assetPath = relativePath.subpath(0, 1);
            Path filename = relativePath.getFileName();
            String extension = Files.getFileExtension(filename.toString());
            String nameOnly = filename.toString().substring(0, filename.toString().length() - extension.length() - 1);
            AssetType assetType = AssetType.getTypeFor(assetPath.toString(), extension);
            if (assetType != null) {
                return assetType.getUri(moduleId, nameOnly);
            }
        }
        return null;
    }
Example 21
public LocalFileResource create(MultipartFile file) {

        String name = file.getOriginalFilename();
        String extension = Files.getFileExtension(name);
        String id = CommonUtil.randomId().toString();

        LocalFileResource localFileResource = new LocalFileResource(name, id, extension);
        localFileResource.setCreatedAt(ZonedDateTime.now());
        localFileResourceDao.save(localFileResource);
        doSaveFile(file, localFileResource);

        localFileResource.setUrl(buildDownloadUrl(localFileResource));
        return localFileResource;
    }
Example 22
public PBXFileReference(String name, String path, SourceTree sourceTree) {
    super(name, path, sourceTree);

    // this is necessary to prevent O(n^2) behavior in xcode project loading
    String fileType = FileTypes.FILE_EXTENSION_TO_UTI.get(Files.getFileExtension(name));
    if (FileTypes.EXPLICIT_FILE_TYPE_BROKEN_UTIS.contains(fileType)) {
      explicitFileType = Optional.absent();
      lastKnownFileType = Optional.of(fileType);
    } else {
      explicitFileType = Optional.fromNullable(fileType);
      lastKnownFileType = Optional.absent();
    }
  }
Example 23
private ClasspathTraverser createTraversalAdapter(File path) {
    String extension = Files.getFileExtension(path.getName());
    if (extension.equalsIgnoreCase("jar") || extension.equalsIgnoreCase("zip")) {
      return new ZipFileTraversalAdapter(path);
    } else if (path.isDirectory()) {
      return new DirectoryTraversalAdapter(path);
    } else if (path.isFile()) {
      return new FileTraversalAdapter(path);
    } else {
      throw new IllegalArgumentException("Unsupported classpath traversal input: " + path);
    }
  }
Example 24
public BuildRule createBuildRule(
      BuildRuleCreationContext context,
      BuildTarget buildTarget,
      BuildRuleParams params,
      AppleWrapperResourceArg args) {
    String extension = Files.getFileExtension(args.getPath().getFileName().toString());
    Preconditions.checkArgument(
        CORE_DATA_MODEL_EXTENSION.equals(extension)
            || VERSIONED_CORE_DATA_MODEL_EXTENSION.equals(extension));

    return new NoopBuildRuleWithDeclaredAndExtraDeps(
        buildTarget, context.getProjectFilesystem(), params);
  }
Example 25
private static String getMLBytecodeOutputName(String name) {
    String base = Files.getNameWithoutExtension(name);
    String ext = Files.getFileExtension(name);
    Preconditions.checkArgument(OcamlCompilables.SOURCE_EXTENSIONS.contains(ext));
    String dotExt = "." + ext;
    if (dotExt.equals(OcamlCompilables.OCAML_ML) || dotExt.equals(OcamlCompilables.OCAML_RE)) {
      return base + OcamlCompilables.OCAML_CMO;
    } else if (dotExt.equals(OcamlCompilables.OCAML_MLI)
        || dotExt.equals(OcamlCompilables.OCAML_REI)) {
      return base + OcamlCompilables.OCAML_CMI;
    } else {
      Preconditions.checkState(false, "Unexpected extension: " + ext);
      return base;
    }
  }