Top Description Inners Fields Constructors Methods
org.newsclub.net.unix

public abstract Class AFSocketAddress

extends InetSocketAddress
Class Inheritance
Known Direct Subclasses
org.newsclub.net.unix.AFSYSTEMSocketAddress, org.newsclub.net.unix.AFTIPCSocketAddress, org.newsclub.net.unix.AFUNIXSocketAddress, org.newsclub.net.unix.AFVSOCKSocketAddress, org.newsclub.net.unix.SentinelSocketAddress, org.newsclub.net.unix.AFGenericSocketAddress
Annotations
@Immutable
@SuppressWarnings:PMD.CouplingBetweenObjects, PMD.CyclomaticComplexity
Imports
java.io.ByteArrayInputStream, .File, .FileDescriptor, .FileNotFoundException, .IOException, .ObjectInputStream, .ObjectOutputStream, java.net.DatagramSocket, .InetAddress, .InetSocketAddress, .ServerSocket, .SocketAddress, .SocketException, .URI, java.nio.ByteBuffer, java.nio.charset.StandardCharsets, java.util.HashMap, .Locale, .Map, .Objects, org.eclipse.jdt.annotation.NonNull, .Nullable, org.newsclub.net.unix.pool.ObjectPool, .ObjectPool.Lease, com.google.errorprone.annotations.Immutable, com.kohlschutter.annotations.compiletime.SuppressFBWarnings

Some SocketAddress that is supported by junixsocket, such as AFUNIXSocketAddress.
Author
Christian Kohlschütter

Nested and Inner Type Summary

Modifier and TypeClass and Description
protected static interface
AFSocketAddress.AFSocketAddressConstructor<
The actual subclass.
T extends AFSocketAddress
>

A reference to the constructor of an AFSocketAddress subclass.

Field Summary

Modifier and TypeField and Description
private static final Map<AFAddressFamily<?>, Map<Integer, Map<ByteBuffer, AFSocketAddress>>>
private transient AFAddressFamily<?>
addressFamily

The address family.

private byte[]
bytes

Some byte-level representation of this address, which can only be converted to a native representation in combination with the domain ID.

private InetAddress
inetAddress

An InetAddress-wrapped representation of this address.

pack-priv static final AFSocketAddress
INTERNAL_DUMMY_BIND

Just a marker for "don't actually bind" (checked with "==").

pack-priv static final AFSocketAddress
pack-priv static final AFSocketAddress
private transient ByteBuffer
nativeAddress

The system-native representation of this address, or null.

private static final long
private static final int
private static final int
private static final int
pack-priv static final ObjectPool<ByteBuffer>
private static final boolean

Constructor Summary

AccessConstructor and Description
protected
AFSocketAddress(int
The port.
port
,
final byte[]
The socket address in junixsocket-specific byte-array representation.
socketAddress
,
ObjectPool.Lease<ByteBuffer>
The socket address in system-native representation.
nativeAddress
,
AFAddressFamily<?>
The address family.
af
)

Creates a new socket address.

pack-priv
AFSocketAddress(Class<SentinelSocketAddress> clazz, int
A sentinel port number.
port
)

Only for SentinelSocketAddress.

Method Summary

Modifier and TypeMethod and Description
public static boolean

Returns:

true if mappable.
canMap
(SocketAddress
The address.
addr
)

Checks if the given SocketAddress can be mapped to an AFSocketAddress.

public static boolean

Returns:

true if mappable.
canMap
(SocketAddress
The address.
addr
,
Class<? extends AFSocketAddress>
The target address class to map to.
targetAddressClass
)

Checks if the given SocketAddress can be mapped to a specific AFSocketAddress subclass.

public boolean

Returns:

true if the other address could be covered.
covers
(AFSocketAddress
The other address that could be covered by this address.
other
)

Checks if the given address could cover another address.

private static byte[]

Returns:

The byte representation.
craftSerializedObject
(Class<? extends AFSocketAddress>
The actual subclass.
className
,
String
The hostname to use (must not be empty or null).
hostname
,
int
The port to use.
port
)

Creates a byte-representation of a serialized AFSocketAddress instance, overriding hostname and port, which allows bypassing DNS resolution.

public final AFAddressFamily<?>

Returns:

The address family instance.
getAddressFamily
()

Returns the corresponding AFAddressFamily.

protected final byte[]

Returns:

The byte array.
getBytes
()

Returns the (non-native) byte-level representation of this address.

public abstract File

Returns:

The filename.
getFile
()

Returns the File corresponding with this address, if possible.

protected static final InetAddress

Returns:

The InetAddress.
getInetAddress
(FileDescriptor
The file descriptor.
fdesc
,
boolean
If true, the remote peer name (instead of the local name) is retrieved.
peerName
,
AFAddressFamily<?>
The address family.
af
)

Wraps the socket name/peer name of a file descriptor as an InetAddress.

protected final synchronized InetAddress

Returns:

The InetAddress.
getInetAddress
(AFAddressFamily<?>
The address family.
af
)

Wraps an address as an InetAddress.

protected final InetAddress

Returns:

The InetAddress.
getInetAddress
()

Wraps this address as an InetAddress.

pack-priv final ObjectPool.Lease<ByteBuffer>

Returns:

The direct ByteBuffer.
getNativeAddressDirectBuffer
()

Returns a thread-local direct ByteBuffer containing the native socket address representation of this AFSocketAddress.

pack-priv static final ObjectPool.Lease<ByteBuffer>
protected static final <
The corresponding address type.
A extends AFSocketAddress
>
@Nullable A

Returns:

The InetAddress.
getSocketAddress
(FileDescriptor
The file descriptor.
fdesc
,
boolean
If true, the remote peer name (instead of the local name) is retrieved.
requestPeerName
,
int
The port.
port
,
AFAddressFamily<A>
The address family.
af
)

Gets the socket name/peer name of a file descriptor as an AFSocketAddress.

public abstract boolean

Returns:

true if the address has a filename.
hasFilename
()

Checks if the address can be resolved to a File.

private static void
initAFSocketAddress(AFSocketAddress addr, int port, final byte[] socketAddress, ObjectPool.Lease<ByteBuffer> nativeAddress, AFAddressFamily<?> af)

protected static final boolean

Returns:

true if supported.
isSupportedAddress
(InetAddress
The address.
addr
,
AFAddressFamily<?>
The address family.
af
)

Checks if the given address is supported by this address family.

protected static boolean

Returns:

true if so.
isUseDeserializationForInit
()

Checks if AFSocketAddress instantiation should be performed via deserialization.

public static AFSocketAddress

Returns:

The AFSocketAddress.
mapOrFail
(SocketAddress
The address.
addr
)

Maps the given address to an AFSocketAddress.

public static <
The target address type.
A extends AFSocketAddress
>
A

Returns:

The AFSocketAddress.
mapOrFail
(SocketAddress
The address.
addr
,
Class<A>
The target address class.
targetAddressClass
)

Maps the given address to a specific AFSocketAddress type.

public AFServerSocket<?>

Returns:

The server socket instance.
newBoundServerSocket
()

Creates a new server socket bound to this address.

public AFSocket<?>

Returns:

The socket instance.
newConnectedSocket
()

Creates a new socket connected to this address.

protected static <
The subclass (must be a direct subclass of AFSocketAddress).
A extends AFSocketAddress
>
A

Returns:

The new instance.
newDeserializedAFSocketAddress
(int
The port to use.
port
,
final byte[]
The junixsocket representation of the socket address.
socketAddress
,
ObjectPool.Lease<ByteBuffer>
The system-native representation of the socket address, or null.
nativeAddress
,
AFAddressFamily<A>
The address family, corresponding to the subclass
af
,
AFSocketAddress.AFSocketAddressConstructor<A>
The constructor to use as fallback
constructor
)

Returns a new AFSocketAddress instance via deserialization.

public AFServerSocket<?>

Returns:

The server socket instance.
newForceBoundServerSocket
()

Creates a new server socket force-bound to this address (i.e., any additional call to ServerSocket#bind(SocketAddress) will ignore the passed address and use this one instead.

pack-priv static final @NonNull ByteBuffer
pack-priv static final @NonNull ByteBuffer
public static AFSocketAddress

Returns:

The address.
of
(URI
The URI.
u
)

Tries to parse the given URI and return a corresponding AFSocketAddress for it.

public static AFSocketAddress

Returns:

The address.
of
(URI
The URI.
u
,
int
The port to forcibly use, or -1 for "don't override".
overridePort
)

Tries to parse the given URI and return a corresponding AFSocketAddress for it.

pack-priv static final <A extends AFSocketAddress> A
ofInternal(ByteBuffer socketAddressBuffer, AFAddressFamily<A> af)

protected static int

Returns:

The integer.
parseUnsignedInt
(String
The string.
s
,
int
The radix.
radix
)

Parses the string argument as an unsigned integer in the radix specified by the second argument.

pack-priv static final AFSocketAddress
preprocessSocketAddress(Class<? extends AFSocketAddress> supportedAddressClass, SocketAddress endpoint, AFSocketAddressFromHostname<?> afh)

private static void
private static void
private void
readObject(ObjectInputStream in)

Hides java.net.InetSocketAddress.readObject.

Custom serialization: Reference AFAddressFamily instance by identifier string.

protected static final <
The concrete AFSocketAddress that is supported by this type.
A extends AFSocketAddress
>
A

Returns:

The instance.
resolveAddress
(final byte[]
The socket address in junixsocket-specific byte-array representation.
socketAddress
,
int
The port.
port
,
AFAddressFamily<A>
The address family.
af
)

Resolves a junixsocket-specific byte-array representation of an AFSocketAddress to an actual AFSocketAddress instance, possibly reusing a cached instance.

public @Nullable String

Returns:

The string (such as 1:0:x2f746d702f796f).
toSocatAddressString
(AFSocketType
The socket type, or null to omit from string.
socketType
,
AFSocketProtocol
The socket protocol, or null to omit from string.
socketProtocol
)

Returns a address string that can be used with socat's SOCKET-CONNECT, SOCKET-LISTEN, SOCKET-DATAGRAM, etc., address types, or null if the address type is not natively supported by this platform.

private static long
pack-priv static String

Returns:

The string.
toUnsignedString
(int
The value.
i
)

Returns a string representation of the argument as an unsigned decimal value.

pack-priv static String

Returns:

The string.
toUnsignedString
(int
The value.
i
,
int
The radix.
radix
)

Returns a string representation of the first argument as an unsigned integer value in the radix specified by the second argument; added to allow execution on Java 1.7.

public URI

Returns:

The URI.
toURI
(String
The target scheme.
scheme
,
URI
An optional template to reuse certain parameters (e.g., the "path" component for an http request), or null.
template
)

Tries to create a URI based on this AFSocketAddress.

protected static final <
The corresponding address type.
A extends AFSocketAddress
>
@NonNull A

Returns:

The AFSocketAddress instance.
unwrap
(InetAddress
The "special" InetAddress.
address
,
int
The port (use 0 for "none").
port
,
AFAddressFamily<A>
The address family.
af
)

Returns an AFSocketAddress given a special InetAddress that encodes the byte sequence of an AF_UNIX etc. socket address, like those returned by wrapAddress().

protected static final <
The corresponding address type.
A extends AFSocketAddress
>
@NonNull A

Returns:

The AFSocketAddress instance.
unwrap
(String
The "special" hostname, as provided by InetAddress#getHostName().
hostname
,
int
The port (use 0 for "none").
port
,
AFAddressFamily<A>
The address family.
af
)

Returns an AFSocketAddress given a special InetAddress hostname that encodes the byte sequence of an AF_UNIX etc. socket address, like those returned by wrapAddress().

pack-priv static final int
public final InetAddress

Returns:

The "special" InetAddress.
wrapAddress
()

Returns a "special" InetAddress that contains information about this AFSocketAddress.

public final void
writeNativeAddressTo(ByteBuffer
The target buffer.
buf
)

Writes the native (system-level) representation of this address to the given buffer.

private void
writeObject(ObjectOutputStream out)

Hides java.net.InetSocketAddress.writeObject.

Custom serialization: Reference AFAddressFamily instance by identifier string.

Inherited from java.net.InetSocketAddress:
createUnresolvedequalsgetAddressgetHostNamegetHostStringgetPorthashCodeisUnresolvedtoString