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_JOIN_GROUPstatic intJAVA_MCAST_LEAVE_GROUP -
Method Summary
Modifier and Type Method Description static intavailable(FileDescriptor fd)static voidbind(FileDescriptor fd, InetAddress address, int port)static voidcloseSocket(FileDescriptor fd)static booleanconnect(FileDescriptor fd, InetAddress inetAddress, int port)Connects socket 'fd' to 'inetAddress' on 'port', with no timeout.static booleanconnect(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 Details
-
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_IP_MULTICAST_TTL
public static final int JAVA_IP_MULTICAST_TTL- See Also:
- Constant Field Values
-
-
Method Details
-
available
- Throws:
IOException
-
bind
- Throws:
SocketException
-
connect
public static boolean connect(FileDescriptor fd, InetAddress inetAddress, int port) throws SocketExceptionConnects 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 boolean connect(FileDescriptor fd, InetAddress inetAddress, int port, int timeoutMs) throws SocketException, SocketTimeoutExceptionConnects socket 'fd' to 'inetAddress' on 'port', with a the given 'timeoutMs'. Use timeoutMs == 0 for a blocking connect with no timeout. -
closeSocket
- Throws:
IOException
-
isConnected
public static boolean isConnected(FileDescriptor fd, InetAddress inetAddress, int port, int timeoutMs, int remainingTimeoutMs) throws IOException- Throws:
IOException
-
getSocketOption
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 SocketExceptionjava.net has its own socket options similar to the underlying Unix ones. We paper over the differences here.- Throws:
SocketException
-
open
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 IOExceptionjava.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 IOExceptionjava.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
- Throws:
SocketException
-
getSocketLocalAddress
- Throws:
SocketException
-
getSocketLocalPort
- Throws:
SocketException
-