Search in sources :

Example 6 with OutputStreamDataOutput

use of org.apache.lucene.store.OutputStreamDataOutput in project elasticsearch by elastic.

the class TruncateTranslogCommand method writeEmptyTranslog.

/**
     * Write a translog containing the given translog UUID to the given location. Returns the number of bytes written.
     */
public static int writeEmptyTranslog(Path filename, String translogUUID) throws IOException {
    final BytesRef translogRef = new BytesRef(translogUUID);
    try (FileChannel fc = FileChannel.open(filename, StandardOpenOption.WRITE, StandardOpenOption.READ, StandardOpenOption.CREATE_NEW);
        OutputStreamDataOutput out = new OutputStreamDataOutput(Channels.newOutputStream(fc))) {
        TranslogWriter.writeHeader(out, translogRef);
        fc.force(true);
    }
    return TranslogWriter.getHeaderLength(translogRef.length);
}
Also used : OutputStreamDataOutput(org.apache.lucene.store.OutputStreamDataOutput) FileChannel(java.nio.channels.FileChannel) BytesRef(org.apache.lucene.util.BytesRef)

Example 7 with OutputStreamDataOutput

use of org.apache.lucene.store.OutputStreamDataOutput in project elasticsearch by elastic.

the class XAnalyzingSuggester method store.

@Override
public boolean store(OutputStream output) throws IOException {
    DataOutput dataOut = new OutputStreamDataOutput(output);
    try {
        if (fst == null) {
            return false;
        }
        fst.save(dataOut);
        dataOut.writeVInt(maxAnalyzedPathsForOneInput);
        dataOut.writeByte((byte) (hasPayloads ? 1 : 0));
    } finally {
        IOUtils.close(output);
    }
    return true;
}
Also used : ByteArrayDataOutput(org.apache.lucene.store.ByteArrayDataOutput) DataOutput(org.apache.lucene.store.DataOutput) OutputStreamDataOutput(org.apache.lucene.store.OutputStreamDataOutput) OutputStreamDataOutput(org.apache.lucene.store.OutputStreamDataOutput)

Example 8 with OutputStreamDataOutput

use of org.apache.lucene.store.OutputStreamDataOutput in project lucene-solr by apache.

the class TestContextSuggestField method testTokenStream.

@Test
public void testTokenStream() throws Exception {
    Analyzer analyzer = new MockAnalyzer(random());
    ContextSuggestField field = new ContextSuggestField("field", "input", 1, "context1", "context2");
    BytesRef surfaceForm = new BytesRef("input");
    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    try (OutputStreamDataOutput output = new OutputStreamDataOutput(byteArrayOutputStream)) {
        output.writeVInt(surfaceForm.length);
        output.writeBytes(surfaceForm.bytes, surfaceForm.offset, surfaceForm.length);
        output.writeVInt(1 + 1);
        output.writeByte(ContextSuggestField.TYPE);
    }
    BytesRef payload = new BytesRef(byteArrayOutputStream.toByteArray());
    String[] expectedOutputs = new String[2];
    CharsRefBuilder builder = new CharsRefBuilder();
    builder.append("context1");
    builder.append(((char) ContextSuggestField.CONTEXT_SEPARATOR));
    builder.append(((char) CompletionAnalyzer.SEP_LABEL));
    builder.append("input");
    expectedOutputs[0] = builder.toCharsRef().toString();
    builder.clear();
    builder.append("context2");
    builder.append(((char) ContextSuggestField.CONTEXT_SEPARATOR));
    builder.append(((char) CompletionAnalyzer.SEP_LABEL));
    builder.append("input");
    expectedOutputs[1] = builder.toCharsRef().toString();
    TokenStream stream = new CompletionTokenStreamTest.PayloadAttrToTypeAttrFilter(field.tokenStream(analyzer, null));
    assertTokenStreamContents(stream, expectedOutputs, null, null, new String[] { payload.utf8ToString(), payload.utf8ToString() }, new int[] { 1, 1 }, null, null);
    CompletionAnalyzer completionAnalyzer = new CompletionAnalyzer(analyzer);
    stream = new CompletionTokenStreamTest.PayloadAttrToTypeAttrFilter(field.tokenStream(completionAnalyzer, null));
    assertTokenStreamContents(stream, expectedOutputs, null, null, new String[] { payload.utf8ToString(), payload.utf8ToString() }, new int[] { 1, 1 }, null, null);
}
Also used : TokenStream(org.apache.lucene.analysis.TokenStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Analyzer(org.apache.lucene.analysis.Analyzer) MockAnalyzer(org.apache.lucene.analysis.MockAnalyzer) StandardAnalyzer(org.apache.lucene.analysis.standard.StandardAnalyzer) MockAnalyzer(org.apache.lucene.analysis.MockAnalyzer) OutputStreamDataOutput(org.apache.lucene.store.OutputStreamDataOutput) CharsRefBuilder(org.apache.lucene.util.CharsRefBuilder) BytesRef(org.apache.lucene.util.BytesRef) Test(org.junit.Test)

Example 9 with OutputStreamDataOutput

use of org.apache.lucene.store.OutputStreamDataOutput in project lucene-solr by apache.

the class BinaryDictionaryWriter method writePosDict.

protected void writePosDict(String filename) throws IOException {
    new File(filename).getParentFile().mkdirs();
    OutputStream os = new FileOutputStream(filename);
    try {
        os = new BufferedOutputStream(os);
        final DataOutput out = new OutputStreamDataOutput(os);
        CodecUtil.writeHeader(out, BinaryDictionary.POSDICT_HEADER, BinaryDictionary.VERSION);
        out.writeVInt(posDict.size());
        for (String s : posDict) {
            if (s == null) {
                out.writeByte((byte) 0);
                out.writeByte((byte) 0);
                out.writeByte((byte) 0);
            } else {
                String[] data = CSVUtil.parse(s);
                assert data.length == 3 : "malformed pos/inflection: " + s;
                out.writeString(data[0]);
                out.writeString(data[1]);
                out.writeString(data[2]);
            }
        }
    } finally {
        os.close();
    }
}
Also used : DataOutput(org.apache.lucene.store.DataOutput) OutputStreamDataOutput(org.apache.lucene.store.OutputStreamDataOutput) OutputStreamDataOutput(org.apache.lucene.store.OutputStreamDataOutput) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) BufferedOutputStream(java.io.BufferedOutputStream) FileOutputStream(java.io.FileOutputStream) File(java.io.File) BufferedOutputStream(java.io.BufferedOutputStream)

Example 10 with OutputStreamDataOutput

use of org.apache.lucene.store.OutputStreamDataOutput in project lucene-solr by apache.

the class BinaryDictionaryWriter method writeDictionary.

protected void writeDictionary(String filename) throws IOException {
    new File(filename).getParentFile().mkdirs();
    final FileOutputStream os = new FileOutputStream(filename);
    try {
        final DataOutput out = new OutputStreamDataOutput(os);
        CodecUtil.writeHeader(out, BinaryDictionary.DICT_HEADER, BinaryDictionary.VERSION);
        out.writeVInt(buffer.position());
        final WritableByteChannel channel = Channels.newChannel(os);
        // Write Buffer
        // set position to 0, set limit to current position
        buffer.flip();
        channel.write(buffer);
        assert buffer.remaining() == 0L;
    } finally {
        os.close();
    }
}
Also used : DataOutput(org.apache.lucene.store.DataOutput) OutputStreamDataOutput(org.apache.lucene.store.OutputStreamDataOutput) OutputStreamDataOutput(org.apache.lucene.store.OutputStreamDataOutput) FileOutputStream(java.io.FileOutputStream) WritableByteChannel(java.nio.channels.WritableByteChannel) File(java.io.File)

Aggregations

OutputStreamDataOutput (org.apache.lucene.store.OutputStreamDataOutput)11 DataOutput (org.apache.lucene.store.DataOutput)6 File (java.io.File)5 FileOutputStream (java.io.FileOutputStream)5 BytesRef (org.apache.lucene.util.BytesRef)5 BufferedOutputStream (java.io.BufferedOutputStream)4 OutputStream (java.io.OutputStream)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 IOException (java.io.IOException)2 FileChannel (java.nio.channels.FileChannel)2 Analyzer (org.apache.lucene.analysis.Analyzer)2 MockAnalyzer (org.apache.lucene.analysis.MockAnalyzer)2 TokenStream (org.apache.lucene.analysis.TokenStream)2 Test (org.junit.Test)2 WritableByteChannel (java.nio.channels.WritableByteChannel)1 CharacterDefinition (org.apache.lucene.analysis.ja.dict.CharacterDefinition)1 ConnectionCosts (org.apache.lucene.analysis.ja.dict.ConnectionCosts)1 StandardAnalyzer (org.apache.lucene.analysis.standard.StandardAnalyzer)1 AlreadyClosedException (org.apache.lucene.store.AlreadyClosedException)1 ByteArrayDataOutput (org.apache.lucene.store.ByteArrayDataOutput)1