Package org.zkoss.image
Class AImage
- java.lang.Object
-
- org.zkoss.image.AImage
-
public class AImage extends java.lang.Object implements Image, java.io.Serializable
Represents an image. Unlike java.awt.Image and javax.swing.ImageIcon, this class holds the raw image data, i.e., the original format, as opaque.In other words, it is used to retrieve and store the opaque data as polymorphic thru the
Mediainterface.To encode AWT image to an instance of
Image, useImages.encode(java.lang.String, java.awt.image.RenderedImage, float, boolean).- Author:
- tomyeh
- See Also:
Images.encode(java.lang.String, java.awt.image.RenderedImage, float, boolean), Serialized Form
-
-
Constructor Summary
Constructors Constructor Description AImage(java.io.File file)Constructs an image with a file.AImage(java.lang.String filename)Constructs an image with a file name.AImage(java.lang.String name, byte[] data)Constructs an image with a byte array.AImage(java.lang.String name, java.io.InputStream is)Constructs an image with an input stream.AImage(java.net.URL url)Constructs an image with an URL.
-
Method Summary
All Methods Instance Methods Concrete 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.intgetHeight()Returns the height.java.lang.StringgetName()Returns the name (usually filename) of this media, or null if not available.java.io.ReadergetReaderData()Always throwsIllegalStateException.java.io.InputStreamgetStreamData()Return aByteArrayInputStreamthat contains data ofgetByteData().java.lang.StringgetStringData()Always throwsIllegalStateException.intgetWidth()Returns the width.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.javax.swing.ImageIcontoImageIcon()Converts to an image icon.
-
-
-
Constructor Detail
-
AImage
public AImage(java.lang.String name, byte[] data) throws java.io.IOExceptionConstructs an image with a byte array.- Throws:
java.io.IOException
-
AImage
public AImage(java.lang.String name, java.io.InputStream is) throws java.io.IOExceptionConstructs an image with an input stream.Note that this method automatically closes the input stream (since ZK 3.0.0).
- Throws:
java.io.IOException
-
AImage
public AImage(java.lang.String filename) throws java.io.IOExceptionConstructs an image with a file name.- Throws:
java.io.IOException
-
AImage
public AImage(java.io.File file) throws java.io.IOExceptionConstructs an image with a file.- Throws:
java.io.IOException
-
AImage
public AImage(java.net.URL url) throws java.io.IOExceptionConstructs an image with an URL.- Throws:
java.io.IOException
-
-
Method Detail
-
isBinary
public final 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.- Specified by:
isBinaryin interfaceMedia- See Also:
Media.getStringData(),Media.getByteData(),Media.getReaderData(),Media.getStreamData()
-
inMemory
public final boolean inMemory()
Description copied from interface:MediaReturns whether the data is cached in memory (in form of byte[] or String).- Specified by:
inMemoryin interfaceMedia- See Also:
Media.getStringData(),Media.getByteData(),Media.getReaderData(),Media.getStreamData()
-
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:
Media.getStringData()
-
getStringData
public final java.lang.String getStringData()
Always throwsIllegalStateException.- Specified by:
getStringDatain interfaceMedia- See Also:
Media.getByteData()
-
getStreamData
public final java.io.InputStream getStreamData()
Return aByteArrayInputStreamthat contains data ofgetByteData().Though harmless, the caller doesn't need to close the returned stream.
- Specified by:
getStreamDatain interfaceMedia- See Also:
Media.getReaderData()
-
getReaderData
public final java.io.Reader getReaderData()
Always throwsIllegalStateException.- Specified by:
getReaderDatain interfaceMedia- See Also:
Media.getStreamData()
-
getName
public final java.lang.String getName()
Description copied from interface:MediaReturns the name (usually filename) of this media, or null if not available.
-
getFormat
public final java.lang.String getFormat()
Description copied from interface:MediaReturns the format name, e.g., "jpeg", or null if not available.- Specified by:
getFormatin interfaceMedia- See Also:
Media.getContentType()
-
getContentType
public final java.lang.String getContentType()
Description copied from interface:MediaReturns the content type, e.g., "image/jpeg", or null if not available.- Specified by:
getContentTypein interfaceMedia- See Also:
Media.getFormat()
-
getHeight
public final int getHeight()
Returns the height.
-
toImageIcon
public final javax.swing.ImageIcon toImageIcon()
Converts to an image icon.- Specified by:
toImageIconin interfaceImage
-
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
-
-