Tabnine Logo
ReleasableBytesStreamOutput
Code IndexAdd Tabnine to your IDE (free)

How to use
ReleasableBytesStreamOutput
in
org.elasticsearch.common.io.stream

Best Java code snippets using org.elasticsearch.common.io.stream.ReleasableBytesStreamOutput (Showing top 20 results out of 315)

origin: org.elasticsearch/elasticsearch

/**
 * Writes all operations in the given iterable to the given output stream including the size of the array
 * use {@link #readOperations(StreamInput, String)} to read it back.
 */
public static void writeOperations(StreamOutput outStream, List<Operation> toWrite) throws IOException {
  final ReleasableBytesStreamOutput out = new ReleasableBytesStreamOutput(BigArrays.NON_RECYCLING_INSTANCE);
  try {
    outStream.writeInt(toWrite.size());
    final BufferedChecksumStreamOutput checksumStreamOutput = new BufferedChecksumStreamOutput(out);
    for (Operation op : toWrite) {
      out.reset();
      final long start = out.position();
      out.skip(Integer.BYTES);
      writeOperationNoSize(checksumStreamOutput, op);
      long end = out.position();
      int operationSize = (int) (out.position() - Integer.BYTES - start);
      out.seek(start);
      out.writeInt(operationSize);
      out.seek(end);
      ReleasablePagedBytesReference bytes = out.bytes();
      bytes.writeTo(outStream);
    }
  } finally {
    Releasables.close(out);
  }
}
origin: org.elasticsearch.plugin/transport-netty3-client

@Override
public BytesStreamOutput newBytesOutput() {
  return new ReleasableBytesStreamOutput(transport.bigArrays);
}
origin: harbby/presto-connectors

boolean addedReleaseListener = false;
try {
  bStream = new ReleasableBytesStreamOutput(transport.bigArrays);
  bStream.skip(NettyHeader.HEADER_SIZE);
  StreamOutput stream = bStream;
  if (options.compress()) {
  stream.close();
  ReleasablePagedBytesReference bytes = bStream.bytes();
  ChannelBuffer buffer = bytes.toChannelBuffer();
  NettyHeader.writeHeader(buffer, requestId, status, version);
} finally {
  if (!addedReleaseListener && bStream != null) {
    Releasables.close(bStream.bytes());
origin: com.strapdata.elasticsearch.test/framework

ReleasableBytesStreamOutput crazyStream = new ReleasableBytesStreamOutput(length, bigarrays);
final int offset = randomIntBetween(0, crazyLength - length);
for (int j = 0; j < offset; j++) {
  crazyStream.writeByte((byte) random().nextInt(1 << 8));
for (int j = crazyStream.size(); j < crazyLength; j++) {
  crazyStream.writeByte((byte) random().nextInt(1 << 8));
PagedBytesReference crazyReference = crazyStream.bytes();
origin: com.strapdata.elasticsearch/elasticsearch

/**
 * Serializes the given message into a bytes representation
 */
private BytesReference buildMessage(long requestId, byte status, Version nodeVersion, TransportMessage message, StreamOutput stream,
                  ReleasableBytesStreamOutput writtenBytes) throws IOException {
  final BytesReference zeroCopyBuffer;
  if (message instanceof BytesTransportRequest) { // what a shitty optimization - we should use a direct send method instead
    BytesTransportRequest bRequest = (BytesTransportRequest) message;
    assert nodeVersion.equals(bRequest.version());
    bRequest.writeThin(stream);
    zeroCopyBuffer = bRequest.bytes;
  } else {
    message.writeTo(stream);
    zeroCopyBuffer = BytesArray.EMPTY;
  }
  // we have to close the stream here - flush is not enough since we might be compressing the content
  // and if we do that the close method will write some marker bytes (EOS marker) and otherwise
  // we barf on the decompressing end when we read past EOF on purpose in the #validateRequest method.
  // this might be a problem in deflate after all but it's important to close it for now.
  stream.close();
  final BytesReference messageBody = writtenBytes.bytes();
  final BytesReference header = buildHeader(requestId, status, stream.getVersion(), messageBody.length() + zeroCopyBuffer.length());
  return new CompositeBytesReference(header, messageBody, zeroCopyBuffer);
}
origin: org.elasticsearch.plugin/transport-netty4-client

@Override
protected BytesStreamOutput newBytesOutput() {
  return new ReleasableBytesStreamOutput(transport.bigArrays);
}
origin: harbby/presto-connectors

status = TransportStatus.setRequest(status);
ReleasableBytesStreamOutput bStream = new ReleasableBytesStreamOutput(bigArrays);
boolean addedReleaseListener = false;
try {
  bStream.skip(NettyHeader.HEADER_SIZE);
  StreamOutput stream = bStream;
    bRequest.writeThin(stream);
    stream.close();
    bytes = bStream.bytes();
    ChannelBuffer headerBuffer = bytes.toChannelBuffer();
    ChannelBuffer contentBuffer = bRequest.bytes().toChannelBuffer();
    request.writeTo(stream);
    stream.close();
    bytes = bStream.bytes();
    buffer = bytes.toChannelBuffer();
} finally {
  if (!addedReleaseListener) {
    Releasables.close(bStream.bytes());
origin: org.elasticsearch/elasticsearch

final ReleasableBytesStreamOutput out = new ReleasableBytesStreamOutput(bigArrays);
try {
  final long start = out.position();
  out.skip(Integer.BYTES);
  writeOperationNoSize(new BufferedChecksumStreamOutput(out), operation);
  final long end = out.position();
  final int operationSize = (int) (end - Integer.BYTES - start);
  out.seek(start);
  out.writeInt(operationSize);
  out.seek(end);
  final ReleasablePagedBytesReference bytes = out.bytes();
  try (ReleasableLock ignored = readLock.acquire()) {
    ensureOpen();
origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.elasticsearch

@Override
protected BytesStreamOutput newBytesOutput() {
  return new ReleasableBytesStreamOutput(transport.bigArrays);
}
origin: harbby/presto-connectors

/**
 * Writes all operations in the given iterable to the given output stream including the size of the array
 * use {@link #readOperations(StreamInput)} to read it back.
 */
public static void writeOperations(StreamOutput outStream, List<Operation> toWrite) throws IOException {
  final ReleasableBytesStreamOutput out = new ReleasableBytesStreamOutput(BigArrays.NON_RECYCLING_INSTANCE);
  try {
    outStream.writeInt(toWrite.size());
    final BufferedChecksumStreamOutput checksumStreamOutput = new BufferedChecksumStreamOutput(out);
    for (Operation op : toWrite) {
      out.reset();
      final long start = out.position();
      out.skip(RamUsageEstimator.NUM_BYTES_INT);
      writeOperationNoSize(checksumStreamOutput, op);
      long end = out.position();
      int operationSize = (int) (out.position() - RamUsageEstimator.NUM_BYTES_INT - start);
      out.seek(start);
      out.writeInt(operationSize);
      out.seek(end);
      ReleasablePagedBytesReference bytes = out.bytes();
      bytes.writeTo(outStream);
    }
  } finally {
    Releasables.close(out.bytes());
  }
}
origin: com.strapdata.elasticsearch.plugin/transport-netty4

@Override
protected BytesStreamOutput newBytesOutput() {
  return new ReleasableBytesStreamOutput(transport.bigArrays);
}
origin: com.strapdata.elasticsearch/elasticsearch

/**
 * Writes all operations in the given iterable to the given output stream including the size of the array
 * use {@link #readOperations(StreamInput)} to read it back.
 */
public static void writeOperations(StreamOutput outStream, List<Operation> toWrite) throws IOException {
  final ReleasableBytesStreamOutput out = new ReleasableBytesStreamOutput(BigArrays.NON_RECYCLING_INSTANCE);
  try {
    outStream.writeInt(toWrite.size());
    final BufferedChecksumStreamOutput checksumStreamOutput = new BufferedChecksumStreamOutput(out);
    for (Operation op : toWrite) {
      out.reset();
      final long start = out.position();
      out.skip(Integer.BYTES);
      writeOperationNoSize(checksumStreamOutput, op);
      long end = out.position();
      int operationSize = (int) (out.position() - Integer.BYTES - start);
      out.seek(start);
      out.writeInt(operationSize);
      out.seek(end);
      ReleasablePagedBytesReference bytes = out.bytes();
      bytes.writeTo(outStream);
    }
  } finally {
    Releasables.close(out);
  }
}
origin: jprante/elasticsearch-transport-websocket

@Override
public org.elasticsearch.common.io.stream.BytesStreamOutput newBytesOutput() {
  return new org.elasticsearch.common.io.stream.ReleasableBytesStreamOutput(transport.bigArrays);
}
origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.elasticsearch

/**
 * Writes all operations in the given iterable to the given output stream including the size of the array
 * use {@link #readOperations(StreamInput, String)} to read it back.
 */
public static void writeOperations(StreamOutput outStream, List<Operation> toWrite) throws IOException {
  final ReleasableBytesStreamOutput out = new ReleasableBytesStreamOutput(BigArrays.NON_RECYCLING_INSTANCE);
  try {
    outStream.writeInt(toWrite.size());
    final BufferedChecksumStreamOutput checksumStreamOutput = new BufferedChecksumStreamOutput(out);
    for (Operation op : toWrite) {
      out.reset();
      final long start = out.position();
      out.skip(Integer.BYTES);
      writeOperationNoSize(checksumStreamOutput, op);
      long end = out.position();
      int operationSize = (int) (out.position() - Integer.BYTES - start);
      out.seek(start);
      out.writeInt(operationSize);
      out.seek(end);
      ReleasablePagedBytesReference bytes = out.bytes();
      bytes.writeTo(outStream);
    }
  } finally {
    Releasables.close(out);
  }
}
origin: apache/servicemix-bundles

@Override
protected BytesStreamOutput newBytesOutput() {
  return new ReleasableBytesStreamOutput(transport.bigArrays);
}
origin: harbby/presto-connectors

final ReleasableBytesStreamOutput out = new ReleasableBytesStreamOutput(bigArrays);
try {
  final BufferedChecksumStreamOutput checksumStreamOutput = new BufferedChecksumStreamOutput(out);
  final long start = out.position();
  out.skip(RamUsageEstimator.NUM_BYTES_INT);
  writeOperationNoSize(checksumStreamOutput, operation);
  final long end = out.position();
  final int operationSize = (int) (end - RamUsageEstimator.NUM_BYTES_INT - start);
  out.seek(start);
  out.writeInt(operationSize);
  out.seek(end);
  final ReleasablePagedBytesReference bytes = out.bytes();
  try (ReleasableLock lock = readLock.acquire()) {
    ensureOpen();
  throw new TranslogException(shardId, "Failed to write operation [" + operation + "]", e);
} finally {
  Releasables.close(out.bytes());
origin: harbby/presto-connectors

@Override
public BytesStreamOutput newBytesOutput() {
  return new ReleasableBytesStreamOutput(transport.bigArrays);
}
origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.elasticsearch

final ReleasableBytesStreamOutput out = new ReleasableBytesStreamOutput(bigArrays);
try {
  final long start = out.position();
  out.skip(Integer.BYTES);
  writeOperationNoSize(new BufferedChecksumStreamOutput(out), operation);
  final long end = out.position();
  final int operationSize = (int) (end - Integer.BYTES - start);
  out.seek(start);
  out.writeInt(operationSize);
  out.seek(end);
  final ReleasablePagedBytesReference bytes = out.bytes();
  try (ReleasableLock ignored = readLock.acquire()) {
    ensureOpen();
origin: org.elasticsearch/elasticsearch

ReleasableBytesStreamOutput bStream = new ReleasableBytesStreamOutput(bigArrays);
CompressibleBytesOutputStream stream = new CompressibleBytesOutputStream(bStream, compressMessage);
boolean addedReleaseListener = false;
origin: apache/servicemix-bundles

final ReleasableBytesStreamOutput out = new ReleasableBytesStreamOutput(bigArrays);
try {
  final long start = out.position();
  out.skip(Integer.BYTES);
  writeOperationNoSize(new BufferedChecksumStreamOutput(out), operation);
  final long end = out.position();
  final int operationSize = (int) (end - Integer.BYTES - start);
  out.seek(start);
  out.writeInt(operationSize);
  out.seek(end);
  final ReleasablePagedBytesReference bytes = out.bytes();
  try (ReleasableLock ignored = readLock.acquire()) {
    ensureOpen();
org.elasticsearch.common.io.streamReleasableBytesStreamOutput

Javadoc

An bytes stream output that allows providing a BigArrays instance expecting it to require releasing its content ( #bytes()) once done.

Please note, its is the responsibility of the caller to make sure the bytes reference do not "escape" and are released only once.

Most used methods

  • <init>
  • bytes
    Returns a Releasable implementation of a org.elasticsearch.common.bytes.BytesReference that represen
  • position
  • reset
  • seek
  • skip
  • writeInt
  • size
  • writeByte

Popular in Java

  • Making http requests using okhttp
  • compareTo (BigDecimal)
  • setScale (BigDecimal)
  • putExtra (Intent)
  • MalformedURLException (java.net)
    This exception is thrown when a program attempts to create an URL from an incorrect specification.
  • Charset (java.nio.charset)
    A charset is a named mapping between Unicode characters and byte sequences. Every Charset can decode
  • Locale (java.util)
    Locale represents a language/country/variant combination. Locales are used to alter the presentatio
  • Annotation (javassist.bytecode.annotation)
    The annotation structure.An instance of this class is returned bygetAnnotations() in AnnotationsAttr
  • JFrame (javax.swing)
  • JPanel (javax.swing)
  • From CI to AI: The AI layer in your organization
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now