本文整理汇总了Java中com.googlecode.totallylazy.Files类的典型用法代码示例。如果您正苦于以下问题:Java Files类的具体用法?Java Files怎么用?Java Files使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Files类属于com.googlecode.totallylazy包,在下文中一共展示了Files类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: canZipAndUnzip
import com.googlecode.totallylazy.Files; //导入依赖的package包/类
@Test
public void canZipAndUnzip() throws Exception {
File playground = emptyVMDirectory("totallylazy");
File a = file(playground, "a.txt");
File b = file(playground, "folder/b.txt");
File zipFile = temporaryFile();
Zip.zip(playground, zipFile);
Files.deleteFiles(playground);
assertThat(a.exists(), is(false));
assertThat(b.exists(), is(false));
Zip.unzip(zipFile, playground);
assertThat(a.exists(), is(true));
assertThat(b.exists(), is(true));
Files.deleteFiles(playground);
zipFile.delete();
}
示例2: preservesModifiedDate
import com.googlecode.totallylazy.Files; //导入依赖的package包/类
@Test
public void preservesModifiedDate() throws Exception {
File playground = emptyVMDirectory("totallylazy");
File a = file(playground, "a.txt");
Date date = date(2001, 1, 10);
a.setLastModified(date.getTime());
File zipFile = temporaryFile();
Zip.zip(playground, zipFile);
Files.deleteFiles(playground);
Zip.unzip(zipFile, playground);
assertThat(a.exists(), is(true));
assertThat(new Date(a.lastModified()), is(date));
Files.deleteFiles(playground);
zipFile.delete();
}
示例3: snap
import com.googlecode.totallylazy.Files; //导入依赖的package包/类
@POST
@Hidden
@Path("snap")
@Produces(MediaType.APPLICATION_JSON)
public Response snap(@FormParam("id") String id) {
Option<WebConsoleClientHandler> clientHandler = agent.client(id);
if (!clientHandler.isEmpty()) {
String snapId = UUID.randomUUID().toString();
Files.write(clientHandler.get().history().toString("\n").getBytes(), snapFile(snapId));
return ok()
.entity(emptyMap(String.class, Object.class)
.insert("snap", snapId)
.insert("uri", snapUri(snapId).toString())
);
} else {
return response(BAD_REQUEST);
}
}
示例4: complete
import com.googlecode.totallylazy.Files; //导入依赖的package包/类
@Override
public void complete(File yatspecOutputDir, Result result) throws Exception {
final File output = outputFile(yatspecOutputDir, result);
output.delete();
output.getParentFile().mkdirs();
String content = render(result);
Files.write(content.getBytes("UTF-8"), output);
System.out.println("Yatspec output:\n" + output);
}
示例5: render
import com.googlecode.totallylazy.Files; //导入依赖的package包/类
private void render(TreeMap<?, ?> map) {
final File file = new File(Files.temporaryDirectory(), getClass().getSimpleName() + ".html");
Files.write(bytes("<html><head><style>" +
".tree { border: 1px solid grey; padding: 0 1px; } " +
".key { text-align: center; } " +
".tree, .left, .right { display: table-cell; }" +
"</style></head><body>" + new TreeMapRenderer().render(map) + "</body></html>"), file);
System.out.println("tree = " + file);
}
示例6: save
import com.googlecode.totallylazy.Files; //导入依赖的package包/类
public boolean save() {
if (file.isEmpty())
return false;
try {
Files.write(history.toString("\n").getBytes(), file.get());
return true;
} catch (Exception e) {
return false;
}
}
示例7: savesAndLoadsMultilineHistory
import com.googlecode.totallylazy.Files; //导入依赖的package包/类
@Test
public void savesAndLoadsMultilineHistory() {
File historyFile = Files.temporaryFile();
ConsoleHistory history = emptyHistory(never(), some(historyFile))
.add("multiline\nexpression")
.add("single line expression")
.add("another\nmultiline\nexpression");
history.save();
assertThat(historyFromFile(never(), some(historyFile)).items(), is(history.items().map(replaceAll("\n", " "))));
}
示例8: fileSource
import com.googlecode.totallylazy.Files; //导入依赖的package包/类
public static FileSource fileSource(File folder) {
return fileSource(folder, Files.recursiveFilesDirectoriesFirst(folder));
}
示例9: relativeTo
import com.googlecode.totallylazy.Files; //导入依赖的package包/类
public static Function1<File, Pair<String, File>> relativeTo(final File folder) {
return file -> Pair.pair(Files.relativePath(folder, file), file);
}