@Override
    public void writeTo(WordWriter out)
        throws IOException {
        WordReader in = new WordReader(new FileInputStream(file), littleEndian);
        int wordsWritten = 0;
        try {
            int word;
            while(true) {
                word = in.readWord();
                if(word == -1)
                    break;
                out.writeWord(word);
                wordsWritten++;
            }
        } finally {
            in.close();
        }
        if(wordsWritten != wordsize) {
            throw new IOException("File size of "+file+" changed unexpectedly");
        }
    }