Interface Media
-
- All Known Implementing Classes:
AAudio,AImage,AMedia,AVideo,RepeatableMedia
public interface MediaRepresents 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.StringgetContentType()Returns the content type, e.g., "image/jpeg", or null if not available.java.lang.StringgetFormat()Returns the format name, e.g., "jpeg", or null if not available.java.lang.StringgetName()Returns the name (usually filename) of this media, or null if not available.java.io.ReadergetReaderData()Returns the raw data in Reader.java.io.InputStreamgetStreamData()Returns the raw data in InputStream.java.lang.StringgetStringData()Returns the raw data in string.booleaninMemory()Returns whether the data is cached in memory (in form of byte[] or String).booleanisBinary()Returns whether the format of this content is binary or text-based.booleanisContentDisposition()Whether to allow Content-Disposition or not when writing the media to response header.
-
-
-
Method Detail
-
isBinary
boolean isBinary()
Returns whether the format of this content is binary or text-based. If true, usegetByteData()orgetStreamData()to retrieve its content. If false, usegetStringData()orgetReaderData()to retrieve its content.- See Also:
getStringData(),getByteData(),getReaderData(),getStreamData()
-
inMemory
boolean inMemory()
Returns whether the data is cached in memory (in form of byte[] or String).- See Also:
getStringData(),getByteData(),getReaderData(),getStreamData()
-
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 fromgetStreamData(). Furthermore, it also implies you can not invoke this method again.- Throws:
java.lang.IllegalStateException- ifisBinary()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 fromgetReaderData(). Furthermore, it also implies you can not invoke this method again.- Throws:
java.lang.IllegalStateException- ifisBinary()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- ifisBinary()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- ifisBinary()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
-
-