Package libcore.io
Class IoBridge
- java.lang.Object
-
- libcore.io.IoBridge
-
public final class IoBridge extends Object
Implements java.io/java.net/java.nio semantics in terms of the underlying POSIX system calls.
-
-
Field Summary
Fields Modifier and Type Field Description static intJAVA_IP_MULTICAST_TTLstatic intJAVA_MCAST_BLOCK_SOURCEstatic intJAVA_MCAST_JOIN_GROUPstatic intJAVA_MCAST_JOIN_SOURCE_GROUPstatic intJAVA_MCAST_LEAVE_GROUPstatic intJAVA_MCAST_LEAVE_SOURCE_GROUPstatic intJAVA_MCAST_UNBLOCK_SOURCE
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static intavailable(FileDescriptor fd)static voidbind(FileDescriptor fd, InetAddress address, int port)static voidcloseAndSignalBlockedThreads(FileDescriptor fd)Closes the supplied file descriptor and sends a signal to any threads are currently blocking.static voidconnect(FileDescriptor fd, InetAddress inetAddress, int port)Connects socket 'fd' to 'inetAddress' on 'port', with no timeout.static voidconnect(FileDescriptor fd, InetAddress inetAddress, int port, int timeoutMs)Connects socket 'fd' to 'inetAddress' on 'port', with a the given 'timeoutMs'.static InetAddressgetSocketLocalAddress(FileDescriptor fd)static intgetSocketLocalPort(FileDescriptor fd)static ObjectgetSocketOption(FileDescriptor fd, int option)java.net has its own socket options similar to the underlying Unix ones.static booleanisConnected(FileDescriptor fd, InetAddress inetAddress, int port, int timeoutMs, int remainingTimeoutMs)static FileDescriptoropen(String path, int flags)java.io only throws FileNotFoundException when opening files, regardless of what actually went wrong.static intread(FileDescriptor fd, byte[] bytes, int byteOffset, int byteCount)java.io thinks that a read at EOF is an error and should return -1, contrary to traditional Unix practice where you'd read until you got 0 bytes (and any future read would return -1).static intrecvfrom(boolean isRead, FileDescriptor fd, byte[] bytes, int byteOffset, int byteCount, int flags, DatagramPacket packet, boolean isConnected)static intrecvfrom(boolean isRead, FileDescriptor fd, ByteBuffer buffer, int flags, DatagramPacket packet, boolean isConnected)static intsendto(FileDescriptor fd, byte[] bytes, int byteOffset, int byteCount, int flags, InetAddress inetAddress, int port)static intsendto(FileDescriptor fd, ByteBuffer buffer, int flags, InetAddress inetAddress, int port)static voidsetSocketOption(FileDescriptor fd, int option, Object value)java.net has its own socket options similar to the underlying Unix ones.static FileDescriptorsocket(boolean stream)static voidwrite(FileDescriptor fd, byte[] bytes, int byteOffset, int byteCount)java.io always writes every byte it's asked to, or fails with an error.
-
-
-
Field Detail
-
JAVA_MCAST_JOIN_GROUP
public static final int JAVA_MCAST_JOIN_GROUP
- See Also:
- Constant Field Values
-
JAVA_MCAST_LEAVE_GROUP
public static final int JAVA_MCAST_LEAVE_GROUP
- See Also:
- Constant Field Values
-
JAVA_MCAST_JOIN_SOURCE_GROUP
public static final int JAVA_MCAST_JOIN_SOURCE_GROUP
- See Also:
- Constant Field Values
-
JAVA_MCAST_LEAVE_SOURCE_GROUP
public static final int JAVA_MCAST_LEAVE_SOURCE_GROUP
- See Also:
- Constant Field Values
-
JAVA_MCAST_BLOCK_SOURCE
public static final int JAVA_MCAST_BLOCK_SOURCE
- See Also:
- Constant Field Values
-
JAVA_MCAST_UNBLOCK_SOURCE
public static final int JAVA_MCAST_UNBLOCK_SOURCE
- See Also:
- Constant Field Values
-
JAVA_IP_MULTICAST_TTL
public static final int JAVA_IP_MULTICAST_TTL
- See Also:
- Constant Field Values
-
-
Method Detail
-
available
public static int available(FileDescriptor fd) throws IOException
- Throws:
IOException
-
bind
public static void bind(FileDescriptor fd, InetAddress address, int port) throws SocketException
- Throws:
SocketException
-
connect
public static void connect(FileDescriptor fd, InetAddress inetAddress, int port) throws SocketException
Connects socket 'fd' to 'inetAddress' on 'port', with no timeout. The lack of a timeout means this method won't throw SocketTimeoutException.- Throws:
SocketException
-
connect
public static void connect(FileDescriptor fd, InetAddress inetAddress, int port, int timeoutMs) throws SocketException, SocketTimeoutException
Connects socket 'fd' to 'inetAddress' on 'port', with a the given 'timeoutMs'. Use timeoutMs == 0 for a blocking connect with no timeout.
-
closeAndSignalBlockedThreads
public static void closeAndSignalBlockedThreads(FileDescriptor fd) throws IOException
Closes the supplied file descriptor and sends a signal to any threads are currently blocking. In order for the signal to be sent the blocked threads must have registered with the AsynchronousCloseMonitor before they entered the blocking operation.This method is a no-op if passed a
nullor already-closed file descriptor.- Throws:
IOException
-
isConnected
public static boolean isConnected(FileDescriptor fd, InetAddress inetAddress, int port, int timeoutMs, int remainingTimeoutMs) throws IOException
- Throws:
IOException
-
getSocketOption
public static Object getSocketOption(FileDescriptor fd, int option) throws SocketException
java.net has its own socket options similar to the underlying Unix ones. We paper over the differences here.- Throws:
SocketException
-
setSocketOption
public static void setSocketOption(FileDescriptor fd, int option, Object value) throws SocketException
java.net has its own socket options similar to the underlying Unix ones. We paper over the differences here.- Throws:
SocketException
-
open
public static FileDescriptor open(String path, int flags) throws FileNotFoundException
java.io only throws FileNotFoundException when opening files, regardless of what actually went wrong. Additionally, java.io is more restrictive than POSIX when it comes to opening directories: POSIX says read-only is okay, but java.io doesn't even allow that. We also have an Android-specific hack to alter the default permissions.- Throws:
FileNotFoundException
-
read
public static int read(FileDescriptor fd, byte[] bytes, int byteOffset, int byteCount) throws IOException
java.io thinks that a read at EOF is an error and should return -1, contrary to traditional Unix practice where you'd read until you got 0 bytes (and any future read would return -1).- Throws:
IOException
-
write
public static void write(FileDescriptor fd, byte[] bytes, int byteOffset, int byteCount) throws IOException
java.io always writes every byte it's asked to, or fails with an error. (That is, unlike Unix it never just writes as many bytes as happens to be convenient.)- Throws:
IOException
-
sendto
public static int sendto(FileDescriptor fd, byte[] bytes, int byteOffset, int byteCount, int flags, InetAddress inetAddress, int port) throws IOException
- Throws:
IOException
-
sendto
public static int sendto(FileDescriptor fd, ByteBuffer buffer, int flags, InetAddress inetAddress, int port) throws IOException
- Throws:
IOException
-
recvfrom
public static int recvfrom(boolean isRead, FileDescriptor fd, byte[] bytes, int byteOffset, int byteCount, int flags, DatagramPacket packet, boolean isConnected) throws IOException- Throws:
IOException
-
recvfrom
public static int recvfrom(boolean isRead, FileDescriptor fd, ByteBuffer buffer, int flags, DatagramPacket packet, boolean isConnected) throws IOException- Throws:
IOException
-
socket
public static FileDescriptor socket(boolean stream) throws SocketException
- Throws:
SocketException
-
getSocketLocalAddress
public static InetAddress getSocketLocalAddress(FileDescriptor fd) throws SocketException
- Throws:
SocketException
-
getSocketLocalPort
public static int getSocketLocalPort(FileDescriptor fd) throws SocketException
- Throws:
SocketException
-
-