Casting char * to jbytearray
Hi all,
I had a urgent problem on casting char * to jbytearray. Can anyone help me out? Thank you very much in advance.
Assume I have char * which has the content I want to cast into jbytearray, then return this jbytearray to java applicaiton.
I did following code, char * buffer is already known:
jbyteArray bArray;
jbyte *byteArrayElement;
long length;
bArray = (*jenv)->NewIntArray(jenv,(jsize)length);
byteArrayElement =(jenv)->GetByteArrayElements(jenv,bArray, &isCopy);
for (i=0;i<length;i++){
byteArrayElement(i]=(jbyte)buffer(i];
if (isCopy == JNI_TRUE){
(*jenv)->ReleaseByteArrayElements(jenv,bArray, byteArrayElement, 0);
return bArray;
The error always shows as follow:
An unexpected exception has been detected in native code outside the VM.
Unexpected Signal : 11 occurred at PC=0x400BEE9C
Function=(null)+0x400BEE9C
Library=/lib/i686/libc.so.6
Trace down to the program, I found that this code cannot pass the last step of casting, which means:
(*jenv)->ReleaseByteArrayElements(jenv,bArray, (jbyte *)byteArrayElement, 0);
This line seems block the whole program, Any ideas?
Many Thanks
Rui
I think you need this:
jbyteArray bArray;
unsigned char * byteArrayElements;
long length;
bArray = (*jenv)->NewByteArray(jenv,(jsize)length);
byteArrayElements=(*jenv)->GetByteArrayElements(jenv,bArray,NULL);
for (i=0;i<length;i++)
byteArrayElements=(jbyte)buffer[i];
// or better: memcpy(byteArrayElements,buffer,length);
(*jenv)->ReleaseByteArrayElements(jenv,bArray, byteArrayElements, 0);
Similar Messages
-
Unsigned char* to jbytearray
could anyone please tell me how I could convert an unsigned char*, which is just some binary data to jbytearray.
the c++ program is being called thru JNI and hence jbytearray.
or is there a cleaner way to capture whatevr I get from the C++ code, and send it as is into my java module, so I can send it out through a UDP socket?mlk thank you. i looked at it earlier in the serach results. But i am having second thoughts now. does it have to be so complicated.
how do i make sure that the raw data returned by my C++ code is maintained as is by java module and ushed out of a UDP socket.
what data types should I rely on.
because at the other end of the socket, i have a client which can understand the raw data which was generated by the c++ code at my end.
any kind of suggestion will be a great help. -
Hi All!
How can I convert currDate -> SYSTDATLO or DATS
e.g.
data currDate(10) type c value '01.09.2007'.
Bye
sashi,
you can use this FM as follows:
data currDate(10) type c value '01.09.2007'.
data v TYPE DATS.
START-OF-SELECTION.
WRITE CURRDATE TO V.
CALL FUNCTION 'CONVERT_DATE_TO_INTERNAL'
EXPORTING
DATE_EXTERNAL = currdate
ACCEPT_INITIAL_DATE =
IMPORTING
DATE_INTERNAL = v
EXCEPTIONS
DATE_EXTERNAL_IS_INVALID = 1
OTHERS = 2
it will give what you want . -
Convert char * [] to jbyte
Hi,
My Native function pass by ref a jbyteArray and I need to copy a char * elem [] in it.I create a char dircc[] and I want to copy the content of the last char into jbyteArray. My source code is the following:
JNIEXPORT jint JNICALL Java_servidor_descubrir_CRastreo_descubreMob(JNIEnv *env, jobject obj,jbyteArray dir){
jsize tam = (*env)->GetArrayLength(env,dir);
char *dircc[10];
INQUIRY_ITEM *devs[20]; //this is an struct
for (i = 0;i < num ;i++ )
//I have to copy a parameter of this struct.
dircc[i] = &devs.bda;
(*env)-> ReleaseByteArrayElements(env ,dir ,dircc, 0);
return 1;
If I make,
(*env)-> ReleaseByteArrayElements(env ,dir ,(jbyte*)dircc, 0);
I return an exception....
Anyone can tell me how I can solve the problem?
Best Regards,
Elena.Sorry this line it's worng...
dircc[i] = &devs.bda;
Elena. -
Getting character by number, char of (int)
I would like to create column header in the excel style for my app, eg AA, AB, AC....BA, BB...etc
Is there a way to get the character by index in Java, so i can iterate the letters in a cycle,
Something like charOf equivalent in java?
DennisI would like to create column header in the excel
style for my app, eg AA, AB, AC....BA, BB...etc
Is there a way to get the character by index in Java,
so i can iterate the letters in a cycle,
Something like charOf equivalent in java?
DennisJust use cast: ((char)65) == 'A'), ((char)66) == 'B'), etc. -
Problems with String.getBytes() method
Consider this code
for(int k=0 ; k<256 ; k++)
char[] cc = {(char)k};
String xxx = new String(cc);
byte b1 = (byte)xxx.charAt(0);
byte[] bb = xxx.getBytes();
byte b2 = bb[0];
boolean diff = (b1!=b2);
if (diff)
System.out.println(k+" - "+b1+" - "+b2);
}for k from 128 to 159 b1 and b2 are different and in particular b2 (that is the result of getString() method) is every time equals to 63.
Does someone know if it is a bug or what else.char variables store 16 bit UNICODE characters. If you cast char to byte you're just taking the low order 8-bits of a unicode character.
On the other hand getBytes attempts to convert a character into a byte, or sequence of bytes using the default character encoding of the machine, which won't generally corespond. National character encodings meen that non-ASCII characters, including national stuff like pound sign, may well map from UNICODE characters above 255 into a single byte.
The character encoding which does corespond to the bottom 8 bits of UNICODE is ISO-8859-1. If you try it with that your discrepancies will disappear. -
Error in Adding Fields.
I am trying to add 2 additional fields to my report below. I highlighted in yellow the code that I added. I keep getting the "failed to retrieve data from the database error." I know it is hard to tell what is wrong from the error I just described, but does anyone see anything wrong with my highlighted lines? Is there something I did wrong or need to do? Any help is greatly appreciated.
with accts as (
select a.rmsfilenum, misddesc,a.attrnycode,rmsacctnum,c.rmszipcode,
cast(char(action_code) as char(16) ccsid 37) as action_code,
cast(char(result_code) as char(16) ccsid 37) as result_code,
a.rmstrandte,
case when action_code = '4' then 'Home Phone' else 'Other Phone' end as Phonetype,
rmstrantim,rmsdateasg,
rmsbrglvl5,
rmsbrglvl6
from
rptingdata.roactreacc a
left join reporting.rmaster b
on a.rmsfilenum = b.rmsfilenum
left join reporting.rcomker c
on a.rmsfilenum = c.rmsfilenum
left join reporting.rsasrecv d
on a.attrnycode = d.rmsrecvrcd
left join reporting.rofcrcd e
on a.attrnycode = e. attrnycode
where c.recordtype = 'D'
and e.rmsbrglvl6 = ‘5006’
and
( action_code = '4'
and rmstrandte between Replace(Char((Cast(Timestamp({?Enddate}||'000000') As Date)) - 6 days, ISO),'-','') and {?Enddate}
or
( action_code in ('3','5','25','26','27')
and rmstrandte between Replace(Char((Cast(Timestamp({?Enddate}||'000000') As Date)) - 29 days, ISO),'-','') and {?Enddate}
totissue as (
select rmsfilenum,phonetype, count(*) as totcount
from accts
group by rmsfilenum,phonetype
having count(*) > 2
totcount as (
select a.*, totcount , Replace(Char((Cast(Timestamp({?Enddate}||'000000') As Date)) - 6 days, ISO),'-','') as strtdt
from accts a
join totissue b
on a.rmsfilenum = b.rmsfilenum
and a.phonetype = b.phonetype),
uniqatty as (
select rmsfilenum,attrnycode from totcount group by rmsfilenum,attrnycode),
attyplcdt as (
select a.rmsfilenum, b.rmstrandte as plcdt, c.rmstrandte as recalldt
from uniqatty a
left join reporting.rhistfl b
on a.rmsfilenum = b.rmsfilenum
and b.rmsfldimpl = 'ATTRNYCODE' and b.hstnewvalu = a.attrnycode
left join reporting.rhistfl c
on a.rmsfilenum = c.rmsfilenum
and c.rmsfldimpl = 'ATTRNYCODE' and c.hstoldvalu = a.attrnycode
select a.*, plcdt,recalldt
from totcount a
join attyplcdt b
on a.rmsfilenum = b.rmsfilenumHave you tried putting the "e." in front of the field names?
Also, I would copy all of this SQL and paste it into a database query tool such as Toad or SQL Server Management Studio (which tool you use depends on what type of database and the tools you have available). Get the query working in there and then paste it back into the Command editor in Crystal.
-Dell -
Stopping SQL Server treating ½ as a numeric value
Hi All,
I've got a problem that is entirely of my predecessors making, but needs a work around without changing code (I was not sure if transact SQL was the place to ask this, as my problem requires a non T-SQL solution). Please let me know if there's a more appropriate
forum.
The application I work on parses some text from a document, and stores values in the databases as nvarchar. One piece of text that it stored was typed in as "1/2", but then helpfully shortened by office to a single character. For me in SQL this
appears to be CHAR(189), but other forum posts I've found on this suggest it is CHAR(171). Either way, having it in my text field is a problem because someone wrote some code for some ordering that tried to order by numbers more cleverly (i.e. make "10-Thing"
come after "9-Thing").
They wrote code that basically parsed the first 10 characters 1 at a time, checked if it was an integer, and concatenated that character into a number they then cast as an int. This formed the first part of the ORDER BY. Their test for the character being
included was CASE WHEN MyChar BETWEEN '0' AND '9' THEN MyChar ELSE '' END.
This causes my problem, it appears that CASE WHEN CHAR(189) BETWEEN '0' AND '9' THEN CHAR(189) ELSE '' END actually outputs that "1/2" character as it treats it numerically for the between comparison. This then blows up on the cast to
an int and causes the SQL to fail.
The SQL is compiled into the application, so I can't change it, and it's a live customer issue. What I need to be able to do is find a setting in SQL Server or some language setting I can apply that makes this character not able to be considered a number,
and is in fact treated as an opaque piece of text.
Any advice on the matter would be appreciated.
Thanks,
Will>> I've got a problem that is entirely of my predecessors making, but needs a work around without changing code (I was not sure if transact SQL was the place to ask this, as my problem requires a non T-SQL solution). <<
It is not legacy code: it is family curse code :)
>> The application I work on parses some text from a document, and stores values in the databases as NVARCHAR. <<
Okay, Chinese UNICODE! We do not care in the SQL world. We do data, not parsing. It should be clean before it goes into a table. Remember the tiered architecture model?
>> One piece of text that it stored was typed in as "1/2", but then helpfully shortened by office to a single character. For me in SQL this appears to be CHAR(189), but other forum posts I've found on this suggest it is CHAR(171). Either way, having it
in my text field [sic: columns are not fields] is a problem because someone wrote some code for some ordering that tried to order by numbers more cleverly (i.e. make "10-Thing" come after "9-Thing").<<
The input layer is failing to clean up the data to something that will fit into the column and pass the constraint. You do have columns constraints.
>> They wrote code that basically parsed the first 10 characters 1 at a time, checked if it was an integer, and concatenated that character into a number they then cast as an INTEGER. This formed the first part of the ORDER BY. Their test for the character
being included was CASE WHEN MyChar BETWEEN '0' AND '9' THEN MyChar ELSE '' END.<<
NO! We do not parse in SQL! This is one of soooo many reason why!
>> This causes my problem, it appears that CASE WHEN CHAR(189) BETWEEN '0' AND '9' THEN CHAR(189) ELSE '' END actually outputs that "1/2" character as it treats it numerically for the between comparison. This then blows up on the cast to an INTEGER and
causes the SQL to fail. <<
I tried CAST (CHAT(189) AS INTEGER) as got
Conversion failed when converting the varchar value '½' to data type int.
I tried CAST (CHAR(171) AS INTEGER) as got
conversion failed when converting the varchar value '«' to data type int.
>> The SQL is compiled into the application, so I can't change it, and it's a live customer issue. What I need to be able to do is find a setting in SQL Server or some language setting I can apply that makes this character not able to be considered
a number, and is in fact treated as an opaque piece of text. <<
You are probably screwed. If you can rig a collation, the rest of the app will have more problems. You need to add a CHECK() to the column, clean up the front end and fix the SQL.
--CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
in Sets / Trees and Hierarchies in SQL -
An unexpected exception has been detected in native code outside the VM.
Unexpected Signal : 11 occurred at PC=0x403db221
Function name=(N/A)
Library=/lib/i686/libc.so.6
NOTE: We are unable to locate the function name symbol for the error
just occurred. Please refer to release documentation for possible
reason and solutions.
Dynamic libraries:
08048000-0804c000 r-xp 00000000 03:05 576926 /home/ydsec/jdk1.3/bin/i386/native_threads/java
0804c000-0804d000 rw-p 00003000 03:05 576926 /home/ydsec/jdk1.3/bin/i386/native_threads/java
40000000-40016000 r-xp 00000000 03:06 163843 /lib/ld-2.2.4.so
40016000-40017000 rw-p 00015000 03:06 163843 /lib/ld-2.2.4.so
40018000-40029000 r-xp 00000000 03:05 544957 /home/ydsec/jdk1.3/jre/lib/i386/libverify.so
40029000-4002b000 rw-p 00010000 03:05 544957 /home/ydsec/jdk1.3/jre/lib/i386/libverify.so
4002b000-4002c000 r--p 00000000 03:02 507909 /usr/lib/locale/en_US/LC_IDENTIFICATION
4002c000-4002d000 r--p 00000000 03:02 852002 /usr/lib/locale/en_US/LC_MEASUREMENT
4002d000-4002e000 r--p 00000000 03:02 557092 /usr/lib/locale/en_US/LC_TELEPHONE
4002e000-4002f000 r--p 00000000 03:02 557094 /usr/lib/locale/en_US/LC_ADDRESS
4002f000-40030000 r--p 00000000 03:02 557093 /usr/lib/locale/en_US/LC_NAME
40030000-40031000 r--p 00000000 03:02 376901 /usr/lib/locale/en_US/LC_PAPER
40031000-40032000 r--p 00000000 03:02 622670 /usr/lib/locale/en_US/LC_MESSAGES/SYS_LC_MESSAGES
40032000-40033000 r--p 00000000 03:02 852001 /usr/lib/locale/en_US/LC_MONETARY
40033000-40040000 r-xp 00000000 03:06 81926 /lib/i686/libpthread-0.9.so
40040000-40048000 rw-p 0000c000 03:06 81926 /lib/i686/libpthread-0.9.so
40048000-40051000 r-xp 00000000 03:05 432940 /home/ydsec/jdk1.3/jre/lib/i386/native_threads/libhpi.so
40051000-40052000 rw-p 00008000 03:05 432940 /home/ydsec/jdk1.3/jre/lib/i386/native_threads/libhpi.so
40052000-40242000 r-xp 00000000 03:05 64936 /home/ydsec/jdk1.3/jre/lib/i386/client/libjvm.so
40242000-40340000 rw-p 001ef000 03:05 64936 /home/ydsec/jdk1.3/jre/lib/i386/client/libjvm.so
40357000-4035a000 r-xp 00000000 03:06 163856 /lib/libdl-2.2.4.so
4035a000-4035b000 rw-p 00002000 03:06 163856 /lib/libdl-2.2.4.so
4035b000-4048d000 r-xp 00000000 03:06 81922 /lib/i686/libc-2.2.4.so
4048d000-40492000 rw-p 00131000 03:06 81922 /lib/i686/libc-2.2.4.so
40496000-404a9000 r-xp 00000000 03:06 163861 /lib/libnsl-2.2.4.so
404a9000-404aa000 rw-p 00012000 03:06 163861 /lib/libnsl-2.2.4.so
404ad000-404cf000 r-xp 00000000 03:06 81924 /lib/i686/libm-2.2.4.so
404cf000-404d0000 rw-p 00021000 03:06 81924 /lib/i686/libm-2.2.4.so
404d0000-40504000 r-xp 00000000 03:02 66553 /usr/lib/libstdc++-2-libc6.1-1-2.9.0.so
40504000-40510000 rw-p 00033000 03:02 66553 /usr/lib/libstdc++-2-libc6.1-1-2.9.0.so
40512000-40533000 r-xp 00000000 03:05 544949 /home/ydsec/jdk1.3/jre/lib/i386/libjava.so
40533000-40535000 rw-p 00020000 03:05 544949 /home/ydsec/jdk1.3/jre/lib/i386/libjava.so
40536000-4054a000 r-xp 00000000 03:05 544958 /home/ydsec/jdk1.3/jre/lib/i386/libzip.so
4054a000-4054d000 rw-p 00013000 03:05 544958 /home/ydsec/jdk1.3/jre/lib/i386/libzip.so
4054d000-4127e000 r--s 00000000 03:05 592950 /home/ydsec/jdk1.3/jre/lib/rt.jar
412ab000-41550000 r--s 00000000 03:05 592948 /home/ydsec/jdk1.3/jre/lib/i18n.jar
41550000-41566000 r--s 00000000 03:05 592955 /home/ydsec/jdk1.3/jre/lib/sunrsasign.jar
4360e000-4360f000 r--p 00000000 03:02 507911 /usr/lib/locale/en_US/LC_TIME
4360f000-43610000 r--p 00000000 03:02 245787 /usr/lib/locale/en_US/LC_NUMERIC
49c6f000-49c9a000 r--p 00000000 03:02 245791 /usr/lib/locale/en_US/LC_CTYPE
49c9a000-49ca0000 r--p 00000000 03:02 393305 /usr/lib/locale/en_US/LC_COLLATE
49ca0000-49ca9000 r-xp 00000000 03:05 544956 /home/ydsec/jdk1.3/jre/lib/i386/libnet.so
49ca9000-49caa000 rw-p 00008000 03:05 544956 /home/ydsec/jdk1.3/jre/lib/i386/libnet.so
49caa000-49cad000 r-xp 00000000 03:05 384015 /home/ydsec/lib/libJCommAgent.so
49cad000-49caf000 rw-p 00002000 03:05 384015 /home/ydsec/lib/libJCommAgent.so
49caf000-49cb7000 r-xp 00000000 03:05 208618 /home/ydsec/comm/lib/libydpk.so
49cb7000-49cb8000 rw-p 00007000 03:05 208618 /home/ydsec/comm/lib/libydpk.so
49cbb000-49cc5000 r-xp 00000000 03:06 163877 /lib/libnss_files-2.2.4.so
49cc5000-49cc6000 rw-p 00009000 03:06 163877 /lib/libnss_files-2.2.4.so
4a532000-4aaa9000 r--s 00000000 03:05 352227 /home/ydsec/platformmain.jar
4c4a9000-4c4d6000 r-xp 00000000 03:05 208614 /home/ydsec/comm/lib/libcryptoYDPK.so
4c4d6000-4c4db000 rw-p 0002c000 03:05 208614 /home/ydsec/comm/lib/libcryptoYDPK.so
4c516000-4c52e000 r-xp 00000000 03:05 208616 /home/ydsec/comm/lib/libydapp.so
4c52e000-4c530000 rw-p 00017000 03:05 208616 /home/ydsec/comm/lib/libydapp.so
4c533000-4c551000 r-xp 00000000 03:05 208617 /home/ydsec/comm/lib/libydpciapp.so
4c551000-4c553000 rw-p 0001e000 03:05 208617 /home/ydsec/comm/lib/libydpciapp.so
4c554000-4c569000 r-xp 00000000 03:05 208610 /home/ydsec/comm/lib/libcadll.so
4c569000-4c56a000 rw-p 00014000 03:05 208610 /home/ydsec/comm/lib/libcadll.so
4c56a000-4c582000 r-xp 00000000 03:05 208612 /home/ydsec/comm/lib/libcomm.so.0
4c582000-4c583000 rw-p 00017000 03:05 208612 /home/ydsec/comm/lib/libcomm.so.0
4c591000-4c597000 r-xp 00000000 03:05 208611 /home/ydsec/comm/lib/libcommapi.so.0
4c597000-4c598000 rw-p 00005000 03:05 208611 /home/ydsec/comm/lib/libcommapi.so.0
4c59b000-4c5a6000 r-xp 00000000 03:05 208014 /home/ydsec/comm/lib/libydxmlbase64.so
4c5a6000-4c5a7000 rw-p 0000a000 03:05 208014 /home/ydsec/comm/lib/libydxmlbase64.so
4c5a7000-4c5af000 r-xp 00000000 03:05 16006 /home/ydsec/lib/libCryptographyAgent.so
4c5af000-4c5b0000 rw-p 00007000 03:05 16006 /home/ydsec/lib/libCryptographyAgent.so
4c5c2000-4c5ec000 r-xp 00000000 03:06 163929 /lib/libldap.so.2.0.6
4c5ec000-4c5ed000 rw-p 00029000 03:06 163929 /lib/libldap.so.2.0.6
4c5ed000-4c5f6000 r-xp 00000000 03:06 163927 /lib/liblber.so.2.0.6
4c5f6000-4c5f7000 rw-p 00008000 03:06 163927 /lib/liblber.so.2.0.6
4c5f7000-4c5fb000 r-xp 00000000 03:02 67384 /usr/lib/libxml.so
4c5fb000-4c5fc000 rw-p 00003000 03:02 67384 /usr/lib/libxml.so
4c5fc000-4c605000 r-xp 00000000 03:02 65626 /usr/lib/libsasl.so.7.1.8
4c605000-4c607000 rw-p 00008000 03:02 65626 /usr/lib/libsasl.so.7.1.8
4c607000-4c616000 r-xp 00000000 03:02 426111 /usr/kerberos/lib/libkrb4.so.2.0
4c616000-4c617000 rw-p 0000e000 03:02 426111 /usr/kerberos/lib/libkrb4.so.2.0
4c61b000-4c61e000 r-xp 00000000 03:02 426103 /usr/kerberos/lib/libdes425.so.3.0
4c61e000-4c61f000 rw-p 00002000 03:02 426103 /usr/kerberos/lib/libdes425.so.3.0
4c61f000-4c674000 r-xp 00000000 03:02 426112 /usr/kerberos/lib/libkrb5.so.3.0
4c674000-4c677000 rw-p 00054000 03:02 426112 /usr/kerberos/lib/libkrb5.so.3.0
4c677000-4c686000 r-xp 00000000 03:02 426107 /usr/kerberos/lib/libk5crypto.so.3.0
4c686000-4c688000 rw-p 0000e000 03:02 426107 /usr/kerberos/lib/libk5crypto.so.3.0
4c688000-4c689000 r-xp 00000000 03:02 426099 /usr/kerberos/lib/libcom_err.so.3.0
4c689000-4c68b000 rw-p 00000000 03:02 426099 /usr/kerberos/lib/libcom_err.so.3.0
4c68b000-4c6b4000 r-xp 00000000 03:02 66838 /usr/lib/libssl.so.0.9.6
4c6b4000-4c6b7000 rw-p 00028000 03:02 66838 /usr/lib/libssl.so.0.9.6
4c6b8000-4c766000 r-xp 00000000 03:02 67168 /usr/lib/libcrypto.so.0.9.6
4c766000-4c771000 rw-p 000ad000 03:02 67168 /usr/lib/libcrypto.so.0.9.6
4c774000-4c779000 r-xp 00000000 03:02 65555 /usr/lib/libgdbm.so.2.0.0
4c779000-4c77b000 rw-p 00004000 03:02 65555 /usr/lib/libgdbm.so.2.0.0
4c77b000-4c780000 r-xp 00000000 03:06 163854 /lib/libcrypt-2.2.4.so
4c780000-4c781000 rw-p 00004000 03:06 163854 /lib/libcrypt-2.2.4.so
4c7a8000-4c7af000 r-xp 00000000 03:06 163922 /lib/libpam.so.0.75
4c7af000-4c7b0000 rw-p 00006000 03:06 163922 /lib/libpam.so.0.75
4c7b0000-4c7be000 r-xp 00000000 03:06 163890 /lib/libresolv-2.2.4.so
4c7be000-4c7c0000 rw-p 0000d000 03:06 163890 /lib/libresolv-2.2.4.so
Local Time = Sat Oct 19 23:52:15 2002
Elapsed Time = 34573
# The exception above was detected in native code outside the VM
# Java VM: Java HotSpot(TM) Client VM (1.3.1_02-b02 mixed mode)
code is:
* Class: platform_jni_JCommAgent
* Method: JniSendMessage
JNIEXPORT void JNICALL Java_platform_jni_JCommAgent_JniSendMessage
P_COMM pcm;
int len = 0, iRet;
char msg = NULL, tmpbuf = NULL;
// signal(SIGSEGV, SIG_IGN);
if(NULL == jmsg) {
printf("No message will be sent.\n");
return;
len = msglen;
msg = (char*)malloc(len + 1);
if(NULL == msg) {
printf("Error in malloc for msgbuf.\n");
return;
memset(msg, 0, len + 1);
tmpbuf = (char*)env->GetByteArrayElements(jmsg, NULL);
memcpy(msg, tmpbuf, len);
env->ReleaseByteArrayElements(jmsg, (jbyte*)tmpbuf, 0);
tmpbuf = (char*)env->GetStringUTFChars(target, 0);
strcpy(pcm.target, tmpbuf);
env->ReleaseStringUTFChars(target, tmpbuf);
tmpbuf = (char*)env->GetStringUTFChars(sendmod, 0);
pcm.sendMod = atoi(tmpbuf);
env->ReleaseStringUTFChars(sendmod, tmpbuf);
tmpbuf = (char*)env->GetStringUTFChars(servid, 0);
pcm.servId = atoi(tmpbuf);
env->ReleaseStringUTFChars(servid, tmpbuf);
tmpbuf = (char*)env->GetStringUTFChars(timeout, 0);
pcm.timeout = atoi(tmpbuf);
env->ReleaseStringUTFChars(timeout, tmpbuf);
tmpbuf = (char*)env->GetStringUTFChars(sync, 0);
pcm.sync = atoi(tmpbuf);
env->ReleaseStringUTFChars(sync, tmpbuf);
if(NULL != filename) {
tmpbuf = (char*)env->GetStringUTFChars(filename, 0);
strcpy(pcm.fileName, tmpbuf);
env->ReleaseStringUTFChars(filename, tmpbuf);
else {
pcm.fileName[0] = '\0';
tmpbuf = (char*)env->GetStringUTFChars(cryptlevel, 0);
pcm.cryptoLevel = atoi(tmpbuf);
env->ReleaseStringUTFChars(cryptlevel, tmpbuf);
iRet = __sendMessage(&pcm, msg, strlen(msg) + 1);
jstring temp = env->NewStringUTF(msg);
env->ReleaseStringUTFChars(temp,msg);
//free(msg);
printf("SendMessage return value:%8d\n", iRet);
* Class: platform_jni_JCommAgent
* Method: JniGetMessage
* Signature: ()[B
JNIEXPORT jbyteArray JNICALL Java_platform_jni_JCommAgent_JniGetMessage
(JNIEnv *env, jclass jcls)
int nRet = 0;
char *request;
jbyteArray jresponse = NULL;
int len, servId = 7777777;
int timeout = 30;
// signal(SIGSEGV, SIG_IGN);
printf("Entering Java_platform_jni_JCommAgent_JniGetMessage...\n");
nRet = __login(7777777);
printf("Login return value %d = %d\n", servId, nRet);
printf("begin receive message \n");
nRet = __getMessage(&request, &len, &servId, timeout);
printf("GetMessage return value = %d\n", nRet);
//printf("request is %s\n",request);
if(NULL == request) return jresponse;
if(nRet != 0) {
printf("Get Message failed!\n");
//if(NULL != request) FreeBuf(request);
return jresponse;
if(len <= 0) {
printf("Get Message length <= 0!\n");
//if(NULL != request) FreeBuf(request);
return jresponse;
//printf("%s\n",request);
jresponse = env->NewByteArray(len);
env->SetByteArrayRegion(jresponse, 0, len, (jbyte *)request);
jstring temp = env->NewStringUTF(request);
env->ReleaseStringUTFChars(temp,request);
// if(NULL != request) FreeBuf(request);
printf("Leaving Java_platform_jni_JCommAgent_JniGetMessage...\n");
return jresponse;What is the question?
I can see a number of places where error checking is missing. And if you do bad things with buffers in C/C++ it blows up.
Additionally the code is not complete as one of the methods is missing the argument parameter list for the method. -
Hello All,
I am facing one problem on database ,I have sysadmin role but I am unable to generate script of stored procedures and views.
getting below error.
please help me .
Property TextHeader is not available for StoredProcedure '[dbo].[spname]'. This property may not exist for this object, or may not be retrievable due to insufficient access rights. The text is encrypted.
mastanvali shaikthanks for immediate reply on my query .
finally I got solution for my problem from one of my friend.
I tried below solution for my problem.
--create procedure on sql server.
create
PROCEDURE dbo.ObjectEncryptionCracker
@object_name
NVARCHAR(MAX)
AS
BEGIN
DECLARE @secret VARBINARY(MAX);
DECLARE @known_encrypted VARBINARY(MAX);
DECLARE @known_plain VARBINARY(MAX);
DECLARE @object_type NVARCHAR(MAX);
SELECT @secret
= imageval
FROM sys.sysobjvalues
WHERE objid
= OBJECT_ID(@object_name);
DECLARE @cmd
NVARCHAR(MAX);
SELECT @cmd =
CASE type_desc
WHEN 'SQL_SCALAR_FUNCTION'
THEN 'ALTER FUNCTION '
+ @object_name +
'()RETURNS INT WITH ENCRYPTION AS BEGIN RETURN 0;END;'
WHEN 'SQL_TABLE_VALUED_FUNCTION'
THEN 'ALTER FUNCTION '
+ @object_name +
'()RETURNS @r TABLE(i INT) WITH ENCRYPTION AS BEGIN RETURN END;'
WHEN 'SQL_INLINE_TABLE_VALUED_FUNCTION'
THEN 'ALTER FUNCTION '
+ @object_name +
'()RETURNS TABLE WITH ENCRYPTION AS RETURN SELECT 0 i;'
WHEN 'SQL_STORED_PROCEDURE'
THEN 'ALTER PROCEDURE '
+ @object_name +
' WITH ENCRYPTION AS RETURN 0;'
END
FROM sys.objects
WHERE object_id
= OBJECT_ID(@object_name);
SELECT @cmd
= REPLICATE(CAST(CHAR(32)
AS NVARCHAR(MAX)),
DATALENGTH(@secret))
+ @cmd;
SELECT @known_plain
= CAST(@cmd
AS VARBINARY(MAX));
BEGIN
TRAN;
EXEC(@cmd);
SELECT @known_encrypted = imageval
FROM sys.sysobjvalues
WHERE objid
= OBJECT_ID(@object_name);
ROLLBACK;
DECLARE @i
INT = 0;
DECLARE @plain VARBINARY(MAX)
= 0x;
WHILE @i
< DATALENGTH(@secret)
BEGIN
SET @plain = @plain
+ CAST(REVERSE(CAST(CAST(SUBSTRING(@secret,
@i, 2)
AS SMALLINT)
^ CAST(SUBSTRING(@known_plain, @i,
2) AS
SMALLINT)
^ CAST(SUBSTRING(@known_encrypted, @i,
2) AS
SMALLINT) AS
BINARY(2)))
AS BINARY(2));
SET @i += 2;
END
SET @cmd
= N'SELECT (SELECT ''--''+CHAR(13)+CHAR(10)+''GO''+CHAR(13)+CHAR(10)+'
+ N'CAST(@plain AS NVARCHAR(MAX))+CHAR(13)+CHAR(10)+''GO''+CHAR(13)+CHAR(10)+''--'''
+ N' AS [processing-instruction(sql)] FOR XML PATH(''''),TYPE) AS [object_definition for '
+ REPLACE(@object_name,
']]') +
EXEC sp_executesql
@cmd, N'@plain VARBINARY(MAX)', @plain;
END;
--connect sql server instance with DAC.
--after that execute below script
exec ObjectEncryptionCracker 'encrypted stored procedure'
--it gives stored procedure code after that altered procedure removed
with encryption from procedure.
it works for me.
Thanks to all who gave the response on immediate!!!
mastanvali shaik -
Convert Unicode characters to ASCII
Hi,
I need to convert few Unicode characters in a text file to ASCII ..Pls help help to get a java program to convert the few Unicode characters and output to a different text file with Ascii .No idea i just did google search hope this might help you
public class UnicodeCast {
public static void main(String[] args) {
// Simple arithmetic on chars - VERY BAD for internationalization!
System.out.println("'a' + 1 = " + (char) ('a' + 1));
// Truncate characters by casting to byte (16-bit to 8-bit casting)
char yen = '\u00a5'; // Japanese Yen
char aeAcute = '\u01FC'; // Roman AE with acute accent
System.out.println("Yen as byte: " + (byte) yen);
System.out.println("AE' as byte: " + (byte) aeAcute);
System.out.println("Yen as byte to char: " + (char) (byte) yen);
System.out.println("AE' as byte to char: " + (char) (byte) aeAcute);
// Convert ints to chars
int iYen = 0xa5;
int iaeAcute = 0x01fc;
System.out.println("Yen from int = " + (char) iYen);
System.out.println("AE' from int = " + (char) iaeAcute);
} -
Character engoding during RFC module call
Hi all!
I have FunctionalModule which calls remote FM and pass string to it. In remote FM I can't see proper symbols but seems encoding problem. I pass char10 variable. Importing variable in remote FM is char10 as well.
Any thoughts?
Seems problem is with casting char and integer. I moved integer to char-like variable before passing it to remote FM
Edited by: Andrey Selivanov on Aug 19, 2010 9:59 AMyes. it is ok.
I have already said - it is the problem with concatenating integer and char and passing as a char. integer seems coming in HEX format... -
JbyteArray - char * and jlong - long
Hi,
I've been trying to figure out how to convert the following:
jbyteArray to a char *, void *, or something similar
jlong to a long
This is for C++ code.
I can't seem to figure it out, or find any documentation about this conversion online!!
Thanks.Generally, avoid casting from jlong to long as the definition of long is platform dependent and not necessarily a 64 bit wide. Otherwise a regular cast works here although you may lose bits when casting to a 32-bit integer.
A byte array can be accessed through the following:
jsize len = (*env)->GetArrayLength(env, arr);
jbyte *body = (*env)->GetByteArrayElements(env, arr, 0);Casting jbyte to char should not be critical as both are most likely single-byte entities.
http://java.sun.com/docs/books/tutorial/native1.1/implementing/array.html
http://java.sun.com/docs/books/tutorial/native1.1/implementing/cpp.html -
Error when try a "cast" in a char(13) to get a varchar....
AVAB_Codigo it's a "char(13)", get me a error :
"Invalid operator for data type. Operator equals boolean AND, type equals varchar."
when i use a cast... the error still appear,..... what should i do ?
-- 1st attemp --------------------------------------------------------------------
case when (SUBSTRING(AVAB_Codigo,5,1)='0')
then Right(AVAB_Codigo,6)
else (SUBSTRING(AVAB_Codigo,5,1) & Right(AVAB_Codigo,6))
end as [UL/UE]
-- 2nd attempt ----------------------------------------------------------------------
case when (SUBSTRING(cast(AVAB_Codigo as varchar(10)),5,1)='0')
then Right(cast(AVAB_Codigo as varchar(10)),6)
else (SUBSTRING(cast(AVAB_Codigo as varchar(10)),5,1) & Right(cast(AVAB_Codigo as varchar(10)),6))
end as [UL/UE],The concatenation operation is the plus sign, not the ampersand.
-
Casting Number as Char - how to hide decimal places?
I am casting a number as a Char because I am concatenating it with other things. The problem is that when I cast to char, it displays two decimal places of just 0's. I really don't want to show the decimal place or anything after it. Is there a way to remove them?
ThanksHi,
You can have two approaches for the same.
1> cast( cast(column as int) as char)
2> Go to the column properties(i.e the finger mark on the coulmn heading). Then select the data format tab and check the override the default data format tab. Then you can set the decimal places.
Maybe you are looking for
-
. I have 6th gen iPod nano. When I try to sync it my computer tells me it has malfunctioned and Windows does not recognize it. My iPhone syncs fine so the problem must be the iPod. I have reset the iPod several times and no luck. Any suggestions
-
Adobe photoshop elements 13 server CONNECTION ERROR
Failed to connect using Adobe Application Manager and whilst trying to activate via PS Elements 13 directly. I have internet connectivity. Tried: reviewing the local hosts redirect file disabling antivirus disabling firewall renaming OOBE folder rena
-
Missing Exposure EXIF Metadata After RAW Conversion
I am running Photoshop CS6 on a 64-bit Windows 7 PC. Since upgrading from CS5 I have noticed that the Exposure EXIF metadata as viewed in Bridge vanishes after RAW conversion/adjustment of my images. I've read at least one other posting to the foru
-
Multiple Genres with Smart Playlists
I've searched a lot on this topic and there appears to be little, so I thought I'd post my solution. (itunes 10) I create my own genres, such as "Easy Rock Jazz" or "Blues Jazz" or "Blues Rock", etc. Even have some that are "Easy Rock Jazz Blues", me
-
Unable to BookMark or resume SCORM captivate projects
We have created a number of flash e-learning modules using captivate 2, these have been published using SCORM 1.2 standards and imported using a manifest file into our LMS system (Essencia), this seems to work fine, it will happily launch the course,