Class ImageUtil
- java.lang.Object
-
- org.apache.xmlgraphics.image.loader.util.ImageUtil
-
public final class ImageUtil extends Object
Helper and convenience methods for working with the image package.
-
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static InputStreamautoDecorateInputStream(InputStream in)Automatically decorates an InputStream so it is buffered.static voidcloseQuietly(Source src)Deprecated.useXmlSourceUtil.closeQuietly(Source)insteadstatic InputStreamdecorateMarkSupported(InputStream in)Decorates an InputStream with a BufferedInputStream if it doesn't support mark()/reset().static MapgetDefaultHints(ImageSessionContext session)Creates a new hint Map with values from the FOUserAgent.static ImageInputStreamgetImageInputStream(Source src)Returns the ImageInputStream of a Source object.static InputStreamgetInputStream(Source src)Deprecated.Please useXmlSourceUtil.getInputStream(Source)instead.static IntegergetPageIndexFromURI(String uri)Extracts page index information from a URI.static booleanhasImageInputStream(Source src)Indicates whether the Source object has an ImageInputStream instance.static booleanhasInputStream(Source src)Indicates whether the Source object has an InputStream instance.static booleanhasReader(Source src)Deprecated.useXmlSourceUtil.hasReader(Source)insteadstatic ImageInputStreamignoreFlushing(ImageInputStream in)Decorates an ImageInputStream so the flush*() methods are ignored and have no effect.static booleanisGZIPCompressed(InputStream in)Indicates whether an InputStream is GZIP compressed.static ImageInputStreamneedImageInputStream(Source src)Returns the ImageInputStream of a Source object.static InputStreamneedInputStream(Source src)Deprecated.useXmlSourceUtil.needInputStream(Source)insteadstatic intneedPageIndexFromURI(String uri)Extracts page index information from a URI.static voidremoveStreams(Source src)Deprecated.useXmlSourceUtil.removeStreams(Source)instead
-
-
-
Method Detail
-
getInputStream
@Deprecated public static InputStream getInputStream(Source src)
Deprecated.Please useXmlSourceUtil.getInputStream(Source)instead.Returns the InputStream of a Source object.- Parameters:
src- the Source object- Returns:
- the InputStream (or null if there's not InputStream available)
-
getImageInputStream
public static ImageInputStream getImageInputStream(Source src)
Returns the ImageInputStream of a Source object.- Parameters:
src- the Source object- Returns:
- the ImageInputStream (or null if there's not ImageInputStream available)
-
needInputStream
@Deprecated public static InputStream needInputStream(Source src)
Deprecated.useXmlSourceUtil.needInputStream(Source)insteadReturns the InputStream of a Source object. This method throws an IllegalArgumentException if there's no InputStream instance available from the Source object.- Parameters:
src- the Source object- Returns:
- the InputStream
-
needImageInputStream
public static ImageInputStream needImageInputStream(Source src)
Returns the ImageInputStream of a Source object. This method throws an IllegalArgumentException if there's no ImageInputStream instance available from the Source object.- Parameters:
src- the Source object- Returns:
- the ImageInputStream
-
hasInputStream
public static boolean hasInputStream(Source src)
Indicates whether the Source object has an InputStream instance.- Parameters:
src- the Source object- Returns:
- true if an InputStream is available
-
hasReader
@Deprecated public static boolean hasReader(Source src)
Deprecated.useXmlSourceUtil.hasReader(Source)insteadIndicates whether the Source object has a Reader instance.- Parameters:
src- the Source object- Returns:
- true if an Reader is available
-
hasImageInputStream
public static boolean hasImageInputStream(Source src)
Indicates whether the Source object has an ImageInputStream instance.- Parameters:
src- the Source object- Returns:
- true if an ImageInputStream is available
-
removeStreams
@Deprecated public static void removeStreams(Source src)
Deprecated.useXmlSourceUtil.removeStreams(Source)insteadRemoves any references to InputStreams or Readers from the given Source to prohibit accidental/unwanted use by a component further downstream.- Parameters:
src- the Source object
-
closeQuietly
@Deprecated public static void closeQuietly(Source src)
Deprecated.useXmlSourceUtil.closeQuietly(Source)insteadCloses the InputStreams or ImageInputStreams of Source objects. Any exception occurring while closing the stream is ignored.- Parameters:
src- the Source object
-
ignoreFlushing
public static ImageInputStream ignoreFlushing(ImageInputStream in)
Decorates an ImageInputStream so the flush*() methods are ignored and have no effect. The decoration is implemented using a dynamic proxy.- Parameters:
in- the ImageInputStream- Returns:
- the decorated ImageInputStream
-
isGZIPCompressed
public static boolean isGZIPCompressed(InputStream in) throws IOException
Indicates whether an InputStream is GZIP compressed. The InputStream must support mark()/reset().- Parameters:
in- the InputStream (must return true on markSupported())- Returns:
- true if the InputStream is GZIP compressed
- Throws:
IOException- in case of an I/O error
-
decorateMarkSupported
public static InputStream decorateMarkSupported(InputStream in)
Decorates an InputStream with a BufferedInputStream if it doesn't support mark()/reset().- Parameters:
in- the InputStream- Returns:
- the decorated InputStream
-
autoDecorateInputStream
public static InputStream autoDecorateInputStream(InputStream in) throws IOException
Automatically decorates an InputStream so it is buffered. Furthermore, it makes sure it is decorated with a GZIPInputStream if the stream is GZIP compressed.- Parameters:
in- the InputStream- Returns:
- the decorated InputStream
- Throws:
IOException- in case of an I/O error
-
getDefaultHints
public static Map getDefaultHints(ImageSessionContext session)
Creates a new hint Map with values from the FOUserAgent.- Parameters:
session- the session context- Returns:
- a Map of hints
-
getPageIndexFromURI
public static Integer getPageIndexFromURI(String uri)
Extracts page index information from a URI. The expected pattern is "page=x" where x is a non-negative integer number. The page index must be specified as part of the URI fragment and is 1-based, i.e. the first page is 1 but the the method returns a zero-based page index. An example:http://www.foo.bar/images/scan1.tif#page=4(The method will return 3.)If no page index information is found in the URI or if the URI cannot be parsed, the method returns null.
- Parameters:
uri- the URI that should be inspected- Returns:
- the page index (0 is the first page) or null if there's no page index information in the URI
-
needPageIndexFromURI
public static int needPageIndexFromURI(String uri)
Extracts page index information from a URI. The expected pattern is "page=x" where x is a non-negative integer number. The page index must be specified as part of the URI fragment and is 1-based, i.e. the first page is 1 but the the method returns a zero-based page index. An example:http://www.foo.bar/images/scan1.tif#page=4(The method will return 3.)If no page index information is found in the URI, the method just returns 0 which indicates the first page.
- Parameters:
uri- the URI that should be inspected- Returns:
- the page index (0 is the first page)
-
-