View Javadoc
1   /*
2    * Copyright 2020 The Netty Project
3    *
4    * The Netty Project licenses this file to you under the Apache License,
5    * version 2.0 (the "License"); you may not use this file except in compliance
6    * with the License. You may obtain a copy of the License at:
7    *
8    *   https://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13   * License for the specific language governing permissions and limitations
14   * under the License.
15   */
16  package io.netty.handler.codec.quic;
17  
18  import io.netty.buffer.ByteBuf;
19  import io.netty.buffer.DefaultByteBufHolder;
20  
21  public final class DefaultQuicStreamFrame extends DefaultByteBufHolder implements QuicStreamFrame {
22  
23      private final boolean fin;
24  
25      public DefaultQuicStreamFrame(ByteBuf data, boolean fin) {
26          super(data);
27          this.fin = fin;
28      }
29  
30      @Override
31      public boolean hasFin() {
32          return fin;
33      }
34  
35      @Override
36      public QuicStreamFrame copy() {
37          return new DefaultQuicStreamFrame(content().copy(), fin);
38      }
39  
40      @Override
41      public QuicStreamFrame duplicate() {
42          return new DefaultQuicStreamFrame(content().duplicate(), fin);
43      }
44  
45      @Override
46      public QuicStreamFrame retainedDuplicate() {
47          return new DefaultQuicStreamFrame(content().retainedDuplicate(), fin);
48      }
49  
50      @Override
51      public QuicStreamFrame replace(ByteBuf content) {
52          return new DefaultQuicStreamFrame(content, fin);
53      }
54  
55      @Override
56      public QuicStreamFrame retain() {
57          super.retain();
58          return this;
59      }
60  
61      @Override
62      public QuicStreamFrame retain(int increment) {
63          super.retain(increment);
64          return this;
65      }
66  
67      @Override
68      public QuicStreamFrame touch() {
69          super.touch();
70          return this;
71      }
72  
73      @Override
74      public QuicStreamFrame touch(Object hint) {
75          super.touch(hint);
76          return this;
77      }
78  
79      @Override
80      public String toString() {
81          return "DefaultQuicStreamFrame{" +
82                  "fin=" + fin +
83                  ", content=" + contentToString() +
84                  '}';
85      }
86  
87      @Override
88      public boolean equals(Object o) {
89          if (this == o) {
90              return true;
91          }
92          if (o == null || getClass() != o.getClass()) {
93              return false;
94          }
95          DefaultQuicStreamFrame that = (DefaultQuicStreamFrame) o;
96  
97          if (fin != that.fin) {
98              return false;
99          }
100 
101         return super.equals(o);
102     }
103 
104     @Override
105     public int hashCode() {
106         int result = super.hashCode();
107         result = 31 * result + (fin ? 1 : 0);
108         return result;
109     }
110 }