View Javadoc
1   /*
2    * Copyright 2012 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.channel.socket;
17  
18  import io.netty.buffer.ByteBuf;
19  import io.netty.buffer.ByteBufHolder;
20  import io.netty.channel.DefaultAddressedEnvelope;
21  
22  import java.net.InetSocketAddress;
23  
24  /**
25   * The message container that is used for {@link DatagramChannel} to communicate with the remote peer.
26   */
27  public class DatagramPacket
28          extends DefaultAddressedEnvelope<ByteBuf, InetSocketAddress> implements ByteBufHolder {
29  
30      /**
31       * Create a new instance with the specified packet {@code data} and {@code recipient} address.
32       */
33      public DatagramPacket(ByteBuf data, InetSocketAddress recipient) {
34          super(data, recipient);
35      }
36  
37      /**
38       * Create a new instance with the specified packet {@code data}, {@code recipient} address, and {@code sender}
39       * address.
40       */
41      public DatagramPacket(ByteBuf data, InetSocketAddress recipient, InetSocketAddress sender) {
42          super(data, recipient, sender);
43      }
44  
45      @Override
46      public DatagramPacket copy() {
47          return replace(content().copy());
48      }
49  
50      @Override
51      public DatagramPacket duplicate() {
52          return replace(content().duplicate());
53      }
54  
55      @Override
56      public DatagramPacket retainedDuplicate() {
57          return replace(content().retainedDuplicate());
58      }
59  
60      @Override
61      public DatagramPacket replace(ByteBuf content) {
62          return new DatagramPacket(content, recipient(), sender());
63      }
64  
65      @Override
66      public DatagramPacket retain() {
67          super.retain();
68          return this;
69      }
70  
71      @Override
72      public DatagramPacket retain(int increment) {
73          super.retain(increment);
74          return this;
75      }
76  
77      @Override
78      public DatagramPacket touch() {
79          super.touch();
80          return this;
81      }
82  
83      @Override
84      public DatagramPacket touch(Object hint) {
85          super.touch(hint);
86          return this;
87      }
88  }