Example usage for java.nio.file.attribute BasicFileAttributes isOther

List of usage examples for java.nio.file.attribute BasicFileAttributes isOther

Introduction

In this page you can find the example usage for java.nio.file.attribute BasicFileAttributes isOther.

Prototype

boolean isOther();

Source Link

Document

Tells whether the file is something other than a regular file, directory, or symbolic link.

Usage

From source file:Main.java

public static void main(String[] args) throws Exception {

    BasicFileAttributes attr = null;
    Path path = Paths.get("C:/tutorial/Java/JavaFX", "Topic.txt");

    attr = Files.readAttributes(path, BasicFileAttributes.class);

    System.out.println("Is other ? " + attr.isOther());

}

From source file:Test.java

public static void main(String[] args) throws Exception {
    Path path = FileSystems.getDefault().getPath("/home/docs/users.txt");
    // BasicFileAttributes attributes = Files.readAttributes(path,
    // BasicFileAttributes.class);
    BasicFileAttributeView view = Files.getFileAttributeView(path, BasicFileAttributeView.class);
    BasicFileAttributes attributes = view.readAttributes();

    System.out.println("Creation Time: " + attributes.creationTime());
    System.out.println("Last Accessed Time: " + attributes.lastAccessTime());
    System.out.println("Last Modified Time: " + attributes.lastModifiedTime());
    System.out.println("File Key: " + attributes.fileKey());
    System.out.println("Directory: " + attributes.isDirectory());
    System.out.println("Other Type of File: " + attributes.isOther());
    System.out.println("Regular File: " + attributes.isRegularFile());
    System.out.println("Symbolic File: " + attributes.isSymbolicLink());
    System.out.println("Size: " + attributes.size());
}

From source file:de.tiqsolutions.hdfs.BasicFileAttributeViewImpl.java

Map<String, Object> readAttributes(String attributes) throws IOException {
    BasicFileAttributes attr = readAttributes();
    List<String> attrlist = Arrays.asList(attributes.split(","));
    boolean readall = attrlist.contains("*");
    Map<String, Object> ret = new HashMap<>();
    if (readall || attrlist.contains("fileKey"))
        ret.put("fileKey", attr.fileKey());
    if (readall || attrlist.contains("creationTime"))
        ret.put("creationTime", attr.creationTime());
    if (readall || attrlist.contains("isDirectory"))
        ret.put("isDirectory", attr.isDirectory());
    if (readall || attrlist.contains("isOther"))
        ret.put("isOther", attr.isOther());
    if (readall || attrlist.contains("isRegularFile"))
        ret.put("isRegularFile", attr.isRegularFile());
    if (readall || attrlist.contains("isSymbolicLink"))
        ret.put("isSymbolicLink", attr.isSymbolicLink());
    if (readall || attrlist.contains("lastAccessTime"))
        ret.put("lastAccessTime", attr.lastAccessTime());
    if (readall || attrlist.contains("lastModifiedTime"))
        ret.put("lastModifiedTime", attr.lastModifiedTime());
    if (readall || attrlist.contains("size"))
        ret.put("size", attr.size());
    return ret;//  w w w .  ja  v  a  2s .  c  o m
}

From source file:gobblin.example.simplejson.SimpleJsonSource.java

@Override
public List<WorkUnit> getWorkunits(SourceState state) {
    List<WorkUnit> workUnits = Lists.newArrayList();

    if (!state.contains(ConfigurationKeys.SOURCE_FILEBASED_FILES_TO_PULL)) {
        return workUnits;
    }//from   ww  w  .j a  v  a 2 s .  c o m

    // Create a single snapshot-type extract for all files
    Extract extract = new Extract(state, Extract.TableType.SNAPSHOT_ONLY,
            state.getProp(ConfigurationKeys.EXTRACT_NAMESPACE_NAME_KEY, "ExampleNamespace"), "ExampleTable");

    String filesToPull = state.getProp(ConfigurationKeys.SOURCE_FILEBASED_FILES_TO_PULL);
    File tempFileDir = new File("test_temp/"); // TODO: Delete the dir after completion.
    tempFileDir.mkdir();
    String tempFileDirAbsolute = "";
    try {
        tempFileDirAbsolute = tempFileDir.getCanonicalPath(); // Retrieve absolute path of temp folder
    } catch (IOException e) {
        e.printStackTrace();
    }

    int nameCount = 0;
    int csvCount = 0;
    for (String file : Splitter.on(',').omitEmptyStrings().split(filesToPull)) {
        Iterator it = FileUtils.iterateFiles(new File(file), null, true);
        while (it.hasNext()) {
            try {
                File newFile = (File) it.next();
                String basePath = newFile.getCanonicalPath(); // Retrieve absolute path of source
                Path path = newFile.toPath();

                //call to rest api:, provide with file basePath
                String extension = "";
                System.out.println("basePath is" + basePath);
                int i = basePath.lastIndexOf('.');
                System.out.println("i");
                if (i > 0) {
                    extension = basePath.substring(i + 1);
                }

                String url_file_name = "";
                int j = basePath.lastIndexOf('/');
                if (j > 0) {
                    url_file_name = basePath.substring(j + 1);
                }

                //hand off to rest api
                if (extension.equals("csv")) {
                    System.out.println("CSVCSVCSV");
                    csvCount += 1;
                    System.out.println("CURL________________________________________");
                    //Include basePath, filename, location you want to store file
                    System.out.println(
                            "curl http://localhost:8080" + basePath + "/" + Integer.toString(nameCount));
                    //10.0.2.2 is localhost from vagrant
                    // Insert the nameCount so that it can be joined back later.
                    Process p = Runtime.getRuntime()
                            .exec("curl http://localhost:8080" + basePath + "/" + Integer.toString(nameCount));
                    // String myUrl = "http://localhost:8080/parse" + basePath + "&" + url_file_name + "&" + tempFileDirAbsolute;
                    // System.out.println("------------------------------");
                    // System.out.println(myUrl);
                    // try {
                    //   URL url = new URL(myUrl);
                    //   HttpURLConnection connection = (HttpURLConnection) url.openConnection();
                    //   connection.setRequestMethod("GET");
                    //   connection.connect();
                    // } catch (Exception e) {
                    //   e.printStackTrace();
                    // }

                }
                // Print filename and associated metadata 
                System.out.println(basePath);
                BasicFileAttributes attr = Files.readAttributes(path, BasicFileAttributes.class);
                // System.out.println("  creationTime: " + attr.creationTime());
                // System.out.println("  lastAccessTime: " + attr.lastAccessTime());
                // System.out.println("  lastModifiedTime: " + attr.lastModifiedTime());
                // System.out.println("  isDirectory: " + attr.isDirectory());
                // System.out.println("  isOther: " + attr.isOther());
                // System.out.println("  isRegularFile: " + attr.isRegularFile());
                // System.out.println("  isSymbolicLink: " + attr.isSymbolicLink());
                // System.out.println("  size: " + attr.size()); 
                // System.out.println(" ");

                //creating intermediate JSON
                JSONObject intermediate = new JSONObject();
                intermediate.put("filename", basePath);
                intermediate.put("timestamp", String.valueOf((new Date()).getTime()));
                intermediate.put("namespace", getMacAddress());

                intermediate.put("creationTime", String.valueOf(attr.creationTime()));
                intermediate.put("lastAccessTime", String.valueOf(attr.lastAccessTime()));
                intermediate.put("lastModifiedTime", String.valueOf(attr.lastModifiedTime()));
                intermediate.put("isDirectory", String.valueOf(attr.isDirectory()));
                intermediate.put("isOther", String.valueOf(attr.isOther()));
                intermediate.put("isRegularFile", String.valueOf(attr.isRegularFile()));
                intermediate.put("isSymbolicLink", String.valueOf(attr.isSymbolicLink()));
                intermediate.put("size", attr.size());

                // Create intermediate temp file
                nameCount += 1;
                String intermediateName = "/generated" + String.valueOf(nameCount) + ".json";
                String finalName = tempFileDirAbsolute + intermediateName;
                FileWriter generated = new FileWriter(finalName);
                generated.write(intermediate.toJSONString());
                generated.flush();
                generated.close();

                // Create one work unit for each file to pull
                WorkUnit workUnit = new WorkUnit(state, extract);
                workUnit.setProp(SOURCE_FILE_KEY, finalName);
                workUnits.add(workUnit);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

        // write out number of files found to temp file
        try {
            FileWriter numCsvFiles = new FileWriter(tempFileDirAbsolute + "/numCsvFiles.txt");
            numCsvFiles.write("" + csvCount);
            numCsvFiles.flush();
            numCsvFiles.close();

            FileWriter numFiles = new FileWriter(tempFileDirAbsolute + "/numFiles.txt");
            numFiles.write("" + nameCount);
            numFiles.flush();
            numFiles.close();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }

    return workUnits;
}

From source file:org.tinymediamanager.core.Utils.java

/**
 * this is the TMM variant of isRegularFiles()<br>
 * because deduplication creates windows junction points, we check here if it is<br>
 * not a directory, and either a regular file or "other" one.<br>
 * see http://serverfault.com/a/667220/*from  w ww .  j a  va 2  s. c o m*/
 * 
 * @param file
 * @return
 */
public static boolean isRegularFile(Path file) {
    // see windows impl http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/7u40-b43/sun/nio/fs/WindowsFileAttributes.java#451
    try {
        BasicFileAttributes attr = Files.readAttributes(file, BasicFileAttributes.class);
        return (attr.isRegularFile() || attr.isOther()) && !attr.isDirectory();
    } catch (IOException e) {
        return false;
    }
}

From source file:org.tinymediamanager.core.Utils.java

/**
 * this is the TMM variant of isRegularFiles()<br>
 * because deduplication creates windows junction points, we check here if it is<br>
 * not a directory, and either a regular file or "other" one.<br>
 * see http://serverfault.com/a/667220/*from  w  w  w .  j av  a2  s  .c  om*/
 * 
 * @param attr
 * @return
 */
public static boolean isRegularFile(BasicFileAttributes attr) {
    // see windows impl http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/7u40-b43/sun/nio/fs/WindowsFileAttributes.java#451
    return (attr.isRegularFile() || attr.isOther()) && !attr.isDirectory();
}