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 package org.apache.hc.core5.http.nio;
29
30 import java.io.IOException;
31 import java.nio.ByteBuffer;
32 import java.nio.channels.WritableByteChannel;
33 import java.util.ArrayList;
34 import java.util.List;
35
36 import org.apache.hc.core5.http.Header;
37
38 public class BasicDataStreamChannel implements DataStreamChannel {
39
40 private final WritableByteChannel byteChannel;
41 private List<Header> trailers;
42
43 public BasicDataStreamChannel(final WritableByteChannel byteChannel) {
44 this.byteChannel = byteChannel;
45 }
46
47 @Override
48 public void requestOutput() {
49 }
50
51 @Override
52 public int write(final ByteBuffer src) throws IOException {
53 return byteChannel.write(src);
54 }
55
56 @Override
57 public void endStream() throws IOException {
58 if (byteChannel.isOpen()) {
59 byteChannel.close();
60 }
61 }
62
63 @Override
64 public void endStream(final List<? extends Header> trailers) throws IOException {
65 endStream();
66 if (trailers != null) {
67 this.trailers = new ArrayList<>();
68 this.trailers.addAll(trailers);
69 }
70 }
71
72 public List<Header> getTrailers() {
73 return trailers;
74 }
75
76 }