java.lang.Object
java.net.SocketAddress
java.net.InetSocketAddress
org.newsclub.net.unix.AFSocketAddress
org.newsclub.net.unix.AFUNIXSocketAddress
- All Implemented Interfaces:
Serializable
Describes an
InetSocketAddress that actually uses AF_UNIX sockets instead of AF_INET.
The ability to specify a port number is not specified by AF_UNIX sockets, but we need it
sometimes, for example for RMI-over-AF_UNIX.- Author:
- Christian Kohlschütter
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class org.newsclub.net.unix.AFSocketAddress
AFSocketAddress.AFSocketAddressConstructor<T extends AFSocketAddress> -
Constructor Summary
ConstructorsConstructorDescriptionAFUNIXSocketAddress(File socketFile) Deprecated.AFUNIXSocketAddress(File socketFile, int port) Deprecated.Useof(File, int)instead. -
Method Summary
Modifier and TypeMethodDescriptionstatic CharsetReturns theCharsetused to encode/decodeAFUNIXSocketAddresses.static AFAddressFamily<AFUNIXSocketAddress> Returns the correspondingAFAddressFamily.getFile()Returns theFilecorresponding with this address, if possible.getPath()Returns the path to the UNIX domain socket, as a human-readable string using the default encoding.byte[]Returns the path to the UNIX domain socket, as bytes.booleanChecks if the address can be resolved to aFile.static AFUNIXSocketAddressinAbstractNamespace(String name) Convenience method to create anAFUNIXSocketAddressin the abstract namespace.static AFUNIXSocketAddressinAbstractNamespace(String name, int port) Convenience method to create anAFUNIXSocketAddressin the abstract namespace.booleanChecks if the address is in the abstract namespace (or, for Haiku OS, in the internal namespace).static booleanChecks if anInetAddresscan be unwrapped to anAFUNIXSocketAddress.static booleanChecks if aSocketAddresscan be unwrapped to anAFUNIXSocketAddress.Creates a new server socket bound to this address.Creates a new socket connected to this address.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.static AFUNIXSocketAddressof(byte[] socketAddress) Returns anAFUNIXSocketAddressthat points to the AF_UNIX socket specified by the given byte sequence.static AFUNIXSocketAddressof(byte[] socketAddress, int port) Returns anAFUNIXSocketAddressthat points to the AF_UNIX socket specified by the given byte sequence, assigning the given port to it.static AFUNIXSocketAddressReturns anAFUNIXSocketAddressthat points to the AF_UNIX socket specified by the given file.static AFUNIXSocketAddressReturns anAFUNIXSocketAddressthat points to the AF_UNIX socket specified by the given file, assigning the given port to it.static AFUNIXSocketAddressof(SocketAddress address) Returns anAFUNIXSocketAddressbased on the givenSocketAddress.static AFUNIXSocketAddressReturns anAFUNIXSocketAddressfor the given URI, if possible.static AFUNIXSocketAddressReturns anAFUNIXSocketAddressfor the given URI, if possible.static AFUNIXSocketAddressReturns anAFUNIXSocketAddressthat points to the AF_UNIX socket specified by the given path.static AFUNIXSocketAddressReturns anAFUNIXSocketAddressthat points to the AF_UNIX socket specified by the given path, assigning the given port to it.static AFUNIXSocketAddressReturns anAFUNIXSocketAddressthat points to a temporary, non-existent but accessible path in the file system.static AFUNIXSocketAddressofNewTempPath(int port) Returns anAFUNIXSocketAddressthat points to a temporary, non-existent but accessible path in the file system, assigning the given port to it.toString()Tries to create a URI based on thisAFSocketAddress.static AFUNIXSocketAddressReturns anAFUNIXSocketAddressgiven a specialInetAddresshostname that encodes the byte sequence of an AF_UNIX socket address, like those returned byAFSocketAddress.wrapAddress().static AFUNIXSocketAddressunwrap(InetAddress address, int port) Returns anAFUNIXSocketAddressgiven a specialInetAddressthat encodes the byte sequence of an AF_UNIX socket address, like those returned byAFSocketAddress.wrapAddress().static AFUNIXSocketAddressunwrap(SocketAddress address) Returns anAFUNIXSocketAddressgiven a genericSocketAddress.Methods inherited from class org.newsclub.net.unix.AFSocketAddress
canMap, canMap, covers, getAddressFamily, getBytes, getInetAddress, getInetAddress, getInetAddress, getSocketAddress, isSupportedAddress, isUseDeserializationForInit, mapOrFail, mapOrFail, newDeserializedAFSocketAddress, parseUnsignedInt, resolveAddress, toSocatAddressString, unwrap, unwrap, wrapAddress, writeNativeAddressToMethods inherited from class java.net.InetSocketAddress
createUnresolved, equals, getAddress, getHostName, getHostString, getPort, hashCode, isUnresolved
-
Constructor Details
-
AFUNIXSocketAddress
Deprecated.Useof(File)instead.Returns anAFUNIXSocketAddressthat points to the AF_UNIX socket specified by the given file and port. Legacy constructor, do not use!- Parameters:
socketFile- The socket to connect to.- Throws:
SocketException- if the operation fails.- See Also:
-
AFUNIXSocketAddress
Deprecated.Useof(File, int)instead.Returns anAFUNIXSocketAddressthat points to the AF_UNIX socket specified by the given file. Legacy constructor, do not use!- Parameters:
socketFile- The socket to connect to.port- The port associated with this socket, or0when no port should be assigned.- Throws:
SocketException- if the operation fails.- See Also:
-
-
Method Details
-
of
Returns anAFUNIXSocketAddressthat points to the AF_UNIX socket specified by the given file.- Parameters:
socketFile- The socket to connect to.- Returns:
- A corresponding
AFUNIXSocketAddressinstance. - Throws:
SocketException- if the operation fails.
-
of
Returns anAFUNIXSocketAddressthat points to the AF_UNIX socket specified by the given file, assigning the given port to it.- Parameters:
socketFile- The socket to connect to.port- The port associated with this socket, or0when no port should be assigned.- Returns:
- A corresponding
AFUNIXSocketAddressinstance. - Throws:
SocketException- if the operation fails.
-
of
Returns anAFUNIXSocketAddressthat points to the AF_UNIX socket specified by the given byte sequence. NOTE: By specifying a byte array that starts with a zero byte, you indicate that the abstract namespace is to be used. This feature is not available on all target platforms.- Parameters:
socketAddress- The socket address (as bytes).- Returns:
- A corresponding
AFUNIXSocketAddressinstance. - Throws:
SocketException- if the operation fails.- See Also:
-
of
Returns anAFUNIXSocketAddressthat points to the AF_UNIX socket specified by the given byte sequence, assigning the given port to it. NOTE: By specifying a byte array that starts with a zero byte, you indicate that the abstract namespace is to be used. This feature is not available on all target platforms.- Parameters:
socketAddress- The socket address (as bytes).port- The port associated with this socket, or0when no port should be assigned.- Returns:
- A corresponding
AFUNIXSocketAddressinstance. - Throws:
SocketException- if the operation fails.- See Also:
-
of
Returns anAFUNIXSocketAddressthat points to the AF_UNIX socket specified by the given path.- Parameters:
socketPath- The socket to connect to.- Returns:
- A corresponding
AFUNIXSocketAddressinstance. - Throws:
SocketException- if the operation fails.
-
of
Returns anAFUNIXSocketAddressthat points to the AF_UNIX socket specified by the given path, assigning the given port to it.- Parameters:
socketPath- The socket to connect to.port- The port associated with this socket, or0when no port should be assigned.- Returns:
- A corresponding
AFUNIXSocketAddressinstance. - Throws:
SocketException- if the operation fails.
-
of
Returns anAFUNIXSocketAddressfor the given URI, if possible.- Parameters:
u- The URI.- Returns:
- The address.
- Throws:
SocketException- if the operation fails.
-
of
Returns anAFUNIXSocketAddressfor the given URI, if possible.- Parameters:
u- The URI.overridePort- The port to forcibly use, or-1for "don't override".- Returns:
- The address.
- Throws:
SocketException- if the operation fails.
-
ofNewTempFile
Returns anAFUNIXSocketAddressthat points to a temporary, non-existent but accessible path in the file system.- Returns:
- A corresponding
AFUNIXSocketAddressinstance. - Throws:
IOException- if the operation fails.
-
ofNewTempPath
Returns anAFUNIXSocketAddressthat points to a temporary, non-existent but accessible path in the file system, assigning the given port to it.- Parameters:
port- The port associated with this socket, or0when no port should be assigned.- Returns:
- A corresponding
AFUNIXSocketAddressinstance. - Throws:
IOException- if the operation fails.
-
of
Returns anAFUNIXSocketAddressbased on the givenSocketAddress. This either simply casts an existingAFUNIXSocketAddress, or converts aUnixDomainSocketAddressto it.- Parameters:
address- The address to convert.- Returns:
- A corresponding
AFUNIXSocketAddressinstance. - Throws:
SocketException- if the operation fails.IOException
-
unwrap
Returns anAFUNIXSocketAddressgiven a specialInetAddressthat encodes the byte sequence of an AF_UNIX socket address, like those returned byAFSocketAddress.wrapAddress().- Parameters:
address- The "special"InetAddress.port- The port (use 0 for "none").- Returns:
- The
AFUNIXSocketAddressinstance. - Throws:
SocketException- if the operation fails, for example when an unsupported address is specified.
-
unwrap
Returns anAFUNIXSocketAddressgiven a genericSocketAddress.- Parameters:
address- The address to unwrap.- Returns:
- The
AFUNIXSocketAddressinstance. - Throws:
SocketException- if the operation fails, for example when an unsupported address is specified.
-
unwrap
Returns anAFUNIXSocketAddressgiven a specialInetAddresshostname that encodes the byte sequence of an AF_UNIX 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
AFUNIXSocketAddressinstance. - Throws:
SocketException- if the operation fails, for example when an unsupported address is specified.
-
inAbstractNamespace
Convenience method to create anAFUNIXSocketAddressin the abstract namespace. The returned socket address will use the byte representation of this identifier (using the system's default character encoding), prefixed with a null byte (to indicate the abstract namespace is used).- Parameters:
name- The identifier in the abstract namespace, without trailing zero or @.- Returns:
- The address.
- Throws:
SocketException- if the operation fails.
-
inAbstractNamespace
Convenience method to create anAFUNIXSocketAddressin the abstract namespace. The returned socket address will use the byte representation of this identifier (using the system's default character encoding), prefixed with a null byte (to indicate the abstract namespace is used).- Parameters:
name- The identifier in the abstract namespace, without trailing zero or @.port- The port associated with this socket, or0when no port should be assigned.- Returns:
- The address.
- Throws:
SocketException- if the operation fails.
-
toString
- Overrides:
toStringin classInetSocketAddress
-
getPath
Returns the path to the UNIX domain socket, as a human-readable string using the default encoding. For addresses in the abstract namespace, the US_ASCII encoding is used; zero-bytes are converted to '@', other non-printable bytes are converted to '.'- Returns:
- The path.
- See Also:
-
addressCharset
Returns theCharsetused to encode/decodeAFUNIXSocketAddresses. This is usually the system default charset, unless that isStandardCharsets.US_ASCII(7-bit), in which caseStandardCharsets.ISO_8859_1is used instead.- Returns:
- The charset.
-
getPathAsBytes
public byte[] getPathAsBytes()Returns the path to the UNIX domain socket, as bytes.- Returns:
- The path.
- See Also:
-
isInAbstractNamespace
public boolean isInAbstractNamespace()Checks if the address is in the abstract namespace (or, for Haiku OS, in the internal namespace).- Returns:
trueif the address is in the abstract namespace.
-
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 anAFUNIXSocketAddress.- Parameters:
addr- The instance to check.- Returns:
trueif so.- See Also:
-
isSupportedAddress
Checks if aSocketAddresscan be unwrapped to anAFUNIXSocketAddress.- Parameters:
addr- The instance to check.- Returns:
trueif so.- See Also:
-
addressFamily
Returns the correspondingAFAddressFamily.- Returns:
- The address family instance.
-
toURI
Description copied from class:AFSocketAddressTries to create a URI based on thisAFSocketAddress.- Overrides:
toURIin classAFSocketAddress- Parameters:
scheme- The target scheme.template- An optional template to reuse certain parameters (e.g., the "path" component for anhttprequest), ornull.- Returns:
- The URI.
- Throws:
IOException- on error.
-
newConnectedSocket
Description copied from class:AFSocketAddressCreates a new socket connected to this address.- Overrides:
newConnectedSocketin classAFSocketAddress- Returns:
- The socket instance.
- Throws:
IOException- on error.
-
newBoundServerSocket
Description copied from class:AFSocketAddressCreates a new server socket bound to this address.- Overrides:
newBoundServerSocketin classAFSocketAddress- Returns:
- The server socket instance.
- Throws:
IOException- on error.
-
newForceBoundServerSocket
Description copied from class:AFSocketAddressCreates 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.- Overrides:
newForceBoundServerSocketin classAFSocketAddress- Returns:
- The server socket instance.
- Throws:
IOException- on error.
-
of(File)instead.