当前位置: 首页>>代码示例>>Java>>正文


Java Files.touch方法代码示例

本文整理汇总了Java中com.google.common.io.Files.touch方法的典型用法代码示例。如果您正苦于以下问题:Java Files.touch方法的具体用法?Java Files.touch怎么用?Java Files.touch使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.google.common.io.Files的用法示例。


在下文中一共展示了Files.touch方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testIncludeEmptyFile

import com.google.common.io.Files; //导入方法依赖的package包/类
@Test
public void testIncludeEmptyFile() throws IOException {
  File f1 = new File(tmpDir, "file1");
  File f2 = new File(tmpDir, "file2");
  Files.write("file1line1\nfile1line2\n", f1, Charsets.UTF_8);
  Files.touch(f2);

  ReliableTaildirEventReader reader = getReader();
  // Expect to read nothing from empty file
  List<String> out = Lists.newArrayList();
  for (TailFile tf : reader.getTailFiles().values()) {
    out.addAll(bodiesAsStrings(reader.readEvents(tf, 5)));
    reader.commit();
  }
  assertEquals(2, out.size());
  assertTrue(out.contains("file1line1"));
  assertTrue(out.contains("file1line2"));
  assertNull(reader.readEvent());
}
 
开发者ID:moueimei,项目名称:flume-release-1.7.0,代码行数:20,代码来源:TestTaildirEventReader.java

示例2: cleanupTest

import com.google.common.io.Files; //导入方法依赖的package包/类
@Test
public void cleanupTest() throws IOException {
    MediaToolConfig config = Mockito.mock(MediaToolConfig.class);
    when(config.getBackupOriginal()).thenReturn(ImmutableMap.of(
            "enabled", "true"
    ));

    CommercialDetect subject = new CommercialDetect();
    subject.configure(config);
    subject.describe();

    Files.touch(new File("/tmp/foo.bar.cut"));
    Assert.assertTrue(new File("/tmp/foo.bar.cut").exists());
    subject.cleanup(testMedia());
    Assert.assertFalse(new File("/tmp/foo.bar.cut").exists());
}
 
开发者ID:KKDad,项目名称:MediaTool,代码行数:17,代码来源:CommercialDetectTest.java

示例3: addToScenarioList

import com.google.common.io.Files; //导入方法依赖的package包/类
private void addToScenarioList(String testId, Set<String> templates, File scenarioList, ResultsStore resultsStore) {
    try {
        long estimatedRuntime = getEstimatedRuntime(testId, resultsStore);
        List<String> args = Lists.newArrayList();
        args.add(testId);
        args.add(String.valueOf(estimatedRuntime));
        args.addAll(templates);
        Files.touch(scenarioList);
        Files.append(Joiner.on(';').join(args) + '\n', scenarioList, Charsets.UTF_8);
    } catch (IOException e) {
        throw new RuntimeException("Could not write to scenario list at " + scenarioList, e);
    }
}
 
开发者ID:lxxlxx888,项目名称:Reer,代码行数:14,代码来源:TestScenarioSelector.java

示例4: onDiffStart

import com.google.common.io.Files; //导入方法依赖的package包/类
@Override
public void onDiffStart(TableAndMetadata source, Optional<TableAndMetadata> replica) {
  try {
    Files.touch(file);
    out = new PrintStream(file, StandardCharsets.UTF_8.name());
  } catch (IOException e) {
    throw new CircusTrainException(e.getMessage(), e);
  }
  out.println("=================================================================================================");
  out.printf("Starting diff on source table 'table=%s, location=%s' and replicate table 'table=%s, location=%s'",
      source.getSourceTable(), source.getSourceLocation(),
      replica.isPresent() ? replica.get().getSourceTable() : "null",
      replica.isPresent() ? replica.get().getSourceLocation() : "null");
  out.println();
}
 
开发者ID:HotelsDotCom,项目名称:circus-train,代码行数:16,代码来源:FileOutputDiffListener.java

示例5: testBehaviorWithEmptyFile

import com.google.common.io.Files; //导入方法依赖的package包/类
@Test
public void testBehaviorWithEmptyFile() throws IOException {
  File f1 = new File(tmpDir.getAbsolutePath() + "/file0");
  Files.touch(f1);

  ReliableSpoolingFileEventReader parser = getParser();

  File f2 = new File(tmpDir.getAbsolutePath() + "/file1");
  Files.write("file1line1\nfile1line2\nfile1line3\nfile1line4\n" +
              "file1line5\nfile1line6\nfile1line7\nfile1line8\n",
              f2, Charsets.UTF_8);

  // Skip over first file, which is empty, and will return an empty event.
  Event event = parser.readEvent();
  assertEquals(0, event.getBody().length);

  List<String> out = bodiesAsStrings(parser.readEvents(8));

  parser.commit();
  assertEquals(8, out.size());

  assertTrue(out.contains("file1line1"));
  assertTrue(out.contains("file1line2"));
  assertTrue(out.contains("file1line3"));
  assertTrue(out.contains("file1line4"));
  assertTrue(out.contains("file1line5"));
  assertTrue(out.contains("file1line6"));
  assertTrue(out.contains("file1line7"));
  assertTrue(out.contains("file1line8"));

  assertNull(parser.readEvent());

  // Make sure original is deleted
  List<File> outFiles = Lists.newArrayList(tmpDir.listFiles(directoryFilter()));
  assertEquals(2, outFiles.size());
  assertTrue("Outfiles should have file0 & file1: " + outFiles,
      outFiles.contains(new File(tmpDir + "/file0" + completedSuffix)));
  assertTrue("Outfiles should have file0 & file1: " + outFiles,
      outFiles.contains(new File(tmpDir + "/file1" + completedSuffix)));
}
 
开发者ID:moueimei,项目名称:flume-release-1.7.0,代码行数:41,代码来源:TestSpoolingFileLineReader.java

示例6: testEndWithZeroByteFiles

import com.google.common.io.Files; //导入方法依赖的package包/类
@Test
public void testEndWithZeroByteFiles() throws IOException, InterruptedException {
  Context context = new Context();

  File f1 = new File(tmpDir.getAbsolutePath() + "/file1");

  Files.write("file1line1\n", f1, Charsets.UTF_8);

  File f2 = new File(tmpDir.getAbsolutePath() + "/file2");
  File f3 = new File(tmpDir.getAbsolutePath() + "/file3");
  File f4 = new File(tmpDir.getAbsolutePath() + "/file4");

  Files.touch(f2);
  Files.touch(f3);
  Files.touch(f4);

  context.put(SpoolDirectorySourceConfigurationConstants.SPOOL_DIRECTORY,
      tmpDir.getAbsolutePath());
  Configurables.configure(source, context);
  source.start();

  // Need better way to ensure all files were processed.
  Thread.sleep(5000);

  Assert.assertFalse("Server did not error", source.hasFatalError());
  Assert.assertEquals("Four messages were read",
      4, source.getSourceCounter().getEventAcceptedCount());
  source.stop();
}
 
开发者ID:moueimei,项目名称:flume-release-1.7.0,代码行数:30,代码来源:TestSpoolDirectorySource.java

示例7: persist

import com.google.common.io.Files; //导入方法依赖的package包/类
public Optional<Entry<FullyQualifiedName,File>> persist(File srcDirectory, boolean overwrite) throws IOException {
    File dstFile = fqn.toFile(srcDirectory);
    if (overwrite || !dstFile.exists()) {
        Files.createParentDirs(dstFile);
        Files.touch(dstFile);
        Files.write(content, dstFile, StandardCharsets.UTF_8);
        return Optional.of(Maps.immutableEntry(fqn, dstFile));
    } else {
        return Optional.absent();
    }
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:12,代码来源:GeneratedObject.java

示例8: downloadProductImage

import com.google.common.io.Files; //导入方法依赖的package包/类
@Test
public void downloadProductImage() throws Exception {
  when(productImageSeeker.seekProductImage(anyLong()))
      .thenReturn(Resources.getResource("Large_Scaled_Forest_Lizard.jpg").openStream());

  AtomicBoolean completed = new AtomicBoolean(false);
  AtomicBoolean error = new AtomicBoolean(false);
  File imageFile = File.createTempFile("image", ".jpg");
  imageFile.deleteOnExit();
  Files.touch(imageFile);
  ByteSink byteSink = Files.asByteSink(imageFile, FileWriteMode.APPEND);
  StreamObserver<DataChunk> streamObserver = new StreamObserver<DataChunk>() {
    @Override
    public void onNext(DataChunk dataChunk) {
      try {
        byteSink.write(dataChunk.getData().toByteArray());
      } catch (IOException e) {
        log.error("error on write files", e);
        onError(e);
      }
    }

    @Override
    public void onError(Throwable t) {
      error.compareAndSet(false, true);
    }

    @Override
    public void onCompleted() {
      log.info("write image to {}", imageFile.getAbsoluteFile());
      completed.compareAndSet(false, true);
    }
  };
  stub.downloadProductImage(DownloadProductImageRequest.getDefaultInstance(), streamObserver);

  while (!completed.get() && !error.get()) {
    Thread.sleep(500);
  }

  assertThat(completed.get()).isTrue();
  assertThat(error.get()).isFalse();

  try (InputStream destImageStream = new FileInputStream(imageFile);
       InputStream origImageStream = Resources.getResource("Large_Scaled_Forest_Lizard.jpg").openStream()) {
    assertThat(DigestUtils.md5Hex(destImageStream)).isEqualTo(
        DigestUtils.md5Hex(origImageStream)
    );
  }
}
 
开发者ID:email2liyang,项目名称:grpc-mate,代码行数:50,代码来源:ProductReadServiceTest.java

示例9: touch

import com.google.common.io.Files; //导入方法依赖的package包/类
/**
 * 创建文件或更新时间戳.
 */
public static void touch(String filePath) throws IOException {
	Files.touch(getFileByPath(filePath));
}
 
开发者ID:zhangjunfang,项目名称:util,代码行数:7,代码来源:FileUtil.java


注:本文中的com.google.common.io.Files.touch方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。