Cannot Find Implementation for Sun. Nio. Ch. Filechannelimpl. Read
I Am Using Sun. Nio. Ch. Filechannelimpl. Read to Read a File in Linux Environment in My Java Project, I Am Getting a Permission Denied on One of My...
I am using sun.nio.ch.FileChannelImpl.read to read a file in linux environment in my java project, I am getting a permission denied on one of my environments, the file has read/write/execute permissions for everyone, but in my environment we have strict policy to allow some commands so I need to find out what commands is this method using to enable this command on my machine.
To find the command I followed up the code until i hit some native methods inside
sun.nio.ch.FileDispatcherImpl
the method is
static native int read0(FileDescriptor fd, long address, int len)
throws IOException;
I followed up and found the implementation which is obviously written with C, you can find it in this link
The native implementation is
JNIEXPORT jint JNICALL
Java_sun_nio_ch_FileDispatcherImpl_read0(JNIEnv *env, jclass clazz,
jobject fdo, jlong address, jint len)
{
jint fd = fdval(env, fdo);
void *buf = (void *)jlong_to_ptr(address);
return convertReturnVal(env, read(fd, buf, len), JNI_TRUE);
}
Now I need to open read function to figure out what it exactly does, but I am unable to find the implementation or even the header file where this function is declared, following the header files included
#include "jni.h"
#include "jni_util.h"
#include "jvm.h"
#include "jlong.h"
#include "sun_nio_ch_FileDispatcherImpl.h"
#include "java_lang_Long.h"
#include <sys/types.h>
#include <sys/socket.h>
#include <fcntl.h>
#include <sys/uio.h>
#include <unistd.h>
#if defined(__linux__)
#include <linux/fs.h>
#include <sys/ioctl.h>
#endif
#include "nio.h"
#include "nio_util.h"
any help is appreciated.
1 Answer
read() is a POSIX standard function to read from an open file descriptor. It is usually provided by your systems libc.so if dynamically linked, or libc.a if statically linked.
One implementation can be found here: