Java Code Examples for org.openide.filesystems.FileObject#lastModified()

The following examples show how to use org.openide.filesystems.FileObject#lastModified() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FolderComparator.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * Sort folders alphabetically first. Then files, newest to oldest.
 */
private static int compareLastModified(Object o1, Object o2) {
    boolean f1 = findFileObject(o1).isFolder();
    boolean f2 = findFileObject(o2).isFolder();

    if (f1 != f2) {
        return f1 ? -1 : 1;
    }

    FileObject fo1 = findFileObject(o1);
    FileObject fo2 = findFileObject(o2);
    Date d1 = fo1.lastModified();
    Date d2 = fo2.lastModified();
    if (d1.after(d2)) {
        return -1;
    } else if (d2.after(d1)) {
        return 1;
    } else {
        return fo1.getNameExt().compareTo(fo2.getNameExt());
    }
}
 
Example 2
Source File: TestUtilTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void testCreateFileFromContent() throws Exception {
    URL content = TestUtilTest.class.getResource("TestUtilTest.class");
    assertNotNull("have TestUtilTest.class", content);
    int length = content.openConnection().getContentLength();
    assertTrue("have some length", length > 0);
    FileObject scratch = TestUtil.makeScratchDir(this);
    assertTrue("scratch is a dir", scratch.isFolder());
    assertEquals("scratch is empty", 0, scratch.getChildren().length);
    FileObject a = TestUtil.createFileFromContent(content, scratch, "d/a");
    assertTrue("a is a file", a.isData());
    assertEquals("right path", "d/a", FileUtil.getRelativePath(scratch, a));
    assertEquals("right length", length, (int)a.getSize());
    FileObject b = TestUtil.createFileFromContent(null, scratch, "d2/b");
    assertTrue("b is a file", b.isData());
    assertEquals("right path", "d2/b", FileUtil.getRelativePath(scratch, b));
    assertEquals("b is empty", 0, (int)b.getSize());
    Date created = b.lastModified();
    Thread.sleep(1500); // Unix has coarse timestamp marking
    assertEquals("got same b back", b, TestUtil.createFileFromContent(null, scratch, "d2/b"));
    Date modified = b.lastModified();
    assertTrue("touched and changed timestamp", modified.after(created));
}
 
Example 3
Source File: StartTomcat.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private boolean isJavaOptsEscaped() {
    if (Utilities.isUnix()) {
        return false;
    }

    FileObject start = FileUtil.toFileObject(FileUtil.normalizeFile(getStartupScript()));
    if (start == null) {
        return false;
    }

    synchronized (this) {
        if (lastCheckedStart != null && !start.lastModified().after(lastCheckedStart)) {
            return javaOptsEscaped;
        }

        javaOptsEscaped = false;
        lastCheckedStart = start.lastModified();
        try {
            for (String line : start.asLines("UTF-8")) { // NOI18N
                if (WINDOWS_ESCAPED_JAVA_OPTS.matcher(line).matches()) {
                    javaOptsEscaped = true;
                    break;
                }
            }
        } catch (IOException ex) {
            LOGGER.log(Level.INFO, null, ex);
        }

        return javaOptsEscaped;
    }
}