org.zkoss.util.media
Class AMedia

java.lang.Object
  extended by org.zkoss.util.media.AMedia
All Implemented Interfaces:
Media

public class AMedia
extends java.lang.Object
implements Media

A media object holding content such PDF, HTML, DOC or XLS content.

Author:
tomyeh

Field Summary
protected static java.io.Reader DYNAMIC_READER
          Used if you want to implement a meida whose reader is created dynamically each time getReaderData() is called.
protected static java.io.InputStream DYNAMIC_STREAM
          Used if you want to implement a meida whose input stream is created dynamically each time getStreamData() is called.
 
Constructor Summary
AMedia(java.lang.String name, java.lang.String format, java.lang.String ctype, byte[] data)
          Construct with name, format, content type and binary data.
AMedia(java.lang.String name, java.lang.String format, java.lang.String ctype, java.io.InputStream data)
          Construct with name, format, content type and stream data (binary).
AMedia(java.lang.String name, java.lang.String format, java.lang.String ctype, java.io.Reader data)
          Construct with name, format, content type and reader data (textual).
AMedia(java.lang.String name, java.lang.String format, java.lang.String ctype, java.lang.String data)
          Construct with name, format, content type and text data.
 
Method Summary
 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 tis content is binary or text-based.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DYNAMIC_STREAM

protected static final java.io.InputStream DYNAMIC_STREAM
Used if you want to implement a meida whose input stream is created dynamically each time getStreamData() is called.

See Also:
AMedia(String,String,String,InputStream)

DYNAMIC_READER

protected static final java.io.Reader DYNAMIC_READER
Used if you want to implement a meida whose reader is created dynamically each time getReaderData() is called.

See Also:
AMedia(String,String,String,Reader)
Constructor Detail

AMedia

public AMedia(java.lang.String name,
              java.lang.String format,
              java.lang.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.
ctype - the content type; might be null.
data - the binary data; never null

AMedia

public AMedia(java.lang.String name,
              java.lang.String format,
              java.lang.String ctype,
              java.lang.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(java.lang.String name,
              java.lang.String format,
              java.lang.String ctype,
              java.io.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 dyanmically each tiime getStreamData() is called, you shall pass DYNAMIC_STREAM as the data argument. Then, override getStreamData() to return the correct stream.

AMedia

public AMedia(java.lang.String name,
              java.lang.String format,
              java.lang.String ctype,
              java.io.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 dyanmically each tiime getReaderData() is called, you shall pass DYNAMIC_READER as the data argument. Then, override getReaderData() to return the correct reader.
Method Detail

isBinary

public boolean isBinary()
Description copied from interface: Media
Returns whether the format of tis content is binary or text-based. If true, use Media.getByteData() or Media.getStreamData(), depending on Media.inMemory(), to retrieve its content. If false, use Media.getStringData() or Media.getReaderData(), depending on Media.inMemory(), to retrieve its content.

To decide which API to use, you need to examine both Media.isBinary() and Media.inMemory().

Specified by:
isBinary in interface Media
See Also:
Media.getStringData(), Media.getByteData(), Media.getReaderData(), Media.getStreamData()

inMemory

public boolean inMemory()
Description copied from interface: Media
Returns whether the data is cached in memory (in form of byte[] or String). If true, use Media.getByteData() or Media.getStringData(), depending on Media.isBinary(), to retrieve its content. If false, use Media.getStreamData() or Media.getReaderData(), depending on Media.isBinary(), to retrieve its content.

To decide which API to use, you need to examine both Media.isBinary() and Media.inMemory().

Specified by:
inMemory in interface Media
See Also:
Media.getStringData(), Media.getByteData(), Media.getReaderData(), Media.getStreamData()

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.

Specified by:
getByteData in interface Media
See Also:
Media.getStringData()

getStringData

public java.lang.String getStringData()
Description copied from interface: Media
Returns the raw data in string.

Specified by:
getStringData in interface Media
See Also:
Media.getByteData()

getStreamData

public java.io.InputStream getStreamData()
Description copied from interface: Media
Returns the raw data in InputStream.

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

Specified by:
getStreamData in interface Media
See Also:
Media.getReaderData()

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 interface Media
See Also:
Media.getStreamData()

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 interface Media

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 interface Media
See Also:
Media.getContentType()

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 interface Media
See Also:
Media.getFormat()

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object


Copyright © 2005-2007 Potix Corporation. All Rights Reserved.