当前位置: 首页>>代码示例>>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;未经允许,请勿转载。