You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@joshua.apache.org by mj...@apache.org on 2016/08/30 21:04:47 UTC

[02/17] incubator-joshua git commit: Fix a number of issues: - Reader now implements autocloseable - Close various leaks from LineReader - LineReader no longer implements custom finalize(). Resources should be explicitly closed when no longer needed. T

http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/840eb4ce/src/main/java/org/apache/joshua/util/Constants.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/joshua/util/Constants.java b/src/main/java/org/apache/joshua/util/Constants.java
index 3d4139d..9612a35 100644
--- a/src/main/java/org/apache/joshua/util/Constants.java
+++ b/src/main/java/org/apache/joshua/util/Constants.java
@@ -20,17 +20,17 @@ package org.apache.joshua.util;
 
 /***
  * One day, all constants should be moved here (many are in Vocabulary).
- * 
+ *
  * @author Matt Post post@cs.jhu.edu
  */
 
 public final class Constants {
-  public static String defaultNT = "[X]";
+  public static final String defaultNT = "[X]";
 
   public static final String START_SYM = "<s>";
   public static final String STOP_SYM = "</s>";
   public static final String UNKNOWN_WORD = "<unk>";
-  
+
   public static final String fieldDelimiter = "\\s\\|{3}\\s";
   public static final String spaceSeparator = "\\s+";
 }

http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/840eb4ce/src/main/java/org/apache/joshua/util/FileUtility.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/joshua/util/FileUtility.java b/src/main/java/org/apache/joshua/util/FileUtility.java
index a36b07f..0f13e6a 100644
--- a/src/main/java/org/apache/joshua/util/FileUtility.java
+++ b/src/main/java/org/apache/joshua/util/FileUtility.java
@@ -18,38 +18,22 @@
  */
 package org.apache.joshua.util;
 
-import java.io.BufferedReader;
 import java.io.BufferedWriter;
-import java.io.Closeable;
 import java.io.File;
 import java.io.FileDescriptor;
-import java.io.FileInputStream;
 import java.io.FileOutputStream;
-import java.io.FileReader;
 import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
 import java.io.OutputStreamWriter;
-import java.nio.charset.Charset;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Scanner;
+import java.nio.charset.StandardCharsets;
 
 /**
  * utility functions for file operations
- * 
+ *
  * @author Zhifei Li, zhifei.work@gmail.com
  * @author wren ng thornton wren@users.sourceforge.net
  * @since 28 February 2009
  */
 public class FileUtility {
-  public static String DEFAULT_ENCODING = "UTF-8";
-
-  /*
-   * Note: charset name is case-agnostic "UTF-8" is the canonical name "UTF8", "unicode-1-1-utf-8"
-   * are aliases Java doesn't distinguish utf8 vs UTF-8 like Perl does
-   */
-  private static final Charset FILE_ENCODING = Charset.forName(DEFAULT_ENCODING);
 
   /**
    * Warning, will truncate/overwrite existing files
@@ -61,122 +45,7 @@ public class FileUtility {
     return new BufferedWriter(new OutputStreamWriter(
     // TODO: add GZIP
         filename.equals("-") ? new FileOutputStream(FileDescriptor.out) : new FileOutputStream(
-            filename, false), FILE_ENCODING));
-  }
-
-  /**
-   * Recursively delete the specified file or directory.
-   * 
-   * @param f File or directory to delete
-   * @return <code>true</code> if the specified file or directory was deleted, <code>false</code>
-   *         otherwise
-   */
-  public static boolean deleteRecursively(File f) {
-    if (null != f) {
-      if (f.isDirectory())
-        for (File child : f.listFiles())
-          deleteRecursively(child);
-      return f.delete();
-    } else {
-      return false;
-    }
-  }
-
-  /**
-   * Writes data from the integer array to disk as raw bytes, overwriting the old file if present.
-   * 
-   * @param data The integer array to write to disk.
-   * @param filename The filename where the data should be written.
-   * @throws IOException if there is a problem writing to the output file
-   * @return the FileOutputStream on which the bytes were written
-   */
-  public static FileOutputStream writeBytes(int[] data, String filename) throws IOException {
-    FileOutputStream out = new FileOutputStream(filename, false);
-    writeBytes(data, out);
-    return out;
-  }
-
-  /**
-   * Writes data from the integer array to disk as raw bytes.
-   * 
-   * @param data The integer array to write to disk.
-   * @param out The output stream where the data should be written.
-   * @throws IOException if there is a problem writing bytes
-   */
-  public static void writeBytes(int[] data, OutputStream out) throws IOException {
-
-    byte[] b = new byte[4];
-
-    for (int word : data) {
-      b[0] = (byte) ((word >>> 24) & 0xFF);
-      b[1] = (byte) ((word >>> 16) & 0xFF);
-      b[2] = (byte) ((word >>> 8) & 0xFF);
-      b[3] = (byte) ((word >>> 0) & 0xFF);
-
-      out.write(b);
-    }
-  }
-
-  public static void copyFile(String srFile, String dtFile) throws IOException {
-    try {
-      File f1 = new File(srFile);
-      File f2 = new File(dtFile);
-      copyFile(f1, f2);
-    } catch (IOException e) {
-      throw new RuntimeException(e);
-    }
-  }
-
-  public static void copyFile(File srFile, File dtFile) throws IOException {
-    try {
-
-      InputStream in = new FileInputStream(srFile);
-
-      // For Append the file.
-      // OutputStream out = new FileOutputStream(f2,true);
-
-      // For Overwrite the file.
-      OutputStream out = new FileOutputStream(dtFile);
-
-      byte[] buf = new byte[1024];
-      int len;
-      while ((len = in.read(buf)) > 0) {
-        out.write(buf, 0, len);
-      }
-      in.close();
-      out.close();
-      System.out.println("File copied.");
-    } catch (IOException e) {
-      throw new RuntimeException(e);
-    }
-  }
-
-  static public boolean deleteFile(String fileName) {
-
-    File f = new File(fileName);
-
-    // Make sure the file or directory exists and isn't write protected
-    if (!f.exists())
-      System.out.println("Delete: no such file or directory: " + fileName);
-
-    if (!f.canWrite())
-      System.out.println("Delete: write protected: " + fileName);
-
-    // If it is a directory, make sure it is empty
-    if (f.isDirectory()) {
-      String[] files = f.list();
-      if (files.length > 0)
-        System.out.println("Delete: directory not empty: " + fileName);
-    }
-
-    // Attempt to delete it
-    boolean success = f.delete();
-
-    if (!success)
-      System.out.println("Delete: deletion failed");
-
-    return success;
-
+            filename, false), StandardCharsets.UTF_8));
   }
 
   /**
@@ -191,128 +60,4 @@ public class FileUtility {
 
     return ".";
   }
-
-  public static void createFolderIfNotExisting(String folderName) {
-    File f = new File(folderName);
-    if (!f.isDirectory()) {
-      System.out.println(" createFolderIfNotExisting -- Making directory: " + folderName);
-      f.mkdirs();
-    } else {
-      System.out.println(" createFolderIfNotExisting -- Directory: " + folderName
-          + " already existed");
-    }
-  }
-
-  public static void closeCloseableIfNotNull(Closeable fileWriter) {
-    if (fileWriter != null) {
-      try {
-        fileWriter.close();
-      } catch (IOException e) {
-        e.printStackTrace();
-      }
-    }
-  }
-
-  /**
-   * Returns the directory were the program has been started,
-   * the base directory you will implicitly get when specifying no
-   * full path when e.g. opening a file
-   * @return the current 'user.dir'
-   */
-  public static String getWorkingDirectory() {
-    return System.getProperty("user.dir");
-  }
-
-  /**
-   * Method to handle standard IO exceptions. catch (Exception e) {Utility.handleIO_exception(e);}
-   * @param e an input {@link java.lang.Exception}
-   */
-  public static void handleExceptions(Exception e) {
-    throw new RuntimeException(e);
-  }
-
-  /**
-   * Convenience method to get a full file as a String
-   * @param file the input {@link java.io.File}
-   * @return The file as a String. Lines are separated by newline character.
-   */
-  public static String getFileAsString(File file) {
-    String result = "";
-    List<String> lines = getLines(file, true);
-    for (int i = 0; i < lines.size() - 1; i++) {
-      result += lines.get(i) + "\n";
-    }
-    if (!lines.isEmpty()) {
-      result += lines.get(lines.size() - 1);
-    }
-    return result;
-  }
-
-  /**
-   * This method returns a List of String. Each element of the list corresponds to a line from the
-   * input file. The boolean keepDuplicates in the input determines if duplicate lines are allowed
-   * in the output LinkedList or not.
-   * @param file the input file
-   * @param keepDuplicates whether to retain duplicate lines
-   * @return a {@link java.util.List} of lines
-   */
-  static public List<String> getLines(File file, boolean keepDuplicates) {
-    LinkedList<String> list = new LinkedList<String>();
-    String line = "";
-    try {
-      BufferedReader InputReader = new BufferedReader(new FileReader(file));
-      for (;;) { // this loop writes writes in a Sting each sentence of
-        // the file and process it
-        int current = InputReader.read();
-        if (current == -1 || current == '\n') {
-          if (keepDuplicates || !list.contains(line))
-            list.add(line);
-          line = "";
-          if (current == -1)
-            break; // EOF
-        } else
-          line += (char) current;
-      }
-      InputReader.close();
-    } catch (Exception e) {
-      handleExceptions(e);
-    }
-    return list;
-  }
-
-  /**
-   * Returns a Scanner of the inputFile using a specific encoding
-   * 
-   * @param inputFile the file for which to get a {@link java.util.Scanner} object
-   * @param encoding the encoding to use within the Scanner
-   * @return a {@link java.util.Scanner} object for a given file
-   */
-  public static Scanner getScanner(File inputFile, String encoding) {
-    Scanner scan = null;
-    try {
-      scan = new Scanner(inputFile, encoding);
-    } catch (IOException e) {
-      FileUtility.handleExceptions(e);
-    }
-    return scan;
-  }
-
-  /**
-   * Returns a Scanner of the inputFile using default encoding
-   * 
-   * @param inputFile the file for which to get a {@link java.util.Scanner} object
-   * @return a {@link java.util.Scanner} object for a given file
-   */
-  public static Scanner getScanner(File inputFile) {
-    return getScanner(inputFile, DEFAULT_ENCODING);
-  }
-
-  static public String getFirstLineInFile(File inputFile) {
-    Scanner scan = FileUtility.getScanner(inputFile);
-    if (!scan.hasNextLine())
-      return null;
-    String line = scan.nextLine();
-    scan.close();
-    return line;
-  }
 }

http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/840eb4ce/src/main/java/org/apache/joshua/util/IntegerPair.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/joshua/util/IntegerPair.java b/src/main/java/org/apache/joshua/util/IntegerPair.java
deleted file mode 100644
index bfbfa23..0000000
--- a/src/main/java/org/apache/joshua/util/IntegerPair.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *  http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.joshua.util;
-
-/**
- * Memory-efficient implementation of an integer tuple.
- * 
- * @author Lane Schwartz
- */
-public final class IntegerPair {
-
-  public final int first;
-  public final int second;
-
-  public IntegerPair(final int first, final int second) {
-    this.first = first;
-    this.second = second;
-  }
-
-}

http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/840eb4ce/src/main/java/org/apache/joshua/util/ListUtil.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/joshua/util/ListUtil.java b/src/main/java/org/apache/joshua/util/ListUtil.java
index afb5af1..14154e8 100644
--- a/src/main/java/org/apache/joshua/util/ListUtil.java
+++ b/src/main/java/org/apache/joshua/util/ListUtil.java
@@ -22,55 +22,6 @@ import java.util.List;
 
 public class ListUtil {
 
-  /**
-   * Static method to generate a list representation for an ArrayList of Strings S1,...,Sn
-   * 
-   * @param list A list of Strings
-   * @return A String consisting of the original list of strings concatenated and separated by
-   *         commas, and enclosed by square brackets i.e. '[S1,S2,...,Sn]'
-   */
-  public static String stringListString(List<String> list) {
-
-    String result = "[";
-    for (int i = 0; i < list.size() - 1; i++) {
-      result += list.get(i) + ",";
-    }
-
-    if (list.size() > 0) {
-      // get the generated word for the last target position
-      result += list.get(list.size() - 1);
-    }
-
-    result += "]";
-
-    return result;
-
-  }
-
-  public static <E> String objectListString(List<E> list) {
-    String result = "[";
-    for (int i = 0; i < list.size() - 1; i++) {
-      result += list.get(i) + ",";
-    }
-    if (list.size() > 0) {
-      // get the generated word for the last target position
-      result += list.get(list.size() - 1);
-    }
-    result += "]";
-    return result;
-  }
-
-  /**
-   * Static method to generate a simple concatenated representation for an ArrayList of Strings
-   * S1,...,Sn
-   * 
-   * @param list A list of Strings
-   * @return todo
-   */
-  public static String stringListStringWithoutBrackets(List<String> list) {
-    return stringListStringWithoutBracketsWithSpecifiedSeparator(list, " ");
-  }
-
   public static String stringListStringWithoutBracketsCommaSeparated(List<String> list) {
     return stringListStringWithoutBracketsWithSpecifiedSeparator(list, ",");
   }
@@ -89,7 +40,5 @@ public class ListUtil {
     }
 
     return result;
-
   }
-
 }

http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/840eb4ce/src/main/java/org/apache/joshua/util/Lists.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/joshua/util/Lists.java b/src/main/java/org/apache/joshua/util/Lists.java
deleted file mode 100644
index d62d1aa..0000000
--- a/src/main/java/org/apache/joshua/util/Lists.java
+++ /dev/null
@@ -1,567 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *  http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.joshua.util;
-
-import java.util.Iterator;
-import java.util.NoSuchElementException;
-
-/**
- * 
- * 
- * @author Lane Schwartz
- */
-public class Lists {
-
-  // public static void main(String[] args) {
-  //
-  // int[] list = {100, 200, 300, 400, 500};
-  //
-  // for (IndexedInt i : eachWithIndex(list)) {
-  //
-  // System.out.println(i.getIndex() + " " + i.getValue());
-  //
-  // }
-  //
-  // Integer[] list2 = new Integer[]{10, 20, 30, 40};
-  // for (Indexed<Integer> i : eachWithIndex(list2)) {
-  //
-  // System.out.println(i.getIndex() + " " + i.getValue());
-  //
-  // }
-  //
-  // java.util.List<Integer> list3 = new java.util.ArrayList<Integer>();
-  // for (int i : list2) { list3.add(i); }
-  //
-  // for (Indexed<Integer> i : eachWithIndex(list3)) {
-  //
-  // System.out.println(i.getIndex() + " " + i.getValue());
-  //
-  // }
-  // }
-
-
-  public static Iterable<Integer> upto(final int exclusiveUpperBound) {
-    return new Iterable<Integer>() {
-      public Iterator<Integer> iterator() {
-        return new Iterator<Integer>() {
-          int next = 0;
-
-          public boolean hasNext() {
-            return next < exclusiveUpperBound;
-          }
-
-          public Integer next() {
-            if (!hasNext()) {
-              throw new NoSuchElementException();
-            }
-            int result = next;
-            next += 1;
-            return result;
-          }
-
-          public void remove() {
-            throw new UnsupportedOperationException();
-          }
-
-        };
-      }
-
-    };
-  }
-
-  public static Iterable<IndexedByte> eachWithIndex(final byte[] list) {
-
-    return new Iterable<IndexedByte>() {
-
-      public Iterator<IndexedByte> iterator() {
-        return new Iterator<IndexedByte>() {
-
-          int nextIndex = -1;
-          IndexedByte indexedValue;
-
-          public boolean hasNext() {
-            return (nextIndex < list.length);
-          }
-
-          public IndexedByte next() {
-            if (nextIndex >= list.length) {
-              throw new NoSuchElementException();
-            } else if (nextIndex < 0) {
-              nextIndex = 0;
-              indexedValue = new IndexedByte(list[nextIndex], nextIndex);
-            } else {
-              indexedValue.value = list[nextIndex];
-              indexedValue.index = nextIndex;
-            }
-
-            nextIndex += 1;
-            return indexedValue;
-          }
-
-          public void remove() {
-            throw new UnsupportedOperationException();
-          }
-
-        };
-      }
-
-    };
-  }
-
-  public static Iterable<IndexedShort> eachWithIndex(final short[] list) {
-
-    return new Iterable<IndexedShort>() {
-
-      public Iterator<IndexedShort> iterator() {
-        return new Iterator<IndexedShort>() {
-
-          int nextIndex = -1;
-          IndexedShort indexedValue;
-
-          public boolean hasNext() {
-            return (nextIndex < list.length);
-          }
-
-          public IndexedShort next() {
-            if (nextIndex >= list.length) {
-              throw new NoSuchElementException();
-            } else if (nextIndex < 0) {
-              nextIndex = 0;
-              indexedValue = new IndexedShort(list[nextIndex], nextIndex);
-            } else {
-              indexedValue.value = list[nextIndex];
-              indexedValue.index = nextIndex;
-            }
-
-            nextIndex += 1;
-            return indexedValue;
-          }
-
-          public void remove() {
-            throw new UnsupportedOperationException();
-          }
-
-        };
-      }
-
-    };
-  }
-
-  public static Iterable<IndexedInt> eachWithIndex(final int[] list) {
-
-    return new Iterable<IndexedInt>() {
-
-      public Iterator<IndexedInt> iterator() {
-        return new Iterator<IndexedInt>() {
-
-          int nextIndex = -1;
-          IndexedInt indexedValue;
-
-          public boolean hasNext() {
-            return (nextIndex < list.length);
-          }
-
-          public IndexedInt next() {
-            if (nextIndex >= list.length) {
-              throw new NoSuchElementException();
-            } else if (nextIndex < 0) {
-              nextIndex = 0;
-              indexedValue = new IndexedInt(list[nextIndex], nextIndex);
-            } else {
-              indexedValue.value = list[nextIndex];
-              indexedValue.index = nextIndex;
-            }
-
-            nextIndex += 1;
-            return indexedValue;
-          }
-
-          public void remove() {
-            throw new UnsupportedOperationException();
-          }
-
-        };
-      }
-
-    };
-  }
-
-  public static Iterable<IndexedLong> eachWithIndex(final long[] list) {
-
-    return new Iterable<IndexedLong>() {
-
-      public Iterator<IndexedLong> iterator() {
-        return new Iterator<IndexedLong>() {
-
-          int nextIndex = -1;
-          IndexedLong indexedValue;
-
-          public boolean hasNext() {
-            return (nextIndex < list.length);
-          }
-
-          public IndexedLong next() {
-            if (nextIndex >= list.length) {
-              throw new NoSuchElementException();
-            } else if (nextIndex < 0) {
-              nextIndex = 0;
-              indexedValue = new IndexedLong(list[nextIndex], nextIndex);
-            } else {
-              indexedValue.value = list[nextIndex];
-              indexedValue.index = nextIndex;
-            }
-
-            nextIndex += 1;
-            return indexedValue;
-          }
-
-          public void remove() {
-            throw new UnsupportedOperationException();
-          }
-
-        };
-      }
-
-    };
-  }
-
-  public static Iterable<IndexedFloat> eachWithIndex(final float[] list) {
-
-    return new Iterable<IndexedFloat>() {
-
-      public Iterator<IndexedFloat> iterator() {
-        return new Iterator<IndexedFloat>() {
-
-          int nextIndex = -1;
-          IndexedFloat indexedValue;
-
-          public boolean hasNext() {
-            return (nextIndex < list.length);
-          }
-
-          public IndexedFloat next() {
-            if (nextIndex >= list.length) {
-              throw new NoSuchElementException();
-            } else if (nextIndex < 0) {
-              nextIndex = 0;
-              indexedValue = new IndexedFloat(list[nextIndex], nextIndex);
-            } else {
-              indexedValue.value = list[nextIndex];
-              indexedValue.index = nextIndex;
-            }
-
-            nextIndex += 1;
-            return indexedValue;
-          }
-
-          public void remove() {
-            throw new UnsupportedOperationException();
-          }
-
-        };
-      }
-
-    };
-  }
-
-  public static Iterable<IndexedDouble> eachWithIndex(final double[] list) {
-
-    return new Iterable<IndexedDouble>() {
-
-      public Iterator<IndexedDouble> iterator() {
-        return new Iterator<IndexedDouble>() {
-
-          int nextIndex = -1;
-          IndexedDouble indexedValue;
-
-          public boolean hasNext() {
-            return (nextIndex < list.length);
-          }
-
-          public IndexedDouble next() {
-            if (nextIndex >= list.length) {
-              throw new NoSuchElementException();
-            } else if (nextIndex < 0) {
-              nextIndex = 0;
-              indexedValue = new IndexedDouble(list[nextIndex], nextIndex);
-            } else {
-              indexedValue.value = list[nextIndex];
-              indexedValue.index = nextIndex;
-            }
-
-            nextIndex += 1;
-            return indexedValue;
-          }
-
-          public void remove() {
-            throw new UnsupportedOperationException();
-          }
-
-        };
-      }
-
-    };
-  }
-
-  public static <V> Iterable<Indexed<V>> eachWithIndex(final V[] list) {
-    return new Iterable<Indexed<V>>() {
-
-      public Iterator<Indexed<V>> iterator() {
-        return new Iterator<Indexed<V>>() {
-
-          int nextIndex = -1;
-          Indexed<V> indexedValue;
-
-          public boolean hasNext() {
-            return (nextIndex < list.length);
-          }
-
-          public Indexed<V> next() {
-            if (nextIndex >= list.length) {
-              throw new NoSuchElementException();
-            } else if (nextIndex < 0) {
-              nextIndex = 0;
-              indexedValue = new Indexed<V>(list[nextIndex], nextIndex);
-            } else {
-              indexedValue.value = list[nextIndex];
-              indexedValue.index = nextIndex;
-            }
-
-            nextIndex += 1;
-            return indexedValue;
-          }
-
-          public void remove() {
-            throw new UnsupportedOperationException();
-          }
-
-        };
-      }
-
-    };
-  }
-
-  public static <V> Iterable<Indexed<V>> eachWithIndex(final Iterator<V> valueIterator) {
-    return new Iterable<Indexed<V>>() {
-
-      public Iterator<Indexed<V>> iterator() {
-        return new Iterator<Indexed<V>>() {
-
-          int nextIndex = -1;
-          Indexed<V> indexedValue;
-
-          public boolean hasNext() {
-            return valueIterator.hasNext();
-          }
-
-          public Indexed<V> next() {
-            if (!valueIterator.hasNext()) {
-              throw new NoSuchElementException();
-            } else if (nextIndex < 0) {
-              nextIndex = 0;
-              indexedValue = new Indexed<V>(valueIterator.next(), nextIndex);
-            } else {
-              indexedValue.value = valueIterator.next();
-              indexedValue.index = nextIndex;
-            }
-
-            nextIndex += 1;
-            return indexedValue;
-          }
-
-          public void remove() {
-            throw new UnsupportedOperationException();
-          }
-
-        };
-      }
-
-    };
-  }
-
-  public static <V> Iterable<Indexed<V>> eachWithIndex(final Iterable<V> iterable) {
-    return eachWithIndex(iterable.iterator());
-  }
-
-
-  public static class Index {
-
-    int index;
-
-    Index(int index) {
-      this.index = index;
-    }
-
-    public int getIndex() {
-      return this.index;
-    }
-
-    void setIndex(int index) {
-      this.index = index;
-    }
-  }
-
-  public static class IndexedBoolean extends Index {
-
-    boolean value;
-
-    IndexedBoolean(boolean value, int index) {
-      super(index);
-      this.value = value;
-    }
-
-    public boolean getValue() {
-      return this.value;
-    }
-
-    void setValue(boolean value) {
-      this.value = value;
-      this.index += 1;
-    }
-  }
-
-  public static class IndexedByte extends Index {
-
-    byte value;
-
-    IndexedByte(byte value, int index) {
-      super(index);
-      this.value = value;
-    }
-
-    public byte getValue() {
-      return this.value;
-    }
-
-    void setValue(byte value) {
-      this.value = value;
-      this.index += 1;
-    }
-  }
-
-  public static class IndexedShort extends Index {
-
-    short value;
-
-    IndexedShort(short value, int index) {
-      super(index);
-      this.value = value;
-    }
-
-    public short getValue() {
-      return this.value;
-    }
-
-    void setValue(short value) {
-      this.value = value;
-      this.index += 1;
-    }
-  }
-
-  public static class IndexedInt extends Index {
-
-    int value;
-
-    IndexedInt(int value, int index) {
-      super(index);
-      this.value = value;
-    }
-
-    public int getValue() {
-      return this.value;
-    }
-
-    void setValue(int value) {
-      this.value = value;
-      this.index += 1;
-    }
-  }
-
-  public static class IndexedLong extends Index {
-
-    long value;
-
-    IndexedLong(long value, int index) {
-      super(index);
-      this.value = value;
-    }
-
-    public long getValue() {
-      return this.value;
-    }
-
-    void setValue(long value) {
-      this.value = value;
-      this.index += 1;
-    }
-  }
-
-  public static class IndexedFloat extends Index {
-
-    float value;
-
-    IndexedFloat(float value, int index) {
-      super(index);
-      this.value = value;
-    }
-
-    public float getValue() {
-      return this.value;
-    }
-
-    void setValue(float value) {
-      this.value = value;
-      this.index += 1;
-    }
-  }
-
-  public static class IndexedDouble extends Index {
-
-    double value;
-
-    IndexedDouble(double value, int index) {
-      super(index);
-      this.value = value;
-    }
-
-    public double getValue() {
-      return this.value;
-    }
-
-    void setValue(double value) {
-      this.value = value;
-      this.index += 1;
-    }
-  }
-
-
-  public static class Indexed<V> extends Index {
-
-    V value;
-
-    Indexed(V value, int index) {
-      super(index);
-      this.value = value;
-    }
-
-    public V getValue() {
-      return this.value;
-    }
-  }
-}

http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/840eb4ce/src/main/java/org/apache/joshua/util/NullIterator.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/joshua/util/NullIterator.java b/src/main/java/org/apache/joshua/util/NullIterator.java
deleted file mode 100644
index c6e4b46..0000000
--- a/src/main/java/org/apache/joshua/util/NullIterator.java
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *  http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.joshua.util;
-
-import java.util.Iterator;
-import java.util.NoSuchElementException;
-
-
-/**
- * This class provides a null-object Iterator. That is, an iterator over an empty collection.
- * 
- * @author wren ng thornton wren@users.sourceforge.net
- * @version $LastChangedDate: 2009-03-26 15:06:57 -0400 (Thu, 26 Mar 2009) $
- */
-public class NullIterator<E> implements Iterable<E>, Iterator<E> {
-
-  // ===============================================================
-  // Iterable -- for foreach loops, because sometimes Java can be very stupid
-  // ===============================================================
-
-  /**
-   * Return self as an iterator. We restrict the return type because some code is written to accept
-   * both Iterable and Iterator, and the fact that we are both confuses Java. So this is just an
-   * upcast, but more succinct to type.
-   */
-  public Iterator<E> iterator() {
-    return this;
-  }
-
-
-  // ===============================================================
-  // Iterator
-  // ===============================================================
-
-  /** Always returns false. */
-  public boolean hasNext() {
-    return false;
-  }
-
-  /** Always throws {@link NoSuchElementException}. */
-  public E next() throws NoSuchElementException {
-    throw new NoSuchElementException();
-  }
-
-  /** Unsupported. */
-  public void remove() throws UnsupportedOperationException {
-    throw new UnsupportedOperationException();
-  }
-}

http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/840eb4ce/src/main/java/org/apache/joshua/util/QuietFormatter.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/joshua/util/QuietFormatter.java b/src/main/java/org/apache/joshua/util/QuietFormatter.java
deleted file mode 100644
index 7220080..0000000
--- a/src/main/java/org/apache/joshua/util/QuietFormatter.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *  http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.joshua.util;
-
-import java.util.logging.Formatter;
-import java.util.logging.LogRecord;
-
-/**
- * Log formatter that prints just the message, with no time stamp.
- * 
- * @author Lane Schwartz
- * @version $LastChangedDate$
- */
-public class QuietFormatter extends Formatter {
-
-  public String format(LogRecord record) {
-    return "" + formatMessage(record) + "\n";
-  }
-
-}

http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/840eb4ce/src/main/java/org/apache/joshua/util/ReverseOrder.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/joshua/util/ReverseOrder.java b/src/main/java/org/apache/joshua/util/ReverseOrder.java
deleted file mode 100644
index 0270036..0000000
--- a/src/main/java/org/apache/joshua/util/ReverseOrder.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *  http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.joshua.util;
-
-import java.util.Comparator;
-
-/**
- * ReverseOrder is a Comparator that reverses the natural order of Comparable objects.
- * 
- * @author Chris Callison-Burch
- * @since 2 June 2008
- */
-public class ReverseOrder<K extends Comparable<K>> implements Comparator<K> {
-
-  public int compare(K obj1, K obj2) {
-    int comparison = obj1.compareTo(obj2);
-    if (comparison != 0) {
-      comparison = comparison * -1;
-    }
-    return comparison;
-  }
-
-}

http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/840eb4ce/src/main/java/org/apache/joshua/util/SampledList.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/joshua/util/SampledList.java b/src/main/java/org/apache/joshua/util/SampledList.java
deleted file mode 100644
index 60b0ef9..0000000
--- a/src/main/java/org/apache/joshua/util/SampledList.java
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *  http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.joshua.util;
-
-import java.util.AbstractList;
-import java.util.List;
-
-/**
- * List that performs sampling at specified intervals.
- * 
- * @author Lane Schwartz
- * @version $LastChangedDate$
- */
-public class SampledList<E> extends AbstractList<E> implements List<E> {
-
-  private final List<E> list;
-  private final int size;
-  private final int stepSize;
-
-  /**
-   * Constructs a sampled list backed by a provided list.
-   * <p>
-   * The maximum size of this list will be no greater than the provided sample size.
-   * 
-   * @param list List from which to sample.
-   * @param sampleSize Maximum number of items to include in the new sampled list.
-   */
-  public SampledList(List<E> list, int sampleSize) {
-    this.list = list;
-
-    int listSize = list.size();
-
-    if (listSize <= sampleSize) {
-      this.size = listSize;
-      this.stepSize = 1;
-    } else {
-      this.size = sampleSize;
-      this.stepSize = listSize / sampleSize;
-    }
-
-  }
-
-  @Override
-  public E get(int index) {
-    return list.get(index * stepSize);
-  }
-
-  @Override
-  public int size() {
-    return size;
-  }
-
-}

http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/840eb4ce/src/main/java/org/apache/joshua/util/SocketUtility.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/joshua/util/SocketUtility.java b/src/main/java/org/apache/joshua/util/SocketUtility.java
deleted file mode 100644
index 134fd35..0000000
--- a/src/main/java/org/apache/joshua/util/SocketUtility.java
+++ /dev/null
@@ -1,144 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *  http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.joshua.util;
-
-import java.io.BufferedReader;
-import java.io.DataInputStream;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.io.OutputStreamWriter;
-import java.io.PrintWriter;
-import java.net.InetAddress;
-import java.net.InetSocketAddress;
-import java.net.Socket;
-import java.net.SocketAddress;
-
-/**
- * 
- * @author Zhifei Li, zhifei.work@gmail.com
- * @version $LastChangedDate$
- */
-public class SocketUtility {
-
-  // ############# client side #########
-  // connect to server
-  public static ClientConnection open_connection_client(String hostname, int port) {
-    ClientConnection res = new ClientConnection();
-    // TODO: remove from class
-    // res.hostname = hostname;
-    // res.port = port;
-    try {
-      InetAddress addr = InetAddress.getByName(hostname);
-      SocketAddress sockaddr = new InetSocketAddress(addr, port);
-
-      res.socket = new Socket(); // Create an unbound socket
-      // This method will block no more than timeoutMs If the timeout occurs, SocketTimeoutException
-      // is thrown.
-      int timeoutMs = 3000; // 2 seconds
-      res.socket.connect(sockaddr, timeoutMs);
-      res.socket.setKeepAlive(true);
-      // file
-      res.in = new BufferedReader(new InputStreamReader(res.socket.getInputStream()));
-      res.out = new PrintWriter(new OutputStreamWriter(res.socket.getOutputStream()));
-
-      // TODO: for debugging, but should be removed
-      // res.data_in = new DataInputStream(new BufferedInputStream( res.socket.getInputStream()));
-      // res.data_out = new DataOutputStream(new BufferedOutputStream
-      // (res.socket.getOutputStream()));
-
-    } catch ( IOException e) {
-      throw new RuntimeException(e);
-    }
-    return res;
-  }
-
-
-  public static class ClientConnection {
-    // TODO: These are never read from, so we're planning to remove them
-    // String hostname; // server name
-    // int port; // server port
-    Socket socket;
-    public BufferedReader in;
-    public PrintWriter out;
-
-    // TODO: for debugging, but should be removed
-    // public DataOutputStream data_out;
-    // public DataInputStream data_in;
-
-    public String exe_request(String line_out) {
-      String line_res = null;
-      try {
-        out.println(line_out);
-        out.flush();
-        line_res = in.readLine(); // TODO block function, big bug, the server may close the section
-                                  // (e.g., the server thread is dead due to out of memory(which is
-                                  // possible due to cache) )
-      } catch (IOException ioe) {
-        ioe.printStackTrace();
-      }
-      return line_res;
-    }
-
-    public void write_line(String line_out) {
-      out.println(line_out);
-      out.flush();
-    }
-
-    public void write_int(int line_out) {
-      out.println(line_out);
-      out.flush();
-    }
-
-    public String read_line() {
-      String line_res = null;
-      try {
-        line_res = in.readLine(); // TODO block function, big bug, the server may close the section
-                                  // (e.g., the server thread is dead due to out of memory(which is
-                                  // possible due to cache) )
-      } catch (IOException ioe) {
-        ioe.printStackTrace();
-      }
-      return line_res;
-    }
-
-
-    public void close() {
-      try {
-        socket.close();
-      } catch (IOException ioe) {
-        ioe.printStackTrace();
-      }
-    }
-
-    public static double readDoubleLittleEndian(DataInputStream d_in) {
-      long accum = 0;
-      try {
-        for (int shiftBy = 0; shiftBy < 64; shiftBy += 8) {
-          // must cast to long or shift done modulo 32
-          accum |= ((long) (d_in.readByte() & 0xff)) << shiftBy;
-        }
-      } catch (IOException ioe) {
-        ioe.printStackTrace();
-      }
-
-      return Double.longBitsToDouble(accum);
-      // there is no such method as Double.reverseBytes(d);
-    }
-  }
-}

http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/840eb4ce/src/main/java/org/apache/joshua/util/encoding/Analyzer.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/joshua/util/encoding/Analyzer.java b/src/main/java/org/apache/joshua/util/encoding/Analyzer.java
index ad2910c..d9bab66 100644
--- a/src/main/java/org/apache/joshua/util/encoding/Analyzer.java
+++ b/src/main/java/org/apache/joshua/util/encoding/Analyzer.java
@@ -87,7 +87,7 @@ public class Analyzer {
         // If the count is not 0, i.e. there were negative values, we should
         // not bucket them with the positive ones. Close out the bucket now.
         if (count != 0 && index < buckets.length - 2) {
-          buckets[index++] = (float) sum / count;
+          buckets[index++] = sum / count;
           count = 0;
           sum = 0;
         }
@@ -98,15 +98,15 @@ public class Analyzer {
       sum += key * value;
       // Check if the bucket is full.
       if (count >= size && index < buckets.length - 2) {
-        buckets[index++] = (float) sum / count;
+        buckets[index++] = sum / count;
         count = 0;
         sum = 0;
       }
       last_key = key;
     }
     if (count > 0 && index < buckets.length - 1)
-      buckets[index++] = (float) sum / count;
-    
+      buckets[index++] = sum / count;
+
     float[] shortened = new float[index];
     for (int i = 0; i < shortened.length; ++i)
       shortened[i] = buckets[i];
@@ -167,7 +167,7 @@ public class Analyzer {
       return PrimitiveFloatEncoder.INT;
     return PrimitiveFloatEncoder.FLOAT;
   }
-  
+
   public FloatEncoder inferType(int bits) {
     if (isBoolean())
       return PrimitiveFloatEncoder.BOOLEAN;
@@ -191,45 +191,46 @@ public class Analyzer {
       sb.append(label + "\t" + String.format("%.5f", val) + "\t" + histogram.get(val) + "\n");
     return sb.toString();
   }
-  
+
   public static void main(String[] args) throws IOException {
-    LineReader reader = new LineReader(args[0]);
-    ArrayList<Float> s = new ArrayList<Float>();
-
-    System.out.println("Initialized.");
-    while (reader.hasNext())
-      s.add(Float.parseFloat(reader.next().trim()));
-    System.out.println("Data read.");
-    int n = s.size();
-    byte[] c = new byte[n];
-    ByteBuffer b = ByteBuffer.wrap(c);
-    Analyzer q = new Analyzer();
-
-    q.initialize();
-    for (int i = 0; i < n; i++)
-      q.add(s.get(i));
-    EightBitQuantizer eb = new EightBitQuantizer(q.quantize(8));
-    System.out.println("Quantizer learned.");
-
-    for (int i = 0; i < n; i++)
-      eb.write(b, s.get(i));
-    b.rewind();
-    System.out.println("Quantization complete.");
-
-    float avg_error = 0;
-    float error = 0;
-    int count = 0;
-    for (int i = -4; i < n - 4; i++) {
-      float coded = eb.read(b, i);
-      if (s.get(i + 4) != 0) {
-        error = Math.abs(s.get(i + 4) - coded);
-        avg_error += error;
-        count++;
+    try (LineReader reader = new LineReader(args[0]);) {
+      ArrayList<Float> s = new ArrayList<Float>();
+
+      System.out.println("Initialized.");
+      while (reader.hasNext())
+        s.add(Float.parseFloat(reader.next().trim()));
+      System.out.println("Data read.");
+      int n = s.size();
+      byte[] c = new byte[n];
+      ByteBuffer b = ByteBuffer.wrap(c);
+      Analyzer q = new Analyzer();
+
+      q.initialize();
+      for (int i = 0; i < n; i++)
+        q.add(s.get(i));
+      EightBitQuantizer eb = new EightBitQuantizer(q.quantize(8));
+      System.out.println("Quantizer learned.");
+
+      for (int i = 0; i < n; i++)
+        eb.write(b, s.get(i));
+      b.rewind();
+      System.out.println("Quantization complete.");
+
+      float avg_error = 0;
+      float error = 0;
+      int count = 0;
+      for (int i = -4; i < n - 4; i++) {
+        float coded = eb.read(b, i);
+        if (s.get(i + 4) != 0) {
+          error = Math.abs(s.get(i + 4) - coded);
+          avg_error += error;
+          count++;
+        }
       }
-    }
-    avg_error /= count;
-    System.out.println("Evaluation complete.");
+      avg_error /= count;
+      System.out.println("Evaluation complete.");
 
-    System.out.println("Average quanitization error over " + n + " samples is: " + avg_error);
+      System.out.println("Average quanitization error over " + n + " samples is: " + avg_error);
+    }
   }
 }

http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/840eb4ce/src/main/java/org/apache/joshua/util/encoding/FeatureTypeAnalyzer.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/joshua/util/encoding/FeatureTypeAnalyzer.java b/src/main/java/org/apache/joshua/util/encoding/FeatureTypeAnalyzer.java
index 504859f..d485ea5 100644
--- a/src/main/java/org/apache/joshua/util/encoding/FeatureTypeAnalyzer.java
+++ b/src/main/java/org/apache/joshua/util/encoding/FeatureTypeAnalyzer.java
@@ -62,26 +62,27 @@ public class FeatureTypeAnalyzer {
   }
 
   public void readConfig(String config_filename) throws IOException {
-    LineReader reader = new LineReader(config_filename);
-    while (reader.hasNext()) {
-      // Clean up line, chop comments off and skip if the result is empty.
-      String line = reader.next().trim();
-      if (line.indexOf('#') != -1)
-        line = line.substring(0, line.indexOf('#'));
-      if (line.isEmpty())
-        continue;
-      String[] fields = line.split("[\\s]+");
-
-      if ("encoder".equals(fields[0])) {
-        // Adding an encoder to the mix.
-        if (fields.length < 3) {
-          throw new RuntimeException("Incomplete encoder line in config.");
+    try(LineReader reader = new LineReader(config_filename);) {
+      while (reader.hasNext()) {
+        // Clean up line, chop comments off and skip if the result is empty.
+        String line = reader.next().trim();
+        if (line.indexOf('#') != -1)
+          line = line.substring(0, line.indexOf('#'));
+        if (line.isEmpty())
+          continue;
+        String[] fields = line.split("[\\s]+");
+
+        if ("encoder".equals(fields[0])) {
+          // Adding an encoder to the mix.
+          if (fields.length < 3) {
+            throw new RuntimeException("Incomplete encoder line in config.");
+          }
+          String encoder_key = fields[1];
+          List<Integer> feature_ids = new ArrayList<Integer>();
+          for (int i = 2; i < fields.length; i++)
+            feature_ids.add(Vocabulary.id(fields[i]));
+          addFeatures(encoder_key, feature_ids);
         }
-        String encoder_key = fields[1];
-        ArrayList<Integer> feature_ids = new ArrayList<Integer>();
-        for (int i = 2; i < fields.length; i++)
-          feature_ids.add(Vocabulary.id(fields[i]));
-        addFeatures(encoder_key, feature_ids);
       }
     }
   }
@@ -182,6 +183,7 @@ public class FeatureTypeAnalyzer {
     out_stream.close();
   }
 
+  @Override
   public String toString() {
     StringBuilder sb = new StringBuilder();
     for (int feature_id : featureToType.keySet()) {
@@ -198,7 +200,7 @@ public class FeatureTypeAnalyzer {
     this.labeled = labeled;
   }
 
-  class FeatureType {
+  static class FeatureType {
     FloatEncoder encoder;
     Analyzer analyzer;
     int bits;
@@ -236,6 +238,7 @@ public class FeatureTypeAnalyzer {
         analyzer.add(value);
     }
 
+    @Override
     public boolean equals(Object t) {
       if (t != null && t instanceof FeatureType) {
         FeatureType that = (FeatureType) t;

http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/840eb4ce/src/main/java/org/apache/joshua/util/io/ExistingUTF8EncodedTextFile.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/joshua/util/io/ExistingUTF8EncodedTextFile.java b/src/main/java/org/apache/joshua/util/io/ExistingUTF8EncodedTextFile.java
new file mode 100644
index 0000000..42dd236
--- /dev/null
+++ b/src/main/java/org/apache/joshua/util/io/ExistingUTF8EncodedTextFile.java
@@ -0,0 +1,77 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.joshua.util.io;
+
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.function.Predicate;
+import java.util.stream.Stream;
+
+/**
+ * A class that represents a {@link StandardCharsets#UTF_8} text file. Will
+ * throw a {@link FileNotFoundException} upon instantiation if the underlying
+ * {@link Path}, or {@link String} representing a Path, is not found.
+ */
+public class ExistingUTF8EncodedTextFile {
+  private static final Predicate<String> emptyStringPredicate = s -> s.isEmpty();
+
+  private final Path p;
+
+  public ExistingUTF8EncodedTextFile(String pathStr) throws FileNotFoundException {
+    this(Paths.get(pathStr));
+  }
+
+  public ExistingUTF8EncodedTextFile(Path p) throws FileNotFoundException {
+    this.p = p;
+    if (!Files.exists(p))
+      throw new FileNotFoundException("Did not find the file at path: " + p.toString());
+  }
+
+  /**
+   * @return the {@link Path} representing this object
+   */
+  public Path getPath() {
+    return this.p;
+  }
+
+  /**
+   * @return the number of lines in the file represented by this object
+   * @throws IOException on inability to read file (maybe it's not a text file)
+   */
+  public int getNumberOfLines() throws IOException {
+    try(Stream<String> ls = Files.lines(this.p, StandardCharsets.UTF_8);) {
+      return (int) ls.count();
+    }
+  }
+
+  /**
+   * @return the number of non-empty lines in the file represented by this object
+   * @throws IOException on inability to read file (maybe it's not a text file)
+   */
+  public int getNumberOfNonEmptyLines() throws IOException {
+    try(Stream<String> ls = Files.lines(this.p, StandardCharsets.UTF_8);) {
+      return (int) ls.filter(emptyStringPredicate.negate())
+          .count();
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/840eb4ce/src/main/java/org/apache/joshua/util/io/IndexedReader.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/joshua/util/io/IndexedReader.java b/src/main/java/org/apache/joshua/util/io/IndexedReader.java
index f357e55..d206544 100644
--- a/src/main/java/org/apache/joshua/util/io/IndexedReader.java
+++ b/src/main/java/org/apache/joshua/util/io/IndexedReader.java
@@ -25,12 +25,11 @@ import java.util.NoSuchElementException;
 
 /**
  * Wraps a reader with "line" index information.
- * 
+ *
  * @author wren ng thornton wren@users.sourceforge.net
  * @version $LastChangedDate: 2009-03-26 15:06:57 -0400 (Thu, 26 Mar 2009) $
  */
 public class IndexedReader<E> implements Reader<E> {
-
   /** A name for the type of elements the reader produces. */
   private final String elementName;
 
@@ -46,7 +45,7 @@ public class IndexedReader<E> implements Reader<E> {
     this.reader = reader;
   }
 
-  /** 
+  /**
    * Return the number of elements delivered so far.
    * @return integer representing the number of elements delivered so far
    */
@@ -72,7 +71,7 @@ public class IndexedReader<E> implements Reader<E> {
   // Reader
   // ===============================================================
 
-  /** 
+  /**
    * Delegated to the underlying reader.
    * @return true if the reader is ready
    * @throws IOException if there is an error determining readiness
@@ -92,6 +91,7 @@ public class IndexedReader<E> implements Reader<E> {
    * however, when we fall out of scope, the underlying reader will too, so its finalizer may be
    * called. For correctness, be sure to manually close all readers.
    */
+  @Override
   public void close() throws IOException {
     try {
       this.reader.close();
@@ -102,6 +102,7 @@ public class IndexedReader<E> implements Reader<E> {
 
 
   /** Delegated to the underlying reader. */
+  @Override
   public E readLine() throws IOException {
     E line;
     try {
@@ -119,6 +120,7 @@ public class IndexedReader<E> implements Reader<E> {
   // ===============================================================
 
   /** Return self as an iterator. */
+  @Override
   public Iterator<E> iterator() {
     return this;
   }
@@ -129,12 +131,14 @@ public class IndexedReader<E> implements Reader<E> {
   // ===============================================================
 
   /** Delegated to the underlying reader. */
+  @Override
   public boolean hasNext() {
     return this.reader.hasNext();
   }
 
 
   /** Delegated to the underlying reader. */
+  @Override
   public E next() throws NoSuchElementException {
     E line = this.reader.next();
     // Let exceptions out, we'll wrap any errors a closing time.
@@ -149,6 +153,7 @@ public class IndexedReader<E> implements Reader<E> {
    * returns the number of elements delivered to the client, so removing an element from the
    * underlying collection does not affect that number.
    */
+  @Override
   public void remove() throws UnsupportedOperationException {
     this.reader.remove();
   }

http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/840eb4ce/src/main/java/org/apache/joshua/util/io/LineReader.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/joshua/util/io/LineReader.java b/src/main/java/org/apache/joshua/util/io/LineReader.java
index 5122994..09e22c2 100644
--- a/src/main/java/org/apache/joshua/util/io/LineReader.java
+++ b/src/main/java/org/apache/joshua/util/io/LineReader.java
@@ -19,13 +19,13 @@
 package org.apache.joshua.util.io;
 
 import java.io.BufferedReader;
+import java.io.File;
 import java.io.FileDescriptor;
 import java.io.FileInputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
-import java.io.File;
-import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
 import java.util.Iterator;
 import java.util.NoSuchElementException;
 import java.util.zip.GZIPInputStream;
@@ -35,19 +35,13 @@ import org.apache.joshua.decoder.Decoder;
 /**
  * This class provides an Iterator interface to a BufferedReader. This covers the most common
  * use-cases for reading from files without ugly code to check whether we got a line or not.
- * 
+ *
  * @author wren ng thornton wren@users.sourceforge.net
  * @author Matt Post post@cs.jhu.edu
  */
 public class LineReader implements Reader<String> {
 
   /*
-   * Note: charset name is case-agnostic "UTF-8" is the canonical name "UTF8", "unicode-1-1-utf-8"
-   * are aliases Java doesn't distinguish utf8 vs UTF-8 like Perl does
-   */
-  private static final Charset FILE_ENCODING = Charset.forName("UTF-8");
-
-  /*
    * The reader and its underlying input stream. We need to keep a hold of the underlying
    * input stream so that we can query how many raw bytes it's read (for a generic progress
    * meter that works across GZIP'ed and plain text files).
@@ -59,9 +53,9 @@ public class LineReader implements Reader<String> {
   private IOException error;
 
   private int lineno = 0;
-  
+
   private boolean display_progress = false;
-  
+
   private int progress = 0;
 
   // ===============================================================
@@ -71,17 +65,17 @@ public class LineReader implements Reader<String> {
   /**
    * Opens a file for iterating line by line. The special "-" filename can be used to specify
    * STDIN. GZIP'd files are tested for automatically.
-   * 
+   *
    * @param filename the file to be opened ("-" for STDIN)
    * @throws IOException if there is an error reading the input file
    */
   public LineReader(String filename) throws IOException {
-    
+
     display_progress = (Decoder.VERBOSE >= 1);
-    
+
     progress = 0;
-    
-    InputStream stream = null; 
+
+    InputStream stream = null;
     long totalBytes = -1;
     if (filename.equals("-")) {
       rawStream = null;
@@ -97,11 +91,11 @@ public class LineReader implements Reader<String> {
         rawStream.close();
         stream = rawStream = new ProgressInputStream(new FileInputStream(filename), totalBytes);
       }
-    } 
-    
-    this.reader = new BufferedReader(new InputStreamReader(stream, FILE_ENCODING));
+    }
+
+    this.reader = new BufferedReader(new InputStreamReader(stream, StandardCharsets.UTF_8));
   }
-  
+
   public LineReader(String filename, boolean show_progress) throws IOException {
     this(filename);
     display_progress = (Decoder.VERBOSE >= 1 && show_progress);
@@ -113,19 +107,19 @@ public class LineReader implements Reader<String> {
    * @param in an {@link java.io.InputStream} to wrap and iterate over line by line
    */
   public LineReader(InputStream in) {
-    this.reader = new BufferedReader(new InputStreamReader(in, FILE_ENCODING));
+    this.reader = new BufferedReader(new InputStreamReader(in, StandardCharsets.UTF_8));
     display_progress = false;
   }
-  
+
   /**
-   * Chain to the underlying {@link ProgressInputStream}. 
-   * 
+   * Chain to the underlying {@link ProgressInputStream}.
+   *
    * @return an integer from 0..100, indicating how much of the file has been read.
    */
   public int progress() {
     return rawStream == null ? 0 : rawStream.progress();
   }
-  
+
   /**
    * This method will close the file handle, and will raise any exceptions that occured during
    * iteration. The method is idempotent, and all calls after the first are no-ops (unless the
@@ -133,6 +127,7 @@ public class LineReader implements Reader<String> {
    * object falls out of scope.
    * @throws IOException if there is an error closing the file handler
    */
+  @Override
   public void close() throws IOException {
 
     this.buffer = null; // Just in case it's a large string
@@ -161,42 +156,13 @@ public class LineReader implements Reader<String> {
     }
   }
 
-
-  /**
-   * We attempt to avoid leaking file descriptors if you fail to call close before the object falls
-   * out of scope. However, the language spec makes <b>no guarantees</b> about timeliness of garbage
-   * collection. It is a bug to rely on this method to release the resources. Also, the garbage
-   * collector will discard any exceptions that have queued up, without notifying the application in
-   * any way.
-   * 
-   * Having a finalizer means the JVM can't do "fast allocation" of LineReader objects (or
-   * subclasses). This isn't too important due to disk latency, but may be worth noting.
-   * 
-   * @see <a
-   *      href="http://java2go.blogspot.com/2007/09/javaone-2007-performance-tips-2-finish.html">Performance
-   *      Tips</a>
-   * @see <a
-   *      href="http://www.javaworld.com/javaworld/jw-06-1998/jw-06-techniques.html?page=1">Techniques</a>
-   */
-  protected void finalize() throws Throwable {
-    try {
-      this.close();
-    } catch (IOException e) {
-      // Do nothing. The GC will discard the exception
-      // anyways, but it may cause us to linger on the heap.
-    } finally {
-      super.finalize();
-    }
-  }
-
-
-
   // ===============================================================
   // Reader
   // ===============================================================
 
   // Copied from interface documentation.
   /** Determine if the reader is ready to read a line. */
+  @Override
   public boolean ready() throws IOException {
     return this.reader.ready();
   }
@@ -206,6 +172,7 @@ public class LineReader implements Reader<String> {
    * This method is like next() except that it throws the IOException directly. If there are no
    * lines to be read then null is returned.
    */
+  @Override
   public String readLine() throws IOException {
     if (this.hasNext()) {
       String line = this.buffer;
@@ -228,6 +195,7 @@ public class LineReader implements Reader<String> {
   // ===============================================================
 
   /** Return self as an iterator. */
+  @Override
   public Iterator<String> iterator() {
     return this;
   }
@@ -243,6 +211,7 @@ public class LineReader implements Reader<String> {
    * <code>true</code> if <code>next</code> would return an element rather than throwing an
    * exception.)
    */
+  @Override
   public boolean hasNext() {
     if (null != this.buffer) {
       return true;
@@ -269,12 +238,13 @@ public class LineReader implements Reader<String> {
    * The actual IOException encountered will be thrown later, when the LineReader is closed. Also if
    * there is no line to be read then NoSuchElementException is thrown.
    */
+  @Override
   public String next() throws NoSuchElementException {
     if (this.hasNext()) {
       if (display_progress) {
         int newProgress = (reader != null) ? progress() : 100;
 //        System.err.println(String.format("OLD %d NEW %d", progress, newProgress));
-        
+
         if (newProgress > progress) {
           for (int i = progress + 1; i <= newProgress; i++)
             if (i == 97) {
@@ -297,7 +267,7 @@ public class LineReader implements Reader<String> {
           progress = newProgress;
         }
       }
-      
+
       String line = this.buffer;
       this.lineno++;
       this.buffer = null;
@@ -306,39 +276,19 @@ public class LineReader implements Reader<String> {
       throw new NoSuchElementException();
     }
   }
-  
+
   /* Get the line number of the last line that was returned */
   public int lineno() {
     return this.lineno;
   }
 
   /** Unsupported. */
+  @Override
   public void remove() throws UnsupportedOperationException {
     throw new UnsupportedOperationException();
   }
 
-
   /**
-   * Iterates over all lines, ignoring their contents, and returns the count of lines. If some lines
-   * have already been read, this will return the count of remaining lines. Because no lines will
-   * remain after calling this method, we implicitly call close.
-   * 
-   * @return the number of lines read
-   * @throws IOException if there is an error reading lines
-   */
-  public int countLines() throws IOException {
-    int lines = 0;
-
-    while (this.hasNext()) {
-      this.next();
-      lines++;
-    }
-    this.close();
-
-    return lines;
-  }
-
-  /** 
    * Example usage code.
    * @param args an input file
    */
@@ -348,19 +298,10 @@ public class LineReader implements Reader<String> {
       System.exit(1);
     }
 
-    try {
-
-      LineReader in = new LineReader(args[0]);
-      try {
-        for (String line : in) {
-
-          System.out.println(line);
-
-        }
-      } finally {
-        in.close();
+    try (LineReader in = new LineReader(args[0]);) {
+      for (String line : in) {
+        System.out.println(line);
       }
-
     } catch (IOException e) {
       e.printStackTrace();
     }

http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/840eb4ce/src/main/java/org/apache/joshua/util/io/NullReader.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/joshua/util/io/NullReader.java b/src/main/java/org/apache/joshua/util/io/NullReader.java
deleted file mode 100644
index f833f00..0000000
--- a/src/main/java/org/apache/joshua/util/io/NullReader.java
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *  http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.joshua.util.io;
-
-import java.io.IOException;
-
-import org.apache.joshua.util.NullIterator;
-
-
-/**
- * This class provides a null-object Reader. This is primarily useful for when you may or may not
- * have a {@link Reader}, and you don't want to check for null all the time. All operations are
- * no-ops.
- * 
- * @author wren ng thornton wren@users.sourceforge.net
- * @version $LastChangedDate: 2009-03-26 15:06:57 -0400 (Thu, 26 Mar 2009) $
- */
-public class NullReader<E> extends NullIterator<E> implements Reader<E> {
-
-  // ===============================================================
-  // Constructors and destructors
-  // ===============================================================
-
-  // TODO: use static factory method and singleton?
-  public NullReader() {}
-
-  /** A no-op. */
-  public void close() throws IOException {}
-
-
-  // ===============================================================
-  // Reader
-  // ===============================================================
-
-  /**
-   * Always returns true. Is this correct? What are the semantics of ready()? We're always capable
-   * of delivering nothing, but we're never capable of delivering anything...
-   */
-  public boolean ready() {
-    return true;
-  }
-
-  /** Always returns null. */
-  public E readLine() throws IOException {
-    return null;
-  }
-}

http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/840eb4ce/src/main/java/org/apache/joshua/util/io/Reader.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/joshua/util/io/Reader.java b/src/main/java/org/apache/joshua/util/io/Reader.java
index cab6d74..e3a150e 100644
--- a/src/main/java/org/apache/joshua/util/io/Reader.java
+++ b/src/main/java/org/apache/joshua/util/io/Reader.java
@@ -23,26 +23,27 @@ import java.util.Iterator;
 
 /**
  * Common interface for Reader type objects.
- * 
+ *
  * @author wren ng thornton wren@users.sourceforge.net
  * @version $LastChangedDate: 2009-03-26 15:06:57 -0400 (Thu, 26 Mar 2009) $
  */
-public interface Reader<E> extends Iterable<E>, Iterator<E> {
+public interface Reader<E> extends Iterable<E>, Iterator<E>, AutoCloseable {
 
-  /** 
+  /**
    * Close the reader, freeing all resources.
    * @throws IOException if there is an error closing the reader instance
    */
+  @Override
   void close() throws IOException;
 
-  /** 
+  /**
    * Determine if the reader is ready to read a line.
    * @return true if it is ready
    * @throws IOException if there is an error whilst determining if the reader if ready
    */
   boolean ready() throws IOException;
 
-  /** 
+  /**
    * Read a "line" and return an object representing it.
    * @return an object representing a single line
    * @throws IOException if there is an error reading lines

http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/840eb4ce/src/main/java/org/apache/joshua/util/quantization/Quantizer.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/joshua/util/quantization/Quantizer.java b/src/main/java/org/apache/joshua/util/quantization/Quantizer.java
index 33a4e9a..ab291be 100644
--- a/src/main/java/org/apache/joshua/util/quantization/Quantizer.java
+++ b/src/main/java/org/apache/joshua/util/quantization/Quantizer.java
@@ -17,29 +17,27 @@
  * under the License.
  */
 package org.apache.joshua.util.quantization;
- 
-import java.io.DataInputStream; 
-import java.io.DataOutputStream; 
-import java.io.IOException; 
-import java.nio.ByteBuffer; 
- 
-public interface Quantizer { 
- 
-  public float read(ByteBuffer stream, int position); 
- 
-  public void write(ByteBuffer stream, float value); 
- 
-  public void initialize(); 
- 
-  public void add(float key); 
- 
-  public void finalize(); 
- 
-  public String getKey(); 
- 
-  public void writeState(DataOutputStream out) throws IOException; 
- 
-  public void readState(DataInputStream in) throws IOException; 
- 
-  public int size(); 
+
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.nio.ByteBuffer;
+
+public interface Quantizer {
+
+  public float read(ByteBuffer stream, int position);
+
+  public void write(ByteBuffer stream, float value);
+
+  public void initialize();
+
+  public void add(float key);
+
+  public String getKey();
+
+  public void writeState(DataOutputStream out) throws IOException;
+
+  public void readState(DataInputStream in) throws IOException;
+
+  public int size();
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/840eb4ce/src/main/java/org/apache/joshua/util/quantization/QuantizerConfiguration.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/joshua/util/quantization/QuantizerConfiguration.java b/src/main/java/org/apache/joshua/util/quantization/QuantizerConfiguration.java
index f4765f9..39aef36 100644
--- a/src/main/java/org/apache/joshua/util/quantization/QuantizerConfiguration.java
+++ b/src/main/java/org/apache/joshua/util/quantization/QuantizerConfiguration.java
@@ -18,102 +18,97 @@
  */
 package org.apache.joshua.util.quantization;
 
-import java.io.BufferedInputStream; 
-import java.io.BufferedOutputStream; 
-import java.io.DataInputStream; 
-import java.io.DataOutputStream; 
-import java.io.File; 
-import java.io.FileInputStream; 
-import java.io.FileOutputStream; 
-import java.io.IOException; 
-import java.util.ArrayList; 
-import java.util.HashMap; 
-import java.util.List; 
-import java.util.Map; 
+import java.io.BufferedInputStream;
+import java.io.BufferedOutputStream;
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
 
-import org.apache.joshua.corpus.Vocabulary; 
+import org.apache.joshua.corpus.Vocabulary;
 
-public class QuantizerConfiguration { 
+public class QuantizerConfiguration {
 
-  private static final Quantizer DEFAULT; 
+  private static final Quantizer DEFAULT;
 
-  private ArrayList<Quantizer> quantizers; 
-  private Map<Integer, Integer> quantizerByFeatureId; 
+  private ArrayList<Quantizer> quantizers;
+  private Map<Integer, Integer> quantizerByFeatureId;
 
-  static { 
-    DEFAULT = new BooleanQuantizer(); 
-  } 
+  static {
+    DEFAULT = new BooleanQuantizer();
+  }
 
-  public QuantizerConfiguration() { 
-    quantizers = new ArrayList<Quantizer>(); 
-    quantizerByFeatureId = new HashMap<Integer, Integer>(); 
-  } 
+  public QuantizerConfiguration() {
+    quantizers = new ArrayList<Quantizer>();
+    quantizerByFeatureId = new HashMap<Integer, Integer>();
+  }
 
-  public void add(String quantizer_key, List<Integer> feature_ids) { 
-    Quantizer q = QuantizerFactory.get(quantizer_key); 
-    quantizers.add(q); 
-    int index = quantizers.size() - 1; 
-    for (int feature_id : feature_ids) 
-      quantizerByFeatureId.put(feature_id, index); 
-  } 
+  public void add(String quantizer_key, List<Integer> feature_ids) {
+    Quantizer q = QuantizerFactory.get(quantizer_key);
+    quantizers.add(q);
+    int index = quantizers.size() - 1;
+    for (int feature_id : feature_ids)
+      quantizerByFeatureId.put(feature_id, index);
+  }
 
-  public void initialize() { 
-    for (Quantizer q : quantizers) 
-      q.initialize(); 
-  } 
+  public void initialize() {
+    for (Quantizer q : quantizers)
+      q.initialize();
+  }
 
-  public void finalize() { 
-    for (Quantizer q : quantizers) 
-      q.finalize(); 
-  } 
+  public final Quantizer get(int feature_id) {
+    Integer index = quantizerByFeatureId.get(feature_id);
+    return (index != null ? quantizers.get(index) : DEFAULT);
+  }
 
-  public final Quantizer get(int feature_id) { 
-    Integer index = quantizerByFeatureId.get(feature_id); 
-    return (index != null ? quantizers.get(index) : DEFAULT); 
-  } 
+  public void read(String file_name) throws IOException {
+    quantizers.clear();
+    quantizerByFeatureId.clear();
 
-  public void read(String file_name) throws IOException { 
-    quantizers.clear(); 
-    quantizerByFeatureId.clear(); 
+    File quantizer_file = new File(file_name);
+    DataInputStream in_stream =
+        new DataInputStream(new BufferedInputStream(new FileInputStream(quantizer_file)));
+    int num_quantizers = in_stream.readInt();
+    quantizers.ensureCapacity(num_quantizers);
+    for (int i = 0; i < num_quantizers; i++) {
+      String key = in_stream.readUTF();
+      Quantizer q = QuantizerFactory.get(key);
+      q.readState(in_stream);
+      quantizers.add(q);
+    }
+    int num_mappings = in_stream.readInt();
+    for (int i = 0; i < num_mappings; i++) {
+      String feature_name = in_stream.readUTF();
+      int feature_id = Vocabulary.id(feature_name);
+      int quantizer_index = in_stream.readInt();
+      if (quantizer_index >= num_quantizers) {
+        throw new RuntimeException("Error deserializing QuanitzerConfig. " + "Feature "
+            + feature_name + " referring to quantizer " + quantizer_index + " when only "
+            + num_quantizers + " known.");
+      }
+      this.quantizerByFeatureId.put(feature_id, quantizer_index);
+    }
+    in_stream.close();
+  }
 
-    File quantizer_file = new File(file_name); 
-    DataInputStream in_stream = 
-        new DataInputStream(new BufferedInputStream(new FileInputStream(quantizer_file))); 
-    int num_quantizers = in_stream.readInt(); 
-    quantizers.ensureCapacity(num_quantizers); 
-    for (int i = 0; i < num_quantizers; i++) { 
-      String key = in_stream.readUTF(); 
-      Quantizer q = QuantizerFactory.get(key); 
-      q.readState(in_stream); 
-      quantizers.add(q); 
-    } 
-    int num_mappings = in_stream.readInt(); 
-    for (int i = 0; i < num_mappings; i++) { 
-      String feature_name = in_stream.readUTF(); 
-      int feature_id = Vocabulary.id(feature_name); 
-      int quantizer_index = in_stream.readInt(); 
-      if (quantizer_index >= num_quantizers) { 
-        throw new RuntimeException("Error deserializing QuanitzerConfig. " + "Feature " 
-            + feature_name + " referring to quantizer " + quantizer_index + " when only " 
-            + num_quantizers + " known."); 
-      } 
-      this.quantizerByFeatureId.put(feature_id, quantizer_index); 
-    } 
-    in_stream.close(); 
-  } 
-
-  public void write(String file_name) throws IOException { 
-    File vocab_file = new File(file_name); 
-    DataOutputStream out_stream = 
-        new DataOutputStream(new BufferedOutputStream(new FileOutputStream(vocab_file))); 
-    out_stream.writeInt(quantizers.size()); 
-    for (int index = 0; index < quantizers.size(); index++) 
-      quantizers.get(index).writeState(out_stream); 
-    out_stream.writeInt(quantizerByFeatureId.size()); 
-    for (int feature_id : quantizerByFeatureId.keySet()) { 
-      out_stream.writeUTF(Vocabulary.word(feature_id)); 
-      out_stream.writeInt(quantizerByFeatureId.get(feature_id)); 
-    } 
-    out_stream.close(); 
-  } 
+  public void write(String file_name) throws IOException {
+    File vocab_file = new File(file_name);
+    DataOutputStream out_stream =
+        new DataOutputStream(new BufferedOutputStream(new FileOutputStream(vocab_file)));
+    out_stream.writeInt(quantizers.size());
+    for (int index = 0; index < quantizers.size(); index++)
+      quantizers.get(index).writeState(out_stream);
+    out_stream.writeInt(quantizerByFeatureId.size());
+    for (int feature_id : quantizerByFeatureId.keySet()) {
+      out_stream.writeUTF(Vocabulary.word(feature_id));
+      out_stream.writeInt(quantizerByFeatureId.get(feature_id));
+    }
+    out_stream.close();
+  }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/840eb4ce/src/main/java/org/apache/joshua/util/quantization/StatelessQuantizer.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/joshua/util/quantization/StatelessQuantizer.java b/src/main/java/org/apache/joshua/util/quantization/StatelessQuantizer.java
index e81e945..a241cdf 100644
--- a/src/main/java/org/apache/joshua/util/quantization/StatelessQuantizer.java
+++ b/src/main/java/org/apache/joshua/util/quantization/StatelessQuantizer.java
@@ -18,21 +18,23 @@
  */
 package org.apache.joshua.util.quantization;
 
-import java.io.DataInputStream; 
-import java.io.DataOutputStream; 
-import java.io.IOException; 
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
 
-abstract class StatelessQuantizer implements Quantizer { 
+abstract class StatelessQuantizer implements Quantizer {
 
-  public void initialize() {} 
+  @Override
+  public void initialize() {}
 
-  public void add(float key) {} 
+  @Override
+  public void add(float key) {}
 
-  public void finalize() {} 
+  @Override
+  public void writeState(DataOutputStream out) throws IOException {
+    out.writeUTF(getKey());
+  }
 
-  public void writeState(DataOutputStream out) throws IOException { 
-    out.writeUTF(getKey()); 
-  } 
-
-  public void readState(DataInputStream in) throws IOException {} 
+  @Override
+  public void readState(DataInputStream in) throws IOException {}
 }
\ No newline at end of file