Writes the contents of the {@link LinkedBuffer} into the {@link OutputStream}.

@return the total content size of the buffer.
336034
public static int writeTo(final OutputStream out, LinkedBuffer node) throws IOException
    {
        int contentSize = 0, len;
        do
        {
            if ((len = node.offset - node.start) > 0)
            {
                out.write(node.buffer, node.start, len);
                contentSize += len;
            }
        } while ((node = node.next) != null);

        return contentSize;
    }
265004
static int fillBufferWithDelimitedMessageFrom(InputStream in,
            boolean drainRemainingBytesIfTooLarge,
            LinkedBuffer lb) throws IOException
    {
        final byte[] buf = lb.buffer;
        int offset = lb.start, len = buf.length - offset, read = in.read(buf, offset, len);

        if (read < 1)
            throw new EOFException("fillBufferWithDelimitedMessageFrom");

        int last = offset + read, size = buf[offset++];
        if (0 != (size & 0x80))
        {
            size = size & 0x7f;

            for (int shift = 7;; shift += 7)
            {
                if (offset == last)
                {
                    // read too few bytes
                    read = in.read(buf, last, len - (last - lb.start));
                    if (read < 1)
                        throw new EOFException("fillBufferWithDelimitedMessageFrom");

                    last += read;
                }

                byte b = buf[offset++];
                size |= (b & 0x7f) << shift;

                if (0 == (b & 0x80))
                    break;

                if (shift == 28)
                {
                    // discard the remaining bytes (5)
                    for (int i = 0;;)
                    {
                        if (offset == last)
                        {
                            // read more
                            read = in.read(buf, last, len - (last - lb.start));
                            if (read < 1)
                                throw new EOFException("fillBufferWithDelimitedMessageFrom");

                            last += read;
                        }

                        if (buf[offset++] >= 0)
                            break;

                        if (5 == ++i)
                        {
                            // we've already consumed 10 bytes
                            throw ProtobufException.malformedVarint();
                        }
                    }

                }
            }
        }

        if (size == 0)
        {
            if (offset != last)
                throw ProtobufException.misreportedSize();

            return size;
        }

        if (size < 0)
            throw ProtobufException.negativeSize();

        final int partial = last - offset;
        if (partial < size)
        {
            // need to read more
            final int delimSize = offset - lb.start;
            if ((size + delimSize) > len)
            {
                // too large.

                if (!drainRemainingBytesIfTooLarge)
                    return size;

                // drain the remaining bytes
                for (int remaining = size - partial; remaining > 0;)
                {
                    read = in.read(buf, lb.start, Math.min(remaining, len));
                    if (read < 1)
                        throw new EOFException("fillBufferWithDelimitedMessageFrom");

                    remaining -= read;
                }

                return size;
            }

            // read the remaining bytes
            fillBufferFrom(in, buf, last, size - partial);
        }

        // set the read offset (start of message)
        lb.offset = offset;

        return size;
    }
1196436
public static <T> int writeTo(LinkedBuffer buffer, T message, Schema<T> schema)
    {
        if (buffer.start != buffer.offset)
            throw new IllegalArgumentException("Buffer previously used and had not been reset.");

        final ProtobufOutput output = new ProtobufOutput(buffer);
        try
        {
            schema.writeTo(output, message);
        }
        catch (IOException e)
        {
            throw new RuntimeException("Serializing to a LinkedBuffer threw an IOException " +
                    "(should never happen).", e);
        }

        return output.getSize();
    }
256067
public int size() {
        int read = readLocation;
        int write = writeLocation;

        if (write < read)
            write += capacity;

        return write - read;

    }
192536
public WriteStreamOld openWrite()
  {
    if (_cb != null)
      _cb.clear();
    else
      _cb = CharBuffer.allocate();

    if (_ws == null)
      _ws = new WriteStreamOld(this);
    else
      _ws.init(this);

    try {
      _ws.setEncoding("utf-8");
    } catch (UnsupportedEncodingException e) {
    }

    return _ws;
  }
1178612
@Override
    public int size () {
        int size = Smb2Constants.SMB2_HEADER_LENGTH + 40;
        if ( this.inputBuffer != null ) {
            size += this.inputBuffer.size();
        }
        return size8(size);
    }
347650
public long write(final InputStream in) throws IOException
	{
		if(in == null) throw new NullPointerException();
		
		final long sizeStart = size;
		while(true) {
			final int n = in.read(buffer, pos, buffer.length - pos);
			if(n < 0) break;
			pos += n;
			size += n;
			if(pos == buffer.length) flushBuffer();
		}
		return(size - sizeStart);
	}
126328
@Override
    public void write(DataOutput out) throws IOException {
        out.writeInt(contentType.ordinal());
        if (content != null) {
            WritableUtils.writeVInt(out, content.length);
            out.write(content, 0, content.length);
        } else if (is != null) {
            content = new byte[MAX_BUFFER_SIZE];
            int len = 0;
            while ((len = is.read(content)) > 0) {
                out.write(content, 0, len);
            }
        }      
    }
82436
public void writeContent(final OutputStream result) throws IOException
    {
        result.write(PARAGRAPH_DEFAULTS);
        result.write(PLAIN);
        if(inTable) {
            result.write(IN_TABLE);
        }
        if(this.lineLeading > 0) {
            result.write(LINE_SPACING);
            result.write(intToByteArray(this.lineLeading));
        }
        for(int i = 0; i < chunks.size(); i++) {
        	RtfBasicElement rbe = (RtfBasicElement) chunks.get(i);
        	rbe.writeContent(result);
        }
    }
1091912
public ByteBuffer serialize () {

        final int size = uncroppedSize();
        if (size == 0) return ByteBuffer.allocate(0);// empty data segment

        // calculate sense length
        int senseLength;
        if (senseData == null)
            senseLength = 0;
        else
            senseLength = senseData.size();

        // allocate buffer of appropriate size
        final ByteBuffer buffer = ByteBuffer.allocate(size);

        // write sense length field
        ReadWrite.writeTwoByteInt(buffer,// buffer
                senseLength,// value
                0);// index

        // write sense data
        if (senseData != null) senseData.serialize(buffer, SENSE_LENGTH_FIELD_LENGTH);

        // write and SCSI response data
        if (responseData != null) responseData.serialize(buffer, SENSE_LENGTH_FIELD_LENGTH + senseLength);

        if (allocationLength > 0 && buffer.capacity() > allocationLength) {
            /*
             * If the allocation length variable is valid and the response data segment is larger than the data-in
             * buffer allocated by the initiator, limit the number of bytes returned.
             */
            buffer.position(0);
            buffer.limit(allocationLength);
            final ByteBuffer croppedBuffer = ByteBuffer.allocate(allocationLength);
            croppedBuffer.put(buffer);
            return croppedBuffer;
        }

        if (LOGGER.isDebugEnabled()) LOGGER.debug("SCSI Response Data Segment:\n" + Debug.byteBufferToString(buffer));

        return buffer;
    }
663215
private WsByteBuffer getBuffer() {
        WsByteBuffer buffer = this._output[this.outputIndex];
        if (null == buffer) {
            buffer = getNewByteBuffer();
            buffer.clear();
            this._output[this.outputIndex] = buffer;
            if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                Tr.debug(tc, "getBuffer, new buffer -->" + buffer + " ,outputIndex -->" + this.outputIndex);
            }
        } else if (!buffer.hasRemaining()) {
            if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                Tr.debug(tc, "getBuffer, buffer  -->" + buffer + " ,outputIndex -->" + this.outputIndex + " ,outputLength -->" + this._output.length);
            }
            buffer.flip();
            this.outputIndex++;
            // next array spot may or may not exist from previous iterations
            if (null == this._output[this.outputIndex]) {
                this._output[this.outputIndex] = getNewByteBuffer();
            }
            buffer = this._output[this.outputIndex];
            buffer.clear();
        }
        return buffer;
    }
876174
public void write(int b) throws IOException
    {
        prepareOutput(1);
        if (!_nulled)
            _out.write(b);
        if (_bytes==_contentLength)
            flush();
    }
1260636
private void writeBuffer() throws IOException {
    for (int pos = 0; pos < currentBufferSize; pos++) {
      if (isByte[pos]) {
        aFile.write((byte) buffer[pos]);
      } else {
        aFile.write(buffer[pos]);
      }
    }
  }
988105
public synchronized int getSize() {
        try {
            ByteArrayOutputStream bOut = new ByteArrayOutputStream();
            ObjectOutputStream oOut = new ObjectOutputStream(bOut);
            oOut.writeObject(historyStore);
            bOut.close();
            return bOut.size();
        } catch (IOException e) {
            throw new IllegalStateException("Cannot serialize internal store: " + e,e);
        }
    }
822072
public InputStream getContents() {
        final byte[] copy;
        synchronized (this) {
            final int length = this.contents.length;
            copy = new byte[length];
            System.arraycopy(this.contents, 0, copy, 0, this.contents.length);
        }
        return new ByteArrayInputStream(copy);
    }
1130991
public byte[] generateLinkContent() throws IOException
   {
      ByteArrayOutputStream outStream = new ByteArrayOutputStream();

      // LINK HEADER
      for (int i = 0; i < linkHeader.length; i++)
      {
         byte curByteValue = (byte)linkHeader[i];
         outStream.write(curByteValue);
      }
      // LINK BODY
      byte[] linkContent = getLinkContent();
      writeInt(linkContent.length + 2, outStream);
      outStream.write(linkContent);

      // WRITE END LINK FILE
      for (int i = 0; i < 6; i++)
      {
         outStream.write(0);
      }

      return outStream.toByteArray();
   }
539313
@Override
  public WritableBuffer allocate(int capacityHint) {
    capacityHint = Math.min(MAX_BUFFER, Math.max(MIN_BUFFER, capacityHint));
    return new OkHttpWritableBuffer(new Buffer(), capacityHint);
  }