public abstract class ImageParser extends BinaryFileParser
Additionally, developers creating or enhancing classes derived from ImageParser are encouraged to include such checks in their code.
Constructor and Description |
---|
ImageParser() |
Modifier and Type | Method and Description |
---|---|
protected boolean |
canAcceptExtension(File file)
Indicates whether the ImageParser implementation can accept
the specified file based on its extension.
|
protected boolean |
canAcceptExtension(String fileName)
Indicates whether the ImageParser implementation can accept
the specified file name based on its extension.
|
boolean |
canAcceptType(ImageFormat type)
Indicates whether the ImageParser implementation can accept
the specified format
|
String |
dumpImageFile(byte[] bytes)
Write the ImageInfo and format-specific information for the image
content of the specified byte array to a string.
|
String |
dumpImageFile(ByteSource byteSource)
Write the ImageInfo and format-specific information for the image
content of the specified byte source to a string.
|
String |
dumpImageFile(File file)
Write the ImageInfo and format-specific information for the image
content of the specified file to a string.
|
boolean |
dumpImageFile(PrintWriter pw,
ByteSource byteSource)
Write the ImageInfo and format-specific information for the image
content of the specified byte source to a PrintWriter
|
protected abstract String[] |
getAcceptedExtensions()
Get an array of all accepted extensions
|
protected abstract ImageFormat[] |
getAcceptedTypes()
Get an array of ImageFormat objects describing all accepted types
|
List<BufferedImage> |
getAllBufferedImages(byte[] bytes)
Gets all images specified by the byte array (some
formats may include multiple images within a single data source).
|
List<BufferedImage> |
getAllBufferedImages(ByteSource byteSource)
Gets all images specified by the byte source (some
formats may include multiple images within a single data source).
|
List<BufferedImage> |
getAllBufferedImages(File file)
Gets all images specified by indicated file (some
formats may include multiple images within a single data source).
|
static ImageParser[] |
getAllImageParsers()
Gets an array of new instances of all image parsers.
|
BufferedImage |
getBufferedImage(byte[] bytes,
Map<String,Object> params)
Gets a buffered image specified by the byte array (for
sources that specify multiple images, choice of which image
is returned is implementation dependent).
|
abstract BufferedImage |
getBufferedImage(ByteSource byteSource,
Map<String,Object> params)
Gets a buffered image specified by the byte source (for
sources that specify multiple images, choice of which image
is returned is implementation dependent).
|
BufferedImage |
getBufferedImage(File file,
Map<String,Object> params)
Gets a buffered image specified by the indicated file (for
sources that specify multiple images, choice of which image
is returned is implementation dependent).
|
protected BufferedImageFactory |
getBufferedImageFactory(Map<String,Object> params)
Get an instance of IBufferedImageFactory based on the presence
of a specification for ImagingConstants..BUFFERED_IMAGE_FACTORY
within the supplied params.
|
abstract String |
getDefaultExtension()
Get the default extension for the format specified by an implementation
of ImageParser.
|
FormatCompliance |
getFormatCompliance(byte[] bytes)
Determines the format compliance of the content of the supplied byte
array based on rules provided by a specific implementation.
|
FormatCompliance |
getFormatCompliance(ByteSource byteSource)
Determines the format compliance of the content of the supplied byte
source based on rules provided by a specific implementation.
|
FormatCompliance |
getFormatCompliance(File file)
Determines the format compliance of the specified file based on
rules provided by a specific implementation.
|
byte[] |
getICCProfileBytes(byte[] bytes)
Get an array of bytes describing the International Color Consortium (ICC)
specification for the color space of the image contained in the
input byte array.
|
byte[] |
getICCProfileBytes(byte[] bytes,
Map<String,Object> params)
Get an array of bytes describing the International Color Consortium (ICC)
specification for the color space of the image contained in the
input byte array.
|
abstract byte[] |
getICCProfileBytes(ByteSource byteSource,
Map<String,Object> params)
Get an array of bytes describing the International Color Consortium (ICC)
specification for the color space of the image contained in the
input byteSource.
|
byte[] |
getICCProfileBytes(File file)
Get an array of bytes describing the International Color Consortium (ICC)
specification for the color space of the image contained in the
input file.
|
byte[] |
getICCProfileBytes(File file,
Map<String,Object> params)
Get an array of bytes describing the International Color Consortium (ICC)
specification for the color space of the image contained in the
input file.
|
ImageInfo |
getImageInfo(byte[] bytes,
Map<String,Object> params)
Get image information from the specified array of bytes.
|
ImageInfo |
getImageInfo(ByteSource byteSource)
Get image information from the specified ByteSource.
|
abstract ImageInfo |
getImageInfo(ByteSource byteSource,
Map<String,Object> params)
Get image information from the specified ByteSource.
|
ImageInfo |
getImageInfo(File file,
Map<String,Object> params)
Get image information from the specified file Format-specific
ImageParser implementations are expected to return a valid
ImageInfo object or to throw an ImageReadException if unable
to process the specified data.
|
Dimension |
getImageSize(byte[] bytes)
Get the size of the image described by the specified byte array.
|
Dimension |
getImageSize(byte[] bytes,
Map<String,Object> params)
Get the size of the image described by the specified byte array.
|
abstract Dimension |
getImageSize(ByteSource byteSource,
Map<String,Object> params)
Get the size of the image described by the specified ByteSource.
|
Dimension |
getImageSize(File file)
Get the size of the image described by the specified file.
|
Dimension |
getImageSize(File file,
Map<String,Object> params)
Get the size of the image described by the specified file.
|
ImageMetadata |
getMetadata(byte[] bytes)
Get image metadata from the specified array of bytes.
|
ImageMetadata |
getMetadata(byte[] bytes,
Map<String,Object> params)
Get image metadata from the specified array of bytes.
|
ImageMetadata |
getMetadata(ByteSource byteSource)
Get image metadata from the specified byte source.
|
abstract ImageMetadata |
getMetadata(ByteSource byteSource,
Map<String,Object> params)
Get image metadata from the specified byte source.
|
ImageMetadata |
getMetadata(File file)
Get image metadata from the specified file.
|
ImageMetadata |
getMetadata(File file,
Map<String,Object> params)
Get image metadata from the specified file.
|
abstract String |
getName()
Get a descriptive name for the implementation of an ImageParser.
|
static boolean |
isStrict(Map<String,Object> params)
A utility method to search a params specification and determine
whether it contains the ImagingConstants.PARAM_KEY_STRICT
specification.
|
void |
writeImage(BufferedImage src,
OutputStream os,
Map<String,Object> params)
Writes the content of a BufferedImage to the specified output
stream.
|
debugNumber, debugNumber, getByteOrder, setByteOrder
public static ImageParser[] getAllImageParsers()
public final ImageMetadata getMetadata(ByteSource byteSource) throws ImageReadException, IOException
byteSource
- A valid byte source.ImageReadException
- In the event that the ByteSource
content does not conform to the format of the specific parser
implementation.IOException
- In the event of unsuccessful data read operation.public abstract ImageMetadata getMetadata(ByteSource byteSource, Map<String,Object> params) throws ImageReadException, IOException
The params argument provides a mechanism for individual implementations to pass optional information into the parser. Not all formats will require this capability. Because the base class may call this method with a null params argument, implementations should always include logic for ignoring null input.
byteSource
- A valid byte source.params
- Optional instructions for special-handling or
interpretation of the input data (null objects are permitted and
must be supported by implementations).ImageReadException
- In the event that the ByteSource
content does not conform to the format of the specific parser
implementation.IOException
- In the event of unsuccessful data read operation.public final ImageMetadata getMetadata(byte[] bytes) throws ImageReadException, IOException
bytes
- A valid array of bytesImageReadException
- In the event that the specified content
does not conform to the format of the specific
parser implementation.IOException
- In the event of unsuccessful data read operation.public final ImageMetadata getMetadata(byte[] bytes, Map<String,Object> params) throws ImageReadException, IOException
The params argument provides a mechanism for individual implementations to pass optional information into the parser. Not all formats will require this capability. Because the base class may call this method with a null params argument, implementations should always include logic for ignoring null input.
bytes
- A valid array of bytesparams
- Optional instructions for special-handling or
interpretation of the input data (null objects are permitted and
must be supported by implementations).ImageReadException
- In the event that the specified content
does not conform to the format of the specific
parser implementation.IOException
- In the event of unsuccessful data read operation.public final ImageMetadata getMetadata(File file) throws ImageReadException, IOException
file
- A valid reference to a file.ImageReadException
- In the event that the specified content
does not conform to the format of the specific
parser implementation.IOException
- In the event of unsuccessful file read or
access operation.public final ImageMetadata getMetadata(File file, Map<String,Object> params) throws ImageReadException, IOException
The params argument provides a mechanism for individual implementations to pass optional information into the parser. Not all formats will require this capability. Because the base class may call this method with a null params argument, implementations should always include logic for ignoring null input.
file
- A valid reference to a file.params
- Optional instructions for special-handling or
interpretation of the input data (null objects are permitted and
must be supported by implementations).ImageReadException
- In the event that the specified content
does not conform to the format of the specific
parser implementation.IOException
- In the event of unsuccessful file read or
access operation.public abstract ImageInfo getImageInfo(ByteSource byteSource, Map<String,Object> params) throws ImageReadException, IOException
The params argument provides a mechanism for individual implementations to pass optional information into the parser. Not all formats will require this capability. Because the base class may call this method with a null params argument, implementations should always include logic for ignoring null input.
byteSource
- A valid ByteSource objectparams
- Optional instructions for special-handling or interpretation
of the input data (null objects are permitted and
must be supported by implementations).ImageReadException
- In the event that the specified content
does not conform to the format of the specific
parser implementation.IOException
- In the event of unsuccessful data access operation.public final ImageInfo getImageInfo(ByteSource byteSource) throws ImageReadException, IOException
byteSource
- A valid ByteSource objectImageReadException
- In the event that the specified content
does not conform to the format of the specific
parser implementation.IOException
- In the event of unsuccessful data
access operation.public final ImageInfo getImageInfo(byte[] bytes, Map<String,Object> params) throws ImageReadException, IOException
The params argument provides a mechanism for individual implementations to pass optional information into the parser. Not all formats will require this capability. Because the base class may call this method with a null params argument, implementations should always include logic for ignoring null input.
bytes
- A valid array of bytesparams
- Optional instructions for special-handling or
interpretation of the input data (null objects are permitted and
must be supported by implementations).ImageReadException
- In the event that the specified content
does not conform to the format of the specific
parser implementation.IOException
- In the event of unsuccessful data
access operation.public final ImageInfo getImageInfo(File file, Map<String,Object> params) throws ImageReadException, IOException
The params argument provides a mechanism for individual implementations to pass optional information into the parser. Not all formats will require this capability. Because the base class may call this method with a null params argument, implementations should always include logic for ignoring null input.
file
- A valid File objectparams
- Optional instructions for special-handling or
interpretation of the input data (null objects are permitted and
must be supported by implementations).ImageReadException
- In the event that the specified content
does not conform to the format of the specific
parser implementation.IOException
- In the event of unsuccessful file read or
access operation.public FormatCompliance getFormatCompliance(ByteSource byteSource) throws ImageReadException, IOException
byteSource
- A valid instance of ByteSourceImageReadException
- may be thrown by sub-classesIOException
- may be thrown by sub-classespublic final FormatCompliance getFormatCompliance(byte[] bytes) throws ImageReadException, IOException
bytes
- A valid byte array.ImageReadException
- may be thrown by sub-classesIOException
- may be thrown by sub-classespublic final FormatCompliance getFormatCompliance(File file) throws ImageReadException, IOException
file
- A valid reference to a file.ImageReadException
- may be thrown by sub-classesIOException
- may be thrown by sub-classespublic List<BufferedImage> getAllBufferedImages(ByteSource byteSource) throws ImageReadException, IOException
byteSource
- A valid instance of ByteSource.ImageReadException
- In the event that the specified content
does not conform to the format of the specific
parser implementation.IOException
- In the event of unsuccessful read or access operation.public final List<BufferedImage> getAllBufferedImages(byte[] bytes) throws ImageReadException, IOException
bytes
- A valid byte arrayImageReadException
- In the event that the specified content
does not conform to the format of the specific
parser implementation.IOException
- In the event of unsuccessful read or access operation.public final List<BufferedImage> getAllBufferedImages(File file) throws ImageReadException, IOException
file
- A valid reference to a file.ImageReadException
- In the event that the specified content
does not conform to the format of the specific
parser implementation.IOException
- In the event of unsuccessful read or access operation.public abstract BufferedImage getBufferedImage(ByteSource byteSource, Map<String,Object> params) throws ImageReadException, IOException
byteSource
- A valid instance of ByteSourceparams
- Optional instructions for special-handling or
interpretation of the input data (null objects are permitted and
must be supported by implementations).ImageReadException
- In the event that the specified content
does not conform to the format of the specific
parser implementation.IOException
- In the event of unsuccessful read or access operation.public final BufferedImage getBufferedImage(byte[] bytes, Map<String,Object> params) throws ImageReadException, IOException
bytes
- A valid byte arrayparams
- Optional instructions for special-handling or
interpretation of the input data (null objects are permitted and
must be supported by implementations).ImageReadException
- In the event that the specified content
does not conform to the format of the specific
parser implementation.IOException
- In the event of unsuccessful read or access operation.public final BufferedImage getBufferedImage(File file, Map<String,Object> params) throws ImageReadException, IOException
file
- A valid file reference.params
- Optional instructions for special-handling or
interpretation of the input data (null objects are permitted and
must be supported by implementations).ImageReadException
- In the event that the specified content
does not conform to the format of the specific
parser implementation.IOException
- In the event of unsuccessful read or access operation.public void writeImage(BufferedImage src, OutputStream os, Map<String,Object> params) throws ImageWriteException, IOException
The params argument provides a mechanism for individual implementations to pass optional information into the parser. Not all formats will support this capability. Currently, some of the parsers do not check for null arguments. So in cases where no optional specifications are supported, application code should pass in an empty instance of an implementation of the map interface (i.e. an empty HashMap).
src
- An image giving the source content for outputos
- A valid output stream for storing the formatted imageparams
- A non-null Map implementation supplying optional,
format-specific instructions for output
(such as selections for data compression, color models, etc.)ImageWriteException
- In the event that the output format
cannot handle the input image or invalid params are specified.IOException
- In the event of an write error from
the output stream.public final Dimension getImageSize(byte[] bytes) throws ImageReadException, IOException
bytes
- A valid byte array.ImageReadException
- In the event that the specified content
does not conform to the format of the specific
parser implementation.IOException
- In the event of unsuccessful read or access operation.public final Dimension getImageSize(byte[] bytes, Map<String,Object> params) throws ImageReadException, IOException
bytes
- A valid byte array.params
- Optional instructions for special-handling or
interpretation of the input data.ImageReadException
- In the event that the specified content
does not conform to the format of the specific
parser implementation.IOException
- In the event of unsuccessful read or access operation.public final Dimension getImageSize(File file) throws ImageReadException, IOException
file
- A valid reference to a file.ImageReadException
- In the event that the specified content
does not conform to the format of the specific
parser implementation.IOException
- In the event of unsuccessful read or access operation.public final Dimension getImageSize(File file, Map<String,Object> params) throws ImageReadException, IOException
file
- A valid reference to a file.params
- Optional instructions for special-handling or
interpretation of the input data.ImageReadException
- In the event that the specified content
does not conform to the format of the specific
parser implementation.IOException
- In the event of unsuccessful read or access operation.public abstract Dimension getImageSize(ByteSource byteSource, Map<String,Object> params) throws ImageReadException, IOException
byteSource
- A valid reference to a ByteSource.params
- Optional instructions for special-handling or
interpretation of the input data.ImageReadException
- In the event that the specified content
does not conform to the format of the specific
parser implementation.IOException
- In the event of unsuccessful read or access operation.public final byte[] getICCProfileBytes(byte[] bytes) throws ImageReadException, IOException
bytes
- A valid array of bytes.ImageReadException
- In the event that the specified content
does not conform to the format of the specific
parser implementation.IOException
- In the event of unsuccessful read or access operation.public final byte[] getICCProfileBytes(byte[] bytes, Map<String,Object> params) throws ImageReadException, IOException
bytes
- A valid array of bytes.params
- Optional instructions for special-handling or
interpretation of the input data.ImageReadException
- In the event that the specified content
does not conform to the format of the specific
parser implementation.IOException
- In the event of unsuccessful read or access operation.public final byte[] getICCProfileBytes(File file) throws ImageReadException, IOException
file
- A valid file reference.ImageReadException
- In the event that the specified content
does not conform to the format of the specific
parser implementation.IOException
- In the event of unsuccessful read or access operation.public final byte[] getICCProfileBytes(File file, Map<String,Object> params) throws ImageReadException, IOException
file
- A valid file reference.params
- Optional instructions for special-handling or
interpretation of the input data.ImageReadException
- In the event that the specified content
does not conform to the format of the specific
parser implementation.IOException
- In the event of unsuccessful read or access operation.public abstract byte[] getICCProfileBytes(ByteSource byteSource, Map<String,Object> params) throws ImageReadException, IOException
byteSource
- A valid ByteSource.params
- Optional instructions for special-handling or
interpretation of the input data.ImageReadException
- In the event that the specified content
does not conform to the format of the specific
parser implementation.IOException
- In the event of unsuccessful read or access operation.public final String dumpImageFile(byte[] bytes) throws ImageReadException, IOException
bytes
- A valid array of bytes.ImageReadException
- In the event that the specified content
does not conform to the format of the specific
parser implementation.IOException
- In the event of unsuccessful read or access operation.public final String dumpImageFile(File file) throws ImageReadException, IOException
file
- A valid file reference.ImageReadException
- In the event that the specified content
does not conform to the format of the specific
parser implementation.IOException
- In the event of unsuccessful read or access operation.public final String dumpImageFile(ByteSource byteSource) throws ImageReadException, IOException
byteSource
- A valid byte source.ImageReadException
- In the event that the specified content
does not conform to the format of the specific
parser implementation.IOException
- In the event of unsuccessful read or access operation.public boolean dumpImageFile(PrintWriter pw, ByteSource byteSource) throws ImageReadException, IOException
pw
- print writer used for writing the ImageInfobyteSource
- A valid byte source.ImageReadException
- In the event that the specified content
does not conform to the format of the specific
parser implementation.IOException
- In the event of unsuccessful read or access operation.public abstract String getName()
public abstract String getDefaultExtension()
protected abstract String[] getAcceptedExtensions()
protected abstract ImageFormat[] getAcceptedTypes()
public boolean canAcceptType(ImageFormat type)
type
- An instance of ImageFormat.protected final boolean canAcceptExtension(File file)
file
- An valid file reference.protected final boolean canAcceptExtension(String fileName)
fileName
- A valid string giving a file name or file path.protected BufferedImageFactory getBufferedImageFactory(Map<String,Object> params)
params
- A valid Map object, or a null.public static boolean isStrict(Map<String,Object> params)
params
- A valid Map object (or a null).Copyright © 2007–2020 The Apache Software Foundation. All rights reserved.