mturk 2005/05/19 10:19:45 Modified: jni/java/org/apache/tomcat/jni File.java jni/native/src file.c Log: Added readFullb and writeFullb (ByteBuffer) to File object. Revision Changes Path 1.5 +47 -1 jakarta-tomcat-connectors/jni/java/org/apache/tomcat/jni/File.java Index: File.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-connectors/jni/java/org/apache/tomcat/jni/File.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- File.java 19 May 2005 17:11:01 -0000 1.4 +++ File.java 19 May 2005 17:19:45 -0000 1.5 @@ -395,6 +395,29 @@ public static native int writeFull(long thefile, byte[] buf, int offset, int nbytes); /** + * Write data to the specified file, ensuring that all of the data is + * written before returning. + * + * Write will write up to the specified number of + * bytes, but never more. If the OS cannot write that many bytes, the + * process/thread will block until they can be written. Exceptional + * error such as "out of space" or "pipe closed" will terminate with + * an error. + * + * It is possible for both bytes to be written and an error to + * be returned. And if *bytes_written is less than nbytes, an + * accompanying error is _always_ returned. + * + * APR_EINTR is never returned. + * @param thefile The file descriptor to write to. + * @param buf The direct ByteBuffer which contains the data. + * @param offset Start offset in buf + * @param nbytes The number of bytes to write. + * @return The number of bytes written. + */ + public static native int writeFullb(long thefile, ByteBuffer buf, int offset, int nbytes); + + /** * Write data from aray of byte arrays to the specified file. * * It is possible for both bytes to be written and an error to @@ -484,6 +507,29 @@ public static native int readFull(long thefile, byte[] buf, int offset, int nbytes); /** + * Read data from the specified file, ensuring that the buffer is filled + * before returning. + * + * Read will read up to the specified number of + * bytes, but never more. If there isn't enough data to fill that + * number of bytes, then the process/thread will block until it is + * available or EOF is reached. If a char was put back into the + * stream via ungetc, it will be the first character returned. + * + * It is possible for both bytes to be read and an error to be + * returned. And if *bytes_read is less than nbytes, an accompanying + * error is _always_ returned. + * + * APR_EINTR is never returned. + * @param thefile The file descriptor to read from. + * @param buf The direct ByteBuffer to store the data to. + * @param offset Start offset in buf + * @param nbytes The number of bytes to read. + * @return the number of bytes read. + */ + public static native int readFullb(long thefile, ByteBuffer buf, int offset, int nbytes); + + /** * Read a string from the specified file. * The buffer will be NUL-terminated if any characters are stored. * @param buf The buffer to store the string in. 1.5 +41 -2 jakarta-tomcat-connectors/jni/native/src/file.c Index: file.c =================================================================== RCS file: /home/cvs/jakarta-tomcat-connectors/jni/native/src/file.c,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- file.c 19 May 2005 17:11:01 -0000 1.4 +++ file.c 19 May 2005 17:19:45 -0000 1.5 @@ -337,6 +337,25 @@ return -(jint)ss; } +TCN_IMPLEMENT_CALL(jint, File, writeFullb)(TCN_STDARGS, jlong file, + jobject buf, jint offset, jint towrite) +{ + apr_file_t *f = J2P(file, apr_file_t *); + apr_size_t nbytes = (apr_size_t)towrite; + apr_size_t written = 0; + apr_status_t ss = APR_EINVAL; + char *bytes = (char *)(*e)->GetDirectBufferAddress(e, buf); + + UNREFERENCED(o); + if (bytes) + ss = apr_file_write_full(f, bytes + offset, nbytes, &written); + + if (ss == APR_SUCCESS) + return (jint)written; + else + return -(jint)ss; +} + TCN_IMPLEMENT_CALL(jint, File, writev)(TCN_STDARGS, jlong file, jobjectArray bufs) { @@ -454,7 +473,7 @@ { apr_file_t *f = J2P(file, apr_file_t *); apr_size_t nbytes = (apr_size_t)toread; - apr_size_t nread; + apr_size_t nread = 0; apr_status_t ss; jbyte *bytes = (*e)->GetByteArrayElements(e, buf, NULL); @@ -464,7 +483,27 @@ (*e)->ReleaseByteArrayElements(e, buf, bytes, ss == APR_SUCCESS ? 0 : JNI_ABORT); if (ss == APR_SUCCESS) - return (jint)nbytes; + return (jint)nread; + else + return -(jint)ss; +} + +TCN_IMPLEMENT_CALL(jint, File, readFullb)(TCN_STDARGS, jlong file, + jobject buf, jint offset, + jint toread) +{ + apr_file_t *f = J2P(file, apr_file_t *); + apr_size_t nbytes = (apr_size_t)toread; + apr_size_t nread = 0; + char *bytes = (char *)(*e)->GetDirectBufferAddress(e, buf); + apr_status_t ss = APR_EINVAL; + + UNREFERENCED(o); + if (bytes) + ss = apr_file_read_full(f, bytes + offset, nbytes, &nread); + + if (ss == APR_SUCCESS) + return (jint)nread; else return -(jint)ss; }
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]