Skip to content

Commit 9bd5f02

Browse files
committed
Expose the DataOutput
1 parent 74ace94 commit 9bd5f02

File tree

3 files changed

+9
-40
lines changed

3 files changed

+9
-40
lines changed

lucene/core/src/java/org/apache/lucene/util/fst/BytesStore.java

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -370,18 +370,6 @@ public void truncate(long newLen) {
370370
assert newLen == getPosition();
371371
}
372372

373-
/** Writes all of our bytes to the target {@link FSTDataOutputWriter}. */
374-
public void writeTo(FSTDataOutputWriter out) throws IOException {
375-
reverse(0, getPosition() - 1);
376-
for (byte[] block : blocks) {
377-
if (block == current) { // last block
378-
out.writeBytes(block, 0, nextWrite);
379-
} else {
380-
out.writeBytes(block, 0, block.length);
381-
}
382-
}
383-
}
384-
385373
/** Writes all of our bytes to the target {@link DataOutput}. */
386374
@Override
387375
public void writeTo(DataOutput out) throws IOException {

lucene/core/src/java/org/apache/lucene/util/fst/FSTCompiler.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,8 @@ public class FSTCompiler<T> {
119119
final float directAddressingMaxOversizingFactor;
120120
long directAddressingExpansionCredit;
121121

122-
// writer for frozen nodes
123-
final FSTDataOutputWriter fstWriter;
122+
// the DataOutput to write the FST to
123+
final DataOutput dataOutput;
124124

125125
// The number of bits for scratch area when adding a node
126126
private static final int SCRATCH_PAGE_BITS = 8;
@@ -160,12 +160,12 @@ private FSTCompiler(
160160
// pad: ensure no node gets address 0 which is reserved to mean
161161
// the stop state w/ no arcs
162162
try {
163-
fstWriter.writeByte((byte) 0);
163+
fstWriter.getDataOutput().writeByte((byte) 0);
164164
numBytesWritten++;
165165
} catch (IOException e) {
166166
throw new RuntimeException(e);
167167
}
168-
this.fstWriter = fstWriter;
168+
this.dataOutput = fstWriter.getDataOutput();
169169
fst =
170170
new FST<>(
171171
new FST.FSTMetadata<>(inputType, null, -1, VERSION_CURRENT, 0),
@@ -513,7 +513,7 @@ long addNode(FSTCompiler.UnCompiledNode<T> nodeIn) throws IOException {
513513
}
514514
}
515515

516-
scratchBytes.writeTo(fstWriter);
516+
scratchBytes.writeTo(dataOutput);
517517
numBytesWritten += scratchBytes.getPosition();
518518

519519
nodeCount++;

lucene/core/src/java/org/apache/lucene/util/fst/FSTDataOutputWriter.java

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@ final class FSTDataOutputWriter {
3535
/** the main DataOutput to store the FST bytes */
3636
private final DataOutput dataOutput;
3737

38-
private long size;
39-
4038
/**
4139
* ctor
4240
*
@@ -46,26 +44,8 @@ public FSTDataOutputWriter(DataOutput dataOutput) {
4644
this.dataOutput = dataOutput;
4745
}
4846

49-
/**
50-
* Write a single byte to the end of the DataOutput
51-
*
52-
* @param b the byte to write
53-
*/
54-
public void writeByte(byte b) throws IOException {
55-
size++;
56-
dataOutput.writeByte(b);
57-
}
58-
59-
/**
60-
* Write a byte array to the end of the DataOutput
61-
*
62-
* @param b the byte array to write
63-
* @param offset the offset of the array
64-
* @param length the number of bytes to write
65-
*/
66-
public void writeBytes(byte[] b, int offset, int length) throws IOException {
67-
size += length;
68-
dataOutput.writeBytes(b, offset, length);
47+
public DataOutput getDataOutput() {
48+
return dataOutput;
6949
}
7050

7151
/**
@@ -78,7 +58,8 @@ public FSTReader getReader() {
7858
return new FSTReader() {
7959
@Override
8060
public long size() {
81-
return size;
61+
// the FSTReader#size() method was no longer being used, hence just outputs 0 here
62+
return 0;
8263
}
8364

8465
@Override

0 commit comments

Comments
 (0)