|
21 | 21 | import java.io.FileDescriptor; |
22 | 22 | import java.io.FileNotFoundException; |
23 | 23 | import java.io.IOException; |
| 24 | +import java.io.ObjectInputStream; |
| 25 | +import java.io.ObjectOutputStream; |
24 | 26 | import java.net.DatagramSocket; |
25 | 27 | import java.net.InetAddress; |
26 | 28 | import java.net.InetSocketAddress; |
@@ -87,12 +89,13 @@ protected ByteBuffer initialValue() { |
87 | 89 | /** |
88 | 90 | * The system-native representation of this address, or {@code null}. |
89 | 91 | */ |
90 | | - private final ByteBuffer nativeAddress; |
| 92 | + @SuppressWarnings("PMD.ImmutableField") |
| 93 | + private transient ByteBuffer nativeAddress; |
91 | 94 |
|
92 | 95 | /** |
93 | 96 | * The address family. |
94 | 97 | */ |
95 | | - private final AFAddressFamily<?> addressFamily; |
| 98 | + private transient AFAddressFamily<?> addressFamily; |
96 | 99 |
|
97 | 100 | /** |
98 | 101 | * Creates a new socket address. |
@@ -643,12 +646,13 @@ public URI toURI(String scheme, URI template) throws IOException { |
643 | 646 | * address type is not natively supported by this platform. |
644 | 647 | * |
645 | 648 | * This call is mostly suited for debugging purposes. The resulting string is specific to the |
646 | | - * platform the code is executed on, and thus may be different among platforms (or {@code null}). |
| 649 | + * platform the code is executed on, and thus may be different among platforms. |
647 | 650 | * |
648 | 651 | * @param socketType The socket type, or {@code null} to omit from string. |
649 | 652 | * @param socketProtocol The socket protocol, or {@code null} to omit from string. |
650 | 653 | * @return The string (such as 1:0:x2f746d702f796f). |
651 | | - * @throws IOException on error. |
| 654 | + * @throws IOException on error (a {@link SocketException} is thrown if the native address cannot |
| 655 | + * be accessed). |
652 | 656 | */ |
653 | 657 | public @Nullable @SuppressWarnings("PMD.NPathComplexity") String toSocatAddressString( |
654 | 658 | AFSocketType socketType, AFSocketProtocol socketProtocol) throws IOException { |
@@ -703,4 +707,28 @@ public URI toURI(String scheme, URI template) throws IOException { |
703 | 707 | public boolean covers(AFSocketAddress other) { |
704 | 708 | return this.equals(other); |
705 | 709 | } |
| 710 | + |
| 711 | + /** |
| 712 | + * Custom serialization: Reference {@link AFAddressFamily} instance by identifier string. |
| 713 | + * |
| 714 | + * @param in The {@link ObjectInputStream}. |
| 715 | + * @throws ClassNotFoundException on error. |
| 716 | + * @throws IOException on error. |
| 717 | + */ |
| 718 | + private void readObject(ObjectInputStream in) throws ClassNotFoundException, IOException { |
| 719 | + in.defaultReadObject(); |
| 720 | + this.addressFamily = Objects.requireNonNull(AFAddressFamily.getAddressFamily(in.readUTF()), |
| 721 | + "address family"); |
| 722 | + } |
| 723 | + |
| 724 | + /** |
| 725 | + * Custom serialization: Reference {@link AFAddressFamily} instance by identifier string. |
| 726 | + * |
| 727 | + * @param out The {@link ObjectOutputStream}. |
| 728 | + * @throws IOException on error. |
| 729 | + */ |
| 730 | + private void writeObject(ObjectOutputStream out) throws IOException { |
| 731 | + out.defaultWriteObject(); |
| 732 | + out.writeUTF(addressFamily.getJuxString()); |
| 733 | + } |
706 | 734 | } |
0 commit comments