1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package io.netty5.handler.codec.http;
16
17 import io.netty5.buffer.api.Buffer;
18 import io.netty5.buffer.api.BufferAllocator;
19 import io.netty5.util.Send;
20 import io.netty5.handler.codec.DecoderResult;
21
22 import java.util.Objects;
23
24 public final class EmptyLastHttpContent implements LastHttpContent<EmptyLastHttpContent> {
25 private final Buffer payload;
26 private final BufferAllocator allocator;
27
28 public EmptyLastHttpContent(BufferAllocator allocator) {
29 payload = allocator.allocate(0);
30 this.allocator = allocator;
31 }
32
33 @Override
34 public Buffer payload() {
35 return payload;
36 }
37
38 @Override
39 public EmptyLastHttpContent copy() {
40 return new EmptyLastHttpContent(allocator);
41 }
42
43 @Override
44 public Send<EmptyLastHttpContent> send() {
45 return Send.sending(EmptyLastHttpContent.class, () -> new EmptyLastHttpContent(allocator));
46 }
47
48 @Override
49 public void close() {
50 payload.close();
51 }
52
53 @Override
54 public boolean isAccessible() {
55 return payload.isAccessible();
56 }
57
58 @Override
59 public EmptyLastHttpContent touch(Object hint) {
60 payload.touch(hint);
61 return this;
62 }
63
64 @Override
65 public HttpHeaders trailingHeaders() {
66 return EmptyHttpHeaders.INSTANCE;
67 }
68
69 @Override
70 public DecoderResult decoderResult() {
71 return DecoderResult.success();
72 }
73
74 @Override
75 public void setDecoderResult(DecoderResult result) {
76 throw new UnsupportedOperationException("read only");
77 }
78
79 @Override
80 public String toString() {
81 return "EmptyLastHttpContent";
82 }
83
84 @Override
85 public boolean equals(Object o) {
86 if (this == o) {
87 return true;
88 }
89 if (o == null || getClass() != o.getClass()) {
90 return false;
91 }
92
93 EmptyLastHttpContent that = (EmptyLastHttpContent) o;
94
95 return Objects.equals(payload, that.payload) && Objects.equals(allocator, that.allocator);
96 }
97
98 @Override
99 public int hashCode() {
100 int result = payload != null ? payload.hashCode() : 0;
101 result = 31 * result + (allocator != null ? allocator.hashCode() : 0);
102 return result;
103 }
104 }