Writes as much data for all the streams as possible given the current flow control windows.

<p>Must be called with holding transport lock.
502067
void writeStreams() {
    OkHttpClientStream[] streams = transport.getActiveStreams();
    int connectionWindow = connectionState.window();
    for (int numStreams = streams.length; numStreams > 0 && connectionWindow > 0;) {
      int nextNumStreams = 0;
      int windowSlice = (int) ceil(connectionWindow / (float) numStreams);
      for (int index = 0; index < numStreams && connectionWindow > 0; ++index) {
        OkHttpClientStream stream = streams[index];
        OutboundFlowState state = state(stream);

        int bytesForStream = min(connectionWindow, min(state.unallocatedBytes(), windowSlice));
        if (bytesForStream > 0) {
          state.allocateBytes(bytesForStream);
          connectionWindow -= bytesForStream;
        }

        if (state.unallocatedBytes() > 0) {
          // There is more data to process for this stream. Add it to the next
          // pass.
          streams[nextNumStreams++] = stream;
        }
      }
      numStreams = nextNumStreams;
    }

    // Now take one last pass through all of the streams and write any allocated bytes.
    WriteStatus writeStatus = new WriteStatus();
    for (OkHttpClientStream stream : transport.getActiveStreams()) {
      OutboundFlowState state = state(stream);
      state.writeBytes(state.allocatedBytes(), writeStatus);
      state.clearAllocatedBytes();
    }

    if (writeStatus.hasWritten()) {
      flush();
    }
  }
1103999
void write(ByteCodeWriter out)
    throws IOException
  {
    out.write(ConstantPool.CP_STRING);
    out.writeShort(_stringIndex);
  }
1078643
public void writeTo(Segment sink, int byteCount) {
    if (!sink.owner) throw new IllegalArgumentException();
    if (sink.limit + byteCount > SIZE) {
      // We can't fit byteCount bytes at the sink's current position. Shift sink first.
      if (sink.shared) throw new IllegalArgumentException();
      if (sink.limit + byteCount - sink.pos > SIZE) throw new IllegalArgumentException();
      System.arraycopy(sink.data, sink.pos, sink.data, 0, sink.limit - sink.pos);
      sink.limit -= sink.pos;
      sink.pos = 0;
    }

    System.arraycopy(data, pos, sink.data, sink.limit, byteCount);
    sink.limit += byteCount;
    pos += byteCount;
  }
611221
void write(ByteCodeWriter out)
    throws IOException
  {
    out.write(ConstantPool.CP_LONG);
    out.writeLong(_value);
  }
1366786
private boolean writeFrameSync() throws FlowControlException {
        if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
            Tr.debug(tc, "writeFrameSync entry: stream: " + myID);
        }
        Frame currentFrame = this.currentFrame;

        if (!currentFrame.getFrameType().equals(FrameTypes.GOAWAY) && isStreamClosed()) {
            if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                Tr.debug(tc, "writeFrameSync exit - stream " + myID + " is closed");
            }
            return false;
        }
        if (currentFrame.isWriteFrame() && currentFrame.getInitialized()) {
            WsByteBuffer writeFrameBuffer = null;
            WsByteBuffer[] writeFrameBuffers = null;
            try {
                if (currentFrame.getFrameType() == FrameTypes.DATA) {
                    FrameData data = (FrameData) currentFrame;
                    boolean timedOut = false;

                    // Check to see if the write window is large enough to write this data.
                    if (isWindowLimitExceeded((FrameData) currentFrame)) {
                        // the connection or stream window is too small to write this data frame.  This thread will wait for a max of
                        // 5 seconds for a window update that's large enough to allow the data frame to be written out
                        long startTime = System.currentTimeMillis();
                        while (isWindowLimitExceeded((FrameData) currentFrame) && !timedOut) {
                            synchronized (this) {
                                this.wait(MAX_TIME_TO_WAIT_FOR_WINDOW_UPDATE_MS);
                            }
                            if (state.equals(StreamState.CLOSED) || muxLink.checkIfGoAwaySendingOrClosing()) {
                                return false;
                            } else if (System.currentTimeMillis() - startTime > MAX_TIME_TO_WAIT_FOR_WINDOW_UPDATE_MS) {
                                timedOut = true;
                            }
                        }
                    }
                    // the flow control window is large enough to write the data frame
                    if (!timedOut) {
                        writeFrameBuffers = data.buildFrameArrayForWrite();
                        muxLink.writeSync(null, writeFrameBuffers, data.getWriteFrameLength(), TCPRequestContext.NO_TIMEOUT,
                                          data.getFrameType(), data.getPayloadLength(), myID);

                        streamWindowUpdateWriteLimit -= currentFrame.getPayloadLength();
                        if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                            Tr.debug(tc, "stream: " + myID + " Data payload written - new streamWindowUpdateWriteLimit: " + streamWindowUpdateWriteLimit);
                        }

                    } else {
                        // timed out waiting for a window update, throw FCE which will cause this stream to be RESET.
                        FlowControlException up = new FlowControlException("Write failed. Window limit exceeded. Stream will be Reset.");
                        up.setConnectionError(false);
                        throw up;
                    }

                } else {
                    // this frame is not a data frame, and so it's not subject to flow control and we can write immediately
                    writeFrameBuffer = currentFrame.buildFrameForWrite();
                    muxLink.writeSync(writeFrameBuffer, null, currentFrame.getWriteFrameLength(), TCPRequestContext.NO_TIMEOUT,
                                      currentFrame.getFrameType(), currentFrame.getPayloadLength(), myID);
                }
            } catch (IOException e) {
                if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                    Tr.debug(tc, "writeFrameSync caught an IOException: " + e);
                }

            } catch (InterruptedException e) {
                if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                    Tr.debug(tc, "writeFrameSync interrupted: " + e);
                }
            } finally {
                // release buffer used to synchronously write the frame
                if (writeFrameBuffer != null) {
                    writeFrameBuffer.release();
                } else if (writeFrameBuffers != null) {
                    for (int i = 0; i < writeFrameBuffers.length; i++) {
                        if (writeFrameBuffers[i] != null) {
                            // buffer at [1] is allocated by old channel code, it will clean it up
                            // later move this logic to a frame cleanup method that can take care of releasing
                            if (i != 1) {
                                writeFrameBuffers[i].release();
                            }
                        }
                    }
                }
            }

        } else {
            if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                Tr.debug(tc, "writeFrameSync internal flow issue - exiting method ");
            }
        }
        if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
            Tr.debug(tc, "writeFrameSync exit: stream-id: " + myID);
        }
        return true;
    }
122949
public synchronized void write(DataOutput out) throws IOException {
    jobid.write(out);
    out.writeFloat(setupProgress);
    out.writeFloat(mapProgress);
    out.writeFloat(reduceProgress);
    out.writeFloat(cleanupProgress);
    out.writeInt(runState);
    out.writeLong(startTime);
    Text.writeString(out, user);
    WritableUtils.writeEnum(out, priority);
    Text.writeString(out, schedulingInfo);
  }
1076885
public void flushData()
  {
    if (isClosed()) {
      if (_pendingFlushEntries.size() > 0) {
        System.out.println("PENDING_FLUSH");
      }
      return;
    }

    WriteStream out = _out;
    
    if (out != null) {
      try {
        out.flush();
      } catch (Exception e) {
        log.log(Level.FINER, e.toString(), e);
      }
    }
    
    // flush entries to allow for stubs to replace buffers
    completePendingFlush();
  }
459088
protected void write() throws Exception {
		ByteBuffer buffer = queue.peek();
		if (buffer == null) {
			if (key != null) {
				key.interestOps(0);
			}
			return;
		}
		if (channel != null) {
			int count;
			while (true) {
				count = channel.write(buffer);

				// Debug
				if (debug) {
					logger.info(count + " bytes submitted to " + channel.getRemoteAddress() + ".");
				}

				// EOF?
				if (count == -1) {
					throw new InvalidPacketDataError(nodeID, "host", host, "port", port);
				}

				// Remove the submitted buffer from the queue
				if (!buffer.hasRemaining()) {
					queue.poll();
				}

				// Turn off write mode (if the queue is empty)
				if (queue.isEmpty()) {
					if (blockerBuffer.compareAndSet(buffer, null) && key != null) {
						key.interestOps(0);
					}
					return;
				} else {
					buffer = queue.peek();
				}
			}
		}
	}
97359
public void writeTo(WritableByteChannel channel) throws IOException {
        for (ByteBuffer buffer : toDirectByteBuffers()) {
            channel.write(buffer);
        }
    }
431491
public void write(ByteCodeWriter out)
    throws IOException
  {
    out.writeShort(_entries.size());

    for (int i = 1; i < _entries.size(); i++) {
      ConstantPoolEntry entry = _entries.get(i);

      if (entry != null)
        entry.write(out);
    }
  }
676970
public void write(final Writer outputWriter) throws IOException {
    try (final DataInputStream keyStream = entry.getKeyStream();
         final DataInputStream valueStream = entry.getValueStream();) {
      outputWriter.write("Container: ");
      outputWriter.write(keyStream.readUTF());
      outputWriter.write("\n");
      this.writeFiles(valueStream, outputWriter);
    }
  }
1301383
@Override
    public void write(int data) throws IOException {
        ensureBufferAvailable();
        buffer.backingBuffer().put((byte) data);
        if (!buffer.hasRemaining()) {
            flush(false);
        }
    }
613969
public void write (@Nonnull final ByteBuffer aSrcBuffer)
  {
    ValueEnforcer.notNull (aSrcBuffer, "SourceBuffer");

    if (m_bCanGrow && aSrcBuffer.remaining () > m_aBuffer.remaining ())
      _growBy (aSrcBuffer.remaining ());

    m_aBuffer.put (aSrcBuffer);
  }
1357457
private void writeObject(ObjectOutputStream stream) throws IOException {
    stream.writeInt(_capacity);
    stream.writeInt(_size);
    int count = 0;
    EntryImpl<K, V> entry = _mapFirst;
    while (entry != null) {
      stream.writeObject(entry._key);
      stream.writeObject(entry._value);
      count++;
      entry = entry._after;
    }
    if (count != _size) { throw new IOException("FastMap Corrupted"); }
  }
1004989
private static void writeStream(final InputStream input, final FileWriter writer)
            throws IOException
    {
        writeStream(input, writer, LineEndingStyle.LOCAL);
    }
60144
def write(self, data):
        """"""
        for chunk in chunks(data, 512):
            self.wait_to_write()
            self.comport.write(chunk)
        self.comport.flush()
688554
public void write(int b) throws IOException
	{
		//PK89810, If WCCustomProperties.FINISH_RESPONSE_ON_CLOSE is set and stream is already obtained and closed. 
		// User will not be allowed to write more data if the above case is met, outputstreamClosed will be true and default is false.
		if (!(WCCustomProperties.FINISH_RESPONSE_ON_CLOSE) || !outputstreamClosed ) //PK89810
		{
		if (com.ibm.ejs.ras.TraceComponent.isAnyTracingEnabled()&&logger.isLoggable (Level.FINE)) {  //306998.15
			logger.logp(Level.FINE, CLASS_NAME,"write", "write --> "+b);
        }
		if (!_hasWritten && obs != null)
		{
			_hasWritten = true;
			if (obsList!=null){
				for (int i=0;i<obsList.size();i++){
					obsList.get(i).alertFirstWrite();
				}
			}
			else {
			obs.alertFirstWrite();
		}
		}
		if (limit > -1)
		{
			if (total >= limit)
			{
				throw new WriteBeyondContentLengthException();
			}
		}
		if (count == buf.length)
		{
			response.setFlushMode(false);
			flushBytes();
			response.setFlushMode(true);
		}
		buf[count++] = (byte) b;
		total++;
	}
		else
		{//PK89810 start
			if (com.ibm.ejs.ras.TraceComponent.isAnyTracingEnabled()&&logger.isLoggable (Level.FINE))
				logger.logp(Level.FINE, CLASS_NAME,"write", " write not allowed, outputstreamClosed value -->" + outputstreamClosed);
			
		}//PK89810 End
	}