|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectus.zuercher.gpx2map.image.netpbm.NetpbmImageFactory
public class NetpbmImageFactory
NetpbmImageFactory is a factory for NetpbmImage objects.
| Nested Class Summary | |
|---|---|
private class |
NetpbmImageFactory.CanLoadLogicTarget
CanLoadLogicTarget implements NetpbmImageFactory.GzipRetryLogicTarget to retrieve
the Netpbm magic number from an image file. |
private static class |
NetpbmImageFactory.ExceptionHolder
ExceptionHolder holds an IOException for later throwing. |
private class |
NetpbmImageFactory.GzipRetryLogic
GzipRetryLogic encapsulates the logic of reading Netpbm files that may or may not be gzipped. |
private static interface |
NetpbmImageFactory.GzipRetryLogicTarget
|
private class |
NetpbmImageFactory.LoadImageLogicTarget
LoadImageLogicTarget implements NetpbmImageFactory.GzipRetryLogicTarget to read
image data from the input stream. |
| Field Summary | |
|---|---|
private static List<ImageFormatDescriptor> |
formatDescriptors
List of ImageFormatDescriptor objects for our supported
formats. |
static NetpbmImageFactory |
instance
NetpbmImageFactory singleton instance. |
static ImageFormatDescriptor |
PAM_IMAGE_FORMAT_DESCRIPTOR
PAM ImageFormatDescriptor. |
static ImageFormatDescriptor |
PPM_IMAGE_FORMAT_DESCRIPTOR
PPM ImageFormatDescriptor. |
| Constructor Summary | |
|---|---|
private |
NetpbmImageFactory()
NetpbmImageFactory is a singleton. |
| Method Summary | |
|---|---|
boolean |
canLoad(File imageFile)
Tests whether the given file contains a supported Netpbm image format. |
private boolean |
canLoad(NetpbmImageFactory.GzipRetryLogic logic)
Tests whether an image's format is supported using the given NetpbmImageFactory.GzipRetryLogic object. |
boolean |
canLoad(URL imageUrl)
Tests whether the given URL refers to a supported Netpbm image format. |
private void |
closeQuietly(InputStream input)
Closes an input stream and silently discards IOExceptions encountered during closure. |
List<ImageFormatDescriptor> |
getSupportedImageFormats()
Returns the ImageFormatDescriptors for
image formats supported by this factory. |
NetpbmImage |
loadImage(File netpbmImageFile)
Loads a Netpbm-compatible image from the given filename. |
private NetpbmImage |
loadImage(NetpbmImageFactory.GzipRetryLogic logic)
Loads an image using the given NetpbmImageFactory.GzipRetryLogic object. |
NetpbmImage |
loadImage(URL netpbmImageUrl)
Loads a Netpbm-compatible image from the given URL. |
private NetpbmImage |
makeImage(InputStream input,
NetpbmImageFactory.ExceptionHolder exceptionHolder)
Load an image given an input stream. |
private BufferedInputStream |
makeInputStream(File file,
boolean useGzip)
Create a input stream from a File. |
private BufferedInputStream |
makeInputStream(URL url,
boolean useGzip)
Create a input stream from a URL. |
private String |
readMagic(InputStream input)
Reads the Netpbm magic number from the start of a file. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final ImageFormatDescriptor PAM_IMAGE_FORMAT_DESCRIPTOR
ImageFormatDescriptor.
public static final ImageFormatDescriptor PPM_IMAGE_FORMAT_DESCRIPTOR
ImageFormatDescriptor.
public static final NetpbmImageFactory instance
private static final List<ImageFormatDescriptor> formatDescriptors
ImageFormatDescriptor objects for our supported
formats.
| Constructor Detail |
|---|
private NetpbmImageFactory()
instance| Method Detail |
|---|
public List<ImageFormatDescriptor> getSupportedImageFormats()
ImageFormatDescriptors for
image formats supported by this factory.
getSupportedImageFormats in interface ImageFactory
public boolean canLoad(File imageFile)
throws IOException
canLoad in interface ImageFactoryimageFile - the file to test
IOException - if the file cannot be read
public boolean canLoad(URL imageUrl)
throws IOException
canLoad in interface ImageFactoryimageUrl - the URL to test
IOException - if the URL cannot be read
private boolean canLoad(NetpbmImageFactory.GzipRetryLogic logic)
throws IOException
NetpbmImageFactory.GzipRetryLogic object.
logic - Gzip retry logic for a file or URL
IOException - if there's an error reading the image data
public NetpbmImage loadImage(File netpbmImageFile)
throws IOException,
UnknownNetpbmFormatException
loadImage in interface ImageFactorynetpbmImageFile - location of a netpbm image
IOException - if the file cannot be read or the magic number
is not recognized.
UnknownNetpbmFormatException - if the file format is not
recognized
public NetpbmImage loadImage(URL netpbmImageUrl)
throws IOException,
UnknownNetpbmFormatException
loadImage in interface ImageFactorynetpbmImageUrl - location of a netpbm image
IOException - if the file cannot be read or the magic number
is not recognized.
UnknownNetpbmFormatException - if the file format is not
recognized
private NetpbmImage loadImage(NetpbmImageFactory.GzipRetryLogic logic)
throws IOException,
UnknownNetpbmFormatException
NetpbmImageFactory.GzipRetryLogic object.
logic - Gzip retry logic for a file or URL
IOException - if there's an error reading the image data
UnknownNetpbmFormatException - if the image format is not
supported
private BufferedInputStream makeInputStream(File file,
boolean useGzip)
throws IOException
file - the file to readuseGzip - flag controlling use of gzip
IOException - if there's an error opening the file
private BufferedInputStream makeInputStream(URL url,
boolean useGzip)
throws IOException
url - the URL to readuseGzip - flag controlling use of gzip
IOException - if there's an error opening the URL
private NetpbmImage makeImage(InputStream input,
NetpbmImageFactory.ExceptionHolder exceptionHolder)
throws IOException
NetpbmImage to close the input stream when all image
data has been loaded.
input - an input stream that supports mark/resetexceptionHolder - place to store the IOException that
caused a null return value, if any.
IOException - if mark/reset is not supported; if there's an
error reading the magic number; if the stream
does not contain enough data to determine the
magic number; if an error occurs while reseting
the stream after reading the magic number.
private String readMagic(InputStream input)
throws IOException
input - an input stream that supports mark/reset.
IOException - if there's an error reading the file or mark/reset
is not supportedprivate void closeQuietly(InputStream input)
input -
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||