Examples of BadImageException


Examples of ru.org.linux.util.BadImageException

   */
  public static ImageParam imageInfo(File file) throws BadImageException, IOException {
    long size = file.length();
    ImageInputStream iis = ImageIO.createImageInputStream(file);
    if(iis == null) {
      throw new BadImageException("Invalid image");
    }
    Iterator<ImageReader> iter = ImageIO.getImageReaders(iis);
    if(!iter.hasNext()) {
      throw new BadImageException("Invalid image");
    }
    ImageReader reader = iter.next();
    reader.setInput(iis);
    String formatName = reader.getFormatName();
    if(!Arrays.asList(supportedFormat).contains(formatName)) {
      throw new BadImageException("Does unsupported format "+formatName);
    }
    boolean animated = false;
    int height = reader.getHeight(0);
    int width = reader.getWidth(0);
    iis.close();
View Full Code Here

Examples of ru.org.linux.util.BadImageException

  public static ImageParam imageCheck(File file) throws BadImageException, IOException {
    long size = file.length();
    ImageInputStream iis = ImageIO.createImageInputStream(file);
    if(iis == null) {
      throw new BadImageException("Invalid image");
    }
    Iterator<ImageReader> iter = ImageIO.getImageReaders(iis);
    if(!iter.hasNext()) {
      throw new BadImageException("Invalid image");
    }
    ImageReader reader = iter.next();
    reader.setInput(iis);
    String formatName = reader.getFormatName();
    if(!Arrays.asList(supportedFormat).contains(formatName)) {
      throw new BadImageException("Does unsupported format "+formatName);
    }
    boolean animated = hasAnimatedPng(reader) || reader.getNumImages(true) > 1;
    int height = reader.getHeight(0);
    int width = reader.getWidth(0);
    iis.close();
View Full Code Here

Examples of ru.org.linux.util.BadImageException

    try {
      BufferedImage source = ImageIO.read(new File(filename));
      BufferedImage destination = Scalr.resize(source, size);
      ImageIO.write(destination, "JPEG", new File(iconname));
    } catch (IIOException ex) {
      throw new BadImageException("Can't resize image", ex);
    }
  }
View Full Code Here

Examples of ru.org.linux.util.BadImageException

      } else if (lowname.endsWith("jpg") || lowname.endsWith("jpeg")) {
        getJpgInfo(fileStream);
      } else if (lowname.endsWith("png")) {
        getPngInfo(fileStream);
      } else {
        throw new BadImageException("Invalid image extension");       
      }

      if (height == -1 || width == -1) {
        throw new BadImageException();
      }
    } finally {
      if (fileStream != null) {
        fileStream.close();
      }
View Full Code Here

Examples of ru.org.linux.util.BadImageException

      } else if ("jpg".equals(extension) || "jpeg".equals(extension)) {
        getJpgInfo(fileStream);
      } else if ("png".equals(extension)) {
        getPngInfo(fileStream);
      } else {
        throw new BadImageException("Invalid image extension");
      }

      if (height == -1 || width == -1) {
        throw new BadImageException();
      }
    } finally {
      if (fileStream != null) {
        fileStream.close();
      }
View Full Code Here

Examples of ru.org.linux.util.BadImageException

      if ("GIF".equals(header.substring(0, 3))) //It's a gif, continue processing
      {
        width = shortLittleEndian(bytes[6], bytes[7]);
        height = shortLittleEndian(bytes[8], bytes[9]);
      } else {
        throw new BadImageException("Bad GIF image: "+filename);
      }
    }
  }
View Full Code Here

Examples of ru.org.linux.util.BadImageException

      String header = new String(bytes);
      if ("PNG".equals(header.substring(1, 4))) {
        width = intBigEndian(bytes[16], bytes[17], bytes[18], bytes[19]);
        height = intBigEndian(bytes[20], bytes[21], bytes[22], bytes[23]);
      } else {
        throw new BadImageException("Bad PNG image: "+filename);
      }
    }
  }
View Full Code Here

Examples of ru.org.linux.util.BadImageException

          break;
        } else {
          int skip = shortBigEndian((byte) fileStream.read(), (byte) fileStream.read()) - 2;

          if (skip<0) {
            throw new BadImageException("Bad JPG image: "+filename);
          }

          fileStream.skip(skip);
        }
      }
    } else {
      throw new BadImageException("Bad JPG image: "+filename);
    }
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.