File Descriptor

Summary

Functions

AFileDescriptor_create(JNIEnv *env)
jobject
Returns a new java.io.FileDescriptor.
AFileDescriptor_getFd(JNIEnv *env, jobject fileDescriptor)
int
Returns the Unix file descriptor represented by the given java.io.FileDescriptor.
AFileDescriptor_setFd(JNIEnv *env, jobject fileDescriptor, int fd)
void
Sets the Unix file descriptor represented by the given java.io.FileDescriptor.

Functions

AFileDescriptor_create

Declared in android/file_descriptor_jni.h
jobject AFileDescriptor_create(
 JNIEnv *env
)

Returns a new java.io.FileDescriptor.

The FileDescriptor created represents an invalid Unix file descriptor (represented by a file descriptor value of -1).

Callers of this method should be aware that it can fail, returning NULL with a pending Java exception.

Available since API level 31.

Details
Parameters
env
a pointer to the JNI Native Interface of the current thread.
Returns
a java.io.FileDescriptor on success, nullptr if insufficient heap memory is available.

AFileDescriptor_getFd

Declared in android/file_descriptor_jni.h
int AFileDescriptor_getFd(
 JNIEnv *env,
 jobject fileDescriptor
)

Returns the Unix file descriptor represented by the given java.io.FileDescriptor.

A return value of -1 indicates that fileDescriptor represents an invalid file descriptor.

Aborts the program if fileDescriptor is not a java.io.FileDescriptor instance.

Available since API level 31.

Details
Parameters
env
a pointer to the JNI Native Interface of the current thread.
fileDescriptor
a java.io.FileDescriptor instance.
Returns
the Unix file descriptor wrapped by fileDescriptor.

AFileDescriptor_setFd

Declared in android/file_descriptor_jni.h
void AFileDescriptor_setFd(
 JNIEnv *env,
 jobject fileDescriptor,
 int fd
)

Sets the Unix file descriptor represented by the given java.io.FileDescriptor.

This function performs no validation of the Unix file descriptor argument, fd. Android uses the value -1 to represent an invalid file descriptor, all other values are considered valid. The validity of a file descriptor can be checked with FileDescriptor::valid().

Aborts the program if fileDescriptor is not a java.io.FileDescriptor instance.

Available since API level 31.

Details
Parameters
env
a pointer to the JNI Native Interface of the current thread.
fileDescriptor
a java.io.FileDescriptor instance.
fd
a Unix file descriptor that fileDescriptor will subsequently represent.

Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.

Last updated 2024年11月19日 UTC.