Package org.zkoss.util.media
Class RepeatableMedia
java.lang.Object
org.zkoss.util.media.RepeatableMedia
- All Implemented Interfaces:
Serializable,Media
RepeatableMedia adds functionality to another media,
the ability to read repeatedly.
Unlike other media, RepeatableMedia uses
RepeatableInputStream, if binary, or RepeatableReader
to make getStreamData() and getReaderData() to
be able to re-open when InputStream.close()
or Reader.close() is called.
In other words, the buffered input stream of the give media
is never closed until it is GC-ed.- Since:
- 3.0.4
- Author:
- jumperchen, tomyeh
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionbyte[]Returns the raw data in byte array.Returns the content type, e.g., "image/jpeg", or null if not available.Returns the format name, e.g., "jpeg", or null if not available.static MediagetInstance(Media media) Returns a repeatable media with a repeatable input stream or reader, or null if the given media is null.getName()Returns the name (usually filename) of this media, or null if not available.Returns the raw data in Reader.Returns the repeatable input stream, if the original input stream is not null.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.booleanWhether to allow Content-Disposition or not when writing the media to response header.
-
Method Details
-
getInstance
Returns a repeatable media with a repeatable input stream or reader, or null if the given media is null. -
getReaderData
Description copied from interface:MediaReturns the raw data in Reader.Note: it wraps
Media.getStringData()with StringReader, if it is in memory (Media.inMemory()returns true).- Specified by:
getReaderDatain interfaceMedia- See Also:
-
getStreamData
Returns the repeatable input stream, if the original input stream is not null.- Specified by:
getStreamDatain interfaceMedia- See Also:
-
getByteData
public byte[] getByteData()Description copied from interface:MediaReturns 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 (
Media.inMemory()return false), the data will be read fromMedia.getStreamData(). Furthermore, it also implies you can not invoke this method again.- Specified by:
getByteDatain interfaceMedia- See Also:
-
getContentType
Description copied from interface:MediaReturns the content type, e.g., "image/jpeg", or null if not available.- Specified by:
getContentTypein interfaceMedia- See Also:
-
getFormat
Description copied from interface:MediaReturns the format name, e.g., "jpeg", or null if not available. -
getName
Description copied from interface:MediaReturns the name (usually filename) of this media, or null if not available. -
getStringData
Description copied from interface:MediaReturns the raw data in string.If the data is not cached in memory (
Media.inMemory()return false), the data will be read fromMedia.getReaderData(). Furthermore, it also implies you can not invoke this method again.- Specified by:
getStringDatain interfaceMedia- See Also:
-
inMemory
public boolean inMemory()Description copied from interface:MediaReturns whether the data is cached in memory (in form of byte[] or String). -
isBinary
public boolean isBinary()Description copied from interface:MediaReturns whether the format of this content is binary or text-based. If true, useMedia.getByteData()orMedia.getStreamData()to retrieve its content. If false, useMedia.getStringData()orMedia.getReaderData()to retrieve its content. -
isContentDisposition
public boolean isContentDisposition()Description copied from interface:MediaWhether to allow Content-Disposition or not when writing the media to response header.Default: true
- Specified by:
isContentDispositionin interfaceMedia- See Also:
-