Class AMedia

java.lang.Object
org.zkoss.util.media.AMedia
All Implemented Interfaces:
Serializable, Media

public class AMedia extends Object implements Media, Serializable
A media object holding content such PDF, HTML, DOC or XLS content.

AMedia is serializable, but, if you are using InputStream or Reader, you have to extend this class, and provide the implementation to serialize and deserialize _isdata or _rddata (they are both transient).

Author:
tomyeh
See Also:
  • Field Details

  • Constructor Details

    • AMedia

      public AMedia(String name, String format, String ctype, byte[] data)
      Construct with name, format, content type and binary data.

      It tries to construct format and ctype from each other or name.

      Parameters:
      name - the name (usually filename); might be null.
      format - the format; might be null. Example: "html" and "xml"
      ctype - the content type; might be null. Example: "text/html" and "text/xml;charset=UTF-8".
      data - the binary data; never null
    • AMedia

      public AMedia(String name, String format, String ctype, String data)
      Construct with name, format, content type and text data.

      It tries to construct format and ctype from each other or name.

      Parameters:
      name - the name (usually filename); might be null.
      format - the format; might be null.
      ctype - the content type; might be null.
      data - the text data; never null
    • AMedia

      public AMedia(String name, String format, String ctype, InputStream data)
      Construct with name, format, content type and stream data (binary).

      It tries to construct format and ctype from each other or name.

      Parameters:
      name - the name (usually filename); might be null.
      format - the format; might be null.
      ctype - the content type; might be null.
      data - the binary data; never null. If the input stream is created dynamically each time getStreamData() is called, you shall pass DYNAMIC_STREAM as the data argument. Then, override getStreamData() to return the correct stream. Note: the caller of getStreamData() has to close the returned input stream.
    • AMedia

      public AMedia(String name, String format, String ctype, Reader data)
      Construct with name, format, content type and reader data (textual).

      It tries to construct format and ctype from each other or name.

      Parameters:
      name - the name (usually filename); might be null.
      format - the format; might be null.
      ctype - the content type; might be null.
      data - the string data; never null If the reader is created dynamically each time getReaderData() is called, you shall pass DYNAMIC_READER as the data argument. Then, override getReaderData() to return the correct reader.
    • AMedia

      public AMedia(String name, String format, String ctype, File file, boolean binary) throws FileNotFoundException
      Construct with name, format, content type and a file.

      Unlike others, it uses the so-called repeatable input stream or reader (depending on binary or not) to represent the file, so the input stream (getStreamData()) or the reader (getReaderData()) will be re-opened in the next invocation of InputStream.read() after InputStream.close() is called. See also RepeatableInputStream and RepeatableReader.

      Parameters:
      name - the name (usually filename); might be null. If null, the file name is used.
      format - the format; might be null.
      ctype - the content type; might be null.
      file - the file; never null.
      binary - whether it is binary. If not binary, "UTF-8" is assumed.
      Throws:
      FileNotFoundException
    • AMedia

      public AMedia(String name, String format, String ctype, File file, String charset) throws FileNotFoundException
      Construct with name, format, content type and a file.

      Unlike others, it uses the so-called repeatable input stream or reader (depending on charset is null or not) to represent the file, so the input stream (getStreamData()) or the reader (getReaderData()) will be re-opened in the next invocation of InputStream.read() after InputStream.close() is called. See also RepeatableInputStream and RepeatableReader.

      Parameters:
      name - the name (usually filename); might be null. If null, the file name is used.
      format - the format; might be null.
      ctype - the content type; might be null.
      file - the file; never null.
      charset - the charset. If null, it is assumed to be binary.
      Throws:
      FileNotFoundException
    • AMedia

      public AMedia(File file, String ctype, String charset) throws FileNotFoundException
      Construct with a file. It is the same as AMedia(null, null, ctype, file, charset).
      Parameters:
      ctype - the content type; might be null. If null, it is retrieved from the file name's extension.
      Throws:
      FileNotFoundException
      Since:
      3.0.8
    • AMedia

      public AMedia(String name, String format, String ctype, URL url, String charset) throws FileNotFoundException
      Construct with name, format, content type and URL.

      Unlike others, it uses the so-called repeatable input stream or reader (depending on charset is null or not) to represent the resource, so the input stream (getStreamData()) or the reader (getReaderData()) will be re-opened in the next invocation of InputStream.read() after InputStream.close() is called. See also RepeatableInputStream and RepeatableReader.

      Parameters:
      name - the name; might be null. If null, URL's name is used.
      format - the format; might be null.
      ctype - the content type; might be null.
      url - the resource URL; never null.
      Throws:
      FileNotFoundException
      Since:
      3.0.8
    • AMedia

      public AMedia(URL url, String ctype, String charset) throws FileNotFoundException
      Construct with a file. It is the same as AMedia(null, null, ctype, url, charset).
      Parameters:
      ctype - the content type; might be null. If null, it is retrieved from the file name's extension.
      Throws:
      FileNotFoundException
      Since:
      3.0.8
  • Method Details