/** * Reads an automaton from a file. */ public static <T> FST<T> read(Path path, Outputs<T> outputs) throws IOException { try (InputStream is = Files.newInputStream(path)) { return new FST<>(new InputStreamDataInput(new BufferedInputStream(is)), outputs); } }
@Override public void parsePayload(BytesRef payload, SuggestPayload ref) throws IOException { ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(payload.bytes, payload.offset, payload.length); InputStreamDataInput input = new InputStreamDataInput(byteArrayInputStream); ref.weight = input.readVLong() - 1; int len = input.readVInt(); ref.surfaceForm.grow(len); ref.surfaceForm.setLength(len); input.readBytes(ref.surfaceForm.bytes(), 0, ref.surfaceForm.length()); len = input.readVInt(); ref.payload.grow(len); ref.payload.setLength(len); input.readBytes(ref.payload.bytes(), 0, ref.payload.length()); input.close(); } }
/** * Deserialize a MonitorQuery from a stream of bytes * @param bytes a BytesRef pointing to the serialized query * @return the deserialized MonitorQuery */ public static MonitorQuery deserialize(BytesRef bytes) { ByteArrayInputStream is = new ByteArrayInputStream(bytes.bytes); try (InputStreamDataInput data = new InputStreamDataInput(is)) { String id = data.readString(); String query = data.readString(); Map<String, String> metadata = new HashMap<>(); for (int i = data.readInt(); i > 0; i--) { metadata.put(data.readString(), data.readString()); } return new MonitorQuery(id, query, metadata); } catch (IOException e) { throw new RuntimeException(e); // shouldn't happen, we're reading from a bytearray! } }
@Override public void close() throws IOException { in.close(); } }
@Override public void parsePayload(BytesRef payload, SuggestPayload ref) throws IOException { ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(payload.bytes, payload.offset, payload.length); InputStreamDataInput input = new InputStreamDataInput(byteArrayInputStream); ref.weight = input.readVLong() - 1; int len = input.readVInt(); ref.surfaceForm.grow(len); ref.surfaceForm.setLength(len); input.readBytes(ref.surfaceForm.bytes(), 0, ref.surfaceForm.length()); len = input.readVInt(); ref.payload.grow(len); ref.payload.setLength(len); input.readBytes(ref.payload.bytes(), 0, ref.payload.length()); input.close(); } }
@Override public void close() throws IOException { in.close(); } }
@Override public boolean load(InputStream input) throws IOException { DataInput dataIn = new InputStreamDataInput(input); try { this.fst = new FST<>(dataIn, new PairOutputs<>( PositiveIntOutputs.getSingleton(), ByteSequenceOutputs.getSingleton())); maxAnalyzedPathsForOneInput = dataIn.readVInt(); hasPayloads = dataIn.readByte() == 1; } finally { IOUtils.close(input); } return true; }
@Override public void parsePayload(BytesRef payload, SuggestPayload ref) throws IOException { ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(payload.bytes, payload.offset, payload.length); InputStreamDataInput input = new InputStreamDataInput(byteArrayInputStream); ref.weight = input.readVLong() - 1; int len = input.readVInt(); ref.surfaceForm.grow(len); ref.surfaceForm.setLength(len); input.readBytes(ref.surfaceForm.bytes(), 0, ref.surfaceForm.length()); len = input.readVInt(); ref.payload.grow(len); ref.payload.setLength(len); input.readBytes(ref.payload.bytes(), 0, ref.payload.length()); input.close(); } }
@Override public void close() throws IOException { in.close(); } }
final int version; try { version = CodecUtil.checkHeader(new InputStreamDataInput(in), TRANSLOG_CODEC, VERSION_CHECKSUMS, VERSION_PRIMARY_TERM); } catch (CorruptIndexException | IndexFormatTooOldException | IndexFormatTooNewException e) { tryReportOldVersionError(path, channel);
/** * Reads an automaton from a file. */ public static <T> FST<T> read(Path path, Outputs<T> outputs) throws IOException { try (InputStream is = Files.newInputStream(path)) { return new FST<>(new InputStreamDataInput(new BufferedInputStream(is)), outputs); } }
public static Checkpoint read(Path path) throws IOException { try (InputStream in = Files.newInputStream(path)) { return new Checkpoint(new InputStreamDataInput(in)); } }
/** * Reads an automaton from a file. */ public static <T> FST<T> read(Path path, Outputs<T> outputs) throws IOException { try (InputStream is = Files.newInputStream(path)) { return new FST<>(new InputStreamDataInput(new BufferedInputStream(is)), outputs); } }
/** * Reads an automaton from a file. */ public static <T> FST<T> read(Path path, Outputs<T> outputs) throws IOException { try (InputStream is = Files.newInputStream(path)) { return new FST<>(new InputStreamDataInput(new BufferedInputStream(is)), outputs); } }
OfflineSliceReader(Path tempFile, long start, long count) throws IOException { InputStream fis = Files.newInputStream(tempFile); long seekFP = start * RangeTreeWriter.BYTES_PER_DOC; long skipped = 0; while (skipped < seekFP) { long inc = fis.skip(seekFP - skipped); skipped += inc; if (inc == 0) { throw new RuntimeException("skip returned 0"); } } in = new InputStreamDataInput(new BufferedInputStream(fis)); this.countLeft = count; }
OfflineReader(Path tempFile, long start, long count) throws IOException { InputStream fis = Files.newInputStream(tempFile); long seekFP = start * BKD3DTreeWriter.BYTES_PER_DOC; long skipped = 0; while (skipped < seekFP) { long inc = fis.skip(seekFP - skipped); skipped += inc; if (inc == 0) { throw new RuntimeException("skip returned 0"); } } in = new InputStreamDataInput(new BufferedInputStream(fis)); this.countLeft = count; }
OfflineLatLonReader(Path tempFile, long start, long count) throws IOException { InputStream fis = Files.newInputStream(tempFile); long seekFP = start * BKDTreeWriter.BYTES_PER_DOC; long skipped = 0; while (skipped < seekFP) { long inc = fis.skip(seekFP - skipped); skipped += inc; if (inc == 0) { throw new RuntimeException("skip returned 0"); } } in = new InputStreamDataInput(new BufferedInputStream(fis)); this.countLeft = count; }
/** * Load surface forms FST. */ private static FST<Object> readMorphyFST() { try { final InputStream is = GermanCompoundSplitter.class.getClassLoader().getResourceAsStream("words.fst"); final FST<Object> fst = new FST<Object>(new InputStreamDataInput(is), NoOutputs.getSingleton()); is.close(); return fst; } catch (IOException e) { throw new RuntimeException(e); } }
@Override public boolean load(InputStream input) throws IOException { try { this.fst = new FST<Long>(new InputStreamDataInput(input), PositiveIntOutputs.getSingleton(true)); } finally { IOUtils.close(input); } return true; }
@Override public boolean load(InputStream input) throws IOException { InputStream is = new BufferedInputStream(input); try { this.automaton = new FST<Object>(new InputStreamDataInput(is), NoOutputs.getSingleton()); cacheRootArcs(); } finally { IOUtils.close(is); } return true; } }