From 715a069017c17416e776a53b4b5553ebddbfdad8 Mon Sep 17 00:00:00 2001 From: Frederic Suter Date: Tue, 17 May 2016 06:38:47 +0200 Subject: [PATCH] add File.seek to Java API --- src/bindings/java/jmsg_file.cpp | 5 ++++ src/bindings/java/jmsg_file.h | 28 ++------------------- src/bindings/java/org/simgrid/msg/File.java | 12 +++++++++ 3 files changed, 19 insertions(+), 26 deletions(-) diff --git a/src/bindings/java/jmsg_file.cpp b/src/bindings/java/jmsg_file.cpp index c716c996f1..5eeca8467d 100644 --- a/src/bindings/java/jmsg_file.cpp +++ b/src/bindings/java/jmsg_file.cpp @@ -43,6 +43,11 @@ JNIEXPORT jlong JNICALL Java_org_simgrid_msg_File_write(JNIEnv *env, jobject jfi return (jlong)MSG_file_write(file, (sg_size_t)jsize); } +JNIEXPORT void JNICALL Java_org_simgrid_msg_File_seek(JNIEnv *env, jobject jfile, jlong offset, jlong origin) { + msg_file_t file = jfile_get_native(env, jfile); + MSG_file_seek(file, (sg_offset_t)offset, (int) origin); +} + JNIEXPORT void JNICALL Java_org_simgrid_msg_File_close(JNIEnv *env, jobject jfile) { msg_file_t file = jfile_get_native(env, jfile); diff --git a/src/bindings/java/jmsg_file.h b/src/bindings/java/jmsg_file.h index 88a451a140..bc8a063fb2 100644 --- a/src/bindings/java/jmsg_file.h +++ b/src/bindings/java/jmsg_file.h @@ -17,36 +17,12 @@ jfieldID jfile_field_bind; void jfile_bind(JNIEnv *env, jobject jfile, msg_file_t fd); msg_file_t jfile_get_native(JNIEnv *env, jobject jfile); -/** - * Class org_simgrid_msg_File - * Method nativeInit - * Signature ()V - */ -JNIEXPORT void JNICALL Java_org_simgrid_msg_File_nativeInit(JNIEnv*, jclass); -/** - * Class org_simgrid_msg_File - * Method open - * Signature (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V - */ +JNIEXPORT void JNICALL Java_org_simgrid_msg_File_nativeInit(JNIEnv*, jclass); JNIEXPORT void JNICALL Java_org_simgrid_msg_File_open(JNIEnv*, jobject, jobject); - -/** - * Class org_simgrid_msg_File - * Method read - */ JNIEXPORT jlong JNICALL Java_org_simgrid_msg_File_read(JNIEnv*, jobject, jlong); - -/** - * Class org_simgrid_msg_File - * Method write - */ JNIEXPORT jlong JNICALL Java_org_simgrid_msg_File_write(JNIEnv*, jobject, jlong); - -/** - * Class org_simgrid_msg_File - * Method close - */ +JNIEXPORT void JNICALL Java_org_simgrid_msg_File_seek(JNIEnv*, jobject, jlong, jlong); JNIEXPORT void JNICALL Java_org_simgrid_msg_File_close(JNIEnv*, jobject); SG_END_DECL() diff --git a/src/bindings/java/org/simgrid/msg/File.java b/src/bindings/java/org/simgrid/msg/File.java index 633f1ffb9f..b1f13f9cb1 100644 --- a/src/bindings/java/org/simgrid/msg/File.java +++ b/src/bindings/java/org/simgrid/msg/File.java @@ -7,6 +7,9 @@ package org.simgrid.msg; public class File { + public final int SEEK_SET = 0; + public final int SEEK_CUR = 1; + public final int SEEK_END = 2; /** * Represents the bind between the java comm and the * native C comm. You must never access it, since it is @@ -41,6 +44,15 @@ public class File { * @param nMemb is the number of elements of data to write */ public native long write(long size, long nMemb); + /** + * Write elements into a file. + * @param offset : number of bytes to offset from origin + * @param origin : Position used as reference for the offset. It is specified by one of the following constants + * defined in <stdio.h> exclusively to be used as arguments for this function (SEEK_SET = + * beginning of file, SEEK_CUR = current position of the file pointer, SEEK_END = end of file) + */ + public native void seek(long offset, long origin); + /** Close the file. */ public native void close(); -- 2.20.1