File Descriptor

#include <file_descriptor_jni.h>

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

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

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

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.