Should make it easier to add transparent compression support.
import com.hughes.util.IndexedObject;
+import java.io.DataInput;
+import java.io.DataOutput;
import java.io.IOException;
-import java.io.RandomAccessFile;
public abstract class AbstractEntry extends IndexedObject {
this.entrySource = entrySource;
}
- public AbstractEntry(Dictionary dictionary, RandomAccessFile raf, final int index)
+ public AbstractEntry(Dictionary dictionary, DataInput raf, final int index)
throws IOException {
super(index);
if (dictionary.dictFileVersion >= 1) {
}
}
- public void write(RandomAccessFile raf) throws IOException {
+ public void write(DataOutput raf) throws IOException {
raf.writeShort(entrySource.index());
}
import com.hughes.util.raf.RAFListSerializer;
import com.hughes.util.raf.RAFSerializable;
+import java.io.DataInput;
+import java.io.DataOutput;
import java.io.File;
import java.io.IOException;
import java.io.PrintStream;
}
@Override
- public void write(RandomAccessFile raf) throws IOException {
+ public void write(DataOutput out) throws IOException {
+ RandomAccessFile raf = (RandomAccessFile)out;
raf.writeInt(dictFileVersion);
raf.writeLong(creationMillis);
raf.writeUTF(dictInfo);
private final RAFListSerializer<Index> indexSerializer = new RAFListSerializer<Index>() {
@Override
- public Index read(RandomAccessFile raf, final int readIndex) throws IOException {
+ public Index read(DataInput raf, final int readIndex) throws IOException {
return new Index(Dictionary.this, raf);
}
@Override
- public void write(RandomAccessFile raf, Index t) throws IOException {
+ public void write(DataOutput raf, Index t) throws IOException {
t.write(raf);
}
};
final RAFListSerializer<HtmlEntry> htmlEntryIndexSerializer = new RAFListSerializer<HtmlEntry>() {
@Override
- public void write(RandomAccessFile raf, HtmlEntry t) throws IOException {
+ public void write(DataOutput raf, HtmlEntry t) throws IOException {
if (t.index() == -1)
throw new IndexOutOfBoundsException();
raf.writeInt(t.index());
}
@Override
- public HtmlEntry read(RandomAccessFile raf, int readIndex) throws IOException {
+ public HtmlEntry read(DataInput raf, int readIndex) throws IOException {
return htmlEntries.get(raf.readInt());
}
};
import com.hughes.util.IndexedObject;
import com.hughes.util.raf.RAFListSerializer;
+import java.io.DataInput;
+import java.io.DataOutput;
import java.io.IOException;
-import java.io.RandomAccessFile;
import java.io.Serializable;
public class EntrySource extends IndexedObject implements Serializable {
}
@Override
- public EntrySource read(RandomAccessFile raf, int readIndex)
+ public EntrySource read(DataInput raf, int readIndex)
throws IOException {
final String name = raf.readUTF();
final int numEntries = dictionary.dictFileVersion >= 3 ? raf.readInt() : 0;
}
@Override
- public void write(RandomAccessFile raf, EntrySource t) throws IOException {
+ public void write(DataOutput raf, EntrySource t) throws IOException {
raf.writeUTF(t.name);
raf.writeInt(t.numEntries);
}
import com.hughes.util.raf.RAFSerializable;
import com.ibm.icu.text.Transliterator;
+import java.io.DataInput;
+import java.io.DataOutput;
import java.io.IOException;
import java.io.PrintStream;
import java.io.RandomAccessFile;
lazyHtmlLoader = null;
}
- public HtmlEntry(Dictionary dictionary, RandomAccessFile raf, final int index)
+ public HtmlEntry(Dictionary dictionary, DataInput raf, final int index)
throws IOException {
super(dictionary, raf, index);
title = raf.readUTF();
}
@Override
- public void write(RandomAccessFile raf) throws IOException {
+ public void write(DataOutput raf) throws IOException {
super.write(raf);
raf.writeUTF(title);
}
@Override
- public HtmlEntry read(RandomAccessFile raf, final int index) throws IOException {
+ public HtmlEntry read(DataInput raf, final int index) throws IOException {
return new HtmlEntry(dictionary, raf, index);
}
@Override
- public void write(RandomAccessFile raf, HtmlEntry t) throws IOException {
+ public void write(DataOutput raf, HtmlEntry t) throws IOException {
t.write(raf);
}
}
boolean isExpanded = false;
- Row(final RandomAccessFile raf, final int thisRowIndex,
+ Row(final DataInput raf, final int thisRowIndex,
final Index index) throws IOException {
super(raf, thisRowIndex, index);
}
// Not sure this volatile is right, but oh well.
volatile SoftReference<String> htmlRef = new SoftReference<String>(null);
- private LazyHtmlLoader(final RandomAccessFile raf) throws IOException {
- this.raf = raf;
+ private LazyHtmlLoader(final DataInput inp) throws IOException {
+ raf = (RandomAccessFile)inp;
numBytes = raf.readInt();
numZipBytes = raf.readInt();
offset = raf.getFilePointer();
import com.ibm.icu.text.Collator;
import com.ibm.icu.text.Transliterator;
+import java.io.DataInput;
+import java.io.DataOutput;
import java.io.IOException;
import java.io.PrintStream;
import java.io.RandomAccessFile;
return new NormalizeComparator(normalizer(), sortLanguage.getCollator());
}
- public Index(final Dictionary dict, final RandomAccessFile raf) throws IOException {
+ public Index(final Dictionary dict, final DataInput inp) throws IOException {
this.dict = dict;
+ RandomAccessFile raf = (RandomAccessFile)inp;
shortName = raf.readUTF();
longName = raf.readUTF();
final String languageCode = raf.readUTF();
}
@Override
- public void write(final RandomAccessFile raf) throws IOException {
+ public void write(final DataOutput out) throws IOException {
+ RandomAccessFile raf = (RandomAccessFile)out;
raf.writeUTF(shortName);
raf.writeUTF(longName);
raf.writeUTF(sortLanguage.getIsoCode());
private final RAFSerializer<IndexEntry> indexEntrySerializer = new RAFSerializer<IndexEntry>() {
@Override
- public IndexEntry read(RandomAccessFile raf) throws IOException {
+ public IndexEntry read(DataInput raf) throws IOException {
return new IndexEntry(Index.this, raf);
}
@Override
- public void write(RandomAccessFile raf, IndexEntry t) throws IOException {
+ public void write(DataOutput raf, IndexEntry t) throws IOException {
t.write(raf);
}
};
this.htmlEntries = new ArrayList<HtmlEntry>();
}
- public IndexEntry(final Index index, final RandomAccessFile raf) throws IOException {
+ public IndexEntry(final Index index, final DataInput inp) throws IOException {
this.index = index;
+ RandomAccessFile raf = (RandomAccessFile)inp;
token = raf.readUTF();
startRow = raf.readInt();
numRows = raf.readInt();
}
}
- public void write(RandomAccessFile raf) throws IOException {
+ public void write(DataOutput out) throws IOException {
+ RandomAccessFile raf = (RandomAccessFile)out;
raf.writeUTF(token);
raf.writeInt(startRow);
raf.writeInt(numRows);
import com.hughes.util.raf.RAFSerializable;
import com.ibm.icu.text.Transliterator;
+import java.io.DataInput;
+import java.io.DataOutput;
import java.io.IOException;
import java.io.PrintStream;
-import java.io.RandomAccessFile;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Pattern;
this.pairs.add(new Pair(lang1, lang2));
}
- public PairEntry(final Dictionary dictionary, final RandomAccessFile raf, final int index)
+ public PairEntry(final Dictionary dictionary, final DataInput raf, final int index)
throws IOException {
super(dictionary, raf, index);
final int size = raf.readInt();
}
@Override
- public void write(RandomAccessFile raf) throws IOException {
+ public void write(DataOutput raf) throws IOException {
super.write(raf);
// TODO: this could be a short.
raf.writeInt(pairs.size());
}
@Override
- public PairEntry read(RandomAccessFile raf, int index) throws IOException {
+ public PairEntry read(DataInput raf, int index) throws IOException {
return new PairEntry(dictionary, raf, index);
}
@Override
- public void write(RandomAccessFile raf, PairEntry t) throws IOException {
+ public void write(DataOutput raf, PairEntry t) throws IOException {
t.write(raf);
}
}
public static class Row extends RowBase {
- Row(final RandomAccessFile raf, final int thisRowIndex,
+ Row(final DataInput raf, final int thisRowIndex,
final Index index) throws IOException {
super(raf, thisRowIndex, index);
}
import com.hughes.util.raf.RAFListSerializer;
import com.ibm.icu.text.Transliterator;
+import java.io.DataInput;
+import java.io.DataOutput;
import java.io.IOException;
import java.io.PrintStream;
-import java.io.RandomAccessFile;
import java.util.Comparator;
import java.util.List;
import java.util.regex.Pattern;
*/
private TokenRow tokenRow = null;
- RowBase(final RandomAccessFile raf, final int thisRowIndex, final Index index)
+ RowBase(final DataInput raf, final int thisRowIndex, final Index index)
throws IOException {
super(thisRowIndex);
this.index = index;
}
@Override
- public RowBase read(RandomAccessFile raf, final int listIndex) throws IOException {
+ public RowBase read(DataInput raf, final int listIndex) throws IOException {
final byte rowType = raf.readByte();
if (rowType == 0) {
return new PairEntry.Row(raf, listIndex, index);
}
@Override
- public void write(RandomAccessFile raf, RowBase t) throws IOException {
+ public void write(DataOutput raf, RowBase t) throws IOException {
if (t instanceof PairEntry.Row) {
raf.writeByte(0);
} else if (t instanceof TokenRow) {
import com.hughes.util.raf.RAFSerializable;
import com.ibm.icu.text.Transliterator;
+import java.io.DataInput;
+import java.io.DataOutput;
import java.io.IOException;
import java.io.PrintStream;
-import java.io.RandomAccessFile;
import java.util.List;
import java.util.regex.Pattern;
final String text;
- public TextEntry(final Dictionary dictionary, final RandomAccessFile raf, final int index)
+ public TextEntry(final Dictionary dictionary, final DataInput raf, final int index)
throws IOException {
super(dictionary, raf, index);
text = raf.readUTF();
}
@Override
- public void write(RandomAccessFile raf) throws IOException {
+ public void write(DataOutput raf) throws IOException {
super.write(raf);
raf.writeUTF(text);
}
}
@Override
- public TextEntry read(RandomAccessFile raf, final int index) throws IOException {
+ public TextEntry read(DataInput raf, final int index) throws IOException {
return new TextEntry(dictionary, raf, index);
}
@Override
- public void write(RandomAccessFile raf, TextEntry t) throws IOException {
+ public void write(DataOutput raf, TextEntry t) throws IOException {
t.write(raf);
}
}
public static class Row extends RowBase {
- Row(final RandomAccessFile raf, final int thisRowIndex,
+ Row(final DataInput raf, final int thisRowIndex,
final Index index) throws IOException {
super(raf, thisRowIndex, index);
}
import com.hughes.android.dictionary.engine.Index.IndexEntry;
import com.ibm.icu.text.Transliterator;
+import java.io.DataInput;
import java.io.IOException;
import java.io.PrintStream;
-import java.io.RandomAccessFile;
import java.util.List;
import java.util.regex.Pattern;
public final boolean hasMainEntry;
- TokenRow(final RandomAccessFile raf, final int thisRowIndex, final Index index,
+ TokenRow(final DataInput raf, final int thisRowIndex, final Index index,
final boolean hasMainEntry) throws IOException {
super(raf, thisRowIndex, index);
this.hasMainEntry = hasMainEntry;