/
OptimizedJettyWriterFactory.java
53 lines (40 loc) · 1.35 KB
/
OptimizedJettyWriterFactory.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package org.davidmoten.rx2.http;
import java.io.IOException;
import java.io.OutputStream;
import java.nio.ByteBuffer;
import org.eclipse.jetty.server.HttpOutput;
public final class OptimizedJettyWriterFactory implements WriterFactory {
public static final OptimizedJettyWriterFactory INSTANCE = new OptimizedJettyWriterFactory();
@Override
public Writer createWriter(OutputStream out) {
if (out instanceof HttpOutput) {
return createWriter((HttpOutput) out);
} else {
return Writer.createDefault(out);
}
}
private static Writer createWriter(HttpOutput out) {
return new Writer() {
@Override
public void write(ByteBuffer bb) throws IOException {
out.write(bb);
}
@Override
public void write(int b) throws IOException {
out.write(b);
}
@Override
public void write(byte[] buffer, int offset, int length) throws IOException {
out.write(buffer, offset, length);
}
@Override
public void flush() throws IOException {
out.flush();
}
@Override
public void close() throws IOException {
out.close();
}
};
}
}