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    *   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.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 final 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 new DatagramPacket(content().copy(), recipient(), sender());
48      }
49  
50      @Override
51      public DatagramPacket duplicate() {
52          return new DatagramPacket(content().duplicate(), recipient(), sender());
53      }
54  
55      @Override
56      public DatagramPacket retain() {
57          super.retain();
58          return this;
59      }
60  
61      @Override
62      public DatagramPacket retain(int increment) {
63          super.retain(increment);
64          return this;
65      }
66  }