本文整理汇总了Java中com.vaadin.server.StreamResource.StreamSource类的典型用法代码示例。如果您正苦于以下问题:Java StreamSource类的具体用法?Java StreamSource怎么用?Java StreamSource使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
StreamSource类属于com.vaadin.server.StreamResource包,在下文中一共展示了StreamSource类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: downloadExport
import com.vaadin.server.StreamResource.StreamSource; //导入依赖的package包/类
protected void downloadExport(final String export, String filename) {
StreamSource ss = new StreamSource() {
private static final long serialVersionUID = 1L;
public InputStream getStream() {
try {
return new ByteArrayInputStream(export.getBytes(Charset.forName("utf-8")));
} catch (Exception e) {
log.error("Failed to export configuration", e);
CommonUiUtils.notify("Failed to export configuration.", Type.ERROR_MESSAGE);
return null;
}
}
};
String datetime = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date());
StreamResource resource = new StreamResource(ss,
String.format("%s-config-%s.json", filename, datetime));
final String KEY = "export";
setResource(KEY, resource);
Page.getCurrent().open(ResourceReference.create(resource, this, KEY).getURL(), null);
}
示例2: exportConfiguration
import com.vaadin.server.StreamResource.StreamSource; //导入依赖的package包/类
protected void exportConfiguration() {
final String export = context.getImportExportService().exportAgent(agent.getId(), AppConstants.SYSTEM_USER);
StreamSource ss = new StreamSource() {
private static final long serialVersionUID = 1L;
public InputStream getStream() {
try {
return new ByteArrayInputStream(export.getBytes());
} catch (Exception e) {
log.error("Failed to export configuration", e);
CommonUiUtils.notify("Failed to export configuration.", Type.ERROR_MESSAGE);
return null;
}
}
};
String datetime = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date());
StreamResource resource = new StreamResource(ss,
String.format("%s-config-%s.json", agent.getName().toLowerCase().replaceAll(" ", "-"), datetime));
final String KEY = "export";
setResource(KEY, resource);
Page.getCurrent().open(ResourceReference.create(resource, this, KEY).getURL(), null);
}
示例3: download
import com.vaadin.server.StreamResource.StreamSource; //导入依赖的package包/类
protected void download() {
String stepId = (String) stepTable.getSelectedRow();
if (stepId != null) {
final File file = executionService.getExecutionStepLog(stepId);
StreamSource ss = new StreamSource() {
private static final long serialVersionUID = 1L;
public InputStream getStream() {
try {
return new FileInputStream(file);
} catch (Exception e) {
log.error("Failed to download log file", e);
CommonUiUtils.notify("Failed to download log file", Type.ERROR_MESSAGE);
return null;
}
}
};
StreamResource resource = new StreamResource(ss, file.getName());
final String KEY = "export";
setResource(KEY, resource);
Page.getCurrent().open(ResourceReference.create(resource, this, KEY).getURL(), null);
}
}
示例4: downloadExport
import com.vaadin.server.StreamResource.StreamSource; //导入依赖的package包/类
protected void downloadExport(final String export, String filename) {
StreamSource ss = new StreamSource() {
private static final long serialVersionUID = 1L;
public InputStream getStream() {
try {
return new ByteArrayInputStream(export.getBytes(Charset.forName("utf-8")));
} catch (Exception e) {
log.error("Failed to export configuration", e);
CommonUiUtils.notify("Failed to export configuration.", Type.ERROR_MESSAGE);
return null;
}
}
};
String datetime = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date());
StreamResource resource = new StreamResource(ss, String.format("%s-config-%s.json", filename, datetime));
final String KEY = "export";
setResource(KEY, resource);
Page.getCurrent().open(ResourceReference.create(resource, this, KEY).getURL(), null);
}
示例5: constructStreamResource
import com.vaadin.server.StreamResource.StreamSource; //导入依赖的package包/类
private StreamResource constructStreamResource(final ReportExportType exportType) {
LazyStreamSource streamSource = new LazyStreamSource() {
private static final long serialVersionUID = 1L;
@Override
protected StreamSource buildStreamSource() {
SimpleReportTemplateExecutor reportTemplateExecutor = new SimpleReportTemplateExecutor.AllItems<>(
UserUIContext.getUserTimeZone(), UserUIContext.getUserLocale(), "Following Tickets",
new RpFieldsBuilder(ticketTable.getDisplayColumns()), exportType, FollowingTicket.class,
AppContextUtil.getSpringBean(ProjectFollowingTicketService.class));
//TODO: correct the report of following tickets
return null;
}
};
return new StreamResource(streamSource, exportType.getDefaultFileName());
}
示例6: getImageResource
import com.vaadin.server.StreamResource.StreamSource; //导入依赖的package包/类
/**
* This function is the actual workhorse for
* {@link RContainer#getEmbeddedGraph}. It gets a Vaadin StreamResource
* object that contains the corresponding R plot generated by submitting and
* evaluating the RPlotCall String. The imageName corresponds to the
* downloadable image name, and device is the format supported by the Cairo
* graphics engine. The full name of the images shown in the browser are
* imageName_ISODate_runningId_[sessionId].[device], e.g.
* 'Image_2012-08-29_001_[bmgolmfgvk].png' to keep them chronologically
* ordered.
*
* @param RPlotCall
* the String to be evaluated by R
* @param width
* plot width in pixels
* @param height
* plot height in pixels
* @param device
* A plot device supported by Cairo ('png','pdf',...)
* @return The image as Embedded Vaadin object
*/
public StreamResource getImageResource(String RPlotCall, int width,
int height, String imageName, String device) {
StreamSource imagesource = new RImageSource(rc, RPlotCall, width,
height, rSemaphore, device);
/* Get a systematic name for the image */
imageCount++;
String fileName = imageName + "_" + getDateAndCount(imageCount) + "_["
+ sessionID + "]." + device;
/*
* Create a resource that uses the stream source and give it a name. The
* constructor will automatically register the resource with the
* application.
*/
StreamResource imageresource = new StreamResource(imagesource, fileName);
/*
* Instruct browser not to cache the image. See the Book of Vaadin 6
* page 131.
*/
imageresource.setCacheTime(0);
return imageresource;
}
示例7: miseAJourContainer
import com.vaadin.server.StreamResource.StreamSource; //导入依赖的package包/类
/** Met a jour le container
* @param ctrCand
*/
private void miseAJourContainer(Commission commission){
containerReadOnly.removeAllItems();
containerGeneral.removeAllItems();
containerLettre.removeAllItems();
labelSignataire.setValue("");
if (commission != null){
containerReadOnly.addAll(commissionController.getListPresentation(commission,ConstanteUtils.COMM_TYP_AFF_READONLY));
containerGeneral.addAll(commissionController.getListPresentation(commission,ConstanteUtils.COMM_TYP_AFF_GEN));
containerLettre.addAll(commissionController.getListPresentation(commission,ConstanteUtils.COMM_TYP_AFF_LETTRE));
labelSignataire.setValue(commission.getSignataireComm());
Fichier file = commission.getFichier();
if (file!=null){
StreamResource imageResource = new StreamResource(new StreamSource() {
/**serialVersionUID**/
private static final long serialVersionUID = -4583630655596056637L;
@Override
public InputStream getStream() {
InputStream is = fileController.getInputStreamFromFichier(file);
if (is != null){
return is;
}
return null;
}
}, file.getNomFichier());
imgSignataire.setSource(imageResource);
btnAddImage.setVisible(false);
btnDeleteImage.setVisible(true);
}else{
imgSignataire.setSource(null);
btnAddImage.setVisible(true);
btnDeleteImage.setVisible(false);
}
}
}
示例8: OnDemandStreamResource
import com.vaadin.server.StreamResource.StreamSource; //导入依赖的package包/类
public OnDemandStreamResource() {
super(new StreamSource() {
@Override
public InputStream getStream() {
return new ByteArrayInputStream(new byte[1]);
}
}, "");
}
示例9: VaadinExportDialog
import com.vaadin.server.StreamResource.StreamSource; //导入依赖的package包/类
public VaadinExportDialog(String title) {
super(title);
try {
HorizontalLayout horizontalLayout = new HorizontalLayout();
horizontalLayout.setMargin(false);
final PipedInputStream pipedInputStream = new PipedInputStream(pipedOutputStream);
StreamSource ss = new StreamSource() {
private static final long serialVersionUID = 1L;
@Override
public InputStream getStream() {
VaadinExportDialog.this.close();
return pipedInputStream;
}
};
StreamResource sr = new StreamResource(ss, "export.xml");
sr.setMIMEType("application/octet-stream");
sr.setCacheTime(0);
link = new Link("Link to Download", sr);
horizontalLayout.addComponent(link);
setContent(horizontalLayout);
setModal(true);
UI.getCurrent().addWindow(this);
} catch (IOException x) {
x.printStackTrace();
}
}
示例10: getLogFileResource
import com.vaadin.server.StreamResource.StreamSource; //导入依赖的package包/类
private StreamResource getLogFileResource() {
StreamSource ss = new StreamSource() {
public InputStream getStream() {
try {
return new BufferedInputStream(new FileInputStream(logFile));
} catch (FileNotFoundException e) {
Notification note = new Notification("File Not Found", "Could not find "
+ logFile.getName() + " to download");
note.show(Page.getCurrent());
return null;
}
}
};
return new StreamResource(ss, logFile.getName());
}
示例11: createResource
import com.vaadin.server.StreamResource.StreamSource; //导入依赖的package包/类
private StreamResource createResource() {
final String format = (String) formatSelect.getValue().toString();
StreamSource ss = new StreamSource() {
private static final long serialVersionUID = 1L;
public InputStream getStream() {
List<String> list = tableSelectionLayout.getSelectedTables();
String[] array = new String[list.size()];
list.toArray(array);
createDbExport();
String script;
try {
script = dbExport.exportTables(array);
return new ByteArrayInputStream(script.getBytes());
} catch (IOException e) {
String msg = "Failed to export to a file";
log.error(msg, e);
CommonUiUtils.notify(msg, e);
}
return null;
}
};
String datetime = new SimpleDateFormat("yyyyMMddhhmmss").format(new Date());
StreamResource sr = new StreamResource(ss, String.format(
"table-export-%s." + format.toLowerCase(), datetime));
return sr;
}
示例12: buildDownloadButton
import com.vaadin.server.StreamResource.StreamSource; //导入依赖的package包/类
private void buildDownloadButton(String title) {
downloadButton = new Button("Download");
final byte[] lobData = getLobData(title);
if (lobData != null) {
Resource resource = new StreamResource(new StreamSource() {
private static final long serialVersionUID = 1L;
public InputStream getStream() {
return new ByteArrayInputStream(lobData);
}
}, title);
FileDownloader fileDownloader = new FileDownloader(resource);
fileDownloader.extend(downloadButton);
buttonLayout.addComponent(downloadButton);
buttonLayout.setComponentAlignment(downloadButton, Alignment.BOTTOM_CENTER);
long fileSize = lobData.length;
String sizeText = fileSize + " Bytes";
if (fileSize / 1024 > 0) {
sizeText = Math.round(fileSize / 1024.0) + " kB";
fileSize /= 1024;
}
if (fileSize / 1024 > 0) {
sizeText = Math.round(fileSize / 1024.0) + " MB";
fileSize /= 1024;
}
if (fileSize / 1024 > 0) {
sizeText = Math.round(fileSize / 1024.0) + " GB";
}
Label sizeLabel = new Label(sizeText);
buttonLayout.addComponent(sizeLabel);
buttonLayout.setExpandRatio(sizeLabel, 1.0f);
buttonLayout.setComponentAlignment(sizeLabel, Alignment.BOTTOM_CENTER);
}
}
示例13: getStreamSourceSupportExtDrive
import com.vaadin.server.StreamResource.StreamSource; //导入依赖的package包/类
public static StreamSource getStreamSourceSupportExtDrive(Collection<Resource> lstRes) {
if (CollectionUtils.isEmpty(lstRes)) {
throw new UserInvalidInputException(UserUIContext.getMessage(FileI18nEnum.ERROR_NO_SELECTED_FILE_TO_DOWNLOAD));
} else {
return new StreamDownloadResourceSupportExtDrive(lstRes);
}
}
示例14: getReportStream
import com.vaadin.server.StreamResource.StreamSource; //导入依赖的package包/类
private StreamSource getReportStream()
{
@SuppressWarnings("serial")
StreamSource source = new StreamSource()
{
@Override
public InputStream getStream()
{
try
{
InputStream stream = manager.getStream();
if (stream == null)
{
Notification.show("Couldn't attach to stream, if you cancelled a report this is normal",
Type.ERROR_MESSAGE);
}
return stream;
}
catch (InterruptedException e)
{
logger.error(e, e);
}
return null;
}
};
return source;
}
示例15: getDownloadResource
import com.vaadin.server.StreamResource.StreamSource; //导入依赖的package包/类
/**
* Get a Vaadin Resource object which links to a file in the R working
* directory. The Resource object can be associated e.g. with Links.
*
* @param filename
* The name of the file stored under R current working directory.
* @return Vaadin Resource object
*/
public Resource getDownloadResource(String filename) {
StreamSource filesource = new RDownloadSource(filename, this);
StreamResource fileresource = new StreamResource(filesource, filename);
fileresource.setCacheTime(0);
return fileresource;
}