/** Write a byte string. */ public final void writeRawBytes(final ByteString value) throws IOException { value.writeTo(this); }
/** * Writes the given {@link ByteString} to the provided {@link ByteOutput}. Calling this method may * result in multiple operations on the target {@link ByteOutput} * (i.e. for roped {@link ByteString}s). * * <p>This method exposes the internal backing buffer(s) of the {@link ByteString} to the {@link * ByteOutput} in order to avoid additional copying overhead. It would be possible for a malicious * {@link ByteOutput} to corrupt the {@link ByteString}. Use with caution! * * <p> NOTE: The {@link ByteOutput} <strong>MUST NOT</strong> modify the provided buffers. Doing * so may result in corrupted data, which would be difficult to debug. * * @param bytes the {@link ByteString} to be written * @param output the output to receive the bytes * @throws IOException if an I/O error occurs */ public static void unsafeWriteTo(ByteString bytes, ByteOutput output) throws IOException { bytes.writeTo(output); }
/** * Writes the complete contents of this byte array output stream to * the specified output stream argument. * * @param out the output stream to which to write the data. * @throws IOException if an I/O error occurs. */ public void writeTo(OutputStream out) throws IOException { ByteString[] cachedFlushBuffers; byte[] cachedBuffer; int cachedBufferPos; synchronized (this) { // Copy the information we need into local variables so as to hold // the lock for as short a time as possible. cachedFlushBuffers = flushedBuffers.toArray(new ByteString[flushedBuffers.size()]); cachedBuffer = buffer; cachedBufferPos = bufferPos; } for (ByteString byteString : cachedFlushBuffers) { byteString.writeTo(out); } out.write(copyArray(cachedBuffer, cachedBufferPos)); }
/** * Writes the complete contents of this byte array output stream to * the specified output stream argument. * * @param out the output stream to which to write the data. * @throws IOException if an I/O error occurs. */ public void writeTo(OutputStream out) throws IOException { ByteString[] cachedFlushBuffers; byte[] cachedBuffer; int cachedBufferPos; synchronized (this) { // Copy the information we need into local variables so as to hold // the lock for as short a time as possible. cachedFlushBuffers = flushedBuffers.toArray(new ByteString[flushedBuffers.size()]); cachedBuffer = buffer; cachedBufferPos = bufferPos; } for (ByteString byteString : cachedFlushBuffers) { byteString.writeTo(out); } out.write(copyArray(cachedBuffer, cachedBufferPos)); }
@Override public void writeBytesNoTag(final ByteString value) throws IOException { writeUInt32NoTag(value.size()); value.writeTo(this); }
@Override public void writeBytesNoTag(final ByteString value) throws IOException { writeUInt32NoTag(value.size()); value.writeTo(this); }
@Override protected void writeBuf(UfsFileWriteRequestContext context, StreamObserver<WriteResponse> observer, ByteString buf, long pos) throws Exception { Preconditions.checkState(context != null); if (context.getOutputStream() == null) { createUfsFile(context); } buf.writeTo(context.getOutputStream()); }
@Override public void writeBytesNoTag(final ByteString value) throws IOException { writeUInt32NoTag(value.size()); value.writeTo(this); }
@Override public void writeBytesNoTag(ByteString value) throws IOException { writeUInt32NoTag(value.size()); value.writeTo(this); }
@Override public final void writeBytesNoTag(final ByteString value) throws IOException { writeUInt32NoTag(value.size()); value.writeTo(this); }
createUfsBlock(context); buf.writeTo(context.getOutputStream());
@Override public final void writeBytesNoTag(final ByteString value) throws IOException { writeUInt32NoTag(value.size()); value.writeTo(this); }
@Override public void onNext(SnapshotResponse snapshotResponse) { try { snapshotResponse.getBlob().writeTo(outputStream); bytes.addAndGet(snapshotResponse.getBlob().size()); } catch (IOException e) { answer.completeExceptionally(toEtcdException(e)); } }
@Override public void onNext(SnapshotResponse snapshotResponse) { try { snapshotResponse.getBlob().writeTo(outputStream); bytes.addAndGet(snapshotResponse.getBlob().size()); } catch (IOException e) { answer.completeExceptionally(toEtcdException(e)); } }
@Override public void encode(ByteString value, OutputStream outStream, Context context) throws IOException, CoderException { if (value == null) { throw new CoderException("cannot encode a null ByteString"); } if (!context.isWholeStream) { // ByteString is not delimited, so write its size before its contents. VarInt.encode(value.size(), outStream); } value.writeTo(outStream); }