/**
  * Reads data from a file and writes it to an index.
  *
  * @param indexWriter the index to write to.
  * @param inputFile the input data for the process.
  * @throws IOException
  * @throws InstantiationException
  * @throws IllegalAccessException
  * @throws ClassNotFoundException
  */
 private void readFile(IndexWriter indexWriter, File inputFile)
     throws IOException, InstantiationException, IllegalAccessException, ClassNotFoundException {
   BufferedInputStream in = new BufferedInputStream(new FileInputStream(inputFile));
   byte[] tempInt = new byte[4];
   int tmp, tmpFeature, count = 0;
   byte[] temp = new byte[100 * 1024];
   // read file hashFunctionsFileName length:
   while (in.read(tempInt, 0, 4) > 0) {
     Document d = new Document();
     tmp = SerializationUtils.toInt(tempInt);
     // read file hashFunctionsFileName:
     in.read(temp, 0, tmp);
     String filename = new String(temp, 0, tmp);
     // normalize Filename to full path.
     filename =
         inputFile
                 .getCanonicalPath()
                 .substring(0, inputFile.getCanonicalPath().lastIndexOf(inputFile.getName()))
             + filename;
     d.add(new StringField(DocumentBuilder.FIELD_NAME_IDENTIFIER, filename, Field.Store.YES));
     //            System.out.print(filename);
     while ((tmpFeature = in.read()) < 255) {
       //                System.out.print(", " + tmpFeature);
       LireFeature f = (LireFeature) Class.forName(Extractor.features[tmpFeature]).newInstance();
       // byte[] length ...
       in.read(tempInt, 0, 4);
       tmp = SerializationUtils.toInt(tempInt);
       // read feature byte[]
       in.read(temp, 0, tmp);
       f.setByteArrayRepresentation(temp, 0, tmp);
       addToDocument(f, d, Extractor.featureFieldNames[tmpFeature]);
       //                d.add(new StoredField(Extractor.featureFieldNames[tmpFeature],
       // f.getByteArrayRepresentation()));
     }
     if (run == 2) indexWriter.addDocument(d);
     docCount++;
     //            if (count%1000==0) System.out.print('.');
     //            if (count%10000==0) System.out.println(" " + count);
   }
   in.close();
 }
 public void setByteArrayRepresentation(byte[] in) {
   byte[] numBinsBytes = new byte[4];
   numBinsBytes[0] = in[in.length - 5];
   numBinsBytes[1] = in[in.length - 4];
   numBinsBytes[2] = in[in.length - 3];
   numBinsBytes[3] = in[in.length - 2];
   int maxDistance = (int) in[in.length - 1];
   numBins = SerializationUtils.toInt(numBinsBytes);
   correlogram = new float[numBins][maxDistance];
   float[] temp = SerializationUtils.toFloatArray(in);
   for (int i = 0; i < correlogram.length; i++) {
     System.arraycopy(temp, i * maxDistance, correlogram[i], 0, maxDistance);
   }
   distanceSet = new int[maxDistance];
   for (int i = 0; i < distanceSet.length; i++) {
     distanceSet[i] = i + 1;
   }
 }