本文整理汇总了Java中com.vaadin.server.DownloadStream类的典型用法代码示例。如果您正苦于以下问题:Java DownloadStream类的具体用法?Java DownloadStream怎么用?Java DownloadStream使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DownloadStream类属于com.vaadin.server包,在下文中一共展示了DownloadStream类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getStream
import com.vaadin.server.DownloadStream; //导入依赖的package包/类
/**
* Gets the stream.
*
* @return the stream
*/
/*
* (non-Javadoc)
*
* @see com.vaadin.terminal.StreamResource#getStream()
*/
@Override
public DownloadStream getStream() {
final DownloadStream stream = new DownloadStream(getStreamSource().getStream(), this.contentType,
this.filename);
stream.setParameter("Content-Disposition", "attachment;filename=" + this.filename);
// This magic incantation should prevent anyone from caching the data
stream.setParameter("Cache-Control", "private,no-cache,no-store");
// In theory <=0 disables caching. In practice Chrome, Safari (and,
// apparently, IE) all
// ignore <=0. Set to 1s
stream.setCacheTime(1000);
return stream;
}
示例2: createFileResource
import com.vaadin.server.DownloadStream; //导入依赖的package包/类
public FileResource createFileResource(File file)
{
return new FileResource(file)
{
private static final long serialVersionUID = -4183674760353232866L;
@Override
public DownloadStream getStream()
{
try
{
final DownloadStream ds = new DownloadStream(new FileInputStream(getSourceFile()), getMIMEType(), getFilename());
ds.setParameter("Content-Length", String.valueOf(getSourceFile().length()));
ds.setCacheTime(getCacheTime());
return ds;
}
catch (final FileNotFoundException e)
{
return null;
}//end try-catch block...
}//end method...
};
}
示例3: getStream
import com.vaadin.server.DownloadStream; //导入依赖的package包/类
@Override
public DownloadStream getStream() {
DownloadStream download = new DownloadStream(super.getStreamSource().getStream(),contentType,fileName);
download.setCacheTime(2000);
return download;
}
示例4: getStream
import com.vaadin.server.DownloadStream; //导入依赖的package包/类
@Override
public DownloadStream getStream()
{
final StreamSource ss = getStreamSource();
PartialDownloadStream ds = new PartialDownloadStream(null, getMIMEType(), getFilename());
if (ss != null)
{
try
{
long contentLength = contentLengthProvider.getContentLength();
ds.setStream(ss.getStream());
ds.setContentLength(contentLength);
ds.setParameter("Content-Length", String.valueOf(contentLength));
ds.setBufferSize(getBufferSize());
ds.setCacheTime(getCacheTime());
}
catch (final Exception e)
{
logger.error(e, e);
if (ui != null)
{
ui.access(new Runnable()
{
@Override
public void run()
{
Notification.show(e.getMessage(), Type.ERROR_MESSAGE);
}
});
}
else
{
ErrorWindow.showErrorWindow(e);
}
}
}
return ds;
}