Java 类com.vaadin.server.DownloadStream 实例源码

项目:vaadin-excel-exporter    文件:TemporaryFileDownloadResource.java   
/**
 * 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;
}
项目:solidsearch-bot    文件:FileResourceUtil.java   
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...
     };        
 }
项目:sqlexplorer-vaadin    文件:ExportFileDownloader.java   
@Override
public DownloadStream getStream() {
    DownloadStream download = new DownloadStream(super.getStreamSource().getStream(),contentType,fileName);
    download.setCacheTime(2000);
    return download;
}
项目:VaadinUtils    文件:StreamResourceWithContentLength.java   
@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;
}