Package org.zkoss.image
Class AImage
java.lang.Object
org.zkoss.image.AImage
- All Implemented Interfaces:
Serializable,Image,Media
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 Media interface.
To encode AWT image to an instance of Image,
use Images.encode(java.lang.String, java.awt.image.RenderedImage, float, boolean).
- Author:
- tomyeh
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionConstructs an image with a file.Constructs an image with a file name.Constructs an image with a byte array.AImage(String name, InputStream is) Constructs an image with an input stream.Constructs an image with an URL. -
Method Summary
Modifier and TypeMethodDescriptionbyte[]Returns the raw data in byte array.final StringReturns the content type, e.g., "image/jpeg", or null if not available.final StringReturns the format name, e.g., "jpeg", or null if not available.final intReturns the height.final StringgetName()Returns the name (usually filename) of this media, or null if not available.final ReaderAlways throwsIllegalStateException.final InputStreamReturn aByteArrayInputStreamthat contains data ofgetByteData().final StringAlways throwsIllegalStateException.final intgetWidth()Returns the width.final booleaninMemory()Returns whether the data is cached in memory (in form of byte[] or String).final 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.final ImageIconConverts to an image icon.
-
Constructor Details
-
AImage
Constructs an image with a byte array.- Throws:
IOException
-
AImage
Constructs an image with an input stream.Note that this method automatically closes the input stream (since ZK 3.0.0).
- Throws:
IOException
-
AImage
Constructs an image with a file name.- Throws:
IOException
-
AImage
Constructs an image with a file.- Throws:
IOException
-
AImage
Constructs an image with an URL.- Throws:
IOException
-
-
Method Details
-
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. -
inMemory
public final boolean inMemory()Description copied from interface:MediaReturns whether the data is cached in memory (in form of byte[] or String). -
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:
-
getStringData
Always throwsIllegalStateException.- Specified by:
getStringDatain interfaceMedia- See Also:
-
getStreamData
Return aByteArrayInputStreamthat contains data ofgetByteData().Though harmless, the caller doesn't need to close the returned stream.
- Specified by:
getStreamDatain interfaceMedia- See Also:
-
getReaderData
Always throwsIllegalStateException.- Specified by:
getReaderDatain interfaceMedia- See Also:
-
getName
Description copied from interface:MediaReturns the name (usually filename) of this media, or null if not available. -
getFormat
Description copied from interface:MediaReturns the format name, e.g., "jpeg", or null if not available. -
getContentType
Description copied from interface:MediaReturns the content type, e.g., "image/jpeg", or null if not available.- Specified by:
getContentTypein interfaceMedia- See Also:
-
getWidth
public final int getWidth()Returns the width. -
getHeight
public final int getHeight()Returns the height. -
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
-