Class JRTypeSniffer


  • public final class JRTypeSniffer
    extends java.lang.Object
    Author:
    George Stojanoff (gstojanoff@jaspersoft.com), Flavius Sana (flavius_sana@users.sourceforge.net)
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static ImageTypeEnum getImageTypeValue​(byte[] data)  
      static boolean isGIF​(byte[] data)
      Sniffs an incoming byte array to see if the first 3 characters are GIF.
      static boolean isJPEG​(byte[] data)
      Sniffs an incoming byte array to see if the starting value is 0xffd8 which is the "header" for JPEG data Note: This method only really needs the first 2 bytes.
      static boolean isPNG​(byte[] data)
      Sniffs an incoming byte array to see if the first eight bytes are the following (decimal) values: 137 80 78 71 13 10 26 10 which is the "signature" for PNG data See http://www.w3.org/TR/PNG/#5PNG-file-signature for more details.
      static boolean isTIFF​(byte[] data)
      Sniffs an incoming byte array to see if the starting value is 0x4949 (little endian) or 0x4D4D (big endian) which is the "header" for TIFF data The TIFF standards supports both endians.
      static boolean isWEBP​(byte[] data)
      Sniffs an incoming byte array to see if the starting values are matching the WEBP magic number.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • isGIF

        public static boolean isGIF​(byte[] data)
        Sniffs an incoming byte array to see if the first 3 characters are GIF. This is also known as the GIF signature. See http://www.dcs.ed.ac.uk/home/mxr/gfx/2d/GIF87a.txt for more details Note: Perhaps we should be checking for the more restive string GIF87a but I am not sure if older GIF images are sill out there in use on the web. Note: This method only really needs the first 3 bytes.
      • isJPEG

        public static boolean isJPEG​(byte[] data)
        Sniffs an incoming byte array to see if the starting value is 0xffd8 which is the "header" for JPEG data Note: This method only really needs the first 2 bytes.
      • isPNG

        public static boolean isPNG​(byte[] data)
        Sniffs an incoming byte array to see if the first eight bytes are the following (decimal) values: 137 80 78 71 13 10 26 10 which is the "signature" for PNG data See http://www.w3.org/TR/PNG/#5PNG-file-signature for more details. Note: This method only really needs the first 8 bytes.
      • isTIFF

        public static boolean isTIFF​(byte[] data)
        Sniffs an incoming byte array to see if the starting value is 0x4949 (little endian) or 0x4D4D (big endian) which is the "header" for TIFF data The TIFF standards supports both endians. See http://palimpsest.stanford.edu/bytopic/imaging/std/tiff5.html for more details. Note: This method only really needs the first 2 bytes.
      • isWEBP

        public static boolean isWEBP​(byte[] data)
        Sniffs an incoming byte array to see if the starting values are matching the WEBP magic number. See https://en.wikipedia.org/wiki/WebP for more details. Note: This method only really needs the first 15 bytes.
      • getImageTypeValue

        public static ImageTypeEnum getImageTypeValue​(byte[] data)