Class AFGenericSocketAddress
java.lang.Object
java.net.SocketAddress
java.net.InetSocketAddress
org.newsclub.net.unix.AFSocketAddress
org.newsclub.net.unix.AFGenericSocketAddress
- All Implemented Interfaces:
Serializable
An
AFSocketAddress for unknown socket types.- Author:
- Christian Kohlschütter
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class AFSocketAddress
AFSocketAddress.AFSocketAddressConstructor<T>Modifier and TypeClassDescriptionprotected static interfaceA reference to the constructor of an AFSocketAddress subclass. -
Method Summary
Modifier and TypeMethodDescriptionReturns the correspondingAFAddressFamily.getFile()Returns theFilecorresponding with this address, if possible.booleanChecks if the address can be resolved to aFile.static booleanChecks if anInetAddresscan be unwrapped to anAFGenericSocketAddress.static booleanChecks if aSocketAddresscan be unwrapped to anAFGenericSocketAddress.static AFGenericSocketAddressReturns anAFGenericSocketAddressfor the given URI, if possible.static AFGenericSocketAddressReturns anAFGenericSocketAddressfor the given URI, if possible.byte[]toBytes()Returns the native representation of this generic address, which is most likely not portable.toString()static AFGenericSocketAddressReturns anAFGenericSocketAddressgiven a specialInetAddresshostname that encodes the byte sequence of an unknown-type socket address, like those returned byAFSocketAddress.wrapAddress().static AFGenericSocketAddressunwrap(InetAddress address, int port) Returns anAFGenericSocketAddressgiven a specialInetAddressthat encodes the byte sequence of an unknown-type socket address, like those returned byAFSocketAddress.wrapAddress().static AFGenericSocketAddressunwrap(SocketAddress address) Returns anAFGenericSocketAddressgiven a genericSocketAddress.Methods inherited from class AFSocketAddress
canMap, canMap, covers, getAddressFamily, getBytes, getInetAddress, getInetAddress, getInetAddress, getSocketAddress, isSupportedAddress, isUseDeserializationForInit, mapOrFail, mapOrFail, newBoundServerSocket, newConnectedSocket, newDeserializedAFSocketAddress, newForceBoundServerSocket, parseUnsignedInt, resolveAddress, toSocatAddressString, toURI, unwrap, unwrap, wrapAddress, writeNativeAddressToModifier and TypeMethodDescriptionstatic booleancanMap(SocketAddress addr) Checks if the givenSocketAddresscan be mapped to anAFSocketAddress.static booleancanMap(SocketAddress addr, Class<? extends AFSocketAddress> targetAddressClass) Checks if the givenSocketAddresscan be mapped to a specificAFSocketAddresssubclass.booleancovers(AFSocketAddress other) Checks if the given address could cover another address.final AFAddressFamily<?> Returns the correspondingAFAddressFamily.protected final byte[]getBytes()Returns the (non-native) byte-level representation of this address.protected final InetAddressWraps this address as anInetAddress.protected static final InetAddressgetInetAddress(FileDescriptor fdesc, boolean peerName, AFAddressFamily<?> af) Wraps the socket name/peer name of a file descriptor as anInetAddress.protected final InetAddressgetInetAddress(AFAddressFamily<?> af) Wraps an address as anInetAddress.protected static final <A extends AFSocketAddress>
@Nullable AgetSocketAddress(FileDescriptor fdesc, boolean requestPeerName, int port, AFAddressFamily<A> af) Gets the socket name/peer name of a file descriptor as anAFSocketAddress.protected static final booleanisSupportedAddress(InetAddress addr, AFAddressFamily<?> af) Checks if the given address is supported by this address family.protected static booleanChecks ifAFSocketAddressinstantiation should be performed via deserialization.static AFSocketAddressmapOrFail(SocketAddress addr) Maps the given address to anAFSocketAddress.static <A extends AFSocketAddress>
AmapOrFail(SocketAddress addr, Class<A> targetAddressClass) Maps the given address to a specificAFSocketAddresstype.Creates a new server socket bound to this address.AFSocket<?> Creates a new socket connected to this address.protected static <A extends AFSocketAddress>
AnewDeserializedAFSocketAddress(int port, byte[] socketAddress, ObjectPool.Lease<ByteBuffer> nativeAddress, AFAddressFamily<A> af, AFSocketAddress.AFSocketAddressConstructor<A> constructor) Returns a newAFSocketAddressinstance via deserialization.Creates a new server socket force-bound to this address (i.e., any additional call toServerSocket.bind(SocketAddress)will ignore the passed address and use this one instead.protected static intparseUnsignedInt(String s, int radix) Parses the string argument as an unsigned integer in the radix specified by the second argument.protected static final <A extends AFSocketAddress>
AresolveAddress(byte[] socketAddress, int port, AFAddressFamily<A> af) Resolves a junixsocket-specific byte-array representation of anAFSocketAddressto an actualAFSocketAddressinstance, possibly reusing a cached instance.@Nullable StringtoSocatAddressString(AFSocketType socketType, AFSocketProtocol socketProtocol) Returns a address string that can be used withsocat'sSOCKET-CONNECT,SOCKET-LISTEN,SOCKET-DATAGRAM, etc., address types, ornullif the address type is not natively supported by this platform.Tries to create a URI based on thisAFSocketAddress.protected static final <A extends AFSocketAddress>
@NonNull Aunwrap(String hostname, int port, AFAddressFamily<A> af) Returns anAFSocketAddressgiven a specialInetAddresshostname that encodes the byte sequence of an AF_UNIX etc. socket address, like those returned byAFSocketAddress.wrapAddress().protected static final <A extends AFSocketAddress>
@NonNull Aunwrap(InetAddress address, int port, AFAddressFamily<A> af) Returns anAFSocketAddressgiven a specialInetAddressthat encodes the byte sequence of an AF_UNIX etc. socket address, like those returned byAFSocketAddress.wrapAddress().final InetAddressReturns a "special"InetAddressthat contains information about thisAFSocketAddress.final voidWrites the native (system-level) representation of this address to the given buffer.Methods inherited from class InetSocketAddress
createUnresolved, equals, getAddress, getHostName, getHostString, getPort, hashCode, isUnresolved
-
Method Details
-
unwrap
Returns anAFGenericSocketAddressgiven a specialInetAddressthat encodes the byte sequence of an unknown-type socket address, like those returned byAFSocketAddress.wrapAddress().- Parameters:
address- The "special"InetAddress.port- The port (use 0 for "none").- Returns:
- The
AFGenericSocketAddressinstance. - Throws:
SocketException- if the operation fails, for example when an unsupported address is specified.
-
unwrap
Returns anAFGenericSocketAddressgiven a specialInetAddresshostname that encodes the byte sequence of an unknown-type socket address, like those returned byAFSocketAddress.wrapAddress().- Parameters:
hostname- The "special" hostname, as provided byInetAddress.getHostName().port- The port (use 0 for "none").- Returns:
- The
AFGenericSocketAddressinstance. - Throws:
SocketException- if the operation fails, for example when an unsupported address is specified.
-
unwrap
Returns anAFGenericSocketAddressgiven a genericSocketAddress.- Parameters:
address- The address to unwrap.- Returns:
- The
AFGenericSocketAddressinstance. - Throws:
SocketException- if the operation fails, for example when an unsupported address is specified.
-
toString
- Overrides:
toStringin classInetSocketAddress
-
toBytes
public byte[] toBytes()Returns the native representation of this generic address, which is most likely not portable.The address contains the sa_family identifier as the first byte, and, on some platforms only, the address length, as the second byte.
- Returns:
- A new byte array containing the system-specific representation of that address.
-
hasFilename
public boolean hasFilename()Description copied from class:AFSocketAddressChecks if the address can be resolved to aFile.- Specified by:
hasFilenamein classAFSocketAddress- Returns:
trueif the address has a filename.
-
getFile
Description copied from class:AFSocketAddressReturns theFilecorresponding with this address, if possible. AFileNotFoundExceptionis thrown if there is no filename associated with the address, which applies to addresses in the abstract namespace, for example.- Specified by:
getFilein classAFSocketAddress- Returns:
- The filename.
- Throws:
FileNotFoundException- if the address is not associated with a filename.
-
isSupportedAddress
Checks if anInetAddresscan be unwrapped to anAFGenericSocketAddress.- Parameters:
addr- The instance to check.- Returns:
trueif so.- See Also:
-
isSupportedAddress
Checks if aSocketAddresscan be unwrapped to anAFGenericSocketAddress.- Parameters:
addr- The instance to check.- Returns:
trueif so.- See Also:
-
addressFamily
Returns the correspondingAFAddressFamily.- Returns:
- The address family instance.
-
of
Returns anAFGenericSocketAddressfor the given URI, if possible.- Parameters:
uri- The URI.- Returns:
- The address.
- Throws:
SocketException- if the operation fails.
-
of
Returns anAFGenericSocketAddressfor the given URI, if possible.- Parameters:
uri- The URI.overridePort- The port to forcibly use, or-1for "don't override".- Returns:
- The address.
- Throws:
SocketException- if the operation fails.
-