Example usage for java.lang IndexOutOfBoundsException getCause

List of usage examples for java.lang IndexOutOfBoundsException getCause

Introduction

In this page you can find the example usage for java.lang IndexOutOfBoundsException getCause.

Prototype

public synchronized Throwable getCause() 

Source Link

Document

Returns the cause of this throwable or null if the cause is nonexistent or unknown.

Usage

From source file:org.uiautomation.ios.server.servlet.ResourceServlet.java

private boolean validImage(File f) throws IOException {
    InputStream is = new FileInputStream(f);
    try {// w  ww .ja  va  2s . c  o  m
        //is = new FileInputStream(f);

        final ImageInputStream imageInputStream = ImageIO.createImageInputStream(is);
        final Iterator<ImageReader> imageReaders = ImageIO.getImageReaders(imageInputStream);
        if (!imageReaders.hasNext()) {
            // not an image
            return false;
        }
        final ImageReader imageReader = imageReaders.next();
        imageReader.setInput(imageInputStream);
        final BufferedImage image = imageReader.read(0);
        if (image == null) {
            // empty
            return false;
        }
        image.flush();
        return true;
    } catch (final IndexOutOfBoundsException e) {
        // truncated
        return false;
    } catch (final IIOException e) {
        if (e.getCause() instanceof EOFException) {
            // truncated
            return false;
        }
    } catch (Exception e) {
        return false;
    } finally {
        is.close();
    }
    return true;
}