本文整理汇总了Java中play.libs.Files类的典型用法代码示例。如果您正苦于以下问题:Java Files类的具体用法?Java Files怎么用?Java Files使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Files类属于play.libs包,在下文中一共展示了Files类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: rebuildAllIndexes
import play.libs.Files; //导入依赖的package包/类
public void rebuildAllIndexes() throws Exception {
stop();
File fl = new File(DATA_PATH);
Files.deleteDirectory(fl);
fl.mkdirs();
List<ApplicationClass> classes = Play.classes.getAnnotatedClasses(Indexed.class);
for (ApplicationClass applicationClass : classes) {
List<JPABase> objects = JPA.em().createQuery(
"select e from " + applicationClass.javaClass.getCanonicalName() + " as e")
.getResultList();
for (JPABase jpaBase : objects) {
index(jpaBase, applicationClass.javaClass.getName());
}
}
Logger.info("Rebuild index finished");
}
示例2: delete
import play.libs.Files; //导入依赖的package包/类
public void delete(String name) {
synchronized (this) {
try {
if (indexSearchers.containsKey(name)) {
IndexReader rd = indexSearchers.get(name).getIndexReader();
indexSearchers.get(name).close();
indexSearchers.remove(name);
}
if (indexWriters.containsKey(name)) {
indexWriters.get(name).close();
indexWriters.remove(name);
}
File target = new File(DATA_PATH, name);
if (target.exists() && target.isDirectory())
Files.deleteDirectory(target);
} catch (Exception e) {
throw new UnexpectedException("Can't reopen reader", e);
}
}
}
示例3: testFileUpload
import play.libs.Files; //导入依赖的package包/类
@Test
public void testFileUpload() {
Application app = fakeApplication();
running(app, () -> {
try {
Files.TemporaryFileCreator temporaryFileCreator = app.injector().instanceOf(Files.TemporaryFileCreator.class);
Materializer materializer = app.injector().instanceOf(Materializer.class);
Path tempfilePath = createTempFile(null, "tempfile");
write(tempfilePath, "My string to save".getBytes("utf-8"));
Source<ByteString, CompletionStage<IOResult>> source = FileIO.fromPath(tempfilePath);
Http.MultipartFormData.FilePart<Source<ByteString, ?>> part = new Http.MultipartFormData.FilePart<>("name", "filename", "text/plain", source);
Http.RequestBuilder request = fakeRequest()
.method(POST)
.bodyMultipart(singletonList(part), temporaryFileCreator, materializer)
.uri("/upload");
Result result = route(app, request);
String actual = contentAsString(result);
assertEquals("file size = 17", actual);
} catch (IOException e) {
fail(e.getMessage());
}
});
}
示例4: asFile
import play.libs.Files; //导入依赖的package包/类
public File asFile(File file) {
try {
Files.copy(defaultFile, file);
return file;
} catch (Exception ex) {
throw new UnexpectedException(ex);
}
}
示例5: download
import play.libs.Files; //导入依赖的package包/类
public static void download(@As(binder=DomainModelBinder.class) List<DomainModel> pk, Format format) throws InterruptedException, IOException, IllegalArgumentException, SecurityException, IllegalAccessException, InvocationTargetException, NoSuchMethodException, NoSuchFieldException {
{
Study study = pk.get(0) instanceof Study ? (Study) pk.get(0) : ((Series) pk.get(0)).study;
PersistentLogger.log("downloaded %s %s %s", pk.get(0) instanceof Study ? "study" : "series", pk, study.patient.pat_id);
}
File tmpDir = new File(Properties.getDownloads(), UUID.randomUUID().toString());
tmpDir.mkdir();
File outDir = await(new Downloader(format == null ? Format.dcm : format, tmpDir, Boolean.TRUE.equals(getUser().preferMultiframe), getUser().niftiMultiframeScript, Item.serialize(pk)).now());
if (FileUtils.listFiles(outDir, TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE).isEmpty()) {
error("Failed to retrieve files");
}
File zip = new File(tmpDir, String.format("%s.zip", outDir.getName()));
Files.zip(outDir, zip);
renderBinary(zip);
}
示例6: doJob
import play.libs.Files; //导入依赖的package包/类
@Override
public void doJob() {
for (String folderName : watchedFolders) {
File folder = new File(Play.tmpDir, folderName);
if (folder.exists()) {
for (File file : folder.listFiles()) {
if (TimeUnit.MILLISECONDS.toDays(System.currentTimeMillis() - file.lastModified()) > 1) {
Files.delete(file);
}
}
}
}
}
示例7: save
import play.libs.Files; //导入依赖的package包/类
void save() {
if (f != null) {
File to = new File(getStore(), model.getClass().getName() + "." + name + "_" + ((Model) model)._key());
Files.copy(f, to);
}
}