下面列出了怎么用com.vaadin.server.FileResource的API类实例代码及写法,或者点击链接到github查看源代码。
@Override
public void sourceGenerationExecuted(final Source source, final TestGenerationType generationType, final long testsCreated) {
UI.getCurrent().access(() -> {
Item item = resultsTable.getItem(source);
if (testsCreated == 0 || item == null)
return;
String column = (generationType.equals(TestGenerationType.AutoGenerated) ? "Automatic" : "Manual");
Property<Link> statusProperty = item.getItemProperty(column);
String fileName;
if (generationType.equals(TestGenerationType.AutoGenerated)) {
fileName = CacheUtils.getSourceAutoTestFile(RDFUnitDemoSession.getBaseDir() + "tests/", source);
statusProperty.setValue(new Link("" + testsCreated, new FileResource(new File(fileName))));
} else {
fileName = CacheUtils.getSourceManualTestFile("/org/aksw/rdfunit/tests/", source);
statusProperty.setValue(new Link("" + testsCreated, new ClassResource(fileName)));
}
CommonAccessUtils.pushToClient();
});
}
private FileResource getFileResource(String path,String type){
InputStream inputStream = null;
try {
ClassPathResource resource = new ClassPathResource(path);
inputStream = resource.getInputStream();
File tempFile = File.createTempFile("ds_" + System.currentTimeMillis(), type);
FileUtils.copyInputStreamToFile(inputStream, tempFile);
return new FileResource(tempFile);
} catch (Exception e) {
e.printStackTrace();
return null;
} finally {
IOUtils.closeQuietly(inputStream);
}
}
private FileResource getFileResource(String path,String type){
InputStream inputStream = null;
try {
ClassPathResource resource = new ClassPathResource(path);
inputStream = resource.getInputStream();
File tempFile = File.createTempFile("ds_" + System.currentTimeMillis(), type);
FileUtils.copyInputStreamToFile(inputStream, tempFile);
return new FileResource(tempFile);
} catch (Exception e) {
e.printStackTrace();
return null;
} finally {
IOUtils.closeQuietly(inputStream);
}
}
@Override
public Resource getIconResource(String iconPath) {
Preconditions.checkNotEmptyString(iconPath, "Icon path should not be empty");
String icon = iconPath.substring(FILE_PREFIX.length());
File iconFile = new File(icon);
if (!iconFile.exists()) {
throw new IllegalArgumentException("Icon file does not exist: " + icon);
}
return new FileResource(iconFile);
}