Example usage for javax.imageio.stream ImageInputStream getStreamPosition

List of usage examples for javax.imageio.stream ImageInputStream getStreamPosition

Introduction

In this page you can find the example usage for javax.imageio.stream ImageInputStream getStreamPosition.

Prototype

long getStreamPosition() throws IOException;

Source Link

Document

Returns the current byte position of the stream.

Usage

From source file:org.apache.xmlgraphics.image.loader.impl.AbstractImageSessionContext.java

/** {@inheritDoc} */
public void returnSource(String uri, Source src) {
    //Safety check to make sure the Preloaders behave
    ImageInputStream in = ImageUtil.getImageInputStream(src);
    try {/*from  w ww .  j a v a2  s  . c o m*/
        if (in != null && in.getStreamPosition() != 0) {
            throw new IllegalStateException("ImageInputStream is not reset for: " + uri);
        }
    } catch (IOException ioe) {
        //Ignore exception
        ImageUtil.closeQuietly(src);
    }

    if (isReusable(src)) {
        //Only return the Source if it's reusable
        log.debug("Returning Source for " + uri);
        sessionSources.put(uri, src);
    } else {
        //Otherwise, try to close if possible and forget about it
        ImageUtil.closeQuietly(src);
    }
}