import java.io.IOException;
import java.io.PrintStream;
import java.io.RandomAccessFile;
+import java.nio.BufferUnderflowException;
import java.nio.MappedByteBuffer;
import java.nio.channels.FileChannel;
import java.util.ArrayList;
import com.hughes.util.DataInputBuffer;
import com.hughes.util.raf.RAFList;
import com.hughes.util.raf.RAFListSerializer;
-import com.hughes.util.raf.RAFSerializable;
-public class Dictionary implements RAFSerializable<Dictionary> {
+public class Dictionary {
private static final int CACHE_SIZE = 5000;
}
}
- @Override
public void write(DataOutput out) throws IOException {
RandomAccessFile raf = (RandomAccessFile)out;
if (dictFileVersion < 7) throw new RuntimeException("write function cannot write formats older than v7!");
return result;
}
+ // get DictionaryInfo for case when Dictionary cannot be opened
+ private static DictionaryInfo getErrorDictionaryInfo(final File file) {
+ final DictionaryInfo dictionaryInfo = new DictionaryInfo();
+ dictionaryInfo.uncompressedFilename = file.getName();
+ dictionaryInfo.uncompressedBytes = file.length();
+ return dictionaryInfo;
+ }
+
public static DictionaryInfo getDictionaryInfo(final File file) {
RandomAccessFile raf = null;
try {
raf.close();
return dictionaryInfo;
} catch (IOException e) {
- final DictionaryInfo dictionaryInfo = new DictionaryInfo();
- dictionaryInfo.uncompressedFilename = file.getName();
- dictionaryInfo.uncompressedBytes = file.length();
- return dictionaryInfo;
+ return getErrorDictionaryInfo(file);
+ } catch (IllegalArgumentException e) {
+ // Most likely due to a Buffer.limit beyond size of file,
+ // do not crash just because of a truncated dictionary file
+ return getErrorDictionaryInfo(file);
+ } catch (BufferUnderflowException e) {
+ // Most likely due to a read beyond the buffer limit set,
+ // do not crash just because of a truncated or corrupt dictionary file
+ return getErrorDictionaryInfo(file);
} finally {
if (raf != null) {
try {