/*
Write at most "length" bytes from "data" starting at position "offset", and
return the number of bytes written. caller is responsible for setting
isDirty.
183096
private int writeAtMost(ByteBuffer data, int offset, int length)
    {
        if (current >= bufferOffset + buffer.length)
            reBuffer();

        assert current < bufferOffset + buffer.length
        : String.format("File (%s) offset %d, buffer offset %d.", getPath(), current, bufferOffset);


        int toCopy = Math.min(length, buffer.length - bufferCursor());

        // copy bytes from external buffer
        ByteBufferUtil.arrayCopy(data, offset, buffer, bufferCursor(), toCopy);

        assert current <= bufferOffset + buffer.length
        : String.format("File (%s) offset %d, buffer offset %d.", getPath(), current, bufferOffset);

        validBufferBytes = Math.max(validBufferBytes, bufferCursor() + toCopy);
        current += toCopy;

        return toCopy;
    }
1100317
public static void write(FileDescriptor fd, byte[] bytes, int byteOffset, int byteCount) throws IOException {
        Arrays.checkOffsetAndCount(bytes.length, byteOffset, byteCount);
        if (byteCount == 0) {
            return;
        }
        try {
            while (byteCount > 0) {
                int bytesWritten = Libcore.os.write(fd, bytes, byteOffset, byteCount);
                byteCount -= bytesWritten;
                byteOffset += bytesWritten;
            }
        } catch (ErrnoException errnoException) {
            throw errnoException.rethrowAsIOException();
        }
    }
299382
@Override
  public void writeChunk(long length, boolean isFinal)
  {
    long chunk;
    
    if (isFinal) {
      chunk = length << 1;
    }
    else {
      chunk = (length << 1) + 1;
    }
    
    writeUnsigned(chunk);
  }
796853
public synchronized void write(byte[] b, int off, int len) throws IOException {
		dataOutputStream.write(b, off, len);
		dataOutputStream.flush();
	}
340550
public void write(byte []buf, int offset, int length, boolean isEnd)
    throws IOException
  {
    if (_stream != null)
      _stream.write(buf, offset, length, isEnd);
  }
190963
public final int writeTo(final OutputStream os,int offset, int maxWriteSize) throws IOException {
        int bytesToWrite = Math.min(blobReference.getBytes().length - offset, maxWriteSize);
        os.write(blobReference.getBytes(), offset, blobReference.getBytes().length);
        return bytesToWrite;
    }
1175799
public void writeBytes(byte header, byte[] bytes) {
    int length = bytes.length;
    while (remaining() < length + 10) {
      grow();
    }
    writeLength(length + 1);
    buf[position++] = header;
    System.arraycopy(bytes, 0, buf, position, length);
    position += length;
  }
1311645
@Override
  public void write(byte []buf, int offset, int length, boolean isEnd)
    throws IOException
  {
    int end = offset + length;
    while (offset < end) {
      int ch1 = buf[offset++] & 0xff;

      if (ch1 < 0x80)
        _cb.append((char) ch1);
      else if ((ch1 & 0xe0) == 0xc0) {
        if (offset >= end)
          throw new EOFException("unexpected end of file in utf8 character");
        
        int ch2 = buf[offset++] & 0xff;
        if ((ch2 & 0xc0) != 0x80)
          throw new CharConversionException("illegal utf8 encoding");
      
        _cb.append((char) (((ch1 & 0x1f) << 6) + (ch2 & 0x3f)));
      }
      else if ((ch1 & 0xf0) == 0xe0) {
        if (offset + 1 >= end)
          throw new EOFException("unexpected end of file in utf8 character");
        
        int ch2 = buf[offset++] & 0xff;
        int ch3 = buf[offset++] & 0xff;
      
        if ((ch2 & 0xc0) != 0x80)
          throw new CharConversionException("illegal utf8 encoding");
      
        if ((ch3 & 0xc0) != 0x80)
          throw new CharConversionException("illegal utf8 encoding");
      
        _cb.append((char) (((ch1 & 0x1f) << 12) + ((ch2 & 0x3f) << 6) + (ch3 & 0x3f)));
      }
      else
        throw new CharConversionException("illegal utf8 encoding at (" +
                                          (int) ch1 + ")");
    }
  }
1339289
public void write(byte b[], int off, int len)
        throws IOException
    {     
        len=prepareOutput(len);
        if (!_nulled)
            _out.write(b,off,len);
        if (_bytes==_contentLength)
            flush();
    }
757253
public void write(byte[] buf, int offset, int len) throws IOException
  {
    if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
    { // 306998.15
      Tr.debug(tc, "write len --> " + len + ", limit->" + limit);
    }
    if (len < 0)
    {
      if (tc.isErrorEnabled())
        Tr.error(tc, "Illegal.Argument.Trying.to.write.chars");
      throw new IllegalArgumentException();
    }
    if (!_hasWritten && obs != null)
    {
      _hasWritten = true;
      obs.alertFirstWrite();
    }

    if (limit > -1)
    {
      if (total + len > limit)
      {
        len = limit - total;
        except = new WriteBeyondContentLengthException();
      }
    }

    int toWrite = 0, amountWritten = 0, remaining = 0;

    while (amountWritten != len)
    {

      checkList();

      toWrite = len - amountWritten;
      remaining = current.remaining();

      if (toWrite <= remaining)
      {

        /*
         * We can write it all in the current buffer
         */
        current.put(buf, offset + amountWritten, toWrite);
        amountWritten += toWrite;
      }
      else
      {

        /*
         * Write what we can to the current position
         */
        current.put(buf, offset + amountWritten, remaining);
        amountWritten += remaining;
      }
    }
    count += len;
    total += len;
    check();
  }
207718
public void write(byte[] buf, int offset, int length) throws IOException
    {
        if (length>_buffer.capacity())
            _flush=ByteBuffer.wrap(buf,offset,length);
        else
         {
             _buffer.clear();
             _buffer.put(buf,offset,length);
             _buffer.flip();
             _flush=_buffer;
         }
         flushBuffer();
    }
1285335
public static void writeUnsignedLong(byte[] bytes, int offset, long i) {
      while ((i & ~0x7F) != 0) {
         bytes[offset++] = (byte) ((i & 0x7f) | 0x80);
         i >>>= 7;
      }
      bytes[offset] = (byte) i;
   }
789623
public void writeByteBufferPart(byte[] buffer, int offset, int length)
        throws IOException
    {
        while (length > 0) {
            flushIfFull();

            int sublen = _buffer.length - _offset;

            if (length < sublen)
                sublen = length;

            _buffer[_offset++] = BC_BINARY_CHUNK;
            _buffer[_offset++] = (byte) (sublen >> 8);
            _buffer[_offset++] = (byte) sublen;

            System.arraycopy(buffer, offset, _buffer, _offset, sublen);

            _offset += sublen;
            length -= sublen;
            offset += sublen;
        }
    }
44451
public boolean write(byte []buffer, int offset, int length)
  {
    if (length == 0) {
      return true; // throw new IllegalStateException();
    }
    
    int count = length / BLOCK_SIZE + 1;
    
    if (_tailAddress <= _index + length + PAD + 2 * count) {
      return false;
    }

    _crc.update(buffer, offset, length);
    
    byte []headerBuffer = _headerBuffer;
    
    while (length > 0) {
      int sublen = Math.min(length, BLOCK_SIZE);
      
      BitsUtil.writeInt16(headerBuffer, 0, sublen);
      
      writeImpl(headerBuffer, 0, 2);
      writeImpl(buffer, offset, sublen);
      
      length -= sublen;
      offset += sublen;
    }
    
    return true;
  }
65710
@Override
	public void write(byte data[], int offset, int len) throws IOException
    {
        if ((capacity - size) < len)
            flush();
        
        // Do we have enough space ?
        if (capacity >= len)
        {
            System.arraycopy(data, offset, buffer, size, len);
            size += len;
        }
        else
        {
            // Too big, write it directly ...
            out.write(data, offset, len);
        }
    }
824039
@Override
  public void write(byte []buf, int offset, int length, boolean isEnd)
    throws IOException
  {
    OutputStream stream = getStream();

    if (stream == null) {
      return;
    }

    synchronized (stream) {
      stream.write(buf, offset, length);
      
      if (isEnd) {
        stream.flush();
      }
    }
  }
639088
def write_bytes(self, data, n):
        """"""
        for pos in xrange(0, n):
            self.payload[self.pos + pos] = data[pos]
            
        self.pos += n