* @return file descriptor
* @exception AFSFileException if an I/O or other file related error occurs.
*/
-JNIEXPORT jint JNICALL Java_org_openafs_jafs_FileInputStream_openReadOnly
- (JNIEnv *env, jobject obj, jstring fileNameUTF)
+JNIEXPORT jint JNICALL
+Java_org_openafs_jafs_FileInputStream_openReadOnly(JNIEnv * env, jobject obj,
+ jstring fileNameUTF)
{
- int err;
- int fd = -1; //file descriptor
-
- fd = openAFSFile(env, fileNameUTF, O_RDONLY, 0, &err);
- if (fd < 0) {
- fprintf(stderr, "FileInputStream::openReadOnly(): err=%d\n", err);
- throwAFSFileException( env, err, NULL );
- }
- return fd;
+ int err;
+ int fd = -1; //file descriptor
+
+ fd = openAFSFile(env, fileNameUTF, O_RDONLY, 0, &err);
+ if (fd < 0) {
+ fprintf(stderr, "FileInputStream::openReadOnly(): err=%d\n", err);
+ throwAFSFileException(env, err, NULL);
+ }
+ return fd;
}
/**
* the file has been reached.
* @exception AFSFileException if an I/O or other file related error occurs.
*/
-JNIEXPORT jint JNICALL Java_org_openafs_jafs_FileInputStream_read
- (JNIEnv *env, jobject obj, jbyteArray jbytes, jint offset, jint length)
+JNIEXPORT jint JNICALL
+Java_org_openafs_jafs_FileInputStream_read(JNIEnv * env, jobject obj,
+ jbyteArray jbytes, jint offset,
+ jint length)
{
- int fd, bytesLen, bytesRead;
- jclass thisClass;
- jmethodID getFileDescriptorID;
- jbyte *bytes;
- jfieldID fid;
-
- /* If we have to read 0 bytes just return */
- if (length == 0) return 0;
-
- thisClass = (*env)->GetObjectClass(env, obj);
- fid = (*env)->GetFieldID(env, thisClass, "fileDescriptor", "I");
- fd = (*env)->GetIntField(env, obj, fid);
-
- if (fd < 0) {
- fprintf(stderr, "FileInputStream::read(): invalid file state\n");
- throwAFSFileException(env, 0, "Invalid file state");
- return -1;
- }
-
- bytes = (*env) -> GetByteArrayElements(env, jbytes, 0);
- bytesLen = (*env) -> GetArrayLength(env, jbytes);
- bytesRead = uafs_read(fd, bytes, bytesLen);
-
- if (errno != 0) throwAFSFileException(env, errno, NULL);
-
- (*env) -> ReleaseByteArrayElements(env, jbytes, bytes, 0);
- return (bytesRead > 0) ? bytesRead : -1;
+ int fd, bytesLen, bytesRead;
+ jclass thisClass;
+ jmethodID getFileDescriptorID;
+ jbyte *bytes;
+ jfieldID fid;
+
+ /* If we have to read 0 bytes just return */
+ if (length == 0)
+ return 0;
+
+ thisClass = (*env)->GetObjectClass(env, obj);
+ fid = (*env)->GetFieldID(env, thisClass, "fileDescriptor", "I");
+ fd = (*env)->GetIntField(env, obj, fid);
+
+ if (fd < 0) {
+ fprintf(stderr, "FileInputStream::read(): invalid file state\n");
+ throwAFSFileException(env, 0, "Invalid file state");
+ return -1;
+ }
+
+ bytes = (*env)->GetByteArrayElements(env, jbytes, 0);
+ bytesLen = (*env)->GetArrayLength(env, jbytes);
+ bytesRead = uafs_read(fd, bytes, bytesLen);
+
+ if (errno != 0)
+ throwAFSFileException(env, errno, NULL);
+
+ (*env)->ReleaseByteArrayElements(env, jbytes, bytes, 0);
+ return (bytesRead > 0) ? bytesRead : -1;
}
/**
*
* @exception AFSFileException if an I/O or other file related error occurs.
*/
-JNIEXPORT void JNICALL Java_org_openafs_jafs_FileInputStream_close
- (JNIEnv *env, jobject obj)
+JNIEXPORT void JNICALL
+Java_org_openafs_jafs_FileInputStream_close(JNIEnv * env, jobject obj)
{
- int fd, rc;
- jclass thisClass;
- jmethodID getFileDescriptorID;
- jfieldID fid;
- char *bytes;
-
- thisClass = (*env)->GetObjectClass(env, obj);
- fid = (*env)->GetFieldID(env, thisClass, "fileDescriptor", "I");
- fd = (*env)->GetIntField(env, obj, fid);
-
- if (fd < 0) {
- fprintf(stderr, "FileInputStream::close(): invalid file state\n");
- throwAFSFileException(env, 0, "Invalid file state");
- return;
- }
-
- rc = uafs_close(fd);
-
- if (rc != 0) {
- throwAFSFileException(env, errno, NULL);
- }
+ int fd, rc;
+ jclass thisClass;
+ jmethodID getFileDescriptorID;
+ jfieldID fid;
+ char *bytes;
+
+ thisClass = (*env)->GetObjectClass(env, obj);
+ fid = (*env)->GetFieldID(env, thisClass, "fileDescriptor", "I");
+ fd = (*env)->GetIntField(env, obj, fid);
+
+ if (fd < 0) {
+ fprintf(stderr, "FileInputStream::close(): invalid file state\n");
+ throwAFSFileException(env, 0, "Invalid file state");
+ return;
+ }
+
+ rc = uafs_close(fd);
+
+ if (rc != 0) {
+ throwAFSFileException(env, errno, NULL);
+ }
}