View Javadoc
1   /*
2    * junixsocket
3    *
4    * Copyright 2009-2024 Christian Kohlschütter
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  package org.newsclub.net.unix;
19  
20  import java.io.IOException;
21  import java.net.DatagramSocket;
22  import java.net.DatagramSocketImpl;
23  import java.net.SocketOption;
24  
25  import org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement;
26  
27  @IgnoreJRERequirement // see src/main/java8
28  abstract class DatagramSocketShim extends DatagramSocket {
29  
30    protected DatagramSocketShim(DatagramSocketImpl impl) {
31      super(impl);
32    }
33  
34    @Override
35    public <T> T getOption(SocketOption<T> name) throws IOException {
36      if (name instanceof AFSocketOption<?>) {
37        return getOption((AFSocketOption<T>) name);
38      } else {
39        return super.getOption(name);
40      }
41    }
42  
43    @Override
44    public <T> DatagramSocket setOption(SocketOption<T> name, T value) throws IOException {
45      if (name instanceof AFSocketOption<?>) {
46        return setOption((AFSocketOption<T>) name, value);
47      } else {
48        return super.setOption(name, value);
49      }
50    }
51  
52    /**
53     * Returns the value of a junixsocket socket option.
54     *
55     * @param <T> The type of the socket option value.
56     * @param name The socket option.
57     * @return The value of the socket option.
58     * @throws IOException on error.
59     */
60    public abstract <T> T getOption(AFSocketOption<T> name) throws IOException;
61  
62    /**
63     * Sets the value of a socket option.
64     *
65     * @param <T> The type of the socket option value.
66     * @param name The socket option.
67     * @param value The value of the socket option.
68     * @return this DatagramSocket.
69     * @throws IOException on error.
70     */
71    @SuppressWarnings("PMD.LinguisticNaming")
72    public abstract <T> DatagramSocket setOption(AFSocketOption<T> name, T value) throws IOException;
73  }