xmlgraphics-commons 1.3.1

org.apache.xmlgraphics.image.loader.util
Class ImageUtil

java.lang.Object
  extended by org.apache.xmlgraphics.image.loader.util.ImageUtil

public class ImageUtil
extends java.lang.Object

Helper and convenience methods for working with the image package.


Constructor Summary
ImageUtil()
           
 
Method Summary
static java.io.InputStream autoDecorateInputStream(java.io.InputStream in)
          Automatically decorates an InputStream so it is buffered.
static void closeQuietly(javax.xml.transform.Source src)
          Closes the InputStreams or ImageInputStreams of Source objects.
static java.io.InputStream decorateMarkSupported(java.io.InputStream in)
          Decorates an InputStream with a BufferedInputStream if it doesn't support mark()/reset().
static java.util.Map getDefaultHints(ImageSessionContext session)
          Creates a new hint Map with values from the FOUserAgent.
static javax.imageio.stream.ImageInputStream getImageInputStream(javax.xml.transform.Source src)
          Returns the ImageInputStream of a Source object.
static java.io.InputStream getInputStream(javax.xml.transform.Source src)
          Returns the InputStream of a Source object.
static java.lang.Integer getPageIndexFromURI(java.lang.String uri)
          Extracts page index information from a URI.
static boolean hasImageInputStream(javax.xml.transform.Source src)
          Indicates whether the Source object has an ImageInputStream instance.
static boolean hasInputStream(javax.xml.transform.Source src)
          Indicates whether the Source object has an InputStream instance.
static boolean hasReader(javax.xml.transform.Source src)
          Indicates whether the Source object has a Reader instance.
static javax.imageio.stream.ImageInputStream ignoreFlushing(javax.imageio.stream.ImageInputStream in)
          Decorates an ImageInputStream so the flush*() methods are ignored and have no effect.
static boolean isGZIPCompressed(java.io.InputStream in)
          Indicates whether an InputStream is GZIP compressed.
static javax.imageio.stream.ImageInputStream needImageInputStream(javax.xml.transform.Source src)
          Returns the ImageInputStream of a Source object.
static java.io.InputStream needInputStream(javax.xml.transform.Source src)
          Returns the InputStream of a Source object.
static int needPageIndexFromURI(java.lang.String uri)
          Extracts page index information from a URI.
static void removeStreams(javax.xml.transform.Source src)
          Removes any references to InputStreams or Readers from the given Source to prohibit accidental/unwanted use by a component further downstream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ImageUtil

public ImageUtil()
Method Detail

getInputStream

public static java.io.InputStream getInputStream(javax.xml.transform.Source src)
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 javax.imageio.stream.ImageInputStream getImageInputStream(javax.xml.transform.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

public static java.io.InputStream needInputStream(javax.xml.transform.Source src)
Returns 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 javax.imageio.stream.ImageInputStream needImageInputStream(javax.xml.transform.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(javax.xml.transform.Source src)
Indicates whether the Source object has an InputStream instance.

Parameters:
src - the Source object
Returns:
true if an InputStream is available

hasReader

public static boolean hasReader(javax.xml.transform.Source src)
Indicates 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(javax.xml.transform.Source src)
Indicates whether the Source object has an ImageInputStream instance.

Parameters:
src - the Source object
Returns:
true if an ImageInputStream is available

removeStreams

public static void removeStreams(javax.xml.transform.Source src)
Removes 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

public static void closeQuietly(javax.xml.transform.Source src)
Closes the InputStreams or ImageInputStreams of Source objects. Any exception occurring while closing the stream is ignored.

Parameters:
src - the Source object

ignoreFlushing

public static javax.imageio.stream.ImageInputStream ignoreFlushing(javax.imageio.stream.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(java.io.InputStream in)
                                throws java.io.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:
java.io.IOException - in case of an I/O error

decorateMarkSupported

public static java.io.InputStream decorateMarkSupported(java.io.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 java.io.InputStream autoDecorateInputStream(java.io.InputStream in)
                                                   throws java.io.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:
java.io.IOException - in case of an I/O error

getDefaultHints

public static java.util.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 java.lang.Integer getPageIndexFromURI(java.lang.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(java.lang.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)

xmlgraphics-commons 1.3.1

Copyright 1999-2008 The Apache Software Foundation. All Rights Reserved.