Example usage for com.vaadin.server StreamResource StreamResource

List of usage examples for com.vaadin.server StreamResource StreamResource

Introduction

In this page you can find the example usage for com.vaadin.server StreamResource StreamResource.

Prototype

public StreamResource(StreamSource streamSource, String filename) 

Source Link

Document

Creates a new stream resource for downloading from stream.

Usage

From source file:com.github.moscaville.contactsdb.util.OnDemandFileDownloader.java

public OnDemandFileDownloader(OnDemandStreamResource onDemandStreamResource) {
    super(new StreamResource(onDemandStreamResource, "contactsdb.csv"));
    this.onDemandStreamResource = onDemandStreamResource;
}

From source file:com.gnts.pem.txn.sbi.SBIBuilding.java

private StreamResource getPDFStream() {
    try {//from w  w w  .  j  a  v a2  s .c  o m
        StreamResource.StreamSource source = new StreamResource.StreamSource() {

            /**
             * 
             */
            private static final long serialVersionUID = 1L;

            public InputStream getStream() {
                TPemCmEvalDetails edit = beans.getItem(tblEvalDetails.getValue()).getBean();
                if (edit.getEvalDoc() != null) {

                    return new ByteArrayInputStream(edit.getEvalDoc());
                } else {
                    return null;
                }

            }
        };
        TPemCmEvalDetails edit = beans.getItem(tblEvalDetails.getValue()).getBean();
        StreamResource resource = new StreamResource(source,
                edit.getEvalNo() + "_" + edit.getCustName() + "_" + propertyType + ".doc");
        return resource;
    } catch (Exception e) {
        return null;
    }
}

From source file:com.gnts.pem.txn.sbi.SBILand.java

private StreamResource getImgStream() {
    List<TPemCmPropImage> list = beanPropImage.getPropImageList(headerid);
    for (final TPemCmPropImage obj : list) {
        StreamResource.StreamSource source = new StreamResource.StreamSource() {
            private static final long serialVersionUID = 1L;

            public InputStream getStream() {

                if (obj.getPropimage1() != null) {

                    return new ByteArrayInputStream(obj.getPropimage1());
                } else {
                    return null;
                }//w  ww  .jav a  2 s  .  c om
            }
        };
        StreamResource resource = new StreamResource(source, obj.getDocId() + ".png");
        return resource;
    }
    return null;
}

From source file:com.gnts.pem.txn.sbi.SBILand.java

private StreamResource getImgStream1() {
    System.out.println("File Name++++++++++++" + new File(basepath1).getName());
    List<TPemCmPropImage> list = beanPropImage.getPropImageList(headerid);
    for (final TPemCmPropImage obj : list) {
        StreamResource.StreamSource source = new StreamResource.StreamSource() {
            private static final long serialVersionUID = 1L;

            public InputStream getStream() {

                if (obj.getPropimage2() != null) {

                    return new ByteArrayInputStream(obj.getPropimage2());
                } else {
                    return null;
                }/* ww  w  . j  ava  2  s  .  c  o m*/
            }
        };
        StreamResource resource = new StreamResource(source, obj.getImgId() + ".png");
        return resource;
    }
    return null;
}

From source file:com.hack23.cia.web.impl.ui.application.views.common.pagelinks.impl.ExternalAttachmentDownloadLink.java

License:Apache License

@Override
public void attach() {
    super.attach();

    final StreamResource.StreamSource source = new StreamResource.StreamSource() {

        /**/*from  w ww .j av  a 2  s  .  c  o m*/
         *
         */
        private static final long serialVersionUID = 1L;

        public InputStream getStream() {

            try {
                return new URL(fileUrl).openStream();
            } catch (final IOException e) {
                LOGGER.warn("Problem opening url:" + fileUrl, e);
                return new ByteArrayInputStream(new byte[0]);
            }
        }
    };

    final StreamResource resource = new StreamResource(source, fileName);

    resource.getStream().setParameter("Content-Disposition", "attachment;filename=\"" + fileName + "\"");
    resource.setMIMEType("application/" + fileType);
    resource.setCacheTime(0);

    setResource(resource);
}

From source file:com.haulmont.cuba.web.filestorage.WebExportDisplay.java

License:Apache License

/**
 * Show/Download resource at client side
 *
 * @param dataProvider ExportDataProvider
 * @param resourceName ResourceName for client side
 * @param exportFormat ExportFormat//from   w ww. j  a  va 2s. c o  m
 * @see com.haulmont.cuba.gui.export.FileDataProvider
 * @see com.haulmont.cuba.gui.export.ByteArrayDataProvider
 */
@Override
public void show(ExportDataProvider dataProvider, String resourceName, final ExportFormat exportFormat) {
    backgroundWorker.checkUIAccess();

    boolean showNewWindow = this.newWindow;

    if (useViewList) {
        String fileExt;

        if (exportFormat != null) {
            fileExt = exportFormat.getFileExt();
        } else {
            fileExt = FilenameUtils.getExtension(resourceName);
        }

        WebConfig webConfig = configuration.getConfig(WebConfig.class);
        showNewWindow = webConfig.getViewFileExtensions().contains(StringUtils.lowerCase(fileExt));
    }

    if (exportFormat != null) {
        if (StringUtils.isEmpty(FilenameUtils.getExtension(resourceName))) {
            resourceName += "." + exportFormat.getFileExt();
        }
    }

    CubaFileDownloader fileDownloader = AppUI.getCurrent().getFileDownloader();

    StreamResource resource = new StreamResource(dataProvider::provide, resourceName);

    if (exportFormat != null && StringUtils.isNotEmpty(exportFormat.getContentType())) {
        resource.setMIMEType(exportFormat.getContentType());
    } else {
        resource.setMIMEType(FileTypesHelper.getMIMEType(resourceName));
    }

    if (showNewWindow) {
        fileDownloader.viewDocument(resource);
    } else {
        fileDownloader.downloadFile(resource);
    }
}

From source file:com.haulmont.cuba.web.gui.components.WebClasspathResource.java

License:Apache License

@Override
protected void createResource() {
    String name = StringUtils.isNotEmpty(fileName) ? fileName : FilenameUtils.getName(path);

    resource = new StreamResource(() -> AppBeans.get(Resources.class).getResourceAsStream(path), name);

    StreamResource streamResource = (StreamResource) this.resource;

    streamResource.setMIMEType(mimeType);
    streamResource.setCacheTime(cacheTime);
    streamResource.setBufferSize(bufferSize);
}

From source file:com.haulmont.cuba.web.gui.components.WebEmbedded.java

License:Apache License

@Override
public void setSource(String fileName, final InputStream src) {
    if (src != null) {
        resource = new StreamResource((StreamResource.StreamSource) () -> {
            try {
                src.reset();/*from  www  .  j av a 2  s. c o m*/
            } catch (IOException e) {
                Logger log = LoggerFactory.getLogger(WebEmbedded.this.getClass());
                log.debug("Ignored IOException on stream reset", e);
            }
            return src;
        }, fileName);
        component.setSource(resource);
    } else {
        resetSource();
    }
}

From source file:com.haulmont.cuba.web.gui.components.WebEmbedded.java

License:Apache License

@Override
public void setSource(String fileName, final ExportDataProvider dataProvider) {
    if (dataProvider != null) {
        resource = new StreamResource(dataProvider::provide, fileName);
        component.setSource(resource);//w  w  w  .  java 2 s  .co  m
    } else {
        resetSource();
    }
}

From source file:com.haulmont.cuba.web.gui.components.WebEmbedded.java

License:Apache License

@Override
public void resetSource() {
    resource = null;//from  w  w w  .  j a  va  2  s . c  o  m
    component.markAsDirty();
    component.setMimeType("image/png");
    component.setType(com.vaadin.ui.Embedded.TYPE_IMAGE);
    component.setSource(new StreamResource(new EmptyStreamSource(), UUID.randomUUID() + ".png"));
}