Passing byte Arrays broken in 1.4?

I have an application that I am porting from 1.2.2 to 1.4. Code that used to work fine is now broken. All byte arrays that are passed through the JNI have each element set to 0.
Is this a known bug, or has something changed in the JNI API? Here is a sample of my code which used to work fine, but is now broken:
From a .h:
* Structure for information about a single target
struct TARGET_INFO_STR
char Name[MAX_TARGET_NAME_SIZE + 1];
char Protocol[MAX_PROTOCOL_NAME_SIZE + 1];
char State[MAX_STATE_SIZE];
int Selected;
int Error;
int Online;
* Structure returned for a target request
struct TARGET_LIST_STR
int Target_Count;
int Selected_Count;
struct TARGET_INFO_STR Targets[MAX_TARGETS];
From the JNI C code:
JNIEXPORT void JNICALL Java_merge_jni_mbinterface_C_1Query_1Targets (JNIEnv *A_env,
jobject A_obj)
struct TARGET_LIST_STR Reply;
int i;
jbyteArray name;
jbyte *bptr;
int j;
jclass class = (*A_env)->GetObjectClass(A_env, A_obj);
jmethodID mid = (*A_env)->GetMethodID(A_env, class, "J_add_target",
     "([BLjava/lang/String;Ljava/lang/String;ZZZ)V");
    jstring protocol;
    jstring state;
    Reply = GetTargets();
    /* Pass the target information to the GUI */
    for (i = 0; i < Reply.Target_Count; i++) {
        protocol = (*A_env)->NewStringUTF(A_env, Reply.Targets[i].Protocol);
state = (*A_env)->NewStringUTF(A_env, Reply.Targets.State);
name = (jbyteArray)(*A_env)->NewByteArray(A_env, strlen(Reply.Targets[i].Name));
bptr = (jbyte *)(*A_env)->GetByteArrayElements(A_env, name, NULL);
for (j=0;j<strlen(Reply.Targets[i].Name);j++)
bptr[j] = (jbyte)Reply.Targets[i].Name[j];
(*A_env)->CallVoidMethod(A_env, A_obj, mid,
               name,
               protocol,
               state,
               (jboolean)Reply.Targets[i].Selected,
               (jboolean)Reply.Targets[i].Online,
(jboolean)Reply.Targets[i].Error );
(*A_env)->ReleaseByteArrayElements( A_env, retn, bptr, 0 );
(*A_env)->DeleteLocalRef( A_env, name );
(*A_env)->DeleteLocalRef( A_env, protocol);
(*A_env)->DeleteLocalRef( A_env, state);
(*A_env)->DeleteLocalRef( A_env, class );
return;
Here is the signature of the Java side of this call:
public void J_add_target (byte[] name, String protocol, String state,
               boolean selected, boolean online, boolean error) {
The strings and booleans are all passed back fine, the byte array is the proper length, but all of its values are 0.

Your call to (*A_env)->ReleaseByteArrayElements( A_env, retn, bptr, 0 );
should be done before the CallVoidMethod call.
Otherwise you will get exactly the effect you describe if the array was copied by GetByteArrayElements instead of it giving you a direct pointer to the array data. This may indeed be a change between the earlier version and 1.3 or 1.4.
Sylvia.

Similar Messages

  • Error passing byte array in soap request

    Hi,
    i am trying to pass byte arrays (and also java.lang.Byte array) as parameter in
    a soap request.
    to do so i have defined a simple web service under weblogic 7.0.
    then i test it through the WebLogic Webservice standard testing home page.
    the value field for testing my web service is already filled by weblogic with:
    <bytes xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:type="xsd:base64Binary">aopd</bytes>
    i only need to invoke my web service to test it.
    then an exception is raised:
    javax.xml.soap.SOAPException: failed to deserialize xml:weblogic.xml.schema.binding.DeserializationException:
    error decoding base64binary - with nested exception: [java.io.IOException: Error
    in encoded stream] javax.xml.soap.SOAPException: failed to deserialize xml:weblogic.xml.schema.binding.DeserializationException:
    error decoding base64binary - with nested exception: [java.io.IOException: Error
    in encoded stream] at weblogic.webservice.core.DefaultPart.toJava(DefaultPart.java:301)
    at weblogic.webservice.tools.pagegen.SampleInstance.getJavaObject(SampleInstance.java:130)
    at weblogic.webservice.server.servlet.ServletBase.getJavaParams(ServletBase.java:296)
    at weblogic.webservice.server.servlet.ServletBase.invokeOperation(ServletBase.java:239)
    at weblogic.webservice.server.servlet.WebServiceServlet.invokeOperation(WebServiceServlet.java:306)
    at weblogic.webservice.server.servlet.ServletBase.handleGet(ServletBase.java:198)
    at weblogic.webservice.server.servlet.ServletBase.doGet(ServletBase.java:124)
    at weblogic.webservice.server.servlet.WebServiceServlet.doGet(WebServiceServlet.java:224)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:740) at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
    at weblogic.servlet.internal.ServletStubImpl$ServletInvocationAction.run(ServletStubImpl.java:1058)
    at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:401)
    at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:306)
    at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:5412)
    at weblogic.security.service.SecurityServiceManager.runAs(SecurityServiceManager.java:744)
    at weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppServletContext.java:3086)
    at weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestImpl.java:2544)
    at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:153) at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:134)
    any idea?

    Hi,
    Looks like a known bug (CR087883).
    Thanks,
    Bruce
    cyrille puget wrote:
    Hi,
    i am trying to pass byte arrays (and also java.lang.Byte array) as parameter in
    a soap request.
    to do so i have defined a simple web service under weblogic 7.0.
    then i test it through the WebLogic Webservice standard testing home page.
    the value field for testing my web service is already filled by weblogic with:
    <bytes xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:type="xsd:base64Binary">aopd</bytes>
    i only need to invoke my web service to test it.
    then an exception is raised:
    javax.xml.soap.SOAPException: failed to deserialize xml:weblogic.xml.schema.binding.DeserializationException:
    error decoding base64binary - with nested exception: [java.io.IOException: Error
    in encoded stream] javax.xml.soap.SOAPException: failed to deserialize xml:weblogic.xml.schema.binding.DeserializationException:
    error decoding base64binary - with nested exception: [java.io.IOException: Error
    in encoded stream] at weblogic.webservice.core.DefaultPart.toJava(DefaultPart.java:301)
    at weblogic.webservice.tools.pagegen.SampleInstance.getJavaObject(SampleInstance.java:130)
    at weblogic.webservice.server.servlet.ServletBase.getJavaParams(ServletBase.java:296)
    at weblogic.webservice.server.servlet.ServletBase.invokeOperation(ServletBase.java:239)
    at weblogic.webservice.server.servlet.WebServiceServlet.invokeOperation(WebServiceServlet.java:306)
    at weblogic.webservice.server.servlet.ServletBase.handleGet(ServletBase.java:198)
    at weblogic.webservice.server.servlet.ServletBase.doGet(ServletBase.java:124)
    at weblogic.webservice.server.servlet.WebServiceServlet.doGet(WebServiceServlet.java:224)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:740) at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
    at weblogic.servlet.internal.ServletStubImpl$ServletInvocationAction.run(ServletStubImpl.java:1058)
    at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:401)
    at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:306)
    at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:5412)
    at weblogic.security.service.SecurityServiceManager.runAs(SecurityServiceManager.java:744)
    at weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppServletContext.java:3086)
    at weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestImpl.java:2544)
    at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:153) at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:134)
    any idea?

  • How to pass byte array / binary data to a webservice as parameter in osb

    i have a webservice that has a byte array input parameter. i tried to use this WS in a message flow via service-callout. the problem i encountered is the following: since webservice call by using service-callout requires you to use an xml input as part of soap message, i insert both of $body/ctx:binary-content and $body/ctx:binary-content/@ref variables individually into this xml-message to pass binary-data to WS. When i debug the code, i see that it make calls to WS with $body/ctx:binary-content/@ref parameter, but the byte array passed is empty(not NULL)...
    note: i tried java-callut instead of service-called and used $body/ctx:binary-content as input parameter it worked. i think, this is because java-callout doesnt need an xml input and enable to take variables as is...
    can anybody help me to solve the problem with service-callout please?
    here is the input i use to call ws with service-callout method...
    <iso2Xml xmlns="http://www.mycompany.com.tr">
    <request>{$body/ctx:binary-content/@ref}</request>
    </iso2Xml>
    and this is my WS's signature:
    @WebMethod
    public String iso2Xml(byte[] request)

    Hi
    See this thread
    /message/2187817#2187817 [original link is broken]
    Kind Regards
    Mukesh

  • Problem with string constructor when using byte array as parameter

    I am creating a string using constructor and passing byte array as parameter.This byte array i am getting from MessageDigest's digest() method,i.e. a hash value.
    The problem is when i iterate through byte array i can able to print all the values in byte array.But when i construct a string from that byte array and printing that string ,that is printing some unknown characters.
    I don't know whether i need to pass charsequence to the constructor and the type of charsequence.Can anybody help me?
    Thanks in advance

    Is there some problem today? I'm getting this sort of thing all over.
    I already told you and so did Kayaman. Don't. String is not a holder for binary data. You have to Base-64 encode it. If you don't you cannot reconstruct the original binary digest value, so putting it into a database is completely utterly and entirely pointless.
    Is that clear enough?

  • How do I get a byte array from an object passed into the JNI?

    This is what my java code looks like:
    public class streamedData
    protected byte[] m_value = null;
    public byte[] getByteArray ()
    return m_value;
    /* code not pertaining to this question snipped. */
    jclass streamedDataClass = env->GetObjectClass(jstreamedData);
    // Get methodIDs for the various NPKI_Extension methods
    value = env->GetMethodID(streamedDataClass, "getByteArray", "()[B");
    lstreamedData->value = (unsigned char *)malloc (lstreamedData->length);
    if (lstreamedData->value == NULL)
    return INSUFFICIENT_MEMORY;
    memset (lstreamedData->value, 0, lstreamedData->length);
    memcpy (lstreamedData->value, env->CallByteMethodA(streamedDataClass, value, NULL), lstreamedData->length);
    This is not working.
    My question is, how do I get a copy of or read m_value in the JNI layer? Do I have to make the byte array public and access it as a field ID?
    Any help would be appreciated. Why oh why can't there be a CallByteArrayMethod????

    My question is, how do I get a copy of or read m_value in the JNI layer? Do I have to make the byte array public and access it as a field ID?
    You can retrieve a handle to the byte array, through a method call, as you're doing now, or by directly accessing it through GetFieldID.
    In the case of the method call, you'll want to do:jmethodID getByteArrayMethod = env->GetMethodID(streamedDataClass, "getByteArray", "()[B");
    jbyteArray byteArray = static_cast<jbyteArray>( env->CallObjectMethod( jstreamedData, getByteArrayMethod ) );In the case of field access, you can do:jfieldID m_valueFieldID = env->GetFieldID( streamedDataClass, "m_value", "[B" );
    jbyteArray byteArray = static_cast<jbyteArray>( env->GetObjectField( jstreamedData, m_valueFieldID ) );Once you have byteArray, you need to access it using the array operations:lstreamedData->value = env->GetByteArrayElements( byteArray, 0 );
    // Do what you want to do, then release the array
    env->ReleaseByteArrayElements( byteArray, lstreamedData->value, 0 );As always, Jace, http://jace.reyelts.com/jace, makes this easier. For example,void printByteArray( jobject jstreamedData ) {
      streamedData data( jstreamedData );
      JArray<JByte> byteArray = streamedData.m_value();
      for ( int i = 0; i < byteArray.length(); ++i ) {
        cout << byteArray[ i ];
    }God bless,
    -Toby Reyelts

  • Converting ASCII text (byte array ending in null) to a String

    Hi all,
    I am trying to convert a null terminated ascii string stored in a byte array to a java String. When I pass the byte array to the String constructor it
    does not detect/interpret the null as a terminator for the ascii string. Is this something I have to manually program in? ie Check for where the null is and then
    pass that subarray of everything before the null to the String constructor?
    example of problem
    //               A   B  C   D   null   F   (note F is junk in the array, and should be ignored since it is after null)
    byte[] asciiArray = { 65, 66, 67, 68, 0,  70 };
    System.out.println(new String(asciiArray, "UTF-8"));
    //this prints ABCD"sqare icon"F

    Why do you expect the null character to terminate the string? If you come from a C or C++ background, you need to understand that java.lang.String is not just a mere character array. It's a full-fledged Java object that knows its length without having any need for null terminator. So Ascii 0 is just another character for String object. To achieve what you want to do, you have to manually loop through the byte array and stop when you encounter a null character.

  • How to add 16 bit message sequential number to the byte array

    hi
    iam trying to implement socket programming over UDP. Iam writing for the server side now.I need to send an image file from server to a client via a gateway so basically ive to do hand-shaking with the gateway first and then ive to send image data in a sequence of small messages with a payload of 1 KB.The data message should also include a header of 16 bit sequential number and a bit to indicate end of file.
    Iam able to complete registration process(Iam not sure yet).I dnt know how to include sequential number and a bit to indicate end of file.
    I would like to have your valuable ideas about how to proceed further
    package udp;
    import java.io.*;
    import java.net.*;
    import java.util.*;
    public class Sender  {
        protected BufferedReader in = null;
        protected FileInputStream image=null;
        protected static boolean end_of_file=true;
    /** pass arguments hostname,port,filename
    * @param args
    * @throws IOException
       public static void main(String[] args) throws IOException{
            DatagramSocket socket = new DatagramSocket(Integer.parseInt(args[1]));
            boolean more_messages = true;
              String str1=null;
                * gateway registration
                try{
                     //send string to emulator
                    String str="%%%GatewayRegistration SENDER test delay 10 drop 0 dupl 0 bandwidth 1000000";
                    byte[] buff=str.getBytes();
                    InetAddress emulator_address = InetAddress.getByName(args[0]);
                    DatagramPacket packet = new DatagramPacket(buff, buff.length,emulator_address,Integer.parseInt(args[0]));
                    socket.send(packet);
                        // figure out response
                    byte[] buf = new byte[1024];
                    DatagramPacket recpack=new DatagramPacket(buf,buf.length);
                    socket.receive(recpack);
                   // socket.setSoTimeout(10000);
                    String str2=str1.valueOf(new String(recpack.getData()));
                    if(socket.equals(null))
                         System.out.println("no acknowledgement from the emulator");
                        socket.close();
                    else if(str2=="%%%GatewayConfirmation")
                    //     String str1=null;
                         System.out.println("rec message"+str2);
                    else
                         System.out.println("not a valid message from emulator");
                         socket.close();
                catch (IOException e) {
                    e.printStackTrace();
                      end_of_file = false;
         /**create a packet with a payload of 1     KB and header of 16 bit sequential number and a bit to indicate end of file
      while(end_of_file!=false)
          String ack="y";
          String seqnum=
           File file = new File(args[2]);                               
                    InputStream is = new FileInputStream(file);                 
            socket.close();
      private byte[] byteArray(InputStream in) throws IOException {
             byte[] readBytes = new byte[1024]; // make a byte array with a length equal to the number of bytes in the stream
          try{
             in.read(readBytes);  // dump all the bytes in the stream into the array
            catch(IOException e)
                 e.printStackTrace();
            return readBytes;
      

    HI Rolf.k.
    Thank you for the small program it was helpfull.
    You got right about that proberly there  will be conflict with some spurios data, I can already detect that when writing the data to a spreadsheet file.
    I writes the data in such a way, that in each line there will be a date, a timestamp, a tab and a timestamp at the end. That means two columns.
    When i set given samplerate up, that controls the rate of the data outflow from the device, (1,56 Hz - 200 Hz),   the data file that i write to , looks unorderet.
     i get more than one timestamp and severel datavalues in every line and so on down the spreadsheet file.
    Now the question is: Could it be that the function that writes the data to the file,  can't handle the speed of the dataflow in such a way that the time stamp cant follow with the data flowspeed. so i'm trying to set the timestamp to be  with fractions of the seconds by adding the unit (<digit>) in the timestamp icon but its not working. Meaby when i take the fractions off a second within the timestamp i can get every timestamp with its right data value. Am i in deeb water or what do You mean!??
    AAttached Pics part of program and a logfile over data written to file
    regards
    Zamzam
    HFZ
    Attachments:
    DataFlowWR.JPG ‏159 KB
    Datalogfile.JPG ‏386 KB

  • How to save a value in a byte array, retrieve it and display it?

    Hi,
    I am doing a project for my data structures class that involves saving a value (given in String format) in a byte array (our 'memory'). Initially I just tried casting character by character into the byte array and casting back to char[] for retrieval (using .toString() to return what's supposed to be the original string), but this did not work. I tried the .getBytes() method, applying it to the string and then trying to recover it by placing the contents of the 'memory' in a byte array and applying toString(), but that didn't work either. I looked a bit and found this class, CharsetEncoder and CharsetDecoder. I tried to use these but when I try the compiler tells me I cannot instantiate CharsetDecoder because it is an abstract class. At this point I'm at a loss as to what I can do. Is there any way to place a string in a byte array and then recover the string in it's original format? For example, I might save a value in my particular class of "456". But when I try to recover the value from my 'memory' i.e. the byte array, it comes out like [gnue@hnju.... or something similar. I need it to output the original string ("456").
    Below is my code as it is right now, for the methods setValue and getValue.
    Thanks!
    public void setValue(String value) throws InvalidValueException {
         //… stores the given value in the memory area assigned to the variable
              if(this.type.isValidValue(value)){
                   bytes = value.getBytes();
                   int i,j,k;
                   int l=0;//might be wrong?
                   int ad=address-(address%4);
                   mem.readWord(ad);
                   reg=mem.getDataRegister();
                   if((address%4)+bytes.length-1<4){
                        for(i=address%4;i<address%4+bytes.length;i++)
                             reg.setByte(i, bytes[i]);
                        mem.setDataRegister(reg);
                        mem.writeWord(ad);
                   else if((address%4)+bytes.length-1>=4){
                        if(address%4!=0){
                             for(i=address%4;i<4;i++){
                                  reg.setByte(i, bytes);
                                  l++;
                             mem.setDataRegister(reg);
                             mem.writeWord(ad);
                             ad+=mem.WORDSIZE;
                        while(ad<address+bytes.length-(address+bytes.length)%4){
                             for(j=0;j<4;j++){
                                  reg.setByte(j, bytes[j+l]);
                                  l++;
                             mem.setDataRegister(reg);
                             mem.writeWord(ad);
                             ad+=mem.WORDSIZE;
                        if((address+bytes.length)%4!=0){
                             mem.readWord(ad);
                             reg=mem.getDataRegister();
                             for(k=0;k<(address+bytes.length)%4;k++){
                                  reg.setByte(k, bytes[k+l]);
                                  l++;
                             mem.setDataRegister(reg);
                             mem.writeWord(ad);
                   else
                        throw new InvalidValueException("The value passed is not valid.");
         /** Gets the current value of the variable.
         @return current value converted to String
         public String getValue() {
              //… returns the current value stored in the corresponding memory area
              //… value is converted to String
              bytes=new byte[this.getType().getSize()];
              int i,j,k;
              int l=0;//might be wrong?
              int ad=address-(address%4);
              mem.readWord(ad);
              reg=mem.getDataRegister();
              if((address%4)+bytes.length-1<4){
                   for(i=address%4;i<address%4+bytes.length;i++)
                        bytes[i] = reg.readByte(i);
              else if((address%4)+bytes.length-1>=4){
                   if(address%4!=0){
                        for(i=address%4;i<4;i++){
                             bytes[i] = reg.readByte(i);
                             l++;
                        ad+=mem.WORDSIZE;
                   mem.readWord(ad);
                   reg=mem.getDataRegister();
                   while(ad<address+bytes.length-(address+bytes.length)%4){
                        for(j=0;j<4;j++){
                             bytes[j+l] = reg.readByte(j);
                             l++;
                        ad+=mem.WORDSIZE;
                   if((address+bytes.length)%4!=0){
                        mem.readWord(ad);
                        reg=mem.getDataRegister();
                        for(k=0;k<(address+bytes.length)%4;k++){
                             bytes[k+l] = reg.readByte(k);
                             l++;
              return bytes.toString();

    You can certainly put it into a byte array and then construct a new String from that byte array. Just calling toString doesn't mean you'll automatically get a meaningful string out of it. Arrays do not override the toString method, so the use the one inherited from object.
    Look at String's constructors.

  • Problem in using the install()'s byte array values?

    I tried to pass the values to the OwnerPIN object at the time of initialization. But when I try to install the applet I will get 6A80 error code . Can anybody tell me why I am getting this message. And if i use some different data values for pin.update() then I wont come across those error codes
    public static void install(byte[] bArray, short bOffset, byte bLength)     {          
              // GP-compliant JavaCard applet registration
              new SampleApp(bArray, (short) (bOffset), bLength);                    
         private SampleApp(byte[] bArray, short bOffset, byte bLength){
              pin = new OwnerPIN(PIN_TRY_LIMIT, MAX_PIN_SIZE);
              pin.update(bArray,bOffset, bLength);          
                    register();
    cm>  install -i a00000006203010c0601 -l -q C9#(1122331122331122) a00000006203010c06 a00000006203010c0601
    => 80 E6 0C 00 2E 09 A0 00 00 00 62 03 01 0C 06 0A    ..........b.....
        A0 00 00 00 62 03 01 0C 06 01 0A A0 00 00 00 62    ....b..........b
        03 01 0C 06 01 01 10 0A C9 08 11 22 33 11 22 33    ..........."3."3
        11 22 00 00
    ( 5411 usec)
    <= 6A 80

    GP 2.1.1, A.2 GlobalPlatform on a Java Card, Installation:
    Installation
    In Section 3.1 - The Method install of the Java Card� 2.1.1 Runtime Environment (JCRE) Specifications,
    the parameters passed to the method are defined to be initialization parameters from the contents of the incoming
    byte array parameter.
    In the definition of the install method of the Class Applet of the Java Card� 2.1.1 Application Programming
    Interface, the install parameters to be supplied must be in the format defined by the applet.
    This specification expands on this requirement and further defines the content of the install parameters. This
    expansion affects both the implementation of an OPEN and the behavior of a Java Card applet developed for a
    GlobalPlatform card. It does not affect the definition of the install method of the Class Applet of the Java
    Card� 2.1.1 Application Programming Interface specification.
    The install parameters shall identify the following data, present in the INSTALL [for install] command (see
    Section 9.5.2.3.2 - Data Field for INSTALL [for install]):
    � The instance AID,
    � The Application Privileges and,
    � The Application Specific Parameters.
    [While the APDU command contains install parameters representing TLV coded system and application specific parameters, the
    application only requires knowledge of the Application Specific Parameters i.e. only LV of the TLV coded structure �C9� are
    present as parameters.]
    The OPEN is responsible for ensuring that the parameters (bArray, bOffset and bLength) contain the
    following information:
    The array, bArray, shall contain the following consecutive LV coded data:
    _� Length of the instance AID,_
    _� The instance AID,_
    _� Length of the Application Privileges,_
    _� The Application Privileges,_
    _� Length of the Application Specific Parameters and,_
    _� The Application Specific Parameters._
    The byte, bOffset, shall contain an offset within the array pointing to the length of the instance AID.
    The byte, bLength, shall contain a length indicating the total length of the above-defined data in the array.
    The applet is required to utilize the instance AID as a parameter when invoking the register (byte []
    bArray, short bOffset, byte bLength) method of the Class Applet of the Java Card� 2.1.1
    Application Programming Interface specification.

  • How to read a large file(size around 100 kbytes) into a byte array in JAVA

    aa

    But I cannot use array subscript as a long value.what do you mean?
    are you rying the following:
    long aSize = 100000;
    byte[] array = new byte[aSize];
    if this is the case, then don't do it, for your 100k file int is far more than enough.
    but in case you jsut get error while:
    byte b = array[100000];
    then it's probably because you'r array is of size 100000, that means you have bytes from 0 to 99999 in there, and 100000 is one passed the end of the array.... jus in case make your array size to be 1234567 (far more than needed for your file) and see if you still get that exception, if not, then your array was too small. but if it fixes your prob, then don't leave it as it is, try to work out the right size for array and use that....
    i wouldn't recommend using static array size, since that file might some day be bigger than you expected, and then you'd have to recompile your program.
    HTH

  • Reading a JPEG as a byte array.

    Hello everyone.
    I am developing a project which involves using JPEG images with Java. I would like to use the java.awt.Image class but there's a snag:
    I am reading the file in as a byte array and then need to pass the bytes to an object to be displayed as an image. "why not just read it as a normal JPEG file in the first place?!" I hear you say. Yes, this would be easier but there is a good reason as to why I am reading as a byte array first and this cannot be worked around.
    If anyone has some suggestions I'd very much like to hear them.
    All the best,
    P.M.

    If all you're going to do is display the image, then you can use Toolkit#createImage(byte[] imagedata). That's about as direct as you can get. If you plan on manipulating the images in any way, though, then as above post says ByteArrayInputStream + ImageIO is the way to go.
    "why not just read it as a normal JPEG file in the first place?!" I hear you say. Yes, this would be easier but there is a good reason as to why I am reading as a byte array first and this cannot be worked around.Fun fact: For the ImageIO package, reading from the file is actually faster than reading from an InputStream that references the file's contents as a byte[] array. Specifically, the ImageInputStream implementation that wraps the file is faster then the one that wraps a generic InputStream.

  • How do i convert an image object to a byte array ?

    Hi
    how do i convert an image object into a byte array
    early reply apperciated

    Oh sorry my method and the other method need to have the pixels from the Image passed to them which you get my using pixelgrabber:
    //create width and height variables from image
              int w = img.getWidth(this);
              int h = img.getHeight(this);
              //retrive picture from image
              int[] pix = new int[w * h];
              PixelGrabber pg = new PixelGrabber(img, 0, 0, w, h, pix, 0, w);
              try{ pg.grabPixels();
              } catch (InterruptedException ioe) {
                   System.err.println("Interrupted");
              if ((pg.getStatus() & ImageObserver.ABORT) != 0) {
              System.err.println("image fetch aborted or errored");
              }

  • How to encrypt byte array with out padding using RSA in Java?

    I've modulus and public exponent as byte[] array, so I'm trying to convert into BigIntegers and then create public key and then Cipher. Here is the example code:
    With this I'm always getting different encrypted bytes, is it because of padding. I dont want to use any padding so what parameter I need to pass along with RSA? I've modulus byte[] array size 64 bytes. I believe I'll get 64 encrypted bytes. I've content size of 32 bytes to be encrypted.
    --------code begin ---------------------------
    BigInteger bexponent = new BigInteger(pubExpo);
    BigInteger bmodulus = new BigInteger(modulus);
    KeyFactory keyFactory = KeyFactory.getInstance("RSA");
    RSAPublicKeySpec pubKeySpec = new RSAPublicKeySpec(bmodulus, bexponent);
    RSAPublicKey pubKey = (RSAPublicKey)keyFactory.generatePublic(pubKeySpec);
    Cipher c = Cipher.getInstance("RSA");
    c.init(Cipher.ENCRYPT_MODE, pubKey);
    return c.doFinal(content);
    --------code end---------------------------

    With this I'm always getting different encrypted
    bytes, is it because of padding. Yes, if you're using PKCS1Padding (which is the default in SunJCE if you don't specify it). Have a look at the PKCS1 spec if you haven't seen it already.
    http://www.rsasecurity.com/rsalabs/pkcs
    Section 7.2.1 talks about type 2 padding, which uses random bytes as the PS string.
    I dont want to use
    any padding so what parameter I need to pass along
    with RSA? NOPADDING. You should be able to find this out by look at the "Supported Paddings" parameter in your provider's database. Which of course, means you'll need to supply the right number of bytes to the Cipher.

  • Java.sql.SQLException: Byte array not long enough

    using thin jdbc returned this exception seems to be connected to the length of the statment:
    ////////create a prepared statement////////
    preUpdateStatement = dbConnection.prepareStatement(updateStatement.toString());
    // build data output stream on byte array output stream
    ByteArrayOutputStream byte_os = new ByteArrayOutputStream();
    DataOutputStream data_os = new DataOutputStream(byte_os);
    // write chars to data output stream
    data_os.writeChars(((Element)m_values_vector.elementAt(i)).m_value);
    // create input stream and pass it to prepared statement
    ByteArrayInputStream byte_is = new ByteArrayInputStream(byte_os.toByteArray());
    preStatement.setUnicodeStream(i+1, byte_is, byte_os.toByteArray().length);
    // execute
    preUpdateStatement.executeUpdate();
    preUpdateStatement.close();
    null

    stack is:
    java.sql.SQLException: Io exception: Char array not long enough: javaCharsToUtf8Bytes
    at java.lang.Throwable.<init>(Compiled Code)
    at java.lang.Exception.<init>(Compiled Code)
    at java.sql.SQLException.<init>(Compiled Code)
    at oracle.jdbc.dbaccess.DBError.throwSqlException(Compiled Code)
    at oracle.jdbc.dbaccess.DBError.throwSqlException(Compiled Code)
    at oracle.jdbc.dbaccess.DBError.throwSqlException(Compiled Code)
    at oracle.jdbc.driver.OracleStatement.executeNonQuery(Compiled Code)
    at oracle.jdbc.driver.OracleStatement.doExecuteOther(Compiled Code)
    at oracle.jdbc.driver.OracleStatement.doExecuteWithBatch(Compiled Code)
    at oracle.jdbc.driver.OracleStatement.doExecute(Compiled Code)
    at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(Compiled Code)
    at oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(Compiled Code)

  • How to create PNG file from byte array of RGB value?

    Hi
    Here is my problem.
    I have drawn some sketchs (through code in runtime) on canvas. I have grabbed the RGB information for the drwan image and converted to byte array.
    I have to pass this byte array to server and generate a png file and save.
    Please help.

    {color:#ff0000}Cross posted{color}
    http://forum.java.sun.com/thread.jspa?threadID=5218093
    {color:#000080}Cross posting is rude.
    db{color}

Maybe you are looking for