當前位置: 首頁>>代碼示例>>Java>>正文


Java Files.setLastModifiedTime方法代碼示例

本文整理匯總了Java中java.nio.file.Files.setLastModifiedTime方法的典型用法代碼示例。如果您正苦於以下問題:Java Files.setLastModifiedTime方法的具體用法?Java Files.setLastModifiedTime怎麽用?Java Files.setLastModifiedTime使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.nio.file.Files的用法示例。


在下文中一共展示了Files.setLastModifiedTime方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: flush

import java.nio.file.Files; //導入方法依賴的package包/類
public void flush() {
    if (!needsFlush) {
        return;
    }
    needsFlush = false;
    LOGGER.info("flushing bucket {}", bucketNumber);
    try {
        synchronized (this) {
            final FileChannel openChannel = getOpenChannel();
            if (openChannel.isOpen()) {
                openChannel.force(wantsTimestampUpdate);
                if (!wantsTimestampUpdate) {
                    Files.setLastModifiedTime(filePath, lastModifiedTime);
                } else {
                    lastModifiedTime = FileTime.from(Instant.now());
                }
                wantsTimestampUpdate = false;
            }
        }
    } catch (IOException e) {
        LOGGER.warn("unable to flush file of bucket {}", bucketNumber);
    }
}
 
開發者ID:MineboxOS,項目名稱:minebox,代碼行數:24,代碼來源:SingleFileBucket.java

示例2: download

import java.nio.file.Files; //導入方法依賴的package包/類
public boolean download(String siaPath, Path destination) {
        LOGGER.info("downloading {}", siaPath);
//        final String dest = destination.toAbsolutePath().toString();
        final FileTime lastModified = SiaFileUtil.getFileTime(siaPath);

        final String tempFileName = destination.getFileName().toString() + ".tempdownload";
        Path tempFile = destination.getParent().resolve(tempFileName);
        final HttpResponse<String> downloadResult = siaCommand(SiaCommand.DOWNLOAD, ImmutableMap.of("destination", tempFile.toAbsolutePath().toString()), siaPath);
        final boolean noHosts = checkErrorFragment(downloadResult, NO_HOSTS);
        if (noHosts) {
            LOGGER.warn("unable to download file {} due to NO_HOSTS  ", siaPath);
            return false;
        }
        if (statusGood(downloadResult)) {
            try {
                Files.setLastModifiedTime(tempFile, lastModified);
                Files.move(tempFile, destination, StandardCopyOption.ATOMIC_MOVE);
                Files.setLastModifiedTime(destination, lastModified);
            } catch (IOException e) {
                throw new RuntimeException("unable to do atomic swap of file " + destination);
            }
            return true;
        }
        LOGGER.warn("unable to download siaPath {} for an unexpected reason: {} ", siaPath, downloadResult.getBody());
        return false;
    }
 
開發者ID:MineboxOS,項目名稱:minebox,代碼行數:27,代碼來源:SiaUtil.java

示例3: postVisitDirectory

import java.nio.file.Files; //導入方法依賴的package包/類
@Override public FileVisitResult postVisitDirectory(Path dir, IOException exc) {
    // fix up modification time of directory when done
    if (exc == null) {
        Path newdir = target.resolve(source.relativize(dir));
        try {
            FileTime time = Files.getLastModifiedTime(dir);
            Files.setLastModifiedTime(newdir, time);
        } catch (IOException x) {
            System.err.format("Unable to copy all attributes to: %s: %s%n", newdir, x);
        }
        try {
            if (operation == Operation.CUT) {
                Files.delete(dir);
            }
        } catch (IOException e) {
            System.err.format("Unable to delete directory: %s: %s%n", newdir, e);
        }
    }
    return CONTINUE;
}
 
開發者ID:jalian-systems,項目名稱:marathonv5,代碼行數:21,代碼來源:Copy.java

示例4: touch

import java.nio.file.Files; //導入方法依賴的package包/類
/**
 * Like the unix command of the same name, creates an empty file or updates the last modified
 * timestamp of the existing file at the given path to the current system time.
 */
public static void touch(Path path) throws IOException {
  checkNotNull(path);

  try {
    Files.setLastModifiedTime(path, FileTime.fromMillis(System.currentTimeMillis()));
  } catch (NoSuchFileException e) {
    try {
      Files.createFile(path);
    } catch (FileAlreadyExistsException ignore) {
      // The file didn't exist when we called setLastModifiedTime, but it did when we called
      // createFile, so something else created the file in between. The end result is
      // what we wanted: a new file that probably has its last modified time set to approximately
      // now. Or it could have an arbitrary last modified time set by the creator, but that's no
      // different than if another process set its last modified time to something else after we
      // created it here.
    }
  }
}
 
開發者ID:zugzug90,項目名稱:guava-mock,代碼行數:23,代碼來源:MoreFiles.java

示例5: isWritable

import java.nio.file.Files; //導入方法依賴的package包/類
/**
 * Returns true if the path is writable.
 * Acts just like {@link Files#isWritable(Path)}, except won't
 * falsely return false for paths on SUBST'd drive letters
 * See https://bugs.openjdk.java.net/browse/JDK-8034057
 * Note this will set the file modification time (to its already-set value)
 * to test access.
 */
@SuppressForbidden(reason = "works around https://bugs.openjdk.java.net/browse/JDK-8034057")
public static boolean isWritable(Path path) throws IOException {
    boolean v = Files.isWritable(path);
    if (v || Constants.WINDOWS == false) {
        return v;
    }

    // isWritable returned false on windows, the hack begins!!!!!!
    // resetting the modification time is the least destructive/simplest
    // way to check for both files and directories, and fails early just
    // in getting the current value if file doesn't exist, etc
    try {
        Files.setLastModifiedTime(path, Files.getLastModifiedTime(path));
        return true;
    } catch (Throwable e) {
        return false;
    }
}
 
開發者ID:baidu,項目名稱:Elasticsearch,代碼行數:27,代碼來源:Environment.java

示例6: test

import java.nio.file.Files; //導入方法依賴的package包/類
/**
 * Exercise Files.setLastModifiedTime on the given file
 */
void test(Path path) throws Exception {
    FileTime now = Files.getLastModifiedTime(path);
    FileTime zero = FileTime.fromMillis(0L);

    Path result = Files.setLastModifiedTime(path, zero);
    assertTrue(result == path);
    assertEquals(Files.getLastModifiedTime(path), zero);

    result = Files.setLastModifiedTime(path, now);
    assertTrue(result == path);
    assertEquals(Files.getLastModifiedTime(path), now);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:16,代碼來源:SetLastModifiedTime.java

示例7: download

import java.nio.file.Files; //導入方法依賴的package包/類
/**
 * Download the resource specified by its URI to the target directory using the provided file name.
 */
Path download(URI uri, Path targetDirectory, String targetFileName, Predicate<Path> useTimeStamp) throws IOException {
  URL url = requireNonNull(uri, "uri must not be null").toURL();
  requireNonNull(targetDirectory, "targetDirectory must be null");
  if (requireNonNull(targetFileName, "targetFileName must be null").isEmpty()) {
    throw new IllegalArgumentException("targetFileName must be blank");
  }
  Files.createDirectories(targetDirectory);
  Path targetPath = targetDirectory.resolve(targetFileName);
  URLConnection urlConnection = url.openConnection();
  FileTime urlLastModifiedTime = FileTime.fromMillis(urlConnection.getLastModified());
  if (Files.exists(targetPath)) {
    if (Files.getLastModifiedTime(targetPath).equals(urlLastModifiedTime)) {
      if (Files.size(targetPath) == urlConnection.getContentLengthLong()) {
        if (useTimeStamp.test(targetPath)) {
          log.log(Level.FINE, "download skipped - using `%s`%n", targetPath);
          return targetPath;
        }
      }
    }
    Files.delete(targetPath);
  }
  log.log(Level.FINE, "download `%s` in progress...%n", uri);
  try (InputStream sourceStream = url.openStream(); OutputStream targetStream = Files.newOutputStream(targetPath)) {
    sourceStream.transferTo(targetStream);
  }
  Files.setLastModifiedTime(targetPath, urlLastModifiedTime);
  log.log(Level.CONFIG, "download `%s` completed%n", uri);
  log.info("stored `%s` [timestamp=%s]%n", targetPath, urlLastModifiedTime.toString());
  return targetPath;
}
 
開發者ID:sormuras,項目名稱:bach,代碼行數:34,代碼來源:Bach-06.java

示例8: testTouchTime

import java.nio.file.Files; //導入方法依賴的package包/類
public void testTouchTime() throws IOException {
  Path temp = createTempFile();
  assertTrue(Files.exists(temp));
  Files.setLastModifiedTime(temp, FileTime.fromMillis(0));
  assertEquals(0, Files.getLastModifiedTime(temp).toMillis());
  MoreFiles.touch(temp);
  assertThat(Files.getLastModifiedTime(temp).toMillis()).isNotEqualTo(0);
}
 
開發者ID:zugzug90,項目名稱:guava-mock,代碼行數:9,代碼來源:MoreFilesTest.java

示例9: setTimestamp

import java.nio.file.Files; //導入方法依賴的package包/類
@Override
public void setTimestamp(final Path file, final Long modified) throws BackgroundException {
    try {
        Files.setLastModifiedTime(session.toPath(file), FileTime.from(modified, TimeUnit.MILLISECONDS));
    }
    catch(IOException e) {
        throw new LocalExceptionMappingService().map("Failure to write attributes of {0}", e, file);
    }
}
 
開發者ID:iterate-ch,項目名稱:cyberduck,代碼行數:10,代碼來源:LocalTimestampFeature.java

示例10: setModificationDate

import java.nio.file.Files; //導入方法依賴的package包/類
public void setModificationDate(final long timestamp) throws AccessDeniedException {
    if(timestamp < 0) {
        return;
    }
    try {
        Files.setLastModifiedTime(Paths.get(path), FileTime.fromMillis(timestamp));
    }
    catch(IOException e) {
        throw new LocalAccessDeniedException(String.format("Cannot change timestamp of %s", path), e);
    }
}
 
開發者ID:iterate-ch,項目名稱:cyberduck,代碼行數:12,代碼來源:LocalAttributes.java

示例11: setLastModifiedTime

import java.nio.file.Files; //導入方法依賴的package包/類
/**
 * altera o longtime da última modificação no arquivo
 *
 * @param time data no formato longtime
 */
public static void setLastModifiedTime(File file, long time) {
    try {
        Path path = file.toPath();
        FileTime fileTime = FileTime.fromMillis(time);
        Files.setLastModifiedTime(path, fileTime);
    } catch (IOException ex) {
    }
}
 
開發者ID:limagiran,項目名稱:hearthstone,代碼行數:14,代碼來源:Dir.java

示例12: postVisitDirectory

import java.nio.file.Files; //導入方法依賴的package包/類
@Override
public FileVisitResult postVisitDirectory(Path dir, IOException exc) {
    // fix up modification time of directory when done
    if (exc == null) {
        Path newdir = target.resolve(source.relativize(dir));            
        try {
            FileTime time = Files.getLastModifiedTime(dir);
            Files.setLastModifiedTime(newdir, time);
        } catch (IOException x) {
            LOGGER.log(Level.WARNING, "Unable to copy all attributes to: " + newdir, x);
        }
    }
    return CONTINUE;
}
 
開發者ID:chipKIT32,項目名稱:chipKIT-importer,代碼行數:15,代碼來源:CopyingFileVisitor.java

示例13: updateTimeStamp

import java.nio.file.Files; //導入方法依賴的package包/類
private void updateTimeStamp() throws IOException {
    long remoteTimestamp = connection.getLastModified();
    if (remoteTimestamp != 0) {
        Files.setLastModifiedTime(dest, FileTime.fromMillis(remoteTimestamp));
    }
}
 
開發者ID:baidu,項目名稱:Elasticsearch,代碼行數:7,代碼來源:HttpDownloadHelper.java

示例14: testOneModule

import java.nio.file.Files; //導入方法依賴的package包/類
@Test
public void testOneModule(Path base) throws Exception {
    Path src = base.resolve("src");
    Path m1 = src.resolve("m1x");
    Path build = base.resolve("build");
    Files.createDirectories(build);

    tb.writeJavaFiles(m1,
            "module m1x {}",
            "package test; public class Test {}");

    new JavacTask(tb)
            .options("-m", "m1x", "--module-source-path", src.toString(), "-d", build.toString())
            .run(Task.Expect.SUCCESS)
            .writeAll();

    Path moduleInfoClass = build.resolve("m1x/module-info.class");
    Path testTestClass = build.resolve("m1x/test/Test.class");

    FileTime moduleInfoTimeStamp = Files.getLastModifiedTime(moduleInfoClass);
    FileTime testTestTimeStamp = Files.getLastModifiedTime(testTestClass);

    Path moduleInfo = m1.resolve("module-info.java");
    if (moduleInfoTimeStamp.compareTo(Files.getLastModifiedTime(moduleInfo)) < 0) {
        throw new AssertionError("Classfiles too old!");
    }

    Path testTest = m1.resolve("test/Test.java");
    if (testTestTimeStamp.compareTo(Files.getLastModifiedTime(testTest)) < 0) {
        throw new AssertionError("Classfiles too old!");
    }

    Thread.sleep(2000); //timestamps

    new JavacTask(tb)
            .options("-m", "m1x", "--module-source-path", src.toString(), "-d", build.toString())
            .run(Task.Expect.SUCCESS)
            .writeAll();

    if (!moduleInfoTimeStamp.equals(Files.getLastModifiedTime(moduleInfoClass))) {
        throw new AssertionError("Classfile update!");
    }

    if (!testTestTimeStamp.equals(Files.getLastModifiedTime(testTestClass))) {
        throw new AssertionError("Classfile update!");
    }

    Thread.sleep(2000); //timestamps

    Files.setLastModifiedTime(testTest, FileTime.fromMillis(System.currentTimeMillis()));

    new JavacTask(tb)
            .options("-m", "m1x", "--module-source-path", src.toString(), "-d", build.toString())
            .run(Task.Expect.SUCCESS)
            .writeAll();

    if (!moduleInfoTimeStamp.equals(Files.getLastModifiedTime(moduleInfoClass))) {
        throw new AssertionError("Classfile update!");
    }

    if (Files.getLastModifiedTime(testTestClass).compareTo(Files.getLastModifiedTime(testTest)) < 0) {
        throw new AssertionError("Classfiles too old!");
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:65,代碼來源:MOptionTest.java

示例15: setLastModified

import java.nio.file.Files; //導入方法依賴的package包/類
private static void setLastModified(String fileName, long newTime) throws IOException {
    Path path = Paths.get(fileName);
    FileTime fileTime = FileTime.fromMillis(newTime);
    Files.setLastModifiedTime(path, fileTime);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:6,代碼來源:LingeredApp.java


注:本文中的java.nio.file.Files.setLastModifiedTime方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。