JNI wchar_t problem (unix platforms)

Hi all,
i have such kind of broblem on unix platforms. I have unicode string in JNI and when i create jstring and return it to java the string is not completed. So,
wchar_t name[50] = L"Ob als Sch�ler";
jstring objectName = NULL;
len = wcslen(name);
objectName = (*env)->NewString(env, name, len);
return objectName;
I receive in Java "Ob als". I receive warning when compile the c code, theat argument #2 is not compatible with prototype. This happened because the second parameter is unsigned short, and wchar_t, which i passed, is four bytes. How can i fix this problem with wide char string? Is it a good idea to convert wchar_t string to char string and after that to create NewStringUTF? I noticed that when the len is twice bigger i.e. len = 2*wcslen(name) the string which is created is full. Is it correct to use this function with twice more length?
Thanks,
Valentin

The problem happens when the size of wchar_t mismatches the size of jchar. Under Linux, wchar_t has size 4 while jchar has size 2. Using the short-wchar option for GCC can surely set wchar_t to have size 2, but problems will occur with any library compiled without the option; this will include all standard libraries.
I have successfully passed strings from Java to JNI using the following workaround. My solution worked with Linux x64, but there is no reason it won't work in 32 bits.
Suppose we have a class with a getString native method returning a string from the C world, and a print method printing a string coming from Java using C' wprintf.
Here is the code for the getString method:
JNIEXPORT jstring JNICALL Java_TestJNI_getString
(JNIEnv * env, jclass cls) {
   const wchar_t* str = L"Here is a quite long and useless string. Note that this even works with non-ASCII characters, like in Allô les élèves.";
   size_t len = wcslen(str);
   if (sizeof(wchar_t) != sizeof(jchar)) {
      // In Linux, we get there.
      // First, allocate a buffer for the string to pass to Java, not forgetting the \0
      jchar* str2 = (jchar*)malloc((len+1)*sizeof(jchar));
      int i;
      for (i = 0; i < len; i++)
         // This discards two bytes in str, but these should be 0 in UTF-16
str2[i] = str[i];
str2[len] = 0;
// Now we have a compatible string!
jstring js = (*env)->NewString(env, str2, len);
// And we can free the buffer, to prevent memory leaks
free(str2);
return js;
else
// Under Windows, we don't need such a hack
return (*env)->NewString(env, str, len);
And now the code for print:JNIEXPORT void JNICALL Java_TestJNI_print
(JNIEnv * env, jclass cls, jstring js) {
const jchar* str = (*env)->GetStringChars(env, js, NULL);
if (sizeof(wchar_t) != sizeof(jchar)) {
// Size mismatch, so translate the string
// Get the length using Java (strlen or wcslen should return the wrong length, or even segfault)
jint len = (*env)->GetStringLength(env, js);
// Allocate a buffer, not forgetting the \0 terminating character
wchar_t* str2 = (wchar_t*)malloc((len+1)*sizeof(wchar_t));
int i;
for (i = 0; i < len; i++)
str2[i] = str[i];
str2[len] = 0;
wprintf(L"%ls\n", str2);
free(str2);
else {
// Under Windows, we don't need the hack
wprintf(L"%ls\n", str);
(*env)->ReleaseStringChars(env, js, str);

Similar Messages

  • JAVA application on a UNIX platform

    I've stripped my code to the very simplest form and I can not fix this strange behaviour I'm getting when I run it on a UNIX machine. Both Linux and Windows work fine. Simply put this code initializes a File object corresponding to a directory on the user machine:
    File dir = new File("/usr/local"); I then query the directory for all Files every couple seconds and print them out
    while(x < 0) {//infinite loop
      list = dir.listFiles();
      for (int y =0; y<=list.length-1; y++{
        System.out.println(list[x].toString());
      thread.slepp(1000);
    } The problem on the UNIX platform is that once the number of file reaches about 82, sometime 83, sometimes 84, it stops seeing all files. Comes up empty. This behaviour is not seen with Linux or Windows, I have listed up to 2500 files on those platforms. Any ideas?
    BTW I'm using a SUN running Solaris

    Well, is there any problem with your Solaris installation?
    if you could run a script like this for a few minutes: (sorry, I have no access to a Solaris machine now in order to test this script, but I think that you can read it and understand the idea:
    while true
    do
        ls -l /usr/local | wc -l
        sleep 1
    donels -l /usr/local lists the files of /usr/local, and wc -l counts the lines of the listing.
    It's approximately the equivalent of your Java program. If it gives strange results like your Java program, you can try making a backup of all your work that you've done in the Solaris machine, and ask for immediate maintenance.

  • Objects to be transported from Windows platform to Unix platform

    Hi experts
    Our current development is on windows platform. and the production server will be on HP Unix platform.
    I just wanted to know that is it possible to transport the webdynpro application and the portal contents.
    Also wanted to know what all components need modification while transport.
    Guide me the steps for the move.
    regards
    vija

    Usually you shouldn´t have any issues transporting. Java bytecode is platform independent.
    What CAN be an issue is the different endianess if you program yourself and assume, that the byte order is little endian - but if you stay on the webdynpro level you shouldn´t have any problems.
    Markus

  • How to find cd rom drive in windows and unix platform using java program

    Hi,
    I am having the requirement of finding the cd rom drive
    using java program. I do not know the label and which
    one is the cd rom drive. also I want to know how many
    cd rom drives are there on my system. I want the solution
    for windows and unix platforms.
    If have any suggestions please mail to [email protected]
    Deepak

    Ughhh.. I had the same problem with multi platform file-system detection
    First off - Unix.
    Do you know for sure you have all your drives mounted?? This could be a big problem because java will not see unmounted drives... So you can scour thru your /etc/fstab to find out which drives are available... or you can mount all and show roots... (Yuck!)... You've got timeouts and all sorts of things to worry about...
    I would then shy away from the java.io.File.listRoots() on unix and rely on parsing your fs file. If a user would like to see the medium in the drive. Do a Runtime.exec and mount the drive, then you can grab the filesystem by wrapping it in the java.io.File object. ( NOTE - this will hold well for your NFS mounts as well which might be buried under other FS. So you now have detection for that as well. ) Labels are also noted in this file. Let me know if you don't know the difference between mtab and fstab....
    Second - Winders.... Corney but I love saying that.
    The listRoots is a good solution. As others have said CD-ROMS will not be writable. Use a combination of getName and getPath to decipher the label and mount point.
    Hope this helps!

  • Sap installation screen shots on UNIX platform

    hi friends,
    can any one send or guide me in getting me the SAP INSTALLATION screen shots on UNIX platform..
    pls mail to [email protected]
    regards,
    satish.

    "Unix" is a generic term for operating systems based on the initial AT & T operating system. There are many flavors of it - on some of them you can install a SAP system, on others not.
    There is (for SAP)
    AIX
    HP-UX (on PA-RISC and IA64)
    Solaris (on SPARC and x86_64)
    Linux (on x86, x86_64, IA64, Power)
    Each one of those has its specialties and special configuration. So without knowing to what "Unix" you are referring, your question can't be answered that easily.
    On top of that, using screenshots to install software is a pretty bad idea. I may work for the one who did those but it may not for you if you have a different hardware configuration, more or less memory, different filesystem layout etc. In that case, you will cry for help the first time you see an error message - and since you don't know what the system was trying to do, you can't find a solution for it.
    Therefore it's MUCH better to use the (very good) installation guides, they will tell you what you need to do, they will explain everything much more in detail than a "screenshot document" could tell you.
    Use the given link to get your guide and try - and if you have problems, ask your questions in the appropriate forum - I'm sure there are people willing to help (including me).
    Markus

  • CPS - Redwood : Error JCS-108003 on an unix platform agent

    Hi,
    I get the following error message u201CJCS-108003: No backends could retrieve the specified jobfile (ID: 664,788); failure possibly transient.u201D
    while running a CPS job on a unix platform agent. Even the command "ls" return that message.
    Could someone help, pls.

    Hi,
    jobs are running now on the platform agent. It was a problem on the security tab of the PA.
    I grant rights to my redwood user and it works after reboot of the PA.
    I'm now dealing with this error below :
    "/home/redwood/agent/var/SAP_RW0_41/PI-DEV/jobs/71565/run_KSH[120]: ./: 0403-006 Execute permission denied"
    eXecute rights is ok on the scripts of the unix target server.
    Re.

  • Differences between Oracle 8i for a UNIX Platform and Oracle 8i for a Linux Platform

    Hello,
    J would like to know if there are some differences between Oracle 8i for a UNIX Platform and Oracle 8i for a Linux Platform.
    I know that there are some differences on Oracle 8i Parallel Server and i know that some products are not include like precompiler (Mod*Ada, Pro*FORTRAN) on a Linux Platform.
    Thank you.

    We have installed Oracle 8i on Solaris 8 and it had a great performance, of course that the hardware and licence invested here was costed my the office where i work. Personaly i'd installed linux reh hat 8 and oracle 8i, imagine that, it could be implemented by any individual that has the time to do so.
    By buyinng from a company that has a good background you could be sure that you will have support.
    Bottom line, if you have the $ to buy great hardware go for a unix platform. But if you don't a Red Hat Linux Server Licence with a 1 year sopport and Oracle data base is about 3500Dls.
    Visit www.red-hat.com
    Rewards... Bye

  • Differences between Oracle 8i for a UNIX Platform and a Linux Platform

    I want to know the differences between Oracle 8i for a UNIX Platform and Oracle 8i for a Linux Platform. And which platform is better?
    Thanks

    We have installed Oracle 8i on Solaris 8 and it had a great performance, of course that the hardware and licence invested here was costed my the office where i work. Personaly i'd installed linux reh hat 8 and oracle 8i, imagine that, it could be implemented by any individual that has the time to do so.
    By buyinng from a company that has a good background you could be sure that you will have support.
    Bottom line, if you have the $ to buy great hardware go for a unix platform. But if you don't a Red Hat Linux Server Licence with a 1 year sopport and Oracle data base is about 3500Dls.
    Visit www.red-hat.com
    Rewards... Bye

  • CM Repository - Windows File System on EP(UNIX Platform)?

    Hi all,
    we have an EP6 SP2 on Unix. We want use CM repository manager to connect remote windows file system which contains all the content. In Global Services we wanted to use the fsmount Service-
    We get the following Message:" not supported for SUN OS to Win2000 System"
    Is it possible to integrate an Windows File System when you have installed the Portal on a UNIX Platform?
    Thanks!

    Hello Antonio,
    With EP6 SP2 Patch 5 KM on a Unix portal can access windows file systems including ACLs. Please have a look at the corresponing release notes
    http://help.sap.com/saphelp_ep60sp2patch5/helpdata/en/4d/8dec404303702ae10000000a155106/frameset.htm
    or in the documentation
    http://help.sap.com/saphelp_ep60sp2patch5/helpdata/en/ed/b334ea02a2704388d1d2fc3e4298ad/frameset.htm
    Kind regards,
    Roland

  • Migrating Oracle DB from OpenVMS to a Unix Platform

    Hello all;
    Wanted to find out if you have experience or info on any tools that assist in migrating a 24X7 OracleDB from an OpenVMS to a Unix platform. We have looked into the basic export and import but since the environment is OLTP-downtime is a concern. The DB is about 2TB of raw data.
    Thank you

    Something in writing from someone authorized by Oracle -- e.g. someone in Licence Sales -- would stand in a court of law.
    Nevertheless, if you want "different inputs" from here :
    Oracle licences by the number of cores.  Off hand, since the number of cores is different, the licence count is not the same.  However, Oracle also has "core scaling factors" (called Oracle Processor Core Factor Table) for different types of CPUs.  You should see the Software Investment Guide at http://www.oracle.com/us/corporate/pricing/index.html and Oracle Database Licensing under Specialty Topics from the same URL.
    Hemant K Chitale

  • Our organization uses an Oracle database hosted on a Unix platform and one of our data processing outputs is a "stuffer" document that has a barcode, and Unix jobs automatically send the document to a printer.   Is there a way, or does Adobe have a produc

    Our organization uses an Oracle database hosted on a Unix platform and one of our data processing outputs is a “stuffer” document that has a barcode, and Unix jobs automatically send the document to a printer.
    Is there a way, or does Adobe have a product or solution, to create a PDF version of the document including the barcode, before it’s sent to a printer?

    What format is the document that is printed? Or what technology is used to format the printer? There isn't a standard way of doing things in Unix.

  • How to use Entrust with java application on unix platform

    Hi all,
    i have question regarding the use of Entrust with java application on unix
    1)I want to use Entrust for encryption/decryption of the file in my core java application on unix platform.
    What should be requiremnet for the same and how it is implemented?.
    2) I want to Use Entrust for Authentication purpose in my java based web application on unix platform.
    What are requirements for Entrust Authentication and how it is implemented ?

    any one has solution?

  • Oracle in Unix Platform

    Hi
    Right now i'm working oracle in windows plaftforms.I want to switch to unix platform.Can anyone tell me how to run oracle pl/sql pgms in unix platform
    Thanks in advance

    Hi,
    if you ask about Oracle Forms, just recompile he Forms fmb files on Unix and you are all set
    Frank

  • Which software do you use on the linux or unix platform

    I am learning oracle, so I am wondering, in the real world, which software do you use to administrate oracle in the company, on the linux or unix platform? sqlplus?
    certainly, I think you can also open the OEM GUI in linux or unix

    If you are learning, surely enough , learning any o/s other than windows will help. About the industry, there is not just one player that rules in the o/s market. It depends on a lot of factors , cost being the most dominating one. Linux, being a little less costlier, is surely a good choice for many but so is HP UX or AIX. Without bothering about what is more popular, learn one which you can get your hands on in your learning environment more easily. For example, it would be tough to have a AIX based machine in your home and a linux based would be lot easier. So learn one, ,learn it good. When you go to a different shop, use your previous knowledge and learn the know-hows of that o/s as well.
    HTH
    Aman....

  • Oracle Unix platform tkprof

    hai
    I am using tkprof utility for execution plan. i have unix platform.
    tkprof <trace file> <output file> [explain=<username/password>]
    kindly tell me where does the trace files stored in unix environment..?
    S

    Don't fear, they made documentation for that version too.
    I'd bet you could even find it if you felt like looking.
    I know i don't ... i already searched once for you.

Maybe you are looking for

  • Computer wont start!

    hey all, I was using my computer running on battery when the battery went empty and computer turned off. so i plugged the computer to the AC and used it. when the green light turned on and the status on screen said fully charged, i unplugged the elec

  • Purchase order history not displayed in correct sequence

    Hi all, We are on SRM 7.1 ECS. The issue we are facing is that the follow on documents for the PO i.e. confirmatin and Invoice are not displayed in the correct sequence i.e. the sequence in which the documents are displayed is : Invoice>confirmation>

  • How to add the BPM column in iTunes 12.01?

    This used to be easily done under View Options but is gone now.  Is it somewhere else now or has this feature been removed?  THX!

  • User exit / BADI for the MATQM01 IDOC type?

    Hello,    I am working on a Material Master conversion that will need to include the Material Inspection Setup. Using BD10 to send the material 'In Full' generates these MATQM01 IDOCs successfully. As part of this conversion I need to map some old pl

  • Authorware, Plugins, and Windows Vista

    I am currently enrolled in an online course through Johns Hopkins University that requires the Adobe authorware player to teach its lessons. The lessons are accessible through cybered.com. Everytime I try to install the Authorware player, a window ap