Package org.zkoss.util.media
Class RepeatableMedia
- java.lang.Object
-
- org.zkoss.util.media.RepeatableMedia
-
- All Implemented Interfaces:
java.io.Serializable
,Media
public class RepeatableMedia extends java.lang.Object implements Media, java.io.Serializable
RepeatableMedia
adds functionality to another media, the ability to read repeatedly. Unlike other media,RepeatableMedia
usesRepeatableInputStream
, if binary, orRepeatableReader
to makegetStreamData()
andgetReaderData()
to be able to re-open whenInputStream.close()
orReader.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:
- Serialized Form
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete 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.static Media
getInstance(Media media)
Returns a repeatable media with a repeatable input stream or reader, or null if the given media is null.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 repeatable input stream, if the original input stream is not null.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
-
getInstance
public static Media getInstance(Media media)
Returns a repeatable media with a repeatable input stream or reader, or null if the given media is null.
-
getReaderData
public java.io.Reader getReaderData()
Description copied from interface:Media
Returns the raw data in Reader.Note: it wraps
Media.getStringData()
with StringReader, if it is in memory (Media.inMemory()
returns true).- Specified by:
getReaderData
in interfaceMedia
- See Also:
Media.getReaderData()
-
getStreamData
public java.io.InputStream getStreamData()
Returns the repeatable input stream, if the original input stream is not null.- Specified by:
getStreamData
in interfaceMedia
- See Also:
Media.getStreamData()
,RepeatableInputStream.getInstance(InputStream)
-
getByteData
public byte[] getByteData()
Description copied from interface:Media
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 (
Media.inMemory()
return false), the data will be read fromMedia.getStreamData()
. Furthermore, it also implies you can not invoke this method again.- Specified by:
getByteData
in interfaceMedia
- See Also:
Media.getByteData()
-
getContentType
public java.lang.String getContentType()
Description copied from interface:Media
Returns the content type, e.g., "image/jpeg", or null if not available.- Specified by:
getContentType
in interfaceMedia
- See Also:
Media.getContentType()
-
getFormat
public java.lang.String getFormat()
Description copied from interface:Media
Returns the format name, e.g., "jpeg", or null if not available.- Specified by:
getFormat
in interfaceMedia
- See Also:
Media.getFormat()
-
getName
public java.lang.String getName()
Description copied from interface:Media
Returns the name (usually filename) of this media, or null if not available.- Specified by:
getName
in interfaceMedia
- See Also:
Media.getName()
-
getStringData
public java.lang.String getStringData()
Description copied from interface:Media
Returns 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:
getStringData
in interfaceMedia
- See Also:
Media.getStringData()
-
inMemory
public boolean inMemory()
Description copied from interface:Media
Returns whether the data is cached in memory (in form of byte[] or String).- Specified by:
inMemory
in interfaceMedia
- See Also:
Media.inMemory()
-
isBinary
public boolean isBinary()
Description copied from interface:Media
Returns 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.- Specified by:
isBinary
in interfaceMedia
- See Also:
Media.isBinary()
-
isContentDisposition
public boolean isContentDisposition()
Description copied from interface:Media
Whether to allow Content-Disposition or not when writing the media to response header.Default: true
- Specified by:
isContentDisposition
in interfaceMedia
- See Also:
Media.isContentDisposition()
-
-