code: public static int getOrientation(InputStream is) {
      try {
        int length = moveToAPP1EXIF(is);
        if (length == 0) {
          return ExifInterface.ORIENTATION_UNDEFINED;
        }
        return TiffUtil.readOrientationFromTIFF(is, length);
      } catch (IOException ioe) {
        return ExifInterface.ORIENTATION_UNDEFINED;
      }
    }
docs: Get orientation information from jpeg input stream.
  
  @param is the input stream of jpeg image
  @return orientation: 1/8/3/6. Returns {@value
  android.media.ExifInterface#ORIENTATION_UNDEFINED} if there is no valid orientation
  information.