View Javadoc
1   /*
2    * Copyright 2017 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.http2;
17  
18  import io.netty.buffer.ByteBuf;
19  import io.netty.buffer.DefaultByteBufHolder;
20  import io.netty.buffer.Unpooled;
21  import io.netty.util.internal.StringUtil;
22  
23  public final class DefaultHttp2UnknownFrame extends DefaultByteBufHolder implements Http2UnknownFrame {
24      private final byte frameType;
25      private final Http2Flags flags;
26      private Http2FrameStream stream;
27  
28      public DefaultHttp2UnknownFrame(byte frameType, Http2Flags flags) {
29          this(frameType, flags, Unpooled.EMPTY_BUFFER);
30      }
31  
32      public DefaultHttp2UnknownFrame(byte frameType, Http2Flags flags, ByteBuf data) {
33          super(data);
34          this.frameType = frameType;
35          this.flags = flags;
36      }
37  
38      @Override
39      public Http2FrameStream stream() {
40          return stream;
41      }
42  
43      @Override
44      public DefaultHttp2UnknownFrame stream(Http2FrameStream stream) {
45          this.stream = stream;
46          return this;
47      }
48  
49      @Override
50      public byte frameType() {
51          return frameType;
52      }
53  
54      @Override
55      public Http2Flags flags() {
56          return flags;
57      }
58  
59      @Override
60      public String name() {
61          return "UNKNOWN";
62      }
63  
64      @Override
65      public DefaultHttp2UnknownFrame copy() {
66          return replace(content().copy());
67      }
68  
69      @Override
70      public DefaultHttp2UnknownFrame duplicate() {
71          return replace(content().duplicate());
72      }
73  
74      @Override
75      public DefaultHttp2UnknownFrame retainedDuplicate() {
76          return replace(content().retainedDuplicate());
77      }
78  
79      @Override
80      public DefaultHttp2UnknownFrame replace(ByteBuf content) {
81          return new DefaultHttp2UnknownFrame(frameType, flags, content).stream(stream);
82      }
83  
84      @Override
85      public DefaultHttp2UnknownFrame retain() {
86          super.retain();
87          return this;
88      }
89  
90      @Override
91      public DefaultHttp2UnknownFrame retain(int increment) {
92          super.retain(increment);
93          return this;
94      }
95  
96      @Override
97      public String toString() {
98          return StringUtil.simpleClassName(this) + "(frameType=" + frameType + ", stream=" + stream +
99                 ", flags=" + flags + ", content=" + contentToString() + ')';
100     }
101 
102     @Override
103     public DefaultHttp2UnknownFrame touch() {
104         super.touch();
105         return this;
106     }
107 
108     @Override
109     public DefaultHttp2UnknownFrame touch(Object hint) {
110         super.touch(hint);
111         return this;
112     }
113 
114     @Override
115     public boolean equals(Object o) {
116         if (!(o instanceof DefaultHttp2UnknownFrame)) {
117             return false;
118         }
119         DefaultHttp2UnknownFrame other = (DefaultHttp2UnknownFrame) o;
120         Http2FrameStream otherStream = other.stream();
121         return (stream == otherStream || otherStream != null && otherStream.equals(stream))
122                && flags.equals(other.flags())
123                && frameType == other.frameType()
124                && super.equals(other);
125     }
126 
127     @Override
128     public int hashCode() {
129         int hash = super.hashCode();
130         hash = hash * 31 + frameType;
131         hash = hash * 31 + flags.hashCode();
132         if (stream != null) {
133             hash = hash * 31 + stream.hashCode();
134         }
135 
136         return hash;
137     }
138 }