/** * 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; }
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... }; }
@Override public DownloadStream getStream() { DownloadStream download = new DownloadStream(super.getStreamSource().getStream(),contentType,fileName); download.setCacheTime(2000); return download; }
@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; }