本文整理汇总了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());
}
}
}
示例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();
}
示例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());
}
示例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()));
}
}
示例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());
}
示例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();
}
示例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();
}
}
示例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();
}
}
示例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();
}
}
示例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();
}
}
示例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);
}
示例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);
}
示例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());
}
}
示例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);
}
示例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();
}
}