Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4639576

java.net.URLConnection.guessContentTypeFromStream cannot handle Exif format

XMLWordPrintable

    • hopper
    • x86
    • windows_nt
    • Verified



      Name: pa48320 Date: 02/19/2002

      The guessContentTypeFromStream(InputStream istrm) on the java.net.URLConnection class returns null for some jpg images. These images are images read from Digital Cameras. Todays cameras all return images that have a magic code of 0xFF, 0xD8, 0xFF, 0xE1 which is not tested for in the code. Frankly that code could be made a bit more extensible. The following code demonstrates the problem. Call it with a jpg downloaded from a camera:
      import java.io.InputStream;
      import java.io.FileInputStream;
      import java.io.FileNotFoundException;

      public class URLConnectionTest
      {
      public URLConnectionTest (String filename)
      {
      FileInputStream inStream = null;
      try
      {
      inStream = new FileInputStream(filename);
      }
      catch (FileNotFoundException e)
      {
      System.out.println("File " + filename + " not found.");
      }

      try
      {
      InputStream bufferedStream = new java.io.BufferedInputStream(inStream);
      System.out.println(" ContentType="+(java.net.URLConnection.guessContentTypeFromStream(bufferedStream)));
      bufferedStream.close();
      }
      catch (Exception e)
      {
      e.printStackTrace();
      }

      }

      public static void main(String[] argv)
      {
      String filename;
      if (argv.length > 0)
      {
      filename = argv[0];
      URLConnectionTest failedTest = new URLConnectionTest(filename);
                      }
      System.exit(0);
      }
      }


      ======================================================================

            jhangalsunw Jayalaxmi Hangal (Inactive)
            pallenba Peter Allenbach (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: