Interface Media

  • All Known Subinterfaces:
    Audio, Image, Video
    All Known Implementing Classes:
    AAudio, AImage, AMedia, AVideo, RepeatableMedia

    public interface Media
    Represents any multi-media, such as a voice, a pdf file, an excel file, an image and so on.

    By implementing this interface, objects can be processed generically by servlets and many other codes.

    Author:
    tomyeh
    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      byte[] getByteData()
      Returns the raw data in byte array.
      java.lang.String getContentType()
      Returns the content type, e.g., "image/jpeg", or null if not available.
      java.lang.String getFormat()
      Returns the format name, e.g., "jpeg", or null if not available.
      java.lang.String getName()
      Returns the name (usually filename) of this media, or null if not available.
      java.io.Reader getReaderData()
      Returns the raw data in Reader.
      java.io.InputStream getStreamData()
      Returns the raw data in InputStream.
      java.lang.String getStringData()
      Returns the raw data in string.
      boolean inMemory()
      Returns whether the data is cached in memory (in form of byte[] or String).
      boolean isBinary()
      Returns whether the format of this content is binary or text-based.
      boolean isContentDisposition()
      Whether to allow Content-Disposition or not when writing the media to response header.
    • Method Detail

      • getByteData

        byte[] getByteData()
        Returns the raw data in byte array.

        It might not be a copy, so don't modify it directly unless you know what you are doing.

        If the data is not cached in memory (inMemory() return false), the data will be read from getStreamData(). Furthermore, it also implies you can not invoke this method again.

        Throws:
        java.lang.IllegalStateException - if isBinary() returns false
        See Also:
        getStringData()
      • getStringData

        java.lang.String getStringData()
        Returns the raw data in string.

        If the data is not cached in memory (inMemory() return false), the data will be read from getReaderData(). Furthermore, it also implies you can not invoke this method again.

        Throws:
        java.lang.IllegalStateException - if isBinary() returns false
        See Also:
        getByteData()
      • getStreamData

        java.io.InputStream getStreamData()
        Returns the raw data in InputStream.

        Note: it wraps getByteData() with ByteArrayInputStream if it is in memory (inMemory() returns true).

        Throws:
        java.lang.IllegalStateException - if isBinary() returns false.
        See Also:
        getReaderData()
      • getReaderData

        java.io.Reader getReaderData()
        Returns the raw data in Reader.

        Note: it wraps getStringData() with StringReader, if it is in memory (inMemory() returns true).

        Throws:
        java.lang.IllegalStateException - if isBinary() returns true.
        See Also:
        getStreamData()
      • getName

        java.lang.String getName()
        Returns the name (usually filename) of this media, or null if not available.
      • getFormat

        java.lang.String getFormat()
        Returns the format name, e.g., "jpeg", or null if not available.
        See Also:
        getContentType()
      • getContentType

        java.lang.String getContentType()
        Returns the content type, e.g., "image/jpeg", or null if not available.
        See Also:
        getFormat()
      • isContentDisposition

        boolean isContentDisposition()
        Whether to allow Content-Disposition or not when writing the media to response header.

        Default: true

        Since:
        7.0.0