List of usage examples for com.vaadin.server DownloadStream setCacheTime
public void setCacheTime(long cacheTime)
From source file:com.cms.utils.FileDownloader.java
License:Apache License
@Override public DownloadStream getStream() { try {//from ww w . j a v a2 s . c o m final DownloadStream ds = new DownloadStream(new FileInputStream(sourceFile), getMIMEType(), fileNameNew); ds.setParameter("Content-Length", String.valueOf(sourceFile.length())); ds.setCacheTime(cacheTime); return ds; } catch (final FileNotFoundException e) { throw new RuntimeException("File not found: " + sourceFile.getName(), e); } }
From source file:com.esofthead.mycollab.vaadin.resources.file.FileStreamDownloadResource.java
License:Open Source License
@Override public DownloadStream getStream() { try {//from w w w . ja v a 2s .c om String fileName = getFilename(); fileName = fileName.replaceAll(" ", "_").replaceAll("-", "_"); final DownloadStream ds = new DownloadStream(new FileInputStream(getSourceFile()), getMIMEType(), fileName); ds.setParameter("Content-Disposition", "attachment; filename=" + fileName); ds.setCacheTime(0); return ds; } catch (final FileNotFoundException e) { LOG.error("Error to create download stream", e); return null; } }
From source file:com.foc.msword.WordTemplateFillerResource.java
License:Apache License
@Override public DownloadStream getStream() { DownloadStream downloadStream = null; try {/*from w w w . j av a 2 s . c o m*/ ClassResource resource = null; InputStream inputStream = null; resource = new ClassResource(tempateFileName); inputStream = resource.getStream().getStream(); ExtendedWordDocument xWord = new ExtendedWordDocument(inputStream); if (xWord != null) { fill(xWord); ByteArrayOutputStream baos = new ByteArrayOutputStream(); xWord.write(baos); bais = new ByteArrayInputStream(baos.toByteArray()); } xWord.dispose(); } catch (Exception e) { Globals.logException(e); } if (bais != null) { String fileName2 = downloadFileName; if (!fileName2.endsWith(".doc") && !fileName2.endsWith(".docx")) { fileName2 += ".docx"; } downloadStream = new DownloadStream(bais, "application/x-unknown", fileName2); downloadStream.setParameter("Content-Disposition", "attachment; filename=" + fileName2); downloadStream.setCacheTime(0); } return downloadStream; }
From source file:com.foc.property.FCloudStoragePropertyResource.java
License:Apache License
@Override public DownloadStream getStream() { DownloadStream downloadStream = null; if (cloudStorageProperty != null) { if (Utils.isStringEmpty(cloudStorageProperty.getKey())) { Globals.logString("DOWNLOAD: newBlobResource 1 Key Empty, generating it"); cloudStorageProperty.generateKey(); }/* www . j ava2 s. com*/ Globals.logString("DOWNLOAD: newBlobResource 1bis Key=" + cloudStorageProperty.getKey()); if (cloudStorageProperty.getDirectory() == null) { Globals.logString("DOWNLOAD: newBlobResource 2 Directory null computing it"); cloudStorageProperty.setDirectory(Globals.getApp().getCloudStorageDirectory(), false); } Globals.logString("DOWNLOAD: newBlobResource 2bis Key=" + cloudStorageProperty.getDirectory()); InputStream is = (InputStream) cloudStorageProperty.getObject(); if (is == null) Globals.logString("DOWNLOAD: newBlobResource 3 inputStream is null"); else Globals.logString("DOWNLOAD: newBlobResource 3bis inputStream is Good"); Globals.logString("DOWNLOAD: newBlobResource 4 FileName : " + cloudStorageProperty.getFileName()); if (is != null) { downloadStream = new DownloadStream(is, "application/x-unknown", cloudStorageProperty.getFileName()); downloadStream.setParameter("Content-Disposition", "attachment; filename=" + DownloadStream.getContentDispositionFilename(cloudStorageProperty.getFileName())); downloadStream.setCacheTime(0); } } return downloadStream; }
From source file:com.foc.vaadin.gui.components.BlobResource.java
License:Apache License
@Override public DownloadStream getStream() { DownloadStream downloadStream = null; if (is != null) { downloadStream = new DownloadStream(is, "application/x-unknown", fileName); downloadStream.setParameter("Content-Disposition", "attachment; filename=" + fileName); downloadStream.setCacheTime(0); }/*w ww . j a va 2 s. c o m*/ return downloadStream; }
From source file:org.hip.vif.admin.admin.print.DownloadFile.java
License:Open Source License
@Override public DownloadStream getStream() { try {/*from w ww . j av a2 s . c o m*/ final DownloadStream out = new DownloadStream(buffer.getInputStream(), getMIMEType(), getFileName()); out.setCacheTime(0); out.setParameter("Content-Disposition", "attachment; filename=\"" + getFileName() + "\""); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ out.setParameter("Content-Length", String.valueOf(buffer.getSize() - buffer.getSpaceLeft())); //$NON-NLS-1$ out.setContentType("application/octet-stream;charset=UTF-8"); LOG.debug("Printed discusion group to file \"{}\".", getFileName()); //$NON-NLS-1$ return out; } catch (final Exception exc) { LOG.error("Error encountered while printing the discussion groups!", exc); //$NON-NLS-1$ } return null; }
From source file:org.hip.vif.web.util.DownloadFileResouce.java
License:Open Source License
@Override public DownloadStream getStream() { try {//from w w w. j av a2 s. c om final DownloadStream out = new DownloadStream(new FileInputStream(download.getFile()), download.getMIMEType(), download.getFileName()); out.setCacheTime(0); out.setParameter("Content-Disposition", "attachment; filename=\"" + download.getFileName() + "\""); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ LOG.debug("Downloaded file \"{}\"", download.getFileName()); //$NON-NLS-1$ return out; } catch (final FileNotFoundException exc) { LOG.error("Couldn't find download file \"{}\"!", download.getFileName(), exc); //$NON-NLS-1$ return null; } }
From source file:org.lucidj.vaadinui.BundleResource.java
License:Apache License
@Override public DownloadStream getStream() { try {/* ww w .j a va 2 s.c o m*/ DownloadStream ds = new DownloadStream(resourceUrl.openStream(), getMIMEType(), getFilename()); ds.setBufferSize(getBufferSize()); ds.setCacheTime(getCacheTime()); return (ds); } catch (IOException e) { throw new IllegalArgumentException(e); } }