Internal helper that writes the current buffer to the output. The
buffer position is reset to its initial value when this returns.
328510
private void refreshBuffer() throws IOException {
    if (output == null) {
      // We're writing to a single buffer.
      throw new OutOfSpaceException();
    }

    // Since we have an output stream, this is our buffer
    // and buffer offset == 0
    output.write(buffer, 0, position);
    position = 0;
  }
84899
public void writeTo(Writer target, boolean flushTarget, boolean emptyAfter) throws IOException {
        if (target instanceof GrailsWrappedWriter) {
            GrailsWrappedWriter wrappedWriter = ((GrailsWrappedWriter)target);
            if (wrappedWriter.isAllowUnwrappingOut()) {
                target = wrappedWriter.unwrap();
            }
        }
        if (target == writer) {
            throw new IllegalArgumentException("Cannot write buffer to itself.");
        }
        if (!emptyAfter && target instanceof StreamCharBufferWriter) {
            ((StreamCharBufferWriter)target).write(this, null);
            return;
        } else if (writeToEncodedAppender(this, target, writer.getEncodedAppender(), true)) {
            if (emptyAfter) {
                emptyAfterReading();
            }
            if (flushTarget) {
                target.flush();
            }
            return;
        }
        writeToImpl(target, flushTarget, emptyAfter);
    }
251267
function writeBuffer() {
      fs.write(fd, buff, 0, buff.length, 0, function (error) {
        fs.close(fd);

        callback(error);
      });
    }
178606
private final void flushBuffer() throws IOException {
		if (bufOutput.position() > 0) {
			bufOutput.flip();
			fcOutput.write(bufOutput);
			bufOutput.clear();
			// log.debug("offsetOutputUncommited=" + offsetOutputUncommited + " offsetOutputCommited=" +
			// offsetOutputCommited + " fcOutput.position()=" + fcOutput.position());
			offsetOutputUncommited = offsetOutputCommited = fcOutput.position();
			if (syncOnFlush) {
				fcOutput.force(false);
				if (callback != null) {
					callback.synched(offsetOutputCommited);
				}
			}
		}
	}
443499
public void writeTo(final OutputStream out) throws IOException
	{
		if(out == null) throw new NullPointerException();
		
		final int n = arrays.size();
		for(int k = 0; k < n; k++) {
			byte[] src = (byte[])arrays.get(k);
			out.write(src);
		}
		if(pos > 0) out.write(buffer, 0, pos);
	}
137196
private void flushCharactersBuffer() throws IOException
  {
    if(charactersBuffer.position() > 0) {
      writer.write(charactersBuffer.array(), 0, charactersBuffer.position());
      charactersBuffer.rewind();
    }
  }
1343430
public void setOutput(Writer output, boolean close)
	{
		reset();
		w = new BufferedWriter(output);
		closeWriter = close;
	}
1058937
public final void writeToBuffer(T t, byte[] buffer) {
        if (t == null) {
            throw new InvalidArgument("cannot write a null");
        } else if (buffer == null) {
            throw new InvalidArgument("cannot write to a null buffer");
        } else if (buffer.length != recordSize) {
            final String fmt = "invalid buffer (%d bytes, expected %d)";
            final String msg = format(fmt, buffer.length, recordSize);
            throw new InvalidArgument(msg);
        }
        writeTo(t, buffer);
    }
1014570
@Override
    public int write(final ByteBuffer source) throws IOException {

        // Precondition checks
        this.checkClosed();
        if (source == null) {
            throw new IllegalArgumentException("Source buffer must be supplied");
        }

        // Put the bytes to be written into a byte[]
        final int totalBytes = source.remaining();
        final byte[] readContents = new byte[totalBytes];
        source.get(readContents);

        // Sync up, we're gonna access shared mutable state
        synchronized (this) {

            // Append the read contents to our internal contents
            this.contents = this.concat(this.contents, readContents, this.position);

            // Increment the position of this channel
            this.position += totalBytes;

        }

        // Return the number of bytes read
        return totalBytes;
    }
868242
@Override
	public void writeToOutput(final ChannelWriterOutputView output) throws IOException {
		int recordsLeft = this.numRecords;
		int currentMemSeg = 0;
		while (recordsLeft > 0)
		{
			final MemorySegment currentIndexSegment = this.sortIndex.get(currentMemSeg++);
			int offset = 0;
			// check whether we have a full or partially full segment
			if (recordsLeft >= this.indexEntriesPerSegment) {
				// full segment
				for (;offset <= this.lastIndexEntryOffset; offset += this.indexEntrySize) {
					final long pointer = currentIndexSegment.getLong(offset);
					this.recordBuffer.setReadPosition(pointer);
					this.serializer.copy(this.recordBuffer, output);
					
				}
				recordsLeft -= this.indexEntriesPerSegment;
			} else {
				// partially filled segment
				for (; recordsLeft > 0; recordsLeft--, offset += this.indexEntrySize)
				{
					final long pointer = currentIndexSegment.getLong(offset);
					this.recordBuffer.setReadPosition(pointer);
					this.serializer.copy(this.recordBuffer, output);
				}
			}
		}
	}
1128871
def buffered_write(self, buf):
        
        if self.closed:
            raise ConnectionClosed()

        if len(buf) + len(self.write_buffer) > self.max_size:
            raise BufferOverflowError()
        else:
            self.write_buffer.extend(buf)
918222
public int write( final ByteBuffer buffer) throws IOException {
		for ( Consumer< ?> consumer : consumers.values()) consumer.consume( buffer.duplicate());
		return channel.write( buffer);
	}

	/**
	 * Closes the underlying channel and completes
	 * any outstanding operations in the consumers.
	 *
	 * @throws IOException if an IO error occurs
	 */
	public void close() throws IOException {
		channel.close();
		super.close();
	}

	/**
	 * Flag indicating whether the underlying channel
	 * is open.
	 *
	 * @return true if it is open, false otherwise
	 */
	public boolean isOpen() {
		return channel.isOpen();
	}
}
359907
@Override
	public void write(int b) throws IOException {
		if (this.position >= this.buffer.length) {
			resize(1);
		}
		this.buffer[this.position++] = (byte) (b & 0xff);
	}
725719
@Override
	public void write(int b) throws IOException
    {
        if ((capacity - size) < 1)
            flush();
        buffer[size++] = (byte)b;
    }
440205
public void write(final int b)
	{
		buffer[pos] = (byte)b;
		size++;
		if(++pos == buffer.length) flushBuffer();
	}
345072
function flush(writeTo) {
    var outputTo = bufferLen + matchStart - chunkLength;

    while (outputTo > 0 && outputTo > bufferStart) {
      if (outputTo > buffer[0].length-1) {
        var part = buffer.shift();
        outputBuffer.push(part.slice(bufferStart));

        bufferStart = Math.max(0, bufferStart - part.length);
        bufferLen -= part.length;
        outputTo -= part.length;
      } else {
        outputBuffer.push(buffer[0].slice(bufferStart, outputTo));
        bufferStart = outputTo;
        break;
      }
    }
    if (writeTo) {
      // Output everything ready as one chunk
      writeTo.push(outputBuffer.join(''));
      outputBuffer.length = 0;
    }
  }
35076
public static int writeTo(OutputStream out, Object message, Schema schema, 
            LinkedBuffer buffer) throws IOException
    {
        if(buffer.start != buffer.offset)
            throw new IllegalArgumentException("Buffer previously used and had not been reset.");
        
        final ProtobufOutput output = new ProtobufOutput(buffer);
        schema.writeTo(output, message);
        return LinkedBuffer.writeTo(out, buffer);
    }