// Path: core/src/main/java/org/hipi/image/HipiImageHeader.java
// public enum HipiImageFormat {
//   UNDEFINED(0x0), JPEG(0x1), PNG(0x2), PPM(0x3);
// 
//   private int format;
// 
//   /**
//    * Creates an ImageFormat from an int.
//    *
//    * @param format Integer representation of ImageFormat.
//    */
//   HipiImageFormat(int format) {
//     this.format = format;
//   }
// 
//   /**
//    * Creates an ImageFormat from an int.
//    *
//    * @param format Integer representation of ImageFormat.
//    *
//    * @return Associated ImageFormat.
//    *
//    * @throws IllegalArgumentException if the parameter value does not correspond to a valid
//    * HipiImageFormat.
//    */
//   public static HipiImageFormat fromInteger(int format) throws IllegalArgumentException {
//     for (HipiImageFormat fmt : values()) {
//       if (fmt.format == format) {
//         return fmt;
//       }
//     }
//     throw new IllegalArgumentException(String.format("There is no HipiImageFormat enum value " +
//       "associated with integer [%d]", format));
//   }
// 
//   /** 
//    * @return Integer representation of ImageFormat.
//    */
//   public int toInteger() {
//     return format;
//   }
// 
//   /**
//    * Default HipiImageFormat.
//    *
//    * @return HipiImageFormat.UNDEFINED
//    */
//   public static HipiImageFormat getDefault() {
//     return UNDEFINED;
//   }
// 
// } // public enum ImageFormat


import org.hipi.imagebundle.HipiImageBundle;
import org.hipi.image.HipiImageHeader.HipiImageFormat;
import org.apache.commons.cli.BasicParser;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.CommandLineParser;
import org.apache.commons.cli.HelpFormatter;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.Parser;
import org.apache.commons.cli.ParseException;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.FileStatus;
import org.apache.hadoop.fs.FSDataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.HashMap;
import java.util.Arrays;
import java.util.List;
    }

    System.out.println("Input image directory: " + imageDir);
    System.out.println("Input FS: " + (hdfsInput ? "HDFS" : "local FS"));
    System.out.println("Output HIB: " + outputHib);
    System.out.println("Overwrite HIB if it exists: " + (overwrite ? "true" : "false"));

    Configuration conf = new Configuration();
    FileSystem fs = FileSystem.get(conf);

    if (hdfsInput) {

      FileStatus[] files = fs.listStatus(new Path(imageDir));
      if (files == null) {
        System.err.println(String.format("Did not find any files in the HDFS directory [%s]", imageDir));
        System.exit(0);
      }
      Arrays.sort(files);

      HipiImageBundle hib = new HipiImageBundle(new Path(outputHib), conf);
      hib.openForWrite(overwrite);

      for (FileStatus file : files) {
        FSDataInputStream fdis = fs.open(file.getPath());
        String source = file.getPath().toString();
        HashMap<String, String> metaData = new HashMap<String,String>();
        metaData.put("source", source);
        String fileName = file.getPath().getName().toLowerCase();
        String suffix = fileName.substring(fileName.lastIndexOf('.'));
        if (suffix.compareTo(".jpg") == 0 || suffix.compareTo(".jpeg") == 0) {
// Path: core/src/main/java/org/hipi/image/HipiImageHeader.java
// public enum HipiImageFormat {
//   UNDEFINED(0x0), JPEG(0x1), PNG(0x2), PPM(0x3);
// 
//   private int format;
// 
//   /**
//    * Creates an ImageFormat from an int.
//    *
//    * @param format Integer representation of ImageFormat.
//    */
//   HipiImageFormat(int format) {
//     this.format = format;
//   }
// 
//   /**
//    * Creates an ImageFormat from an int.
//    *
//    * @param format Integer representation of ImageFormat.
//    *
//    * @return Associated ImageFormat.
//    *
//    * @throws IllegalArgumentException if the parameter value does not correspond to a valid
//    * HipiImageFormat.
//    */
//   public static HipiImageFormat fromInteger(int format) throws IllegalArgumentException {
//     for (HipiImageFormat fmt : values()) {
//       if (fmt.format == format) {
//         return fmt;
//       }
//     }
//     throw new IllegalArgumentException(String.format("There is no HipiImageFormat enum value " +
//       "associated with integer [%d]", format));
//   }
// 
//   /** 
//    * @return Integer representation of ImageFormat.
//    */
//   public int toInteger() {
//     return format;
//   }
// 
//   /**
//    * Default HipiImageFormat.
//    *
//    * @return HipiImageFormat.UNDEFINED
//    */
//   public static HipiImageFormat getDefault() {
//     return UNDEFINED;
//   }
// 
// } // public enum ImageFormat


// Path: tools/hibImport/src/main/java/org/hipi/tools/HibImport.java
import org.hipi.imagebundle.HipiImageBundle;
import org.hipi.image.HipiImageHeader.HipiImageFormat;
import org.apache.commons.cli.BasicParser;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.CommandLineParser;
import org.apache.commons.cli.HelpFormatter;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.Parser;
import org.apache.commons.cli.ParseException;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.FileStatus;
import org.apache.hadoop.fs.FSDataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.HashMap;
import java.util.Arrays;
import java.util.List;

    }

    System.out.println("Input image directory: " + imageDir);
    System.out.println("Input FS: " + (hdfsInput ? "HDFS" : "local FS"));
    System.out.println("Output HIB: " + outputHib);
    System.out.println("Overwrite HIB if it exists: " + (overwrite ? "true" : "false"));

    Configuration conf = new Configuration();
    FileSystem fs = FileSystem.get(conf);

    if (hdfsInput) {

      FileStatus[] files = fs.listStatus(new Path(imageDir));
      if (files == null) {
        System.err.println(String.format("Did not find any files in the HDFS directory [%s]", imageDir));
        System.exit(0);
      }
      Arrays.sort(files);

      HipiImageBundle hib = new HipiImageBundle(new Path(outputHib), conf);
      hib.openForWrite(overwrite);

      for (FileStatus file : files) {
        FSDataInputStream fdis = fs.open(file.getPath());
        String source = file.getPath().toString();
        HashMap<String, String> metaData = new HashMap<String,String>();
        metaData.put("source", source);
        String fileName = file.getPath().getName().toLowerCase();
        String suffix = fileName.substring(fileName.lastIndexOf('.'));
        if (suffix.compareTo(".jpg") == 0 || suffix.compareTo(".jpeg") == 0) {
         hib.addImage(fdis, HipiImageFormat.JPEG, metaData);