Class ContentTypeDetector


  • public class ContentTypeDetector
    extends java.lang.Object
    Detector for content types of binary streams based on a magic headers.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static int BUFFER_SIZE  
      static int CLASSFILE
      File type Java class
      static int GZFILE
      File type GZIP compressed Data
      private java.io.InputStream in  
      static int PACK200FILE
      File type Pack200 archive
      private int type  
      static int UNKNOWN
      Unknown file type
      static int ZIPFILE
      File type ZIP archive
    • Constructor Summary

      Constructors 
      Constructor Description
      ContentTypeDetector​(java.io.InputStream in)
      Creates a new detector based on the given input.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private static int determineType​(java.io.InputStream in)  
      java.io.InputStream getInputStream()
      Returns an input stream instance to read the complete content (including the header) of the underlying stream.
      int getType()
      Returns the detected file type.
      private static int readInt​(java.io.InputStream in)  
      • Methods inherited from class java.lang.Object

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

      • ContentTypeDetector

        public ContentTypeDetector​(java.io.InputStream in)
                            throws java.io.IOException
        Creates a new detector based on the given input. To process the complete original input afterwards use the stream returned by getInputStream().
        Parameters:
        in - input to read the header from
        Throws:
        java.io.IOException - if the stream can't be read
    • Method Detail

      • determineType

        private static int determineType​(java.io.InputStream in)
                                  throws java.io.IOException
        Throws:
        java.io.IOException
      • readInt

        private static int readInt​(java.io.InputStream in)
                            throws java.io.IOException
        Throws:
        java.io.IOException
      • getInputStream

        public java.io.InputStream getInputStream()
        Returns an input stream instance to read the complete content (including the header) of the underlying stream.
        Returns:
        input stream containing the complete content
      • getType

        public int getType()
        Returns the detected file type.
        Returns:
        file type