Overwrite content and length of any jString variable?

I have native C function (Example bellow) which as the parametr I give 'char* buffer' variable. To this buffer is placed received data and is returned length of received data (without any reallocation of memory).

Please, how can I do the same using JNI? Is it possible? I mean something like:

publicclass MySocket{

publicnativevoid receive(String str);

}

Where 'str' should be filled with received data of any length.

C example:

#include <stdlib.h>

#include <stdio.h>

#include <string.h>

/** @return length of received data

*/

int receive(char *buffer,int bufLen){

/* EXAMPLE OF SAME DATA */

const char* dataFromNetwork ="_data_received_from_network";

/* FILL BUFFER WITH RECEIVED DATA */

strcpy (buffer, dataFromNetwork);

/* RETURN ITS LENGTH */

return strlen(buffer);

}

int main (){

constint bufLen = 100;

char buffer[bufLen];

/***** THIS METHOD DOES NOT AFFECTS ANY MEMORY ALLOCATION *****/

int recvLen = receive(buffer, bufLen);

}

return 0;

}

Any advice would be really, really appreciated.

[2098 byte] By [radonea] at [2007-10-3 1:23:53]
# 1

Instead of using String you could use byte[]:public class MySocket {

public native void receive(byte[] bArray);

void test() {

int bufLen = 100;

byte[] buffer = new byte[bufLen];

receive(buffer);

}

}

Regards

jfbrierea at 2007-7-14 18:21:12 > top of Java-index,Java HotSpot Virtual Machine,Specifications...