Index: lucene/src/java/org/apache/lucene/util/CodecUtil.java =================================================================== --- lucene/src/java/org/apache/lucene/util/CodecUtil.java (revision 1086636) +++ lucene/src/java/org/apache/lucene/util/CodecUtil.java (working copy) @@ -18,8 +18,8 @@ */ -import org.apache.lucene.store.IndexOutput; -import org.apache.lucene.store.IndexInput; +import org.apache.lucene.store.DataInput; +import org.apache.lucene.store.DataOutput; import org.apache.lucene.index.CorruptIndexException; import org.apache.lucene.index.IndexFormatTooNewException; import org.apache.lucene.index.IndexFormatTooOldException; @@ -35,18 +35,16 @@ private final static int CODEC_MAGIC = 0x3fd76c17; - public static IndexOutput writeHeader(IndexOutput out, String codec, int version) + public static DataOutput writeHeader(DataOutput out, String codec, int version) throws IOException { - final long start = out.getFilePointer(); + BytesRef bytes = new BytesRef(codec); + if (bytes.length != codec.length() || bytes.length >= 128) { + throw new IllegalArgumentException("codec must be simple ASCII, less than 128 characters in length [got " + codec + "]"); + } out.writeInt(CODEC_MAGIC); out.writeString(codec); out.writeInt(version); - // We require this so we can easily pre-compute header length - if (out.getFilePointer()-start != codec.length()+9) { - throw new IllegalArgumentException("codec must be simple ASCII, less than 128 characters in length [got " + codec + "]"); - } - return out; } @@ -54,7 +52,7 @@ return 9+codec.length(); } - public static int checkHeader(IndexInput in, String codec, int minVersion, int maxVersion) + public static int checkHeader(DataInput in, String codec, int minVersion, int maxVersion) throws IOException { // Safety to guard against reading a bogus string: Index: lucene/src/java/org/apache/lucene/util/automaton/fst/FST.java =================================================================== --- lucene/src/java/org/apache/lucene/util/automaton/fst/FST.java (revision 1086636) +++ lucene/src/java/org/apache/lucene/util/automaton/fst/FST.java (working copy) @@ -21,8 +21,6 @@ import org.apache.lucene.store.DataInput; import org.apache.lucene.store.DataOutput; -import org.apache.lucene.store.IndexInput; -import org.apache.lucene.store.IndexOutput; import org.apache.lucene.util.ArrayUtil; import org.apache.lucene.util.CodecUtil; import org.apache.lucene.util.automaton.fst.Builder.UnCompiledNode; @@ -168,7 +166,7 @@ } // create an existing FST - public FST(IndexInput in, Outputs outputs) throws IOException { + public FST(DataInput in, Outputs outputs) throws IOException { this.outputs = outputs; writer = null; CodecUtil.checkHeader(in, FILE_FORMAT_NAME, VERSION_START, VERSION_START); @@ -250,7 +248,7 @@ writer.posWrite = posSave; } - public void save(IndexOutput out) throws IOException { + public void save(DataOutput out) throws IOException { if (startNode == -1) { throw new IllegalStateException("call finish first"); }