(ByteBuffer chunk)
| 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(); |
nothing calls this directly
no test coverage detected