コード例 #1
0
  @Override
  public void write(final byte[] b, int off, int len) throws IOException {
    while (0 < len) {
      int capacity = buffer.length - cnt;
      if (cnt == HDR_SIZE && capacity < len) {
        // Our block to write is bigger than the packet size,
        // stream it out as-is to avoid unnecessary copies.
        PacketLineOut.formatLength(buffer, buffer.length);
        out.write(buffer, 0, HDR_SIZE);
        out.write(b, off, capacity);
        off += capacity;
        len -= capacity;

      } else {
        if (capacity == 0) writeBuffer();

        int n = Math.min(len, capacity);
        System.arraycopy(b, off, buffer, cnt, n);
        cnt += n;
        off += n;
        len -= n;
      }
    }
  }
コード例 #2
0
 @Override
 public void write(final int b) throws IOException {
   if (cnt == buffer.length) writeBuffer();
   buffer[cnt++] = (byte) b;
 }
コード例 #3
0
 void flushBuffer() throws IOException {
   if (HDR_SIZE < cnt) writeBuffer();
 }