Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ public interface BufferWritableOutputStream {

void write(ByteBuffer byteBuffer) throws IOException;

/**
* Transfer the remaining content of the input FileChannel (from its current position, to end of file).
*/
@Deprecated
void transferFrom(FileChannel source) throws IOException;

}
8 changes: 4 additions & 4 deletions core/src/main/java/io/undertow/io/UndertowOutputStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,8 @@ private void writeBufferBlocking(final boolean writeFinal) throws IOException {

@Override
public void transferFrom(FileChannel source) throws IOException {
final long startPosition = source.position();
final long count = source.size() - source.position();
if (anyAreSet(state, FLAG_CLOSED)) {
throw UndertowMessages.MESSAGES.streamIsClosed();
}
Expand All @@ -318,10 +320,8 @@ public void transferFrom(FileChannel source) throws IOException {
if (channel == null) {
channel = exchange.getResponseChannel();
}
long position = source.position();
long size = source.size();
Channels.transferBlocking(channel, source, position, size);
updateWritten(size - position);
Channels.transferBlocking(channel, source, startPosition, count);
updateWritten(count);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -556,46 +556,44 @@ public void transferFrom(FileChannel source) throws IOException {
if (anyAreSet(state, FLAG_CLOSED) || servletRequestContext.getOriginalResponse().isTreatAsCommitted()) {
throw UndertowServletMessages.MESSAGES.streamIsClosed();
}
final long startPosition = source.position();
long count = source.size() - source.position();
final long remainingContentLength = remainingContentLength();
if (count > remainingContentLength) {
count = remainingContentLength;
}
if (listener == null) {
if (buffer != null && buffer.position() != 0) {
writeBufferBlocking(false);
}
if (channel == null) {
channel = servletRequestContext.getExchange().getResponseChannel();
}
long position = source.position();
long count = source.size() - position;
if (count > remainingContentLength) {
count = remainingContentLength;
}
Channels.transferBlocking(channel, source, position, count);
Channels.transferBlocking(channel, source, startPosition, count);
updateWritten(count);
} else {
setFlags(FLAG_WRITE_STARTED);
createChannel();

long pos = 0;
try {
long size = Math.min (source.size(), remainingContentLength);
pos = source.position();
long end = pos + count;
pos = startPosition;

while (size - pos > 0) {
long ret = channel.transferFrom(pendingFile, pos, size - pos);
while (end - pos > 0) {
long ret = channel.transferFrom(pendingFile, pos, end - pos);
if (ret <= 0) {
clearFlags(FLAG_READY);
pendingFile = source;
source.position(pos);
channel.resumeWrites();
return;
}
pos += ret;
}
} finally {
updateWrittenAsync(pos - source.position());
updateWrittenAsync(pos - startPosition);
}
}

}


Expand Down
Loading