Java Path Create nio isTempCreatedFile(Path filePath)

Here you can find the source of isTempCreatedFile(Path filePath)

Description

is Temp Created File

License

Open Source License

Declaration

public static boolean isTempCreatedFile(Path filePath) 

Method Source Code

//package com.java2s;
/**//from  ww  w . java  2 s . c o m
 * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 */

import java.nio.file.Files;
import java.nio.file.Path;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main {
    private static final Pattern _tempCreatedFilePattern = Pattern
            .compile("[0-9A-F]{6,8}\\.tmp");

    public static boolean isTempCreatedFile(Path filePath) {
        String fileName = String.valueOf(filePath.getFileName());

        if ((fileName.startsWith("~$") || ((fileName.startsWith("~")
                || fileName.startsWith("ppt") || fileName.startsWith("pub")) && fileName
                .endsWith(".tmp"))) && !Files.isDirectory(filePath)) {

            return true;
        }

        Matcher matcher = _tempCreatedFilePattern.matcher(String
                .valueOf(filePath.getFileName()));

        if (matcher.matches() && !Files.isDirectory(filePath)) {
            return true;
        }

        return false;
    }
}

Related

  1. createZipFileSystem(Path path)
  2. createZipFileSystem(Path zipFile)
  3. createZipFs(Path path)
  4. createZkNodeName(String zkRoot, Path root, Path file)
  5. getOrCreateDir(Path path)
  6. setTimes(FileTime lastModifiedTime, FileTime lastAccessTime, FileTime createTime, Path... files)
  7. toPath(@Nullable String plain)
  8. toPath(String first, String... more)
  9. toPath(String path)