@@ -537,56 +537,10 @@ public FSTMetadata<T> getMetadata() {
537
537
* @param out the DataOutput to write the FST bytes to
538
538
*/
539
539
public void save (DataOutput metaOut , DataOutput out ) throws IOException {
540
- saveMetadata (metaOut );
540
+ metadata . save (metaOut );
541
541
fstReader .writeTo (out );
542
542
}
543
543
544
- /**
545
- * Save the metadata to a DataOutput
546
- *
547
- * @param metaOut the DataOutput to write the metadata to
548
- */
549
- public void saveMetadata (DataOutput metaOut ) throws IOException {
550
- CodecUtil .writeHeader (metaOut , FILE_FORMAT_NAME , VERSION_CURRENT );
551
- // TODO: really we should encode this as an arc, arriving
552
- // to the root node, instead of special casing here:
553
- if (metadata .emptyOutput != null ) {
554
- // Accepts empty string
555
- metaOut .writeByte ((byte ) 1 );
556
-
557
- // Serialize empty-string output:
558
- ByteBuffersDataOutput ros = new ByteBuffersDataOutput ();
559
- outputs .writeFinalOutput (metadata .emptyOutput , ros );
560
- byte [] emptyOutputBytes = ros .toArrayCopy ();
561
- int emptyLen = emptyOutputBytes .length ;
562
-
563
- // reverse
564
- final int stopAt = emptyLen / 2 ;
565
- int upto = 0 ;
566
- while (upto < stopAt ) {
567
- final byte b = emptyOutputBytes [upto ];
568
- emptyOutputBytes [upto ] = emptyOutputBytes [emptyLen - upto - 1 ];
569
- emptyOutputBytes [emptyLen - upto - 1 ] = b ;
570
- upto ++;
571
- }
572
- metaOut .writeVInt (emptyLen );
573
- metaOut .writeBytes (emptyOutputBytes , 0 , emptyLen );
574
- } else {
575
- metaOut .writeByte ((byte ) 0 );
576
- }
577
- final byte t ;
578
- if (metadata .inputType == INPUT_TYPE .BYTE1 ) {
579
- t = 0 ;
580
- } else if (metadata .inputType == INPUT_TYPE .BYTE2 ) {
581
- t = 1 ;
582
- } else {
583
- t = 2 ;
584
- }
585
- metaOut .writeByte (t );
586
- metaOut .writeVLong (metadata .startNode );
587
- metaOut .writeVLong (numBytes ());
588
- }
589
-
590
544
/** Writes an automaton to a file. */
591
545
public void save (final Path path ) throws IOException {
592
546
try (OutputStream os = new BufferedOutputStream (Files .newOutputStream (path ))) {
@@ -1258,5 +1212,46 @@ public FSTMetadata(
1258
1212
public int getVersion () {
1259
1213
return version ;
1260
1214
}
1215
+
1216
+ public void save (DataOutput metaOut ) throws IOException {
1217
+ CodecUtil .writeHeader (metaOut , FILE_FORMAT_NAME , VERSION_CURRENT );
1218
+ // TODO: really we should encode this as an arc, arriving
1219
+ // to the root node, instead of special casing here:
1220
+ if (emptyOutput != null ) {
1221
+ // Accepts empty string
1222
+ metaOut .writeByte ((byte ) 1 );
1223
+
1224
+ // Serialize empty-string output:
1225
+ ByteBuffersDataOutput ros = new ByteBuffersDataOutput ();
1226
+ outputs .writeFinalOutput (emptyOutput , ros );
1227
+ byte [] emptyOutputBytes = ros .toArrayCopy ();
1228
+ int emptyLen = emptyOutputBytes .length ;
1229
+
1230
+ // reverse
1231
+ final int stopAt = emptyLen / 2 ;
1232
+ int upto = 0 ;
1233
+ while (upto < stopAt ) {
1234
+ final byte b = emptyOutputBytes [upto ];
1235
+ emptyOutputBytes [upto ] = emptyOutputBytes [emptyLen - upto - 1 ];
1236
+ emptyOutputBytes [emptyLen - upto - 1 ] = b ;
1237
+ upto ++;
1238
+ }
1239
+ metaOut .writeVInt (emptyLen );
1240
+ metaOut .writeBytes (emptyOutputBytes , 0 , emptyLen );
1241
+ } else {
1242
+ metaOut .writeByte ((byte ) 0 );
1243
+ }
1244
+ final byte t ;
1245
+ if (inputType == INPUT_TYPE .BYTE1 ) {
1246
+ t = 0 ;
1247
+ } else if (inputType == INPUT_TYPE .BYTE2 ) {
1248
+ t = 1 ;
1249
+ } else {
1250
+ t = 2 ;
1251
+ }
1252
+ metaOut .writeByte (t );
1253
+ metaOut .writeVLong (startNode );
1254
+ metaOut .writeVLong (numBytes );
1255
+ }
1261
1256
}
1262
1257
}
0 commit comments