Example usage for java.nio.file.attribute FileTime toMillis

List of usage examples for java.nio.file.attribute FileTime toMillis

Introduction

In this page you can find the example usage for java.nio.file.attribute FileTime toMillis.

Prototype

public long toMillis() 

Source Link

Document

Returns the value in milliseconds.

Usage

From source file:Main.java

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

    long time = System.currentTimeMillis();
    FileTime fileTime = FileTime.fromMillis(time);
    System.out.println(fileTime.toMillis());

}

From source file:net.mozq.picto.core.ProcessCore.java

private static Date toDate(FileTime fileTime) {
    if (fileTime == null) {
        return null;
    }//  w w w . j a v a2  s.  c  o m
    return new Date(fileTime.toMillis());
}

From source file:com.liferay.sync.engine.util.FileUtilTest.java

@Test
public void testSetModifiedTime() throws Exception {
    Path filePath = Files.createTempFile("test", "test");

    long modifiedTime = System.currentTimeMillis();

    FileUtil.setModifiedTime(filePath, modifiedTime);

    FileTime modifiedFileTime = Files.getLastModifiedTime(filePath);

    Assert.assertEquals(modifiedTime / 1000, modifiedFileTime.toMillis() / 1000);
}

From source file:com.ignorelist.kassandra.steam.scraper.FileCache.java

private long getModified(String key) throws IOException {
    FileTime lastModifiedTime = Files.getLastModifiedTime(buildCacheFile(key), LinkOption.NOFOLLOW_LINKS);
    return lastModifiedTime.toMillis();
}

From source file:com.codealot.textstore.FileStore.java

@Override
public Date getStoreDate(final String id) throws IOException {
    checkId(id);//w w  w.  ja  v a 2s  . co  m
    final Path textPath = idToPath(id);
    final FileTime time = Files.getLastModifiedTime(textPath);
    return new Date(time.toMillis());
}

From source file:desktopsearch.WatchDir.java

private void UpdateDB(String Event, Path FullLocation) throws SQLException, IOException {

    File file = new File(FullLocation.toString());
    String path = file.getParent();
    String Name = file.getName();

    if (Name.contains("'")) {
        Name = Name.replace("'", "''");
    }/*from  w w w  .j  a  va 2s . c  o m*/
    if (path.contains("'")) {
        path = path.replace("'", "''");
    }

    if (Event.equals("ENTRY_CREATE") && file.exists()) {
        FileTime LastModifiedTime = Files.getLastModifiedTime(FullLocation);
        Calendar calendar = Calendar.getInstance();
        calendar.setTimeInMillis(LastModifiedTime.toMillis());
        String Query;
        if (file.isFile()) {
            String Type = FilenameUtils.getExtension(FullLocation.toString());
            if (Type.endsWith("~") || Type.equals("")) {
                Type = "Text";
            }
            Query = "INSERT INTO FileInfo VALUES('" + path + "','" + Name + "','" + Type + "','"
                    + calendar.getTime() + "'," + (file.length() / 1024) + ");";
        } else if (!Files.isSymbolicLink(FullLocation)) {
            long size = FileUtils.sizeOfDirectory(file);
            Query = "INSERT INTO FileInfo VALUES('" + path + "','" + Name + "','FOLDER','" + calendar.getTime()
                    + "'," + size + ");";
        } else {
            Query = "INSERT INTO FileInfo VALUES('" + path + "','" + Name + "','LINK','" + calendar.getTime()
                    + "',0);";
        }
        statement.executeUpdate(Query);

    } else if (Event.equals("ENTRY_MODIFY")) {
        System.out.println(path + "/" + Name);
        FileTime LastModifiedTime = Files.getLastModifiedTime(FullLocation);
        Calendar calendar = Calendar.getInstance();
        calendar.setTimeInMillis(LastModifiedTime.toMillis());
        String Query = "UPDATE FileInfo SET LastModified='" + calendar.getTime() + "' WHERE FileLocation='"
                + path + "' and FileName='" + Name + "';";
        System.out.println(Query);
        statement.executeUpdate(Query);

    } else if (Event.equals("ENTRY_DELETE")) {

        String Query = "DELETE FROM FileInfo WHERE FileLocation = '" + path + "' AND FileName = '" + Name
                + "';";
        statement.executeUpdate(Query);

    }
    connection.commit();

}

From source file:at.beris.virtualfile.client.sftp.SftpClient.java

@Override
public void setLastModifiedTime(String path, FileTime time) throws IOException {
    LOGGER.debug("setLastModifiedTime (path : {}, time: {})", path, time);
    try {//from www  . jav  a  2 s . co m
        checkChannel();
        sftpChannel.setMtime(path, (int) (time.toMillis() / 1000));
    } catch (SftpException e) {
        handleSftpException(e);
    }
}

From source file:com.att.aro.datacollector.ioscollector.utilities.AppSigningHelper.java

private void verifyFileUpdated(String filename, FileTime before, FileTime after) throws IOSAppException {
    if (after.toMillis() <= before.toMillis()) {
        throw new IOSAppException(ErrorCodeRegistry.getFileUpdateError(filename));
    }//w w  w .  java2  s .  c  om
}

From source file:desktopsearch.ExploreFiles.java

private void RecursivelyExplore(File Directory) {

    String[] List = Directory.list();
    String AbsPath = Directory.getAbsolutePath() + "/";
    String SQLQuery = null;// w ww .j  av a 2s.c  o  m
    ArrayList<String> DirList = new ArrayList();

    String FormattedPath = Directory.getPath();
    if (FormattedPath.contains("'")) {
        FormattedPath = FormattedPath.replace("'", "''");
    }

    try {
        for (int i = 0; i < List.length; i++) {
            File path = new File(AbsPath + List[i]);
            Path Location = Paths.get(path.getAbsolutePath());

            FileTime LastModifiedTime = Files.getLastModifiedTime(Location);
            Calendar calendar = Calendar.getInstance();
            calendar.setTimeInMillis(LastModifiedTime.toMillis());

            try {

                if (path.isFile()) {

                    String Type = FilenameUtils.getExtension(Directory.getPath() + "/" + List[i]);

                    if (Type.endsWith("~") || Type.equals("")) {
                        Type = "Text";
                    }

                    if (List[i].contains("'")) {
                        List[i] = List[i].replace("'", "''");
                        System.out.println(List[i]);
                    }

                    SQLQuery = "INSERT INTO FileInfo VALUES('" + Directory.getPath() + "','" + List[i] + "','"
                            + Type + "','" + calendar.getTime() + "'," + (path.length() / 1024) + ");";

                } else {

                    if (List[i].contains("'")) {
                        List[i] = List[i].replace("'", "''");
                        System.out.println(List[i]);
                    }

                    if (!Files.isSymbolicLink(Location)) {
                        long size = FileUtils.sizeOfDirectory(path);
                        SQLQuery = "INSERT INTO FileInfo VALUES('" + Directory.getPath() + "','" + List[i]
                                + "','FOLDER','" + calendar.getTime() + "'," + size + ");";
                    } else {

                        SQLQuery = "INSERT INTO FileInfo VALUES('" + Directory.getPath() + "','" + List[i]
                                + "','LINK','" + calendar.getTime() + "',0);";
                    }

                    DirList.add(List[i]);
                }

                output.println(SQLQuery);
            } catch (Exception exp) {
                exp.printStackTrace();
            }
            ;

        }

        for (int i = 0; i < DirList.size(); i++) {
            File subDir = new File(AbsPath + DirList.get(i));
            Path path = Paths.get(AbsPath + DirList.get(i));
            if (subDir.canRead() && !Files.isSymbolicLink(path)) {
                RecursivelyExplore(subDir);
            }

        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.nridge.connector.fs.con_fs.core.FileCrawler.java

private void processCSVFile(Path aPath, BasicFileAttributes aFileAttributes, String aViewURL)
        throws IOException {
    String docId;/*from   ww w  . j av  a2  s .c  o  m*/
    StopWatch stopWatch;
    Document fsDocument;
    Logger appLogger = mAppMgr.getLogger(this, "processCSVFile");

    appLogger.trace(mAppMgr.LOGMSG_TRACE_ENTER);

    File fsFile = aPath.toFile();
    String pathFileName = aPath.toAbsolutePath().toString();

    appLogger.debug(String.format("Processing CSV File: %s", pathFileName));

    CSVDocument csvDocument = new CSVDocument(mAppMgr, mBag);
    csvDocument.open(pathFileName);

    int row = 1;
    DataBag csvBag = csvDocument.extractNext();
    while (csvBag != null) {
        stopWatch = new StopWatch();
        stopWatch.start();

        docId = csvBag.generateUniqueHash(true);
        appLogger.debug(String.format(" Expanding Row [%d]: %s", row++, docId));

        csvBag.setValueByName("nsd_id", mIdValuePrefix + docId);
        csvBag.setValueByName("nsd_url", fsFile.toURI().toURL().toString());
        csvBag.setValueByName("nsd_url_view", aViewURL);
        csvBag.setValueByName("nsd_url_display", aViewURL);
        csvBag.setValueByName("nsd_file_name", fsFile.getName());
        csvBag.setValueByName("nsd_mime_type", Content.CONTENT_TYPE_TXT_CSV);
        FileTime creationTime = aFileAttributes.creationTime();
        Date cDate = new Date(creationTime.toMillis());
        csvBag.setValueByName("nsd_doc_created_ts", cDate);
        FileTime lastModifiedTime = aFileAttributes.lastModifiedTime();
        Date lmDate = new Date(lastModifiedTime.toMillis());
        csvBag.setValueByName("nsd_doc_modified_ts", lmDate);
        csvBag.setValueByName("nsd_crawl_type", mCrawlQueue.getCrawlType());
        fsDocument = new Document(Constants.FS_DOCUMENT_TYPE, csvBag);
        csvBag.setValueByName("nsd_doc_hash", fsDocument.generateUniqueHash(false));

        saveAddQueueDocument(fsDocument, stopWatch);

        csvBag = csvDocument.extractNext();
    }

    csvDocument.close();

    appLogger.trace(mAppMgr.LOGMSG_TRACE_DEPART);
}