MCPcopy Index your code
hub / github.com/apache/tomcat / doWrite

Method doWrite

java/org/apache/coyote/http2/Stream.java:998–1032  ·  view source on GitHub ↗
(ByteBuffer chunk)

Source from the content-addressed store, hash-verified

996 */
997
998 @Override
999 public final int doWrite(ByteBuffer chunk) throws IOException {
1000 writeLock.lock();
1001 try {
1002 if (closed) {
1003 throw new IOException(sm.getString("stream.closed", getConnectionId(), getIdAsString()));
1004 }
1005 // chunk is always fully written
1006 int result = chunk.remaining();
1007 if (writeBuffer.isEmpty()) {
1008 int chunkLimit = chunk.limit();
1009 while (chunk.remaining() > 0) {
1010 int thisTime = Math.min(buffer.remaining(), chunk.remaining());
1011 chunk.limit(chunk.position() + thisTime);
1012 buffer.put(chunk);
1013 chunk.limit(chunkLimit);
1014 if (chunk.remaining() > 0 && !buffer.hasRemaining()) {
1015 // Only flush if we have more data to write and the buffer
1016 // is full
1017 if (flush(true, coyoteResponse.getWriteListener() == null)) {
1018 writeBuffer.add(chunk);
1019 dataLeft = true;
1020 break;
1021 }
1022 }
1023 }
1024 } else {
1025 writeBuffer.add(chunk);
1026 }
1027 written += result;
1028 return result;
1029 } finally {
1030 writeLock.unlock();
1031 }
1032 }
1033
1034 final boolean flush(boolean block) throws IOException {
1035 writeLock.lock();

Callers

nothing calls this directly

Calls 15

flushMethod · 0.95
getIdAsStringMethod · 0.80
remainingMethod · 0.80
positionMethod · 0.80
hasRemainingMethod · 0.80
getWriteListenerMethod · 0.80
lockMethod · 0.65
getStringMethod · 0.65
getConnectionIdMethod · 0.65
putMethod · 0.65
addMethod · 0.65
unlockMethod · 0.65

Tested by

no test coverage detected