本文整理汇总了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());
}
示例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());
}
示例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);
}
}
示例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();
}
示例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)));
}
示例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();
}
示例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();
}
}
示例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)
);
}
}
示例9: touch
import com.google.common.io.Files; //导入方法依赖的package包/类
/**
* 创建文件或更新时间戳.
*/
public static void touch(String filePath) throws IOException {
Files.touch(getFileByPath(filePath));
}