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