Browse Source

ObjectDownloadListener#onWritePossible: Make code spec compatible

Current code violates the ServletOutputStream contract. For every
out.isReady() == true either write or close of that ServletOutputStream
should be called.

See also this issue upstream for more context: [1].

[1] https://github.com/eclipse/jetty.project/issues/2911

Change-Id: Ied575f3603a6be0d2dafc6c3329d685fc212c7a3
Signed-off-by: David Ostrovsky <david@ostrovsky.org>
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
tags/v4.7.4.201809180905-r
David Ostrovsky 5 years ago
parent
commit
5c134f4d42

+ 19
- 13
org.eclipse.jgit.lfs.server/src/org/eclipse/jgit/lfs/server/fs/ObjectDownloadListener.java View File



private final WritableByteChannel outChannel; private final WritableByteChannel outChannel;


private final ByteBuffer buffer = ByteBuffer.allocateDirect(8192);
private ByteBuffer buffer = ByteBuffer.allocateDirect(8192);


/** /**
* @param repository * @param repository
@Override @Override
public void onWritePossible() throws IOException { public void onWritePossible() throws IOException {
while (out.isReady()) { while (out.isReady()) {
if (in.read(buffer) != -1) {
buffer.flip();
outChannel.write(buffer);
buffer.compact();
} else {
in.close();
buffer.flip();
while (out.isReady()) {
if (buffer.hasRemaining()) {
outChannel.write(buffer);
} else {
try {
buffer.clear();
if (in.read(buffer) < 0) {
buffer = null;
} else {
buffer.flip();
}
} catch(Throwable t) {
LOG.log(Level.SEVERE, t.getMessage(), t);
buffer = null;
} finally {
if (buffer != null) {
outChannel.write(buffer);
} else {
try {
out.close();
} finally {
context.complete(); context.complete();
return;
} }
return;
} }
} }
} }

Loading…
Cancel
Save