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
ConstructorDescriptionAFUNIXSocketAddress
(File socketFile) Deprecated.AFUNIXSocketAddress
(File socketFile, int port) Deprecated.Useof(File, int)
instead. -
Method Summary
Modifier and TypeMethodDescriptionstatic Charset
Returns theCharset
used to encode/decodeAFUNIXSocketAddress
es.static AFAddressFamily
<AFUNIXSocketAddress> Returns the correspondingAFAddressFamily
.getFile()
Returns theFile
corresponding 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.boolean
Checks if the address can be resolved to aFile
.static AFUNIXSocketAddress
inAbstractNamespace
(String name) Convenience method to create anAFUNIXSocketAddress
in the abstract namespace.static AFUNIXSocketAddress
inAbstractNamespace
(String name, int port) Convenience method to create anAFUNIXSocketAddress
in the abstract namespace.boolean
Checks if the address is in the abstract namespace (or, for Haiku OS, in the internal namespace).static boolean
Checks if anInetAddress
can be unwrapped to anAFUNIXSocketAddress
.static boolean
Checks if aSocketAddress
can 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 AFUNIXSocketAddress
of
(byte[] socketAddress) Returns anAFUNIXSocketAddress
that points to the AF_UNIX socket specified by the given byte sequence.static AFUNIXSocketAddress
of
(byte[] socketAddress, int port) Returns anAFUNIXSocketAddress
that points to the AF_UNIX socket specified by the given byte sequence, assigning the given port to it.static AFUNIXSocketAddress
Returns anAFUNIXSocketAddress
that points to the AF_UNIX socket specified by the given file.static AFUNIXSocketAddress
Returns anAFUNIXSocketAddress
that points to the AF_UNIX socket specified by the given file, assigning the given port to it.static AFUNIXSocketAddress
of
(SocketAddress address) Returns anAFUNIXSocketAddress
based on the givenSocketAddress
.static AFUNIXSocketAddress
Returns anAFUNIXSocketAddress
for the given URI, if possible.static AFUNIXSocketAddress
Returns anAFUNIXSocketAddress
for the given URI, if possible.static AFUNIXSocketAddress
Returns anAFUNIXSocketAddress
that points to the AF_UNIX socket specified by the given path.static AFUNIXSocketAddress
Returns anAFUNIXSocketAddress
that points to the AF_UNIX socket specified by the given path, assigning the given port to it.static AFUNIXSocketAddress
Returns anAFUNIXSocketAddress
that points to a temporary, non-existent but accessible path in the file system.static AFUNIXSocketAddress
ofNewTempPath
(int port) Returns anAFUNIXSocketAddress
that 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 AFUNIXSocketAddress
Returns anAFUNIXSocketAddress
given a specialInetAddress
hostname that encodes the byte sequence of an AF_UNIX socket address, like those returned byAFSocketAddress.wrapAddress()
.static AFUNIXSocketAddress
unwrap
(InetAddress address, int port) Returns anAFUNIXSocketAddress
given a specialInetAddress
that encodes the byte sequence of an AF_UNIX socket address, like those returned byAFSocketAddress.wrapAddress()
.static AFUNIXSocketAddress
unwrap
(SocketAddress address) Returns anAFUNIXSocketAddress
given 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, writeNativeAddressTo
Methods inherited from class java.net.InetSocketAddress
createUnresolved, equals, getAddress, getHostName, getHostString, getPort, hashCode, isUnresolved
-
Constructor Details
-
AFUNIXSocketAddress
Deprecated.Useof(File)
instead.Returns anAFUNIXSocketAddress
that 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 anAFUNIXSocketAddress
that 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, or0
when no port should be assigned.- Throws:
SocketException
- if the operation fails.- See Also:
-
-
Method Details
-
of
Returns anAFUNIXSocketAddress
that points to the AF_UNIX socket specified by the given file.- Parameters:
socketFile
- The socket to connect to.- Returns:
- A corresponding
AFUNIXSocketAddress
instance. - Throws:
SocketException
- if the operation fails.
-
of
Returns anAFUNIXSocketAddress
that 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, or0
when no port should be assigned.- Returns:
- A corresponding
AFUNIXSocketAddress
instance. - Throws:
SocketException
- if the operation fails.
-
of
Returns anAFUNIXSocketAddress
that 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
AFUNIXSocketAddress
instance. - Throws:
SocketException
- if the operation fails.- See Also:
-
of
Returns anAFUNIXSocketAddress
that 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, or0
when no port should be assigned.- Returns:
- A corresponding
AFUNIXSocketAddress
instance. - Throws:
SocketException
- if the operation fails.- See Also:
-
of
Returns anAFUNIXSocketAddress
that points to the AF_UNIX socket specified by the given path.- Parameters:
socketPath
- The socket to connect to.- Returns:
- A corresponding
AFUNIXSocketAddress
instance. - Throws:
SocketException
- if the operation fails.
-
of
Returns anAFUNIXSocketAddress
that 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, or0
when no port should be assigned.- Returns:
- A corresponding
AFUNIXSocketAddress
instance. - Throws:
SocketException
- if the operation fails.
-
of
Returns anAFUNIXSocketAddress
for the given URI, if possible.- Parameters:
u
- The URI.- Returns:
- The address.
- Throws:
SocketException
- if the operation fails.
-
of
Returns anAFUNIXSocketAddress
for the given URI, if possible.- Parameters:
u
- The URI.overridePort
- The port to forcibly use, or-1
for "don't override".- Returns:
- The address.
- Throws:
SocketException
- if the operation fails.
-
ofNewTempFile
Returns anAFUNIXSocketAddress
that points to a temporary, non-existent but accessible path in the file system.- Returns:
- A corresponding
AFUNIXSocketAddress
instance. - Throws:
IOException
- if the operation fails.
-
ofNewTempPath
Returns anAFUNIXSocketAddress
that 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, or0
when no port should be assigned.- Returns:
- A corresponding
AFUNIXSocketAddress
instance. - Throws:
IOException
- if the operation fails.
-
of
Returns anAFUNIXSocketAddress
based on the givenSocketAddress
. This either simply casts an existingAFUNIXSocketAddress
, or converts aUnixDomainSocketAddress
to it.- Parameters:
address
- The address to convert.- Returns:
- A corresponding
AFUNIXSocketAddress
instance. - Throws:
SocketException
- if the operation fails.IOException
-
unwrap
Returns anAFUNIXSocketAddress
given a specialInetAddress
that 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
AFUNIXSocketAddress
instance. - Throws:
SocketException
- if the operation fails, for example when an unsupported address is specified.
-
unwrap
Returns anAFUNIXSocketAddress
given a genericSocketAddress
.- Parameters:
address
- The address to unwrap.- Returns:
- The
AFUNIXSocketAddress
instance. - Throws:
SocketException
- if the operation fails, for example when an unsupported address is specified.
-
unwrap
Returns anAFUNIXSocketAddress
given a specialInetAddress
hostname 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
AFUNIXSocketAddress
instance. - Throws:
SocketException
- if the operation fails, for example when an unsupported address is specified.
-
inAbstractNamespace
Convenience method to create anAFUNIXSocketAddress
in 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 anAFUNIXSocketAddress
in 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, or0
when no port should be assigned.- Returns:
- The address.
- Throws:
SocketException
- if the operation fails.
-
toString
- Overrides:
toString
in 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 theCharset
used to encode/decodeAFUNIXSocketAddress
es. This is usually the system default charset, unless that isStandardCharsets.US_ASCII
(7-bit), in which caseStandardCharsets.ISO_8859_1
is 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:
true
if the address is in the abstract namespace.
-
hasFilename
public boolean hasFilename()Description copied from class:AFSocketAddress
Checks if the address can be resolved to aFile
.- Specified by:
hasFilename
in classAFSocketAddress
- Returns:
true
if the address has a filename.
-
getFile
Description copied from class:AFSocketAddress
Returns theFile
corresponding with this address, if possible. AFileNotFoundException
is thrown if there is no filename associated with the address, which applies to addresses in the abstract namespace, for example.- Specified by:
getFile
in classAFSocketAddress
- Returns:
- The filename.
- Throws:
FileNotFoundException
- if the address is not associated with a filename.
-
isSupportedAddress
Checks if anInetAddress
can be unwrapped to anAFUNIXSocketAddress
.- Parameters:
addr
- The instance to check.- Returns:
true
if so.- See Also:
-
isSupportedAddress
Checks if aSocketAddress
can be unwrapped to anAFUNIXSocketAddress
.- Parameters:
addr
- The instance to check.- Returns:
true
if so.- See Also:
-
addressFamily
Returns the correspondingAFAddressFamily
.- Returns:
- The address family instance.
-
toURI
Description copied from class:AFSocketAddress
Tries to create a URI based on thisAFSocketAddress
.- Overrides:
toURI
in classAFSocketAddress
- Parameters:
scheme
- The target scheme.template
- An optional template to reuse certain parameters (e.g., the "path" component for anhttp
request), ornull
.- Returns:
- The URI.
- Throws:
IOException
- on error.
-
newConnectedSocket
Description copied from class:AFSocketAddress
Creates a new socket connected to this address.- Overrides:
newConnectedSocket
in classAFSocketAddress
- Returns:
- The socket instance.
- Throws:
IOException
- on error.
-
newBoundServerSocket
Description copied from class:AFSocketAddress
Creates a new server socket bound to this address.- Overrides:
newBoundServerSocket
in classAFSocketAddress
- Returns:
- The server socket instance.
- Throws:
IOException
- on error.
-
newForceBoundServerSocket
Description copied from class:AFSocketAddress
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.- Overrides:
newForceBoundServerSocket
in classAFSocketAddress
- Returns:
- The server socket instance.
- Throws:
IOException
- on error.
-
of(File)
instead.