Package org.zkoss.zul

Class Filedownload

  • Direct Known Subclasses:
    Filedownload

    public class Filedownload
    extends java.lang.Object
    File download utilities.
    Author:
    tomyeh
    See Also:
    Fileupload
    • Constructor Summary

      Constructors 
      Constructor Description
      Filedownload()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void save​(byte[] content, java.lang.String contentType, java.lang.String flnm)
      Open a download dialog to save the specified content at the client with the suggested file name.
      static void save​(java.io.File file, java.lang.String contentType)
      Open a download dialog to save the specified file at the client.
      static void save​(java.io.InputStream content, java.lang.String contentType, java.lang.String flnm)
      Open a download dialog to save the specified content at the client with the suggested file name.
      Note: You don't need to close the content (a InputStream), it will be closed automatically after download.
      static void save​(java.io.Reader content, java.lang.String contentType, java.lang.String flnm)
      Open a download dialog to save the specified content at the client with the suggested file name.
      Note: You don't need to close the content (a Reader), it will be closed automatically after download.
      static void save​(java.lang.String path, java.lang.String contentType)
      Open a download dialog to save the resource of the specified path at the client.
      static void save​(java.lang.String content, java.lang.String contentType, java.lang.String flnm)
      Open a download dialog to save the specified content at the client with the suggested file name.
      static void save​(java.net.URL url, java.lang.String contentType)
      Open a download dialog to save the resource of the specified URL at the client.
      static void save​(Media media)
      Open a download dialog to save the specified content at the client.
      static void save​(Media media, java.lang.String flnm)
      Open a download dialog to save the specified content at the client with the suggested file name.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Filedownload

        public Filedownload()
    • Method Detail

      • save

        public static void save​(Media media)
        Open a download dialog to save the specified content at the client.
      • save

        public static void save​(Media media,
                                java.lang.String flnm)
        Open a download dialog to save the specified content at the client with the suggested file name.
        Parameters:
        media - the media to download
        flnm - the suggested file name, e.g., myfile.pdf. If null, Media.getName() is assumed.
      • save

        public static void save​(byte[] content,
                                java.lang.String contentType,
                                java.lang.String flnm)
        Open a download dialog to save the specified content at the client with the suggested file name.
        Parameters:
        content - the content
        contentType - the content type (a.k.a., MIME type), e.g., application/pdf
        flnm - the suggested file name, e.g., myfile.pdf. If null, no suggested name is provided.
      • save

        public static void save​(java.lang.String content,
                                java.lang.String contentType,
                                java.lang.String flnm)
        Open a download dialog to save the specified content at the client with the suggested file name.
        Parameters:
        content - the content
        contentType - the content type (a.k.a., MIME type), e.g., application/pdf
        flnm - the suggested file name, e.g., myfile.pdf. If null, no suggested name is provided.
      • save

        public static void save​(java.io.InputStream content,
                                java.lang.String contentType,
                                java.lang.String flnm)
        Open a download dialog to save the specified content at the client with the suggested file name.
        Note: You don't need to close the content (a InputStream), it will be closed automatically after download.
        Parameters:
        content - the content
        contentType - the content type (a.k.a., MIME type), e.g., application/pdf
        flnm - the suggested file name, e.g., myfile.pdf. If null, no suggested name is provided.
      • save

        public static void save​(java.io.Reader content,
                                java.lang.String contentType,
                                java.lang.String flnm)
        Open a download dialog to save the specified content at the client with the suggested file name.
        Note: You don't need to close the content (a Reader), it will be closed automatically after download.
        Parameters:
        content - the content
        contentType - the content type (a.k.a., MIME type), e.g., application/pdf
        flnm - the suggested file name, e.g., myfile.pdf. If null, no suggested name is provided.
      • save

        public static void save​(java.io.File file,
                                java.lang.String contentType)
                         throws java.io.FileNotFoundException
        Open a download dialog to save the specified file at the client.
        Parameters:
        file - the file to download to the client
        contentType - the content type, e.g., application/pdf. Unlike other save methods, it is optional. If null, the file name's extension is used to determine the content type.
        Throws:
        java.io.FileNotFoundException - if the file is not found.
        Since:
        3.0.8
      • save

        public static void save​(java.net.URL url,
                                java.lang.String contentType)
                         throws java.io.FileNotFoundException
        Open a download dialog to save the resource of the specified URL at the client. The path must be retrievable by use of WebApp.getResource(java.lang.String).
        Parameters:
        url - the URL to get the resource
        contentType - the content type, e.g., application/pdf. Unlike other save methods, it is optional. If null, the path's extension is used to determine the content type.
        Throws:
        java.io.FileNotFoundException - if the resource is not found.
        Since:
        3.0.8
      • save

        public static void save​(java.lang.String path,
                                java.lang.String contentType)
                         throws java.io.FileNotFoundException
        Open a download dialog to save the resource of the specified path at the client.
        Parameters:
        path - the path of the resource. It must be retrievable by use of WebApp.getResource(java.lang.String).
        contentType - the content type, e.g., application/pdf. Unlike other save methods, it is optional. If null, the path's extension is used to determine the content type.
        Throws:
        java.io.FileNotFoundException - if the resource is not found.
        Since:
        3.0.8