當前位置: 首頁>>代碼示例>>Java>>正文


Java BytesReference.writeTo方法代碼示例

本文整理匯總了Java中org.elasticsearch.common.bytes.BytesReference.writeTo方法的典型用法代碼示例。如果您正苦於以下問題:Java BytesReference.writeTo方法的具體用法?Java BytesReference.writeTo怎麽用?Java BytesReference.writeTo使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.elasticsearch.common.bytes.BytesReference的用法示例。


在下文中一共展示了BytesReference.writeTo方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: writeBlob

import org.elasticsearch.common.bytes.BytesReference; //導入方法依賴的package包/類
/**
 * Writes blob in atomic manner without resolving the blobName using using {@link #blobName} method.
 * <p>
 * The blob will be compressed and checksum will be written if required.
 *
 * @param obj           object to be serialized
 * @param blobContainer blob container
 * @param blobName          blob name
 */
protected void writeBlob(T obj, BlobContainer blobContainer, String blobName) throws IOException {
    BytesReference bytes = write(obj);
    try (ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream()) {
        final String resourceDesc = "ChecksumBlobStoreFormat.writeBlob(blob=\"" + blobName + "\")";
        try (OutputStreamIndexOutput indexOutput = new OutputStreamIndexOutput(resourceDesc, blobName, byteArrayOutputStream, BUFFER_SIZE)) {
            CodecUtil.writeHeader(indexOutput, codec, VERSION);
            try (OutputStream indexOutputOutputStream = new IndexOutputOutputStream(indexOutput) {
                @Override
                public void close() throws IOException {
                    // this is important since some of the XContentBuilders write bytes on close.
                    // in order to write the footer we need to prevent closing the actual index input.
                } }) {
                bytes.writeTo(indexOutputOutputStream);
            }
            CodecUtil.writeFooter(indexOutput);
        }
        BytesArray bytesArray = new BytesArray(byteArrayOutputStream.toByteArray());
        try (InputStream stream = bytesArray.streamInput()) {
            blobContainer.writeBlob(blobName, stream, bytesArray.length());
        }
    }
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:32,代碼來源:ChecksumBlobStoreFormat.java

示例2: CompressedXContent

import org.elasticsearch.common.bytes.BytesReference; //導入方法依賴的package包/類
/**
 * Create a {@link CompressedXContent} out of a serialized {@link ToXContent}
 * that may already be compressed.
 */
public CompressedXContent(BytesReference data) throws IOException {
    Compressor compressor = CompressorFactory.compressor(data);
    if (compressor != null) {
        // already compressed...
        this.bytes = BytesReference.toBytes(data);
        this.crc32 = crc32(new BytesArray(uncompressed()));
    } else {
        BytesStreamOutput out = new BytesStreamOutput();
        try (OutputStream compressedOutput = CompressorFactory.COMPRESSOR.streamOutput(out)) {
            data.writeTo(compressedOutput);
        }
        this.bytes = BytesReference.toBytes(out.bytes());
        this.crc32 = crc32(data);
    }
    assertConsistent();
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:21,代碼來源:CompressedXContent.java

示例3: writeToLocal

import org.elasticsearch.common.bytes.BytesReference; //導入方法依賴的package包/類
public Location writeToLocal(BytesReference data) throws IOException {
    final long position;
    final long generation;
    try (ReleasableLock lock = writeLock.acquire()) {
        ensureOpen();
        if (writtenOffset > TRANSLOG_ROLLING_SIZE_BYTES) {
            IOUtils.close(writeChannel);
            tmpTranslogGeneration.incrementAndGet();
            writeChannel = FileChannel.open(this.translogPath.resolve(getFileNameFromId(tmpTranslogGeneration.get())), StandardOpenOption.CREATE_NEW, StandardOpenOption.WRITE);
            writtenOffset = 0;
        }
        generation = tmpTranslogGeneration.get();
        position = writtenOffset;
        try {
            data.writeTo(writeChannel);
        } catch (Throwable e) {
            throw e;
        }
        writtenOffset = writtenOffset + data.length();
    }
    return new Translog.Location(generation, position, data.length());
}
 
開發者ID:baidu,項目名稱:Elasticsearch,代碼行數:23,代碼來源:LocalTranslog.java

示例4: writeBlob

import org.elasticsearch.common.bytes.BytesReference; //導入方法依賴的package包/類
/**
 * Writes blob in atomic manner without resolving the blobName using using {@link #blobName} method.
 * <p>
 * The blob will be compressed and checksum will be written if required.
 *
 * @param obj           object to be serialized
 * @param blobContainer blob container
 * @param blobName          blob name
 */
protected void writeBlob(T obj, BlobContainer blobContainer, String blobName) throws IOException {
    BytesReference bytes = write(obj);
    try (ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream()) {
        final String resourceDesc = "ChecksumBlobStoreFormat.writeBlob(blob=\"" + blobName + "\")";
        try (OutputStreamIndexOutput indexOutput = new OutputStreamIndexOutput(resourceDesc, byteArrayOutputStream, BUFFER_SIZE)) {
            CodecUtil.writeHeader(indexOutput, codec, VERSION);
            try (OutputStream indexOutputOutputStream = new IndexOutputOutputStream(indexOutput) {
                @Override
                public void close() throws IOException {
                    // this is important since some of the XContentBuilders write bytes on close.
                    // in order to write the footer we need to prevent closing the actual index input.
                } }) {
                bytes.writeTo(indexOutputOutputStream);
            }
            CodecUtil.writeFooter(indexOutput);
        }
        blobContainer.writeBlob(blobName, new BytesArray(byteArrayOutputStream.toByteArray()));
    }
}
 
開發者ID:baidu,項目名稱:Elasticsearch,代碼行數:29,代碼來源:ChecksumBlobStoreFormat.java

示例5: add

import org.elasticsearch.common.bytes.BytesReference; //導入方法依賴的package包/類
/**
 * add the given bytes to the translog and return the location they were written at
 */
public Translog.Location add(BytesReference data) throws IOException {
    final long position;
    try (ReleasableLock lock = writeLock.acquire()) {
        ensureOpen();
        position = writtenOffset;
        try {
            data.writeTo(channel);
        } catch (Throwable e) {
            closeWithTragicEvent(e);
            throw e;
        }
        writtenOffset = writtenOffset + data.length();
        operationCounter++;;
    }
    return new Translog.Location(generation, position, data.length());
}
 
開發者ID:baidu,項目名稱:Elasticsearch,代碼行數:20,代碼來源:TranslogWriter.java

示例6: CompressedXContent

import org.elasticsearch.common.bytes.BytesReference; //導入方法依賴的package包/類
/**
 * Create a {@link CompressedXContent} out of a serialized {@link ToXContent}
 * that may already be compressed.
 */
public CompressedXContent(BytesReference data) throws IOException {
    Compressor compressor = CompressorFactory.compressor(data);
    if (compressor != null) {
        // already compressed...
        this.bytes = data.toBytes();
        this.crc32 = crc32(new BytesArray(uncompressed()));
    } else {
        BytesStreamOutput out = new BytesStreamOutput();
        try (OutputStream compressedOutput = CompressorFactory.defaultCompressor().streamOutput(out)) {
            data.writeTo(compressedOutput);
        }
        this.bytes = out.bytes().toBytes();
        this.crc32 = crc32(data);
    }
    assertConsistent();
}
 
開發者ID:baidu,項目名稱:Elasticsearch,代碼行數:21,代碼來源:CompressedXContent.java

示例7: writeRawField

import org.elasticsearch.common.bytes.BytesReference; //導入方法依賴的package包/類
@Override
public final void writeRawField(String fieldName, BytesReference content) throws IOException {
    XContentType contentType = XContentFactory.xContentType(content);
    if (contentType == null) {
        throw new IllegalArgumentException("Can't write raw bytes whose xcontent-type can't be guessed");
    }
    if (mayWriteRawData(contentType) == false) {
        writeFieldName(fieldName);
        copyRawValue(content, contentType.xContent());
    } else {
        writeStartRaw(fieldName);
        flush();
        content.writeTo(os);
        writeEndRaw();
    }
}
 
開發者ID:baidu,項目名稱:Elasticsearch,代碼行數:17,代碼來源:JsonXContentGenerator.java

示例8: sendMessage

import org.elasticsearch.common.bytes.BytesReference; //導入方法依賴的package包/類
@Override
protected void sendMessage(MockChannel mockChannel, BytesReference reference, Runnable sendListener) throws IOException {
    synchronized (mockChannel) {
        final Socket socket = mockChannel.activeChannel;
        OutputStream outputStream = new BufferedOutputStream(socket.getOutputStream());
        reference.writeTo(outputStream);
        outputStream.flush();
    }
    if (sendListener != null) {
        sendListener.run();
    }
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:13,代碼來源:MockTcpTransport.java

示例9: writeRawField

import org.elasticsearch.common.bytes.BytesReference; //導入方法依賴的package包/類
@Override
public final void writeRawField(String name, BytesReference content, XContentType contentType) throws IOException {
    if (mayWriteRawData(contentType) == false) {
        writeFieldName(name);
        copyRawValue(content, contentType.xContent());
    } else {
        writeStartRaw(name);
        flush();
        content.writeTo(os);
        writeEndRaw();
    }
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:13,代碼來源:JsonXContentGenerator.java

示例10: writeRawValue

import org.elasticsearch.common.bytes.BytesReference; //導入方法依賴的package包/類
@Override
public final void writeRawValue(BytesReference content, XContentType contentType) throws IOException {
    if (mayWriteRawData(contentType) == false) {
        copyRawValue(content, contentType.xContent());
    } else {
        if (generator.getOutputContext().getCurrentName() != null) {
            // If we've just started a field we'll need to add the separator
            generator.writeRaw(':');
        }
        flush();
        content.writeTo(os);
        writeEndRaw();
    }
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:15,代碼來源:JsonXContentGenerator.java

示例11: writeBytesReference

import org.elasticsearch.common.bytes.BytesReference; //導入方法依賴的package包/類
/**
 * Writes the bytes reference, including a length header.
 */
public void writeBytesReference(@Nullable BytesReference bytes) throws IOException {
    if (bytes == null) {
        writeVInt(0);
        return;
    }
    writeVInt(bytes.length());
    bytes.writeTo(this);
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:12,代碼來源:StreamOutput.java

示例12: writeOptionalBytesReference

import org.elasticsearch.common.bytes.BytesReference; //導入方法依賴的package包/類
/**
 * Writes an optional bytes reference including a length header. Use this if you need to differentiate between null and empty bytes
 * references. Use {@link #writeBytesReference(BytesReference)} and {@link StreamInput#readBytesReference()} if you do not.
 */
public void writeOptionalBytesReference(@Nullable BytesReference bytes) throws IOException {
    if (bytes == null) {
        writeVInt(0);
        return;
    }
    writeVInt(bytes.length() + 1);
    bytes.writeTo(this);
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:13,代碼來源:StreamOutput.java

示例13: add

import org.elasticsearch.common.bytes.BytesReference; //導入方法依賴的package包/類
@Override
public Translog.Location add(BytesReference data) throws IOException {
    try (ReleasableLock lock = writeLock.acquire()) {
        ensureOpen();
        final long offset = totalOffset;
        if (data.length() >= buffer.length) {
            flush();
            // we use the channel to write, since on windows, writing to the RAF might not be reflected
            // when reading through the channel
            try {
                data.writeTo(channel);
            } catch (Throwable ex) {
                closeWithTragicEvent(ex);
                throw ex;
            }
            writtenOffset += data.length();
            totalOffset += data.length();
        } else {
            if (data.length() > buffer.length - bufferCount) {
                flush();
            }
            data.writeTo(bufferOs);
            totalOffset += data.length();
        }
        operationCounter++;
        return new Translog.Location(generation, offset, data.length());
    }
}
 
開發者ID:baidu,項目名稱:Elasticsearch,代碼行數:29,代碼來源:BufferingTranslogWriter.java

示例14: writeBlob

import org.elasticsearch.common.bytes.BytesReference; //導入方法依賴的package包/類
@Override
public void writeBlob(String blobName, BytesReference data) throws IOException {
    final Path file = path.resolve(blobName);
    try (OutputStream outputStream = Files.newOutputStream(file)) {
        data.writeTo(outputStream);
    }
    IOUtils.fsync(file, false);
    IOUtils.fsync(path, true);
}
 
開發者ID:baidu,項目名稱:Elasticsearch,代碼行數:10,代碼來源:FsBlobContainer.java

示例15: writeRawValue

import org.elasticsearch.common.bytes.BytesReference; //導入方法依賴的package包/類
public final void writeRawValue(BytesReference content) throws IOException {
    XContentType contentType = XContentFactory.xContentType(content);
    if (contentType == null) {
        throw new IllegalArgumentException("Can't write raw bytes whose xcontent-type can't be guessed");
    }
    if (mayWriteRawData(contentType) == false) {
        copyRawValue(content, contentType.xContent());
    } else {
        flush();
        content.writeTo(os);
        writeEndRaw();
    }
}
 
開發者ID:baidu,項目名稱:Elasticsearch,代碼行數:14,代碼來源:JsonXContentGenerator.java


注:本文中的org.elasticsearch.common.bytes.BytesReference.writeTo方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。