List of usage examples for java.lang IndexOutOfBoundsException getCause
public synchronized Throwable getCause()
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; }