Returning byte array in JNI

Hi,
I am trying to return an array of byte from JNI to java. I read the tutorial but i still find it hard to understand.
BYTE *encoded is the variable that has the contents to be sent back to java.
jbytearray jb=encoded;
ret jb;
This does not seem to reurn anything!! Please help

This is the JNI implementation of the method:
public native byte[] returnArray (int size, byte initialValue).
JNIEXPORT jbyteArray JNICALL Java_Test_returnArray
  (JNIEnv *env, jobject This, jint size, jbyte initialValue) {
       //-- No error handling is being done...
       jbyte* buf = new jbyte[size];
       memset (buf, initialValue, size);
       jbyteArray ret = env->NewByteArray(size);
       env->SetByteArrayRegion (ret, 0, size, buf);
       delete[] buf;
       return ret;
}A jbyte is a signed char (a signed byte). You can mix signed bytes and unsigned bytes in C++ depending on your needs. This JNI method is the functional equivalent of the 100% Java function:
public byte[] returnArray (int size, byte initialValue) {
    byte[] ret = new byte[size];
    for (int i = 0; i < size; ++i) {
        ret[i] = initialValue;
    return ret;

Similar Messages

  • Return byte array

    Hello i have a function that return a byte array. I did it this way but i m wondering if it is the good way, so if someone can help improve it. Thank you.
    try
                InputStream is = new BufferedInputStream(new FileInputStream(nomFichierDemande));
                byte[] readData = null;
                while (is.available() > 0)
                    readData = new byte[is.available()];
                    is.read(readData);
    return readData;
            catch (IOException e)
                System.out.println("probleme lors de lecture de l'image");
                e.printStackTrace();
            }the source for my stream is an image file, bmp, gif or png, will it work the same for all kinds of file ?
    Thanks for help.
    Message was edited by:
    JusteUneQuestion
    Message was edited by:
    JusteUneQuestion

    (a) You should use File.length() rather than
    InputStream.available(): that's not what it's for.Hello i change the code like this :
    InputStream is = new BufferedInputStream(new FileInputStream(imageFile));
                    byte[] readData = null;
                    readData = new byte[(int)imageFile.length()];
                    is.read(readData);
                    return readData;Is it like this that u mean i have to use File.length, or was it only for the while loop ? I dont think that i need this while loop finally.
    (b) You should reconsider the whole idea of loading
    the entire file into memory. It doesn't scale. Sooner
    or later you'll encounter a file that doesn't fit
    into memory - then what?Can you give me a better idea? i thought about this but dont really know how to do to improve it. There is a limitation in the size of image anyway but i d like to have a good code in case for later.
    With this code i could read gif file but i m having problem for bmp so maybe its because it doesnt scale like you said.
    Message was edited by:
    JusteUneQuestion

  • C++ do not support  JNi && how to return the array from jni?

    hi,
    1.. I have created the Cpp file to implemement the native method but it seems that the native method can not complie rightly , it tells me follows
    error C2819: type 'JNIEnv_' does not have an overloaded member 'operator ->'
    c:\program files\microsoft visual studio\vc98\include\jni.h(764) : see declaration of 'JNIEnv_'
    c:\users\wangyue\desktop\java_gui\beattrack 5.6 - ������_������_������������ 5.7\beattrack.cpp(202) : error C2227: left of '->GetByteArrayRegion' must point to class/struct/union
    then I use the c file to paste the same code, it can complie rightly , why? I really need my native method to complie rightly in Cpp file, how to solve it?
    2.I want to return a double, for the most simple way, I do the following
    #include "RealBeatTrack_BeatTrack.h"
    JNIEXPORT jdoubleArray JNICALL Java_playaudio_BeatTrack_BeatTrack
    (JNIEnv *env, jobject j, jbyteArray data)
    jdouble outdata[4]={1,2,3,4};
    return (*env)->NewDoubleArray(env, outdata);
    then in the java code, I difine a array to receive it,
    say double mydata[] = new double[4];
    mydata= BeatTrack(buffedata);
    but the java comlier tells me the Exception in thread "Thread-2" java.lang.OutOfMemoryError: Java heap space?
    anyone can help me?
    Thanks

    thanks for your reply
    another problem of my!
    the jni pass the string, I then convert it to the
    const char* filename = env->GetStringUTFChars(fname,NULL);
    then I use the filename to opent the file but fails, what is the problem???
    FILE *fp= fopen(filename,"w"); // there are some problem here!!!
         fprintf(fp, "%s\n","wangyue fighting!");
    the error is as follows
    # An unexpected error has been detected by Java Runtime Environment:
    # EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x0bfc1a55, pid=7040, tid=11384
    # Java VM: Java HotSpot(TM) Client VM (10.0-b19 mixed mode windows-x86)
    # Problematic frame:
    # C [beattrack.dll+0x1a55]
    # An error report file with more information is saved as:
    # D:\programs\playAudio\hs_err_pid7040.log
    # If you would like to submit a bug report, please visit:
    # http://java.sun.com/webapps/bugreport/crash.jsp
    # The crash happened outside the Java Virtual Machine in native code.
    # See problematic frame for where to report the bug.
    #

  • Why getBytes for VARCHAR type return byte array in UTF8 Codemap?

    I have found that the getBytes method is double speed than getString method for CHAR and VARCHAR data type in the ResultSet object,when I am process Chinese I met this problem.

    I have found that the getBytes method is double speed than getString method for CHAR and VARCHAR data type in the ResultSet object,when I am process Chinese I met this problem.

  • Generated Webservice proxy: Maximimum size of byte array

    Hi,
    We have generated a webservice proxy with JDeveloper (version 10.1.3.4.0) from a WSDL supplied by a .Net webservice. One of the Webservice returns a byte array. We are facing a problem when the size of the returned byte array exceeds the limit of 5 MB. We have tried to increase the heap size of the OC4J but that did not solve the problem.
    Does anyone know if there is a maximum value limit which can be passed through a byte array? Is it configurable?
    A workaround would be flushing the byte array in chunks, but the webservice returns the byte array as a single returned value.
    Regards,
    Sjoerd

    Hi,
    The webservice was called by Oracle Forms. The problem was solved by Metalink Note 562561.1 - Webservice Fails To Run With java.lang.OutOfMemoryError.
    Regards,
    Sjoerd

  • 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

  • How can i convert object to byte array very*100 fast?

    i need to transfer a object by datagram packet in embeded system.
    i make a code fallowing sequence.
    1) convert object to byte array ( i append object attribute to byte[] sequencailly )
    2) send the byte array by datagram packet ( by JNI )
    but, it's not satisfied my requirement.
    it must be finished in 1ms.
    but, converting is spending 2ms.
    network speed is not bottleneck. ( transfer time is 0.3ms and packet size is 4096 bytes )
    Using ObjectOutputStream is very slow, so i'm using this way.
    is there antoher way? or how can i improve?
    Edited by: JongpilKim on May 17, 2009 10:48 PM
    Edited by: JongpilKim on May 17, 2009 10:51 PM
    Edited by: JongpilKim on May 17, 2009 10:53 PM

    thanks a lot for your reply.
    now, i use udp socket for communication, but, i must use hardware pci communication later.
    so, i wrap the communication logic to use jni.
    for convert a object to byte array,
    i used ObjectInputStream before, but it was so slow.
    so, i change the implementation to use byte array directly, like ByteBuffer.
    ex)
    public class ByteArrayHelper {
    private byte[] buf = new byte[1024];
    int idx = 0;
    public void putInt(int val){
    buf[idx++] = (byte)(val & 0xff);
    buf[idx++] = (byte)((val>>8) & 0xff);
    buf[idx++] = (byte)((val>>16) & 0xff);
    buf[idx++] = (byte)((val>>24) & 0xff);
    public void putDouble(double val){ .... }
    public void putFloat(float val){ ... }
    public byte[] toByteArray(){ return this.buf; }
    public class PacketData {
    priavte int a;
    private int b;
    public byte[] getByteArray(){
    ByteArrayHelper helper = new ByteArrayHelper();
    helper.putInt(a);
    helper.putInt(b);
    return helper.toByteArray();
    but, it's not enough.
    is there another way to send a object data?
    in java language, i can't access memory directly.
    in c language, if i use struct, i can send struct data to copy memory by socket and it's very fast.
    Edited by: JongpilKim on May 18, 2009 5:26 PM

  • 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.

  • NetBeans MobilityPack 5 BUG?? how can I send a byte array?

    I�ve created a WebApp and a Simple servlet with one public method.
    public byte[] getStr(byte[] b) {       
    String s = "A string";
    return s.getBytes();
    Then I've used "Mobile To Web App" wizard to generate stubs to that getStr method. And when I�ve tried to call that getStr method:
    byte[] aByte = "st".getBytes();
    byte[] b = client.getStr(aByte);
    I've got an error at Server in Utility.java in generated ReadArray method.
    * Reads an array from the given data source and returns it.
    *@param source The source from which the data is extracted.
    *@return The array from the data source
    *@exception IOException If an error occured while reading the data.
    public static Object readArray(DataInput in) throws IOException {
    short type = in.readShort();
    int length = in.readInt();
    if (length == -1) {
    return null;
    } else {
    switch (type) {
    case BYTE_TYPE: {
    byte[] data = new byte[length];
    in.readFully(data);
    return data;
    default: {
    throw new IllegalArgumentException("Unsupported return type (" + type + ")");
    At this line "in.readFully(data);" I�ve got an EOFException.
    The the aByte = "st".getBytes(); was 2bytes long and at the server "int length = in.readInt();" it was 363273. Why?
    All code was generated by NetBeans Mobility pack 5 it's not mine so its a bug?
    How can I fix this?

    I found that bug. I've described it here
    http://www.netbeans.org/issues/show_bug.cgi?id=74109
    There's a solution how to fix the generated code.

  • Convert XML data to byte array...

    Hello All,
    In my application, i have an XML file and the corresponding XSD file. This XML file is having some date, which i want to convert into an byte[] and then save it in a file. 
    How i can convert the XML data in the byte[]? Here as an example of the xml file and the byte[] data which i want to save in a file.
    <?xml version="1.0" encoding="utf-8"?>
    <HeadersInfo>
    <header>
    <id>0</id>
    <Name>H1</Name>
    </header>
    <header>
    <id>1</id>
    <Name>H2</Name>
    </header>
    </HeasersInfo>
    In the above example 'id' field is of type 'uint' and 'name' field is of type 'string' with max length of '5'. So in this case my byte array should be as shown below:
    00 00 00 01 48 31 00 00 00
    00 00 00 02 48 32 00 00 00
    Here underlines values are for the 'id' parameter where as values in bold are for 'Name' parameter for all the header values in sequence. Name parameter is null (0x00) padded.
    Thanks in advance,
    IamHuM

    Hi,
    the following example extract the id, name values using LINQ To Xml and writes it to a memory stream using a binary writer and returns the result as a byte array:
    internal static byte[] GetXmlAsByteArray()
    var document = XDocument.Parse("<HeadersInfo>"
    + " <header><id>1</id><Name>H1</Name></header>"
    + " <header><id>2</id><Name>H2</Name></header>"
    // additional testing
    + " <header><id>32767</id><Name>H1234</Name></header>"
    + " <header><id>305419896</id><Name>H56789</Name></header>"
    + "</HeadersInfo>");
    const int NameLength = 5; // Max length for a name
    byte[] zeroBytes = new byte[NameLength]; // Helper to fill name
    using (var ms = new MemoryStream())
    using (var writer = new BinaryWriter(ms))
    // write each header
    foreach (var header in document.Root.Elements("header"))
    int id = (int)header.Element("id");
    string name = (string)header.Element("Name");
    byte[] nameBytes = System.Text.Encoding.UTF8.GetBytes(name);
    Console.WriteLine("id: {0}, Name: {1}", id, name);
    // Write id
    writer.Write(GetUIntBytes((uint)id));
    // Write name NameLength (5) max, otherwise padded
    if (nameBytes.Length > NameLength)
    writer.Write(nameBytes, 0, NameLength);
    else
    writer.Write(nameBytes, 0, nameBytes.Length);
    if (nameBytes.Length < NameLength)
    writer.Write(zeroBytes, 0, NameLength - nameBytes.Length);
    byte[] result = ms.ToArray();
    // dump array
    foreach (var value in result)
    Console.Write("{0:X2} ", value);
    Console.WriteLine();
    return result;
    public static byte[] GetUIntBytes(uint value)
    if (BitConverter.IsLittleEndian)
    // swap bytes
    value = ((value & 0x00ff) << 24)
    | ((value & 0xff00) << 8)
    | ((value & 0x00ff0000) >> 8)
    | ((value & 0xff000000) >> 24);
    return BitConverter.GetBytes(value);
    For a general purpose solution you should create a class and split the example into separate methods to extract the data and write the values (integers, strings).
    Regards, Elmar

  • Convert byte array to table of int

    [http://www.codeproject.com/KB/database/PassingArraysIntoSPs.aspx?display=Print|http://www.codeproject.com/KB/database/PassingArraysIntoSPs.aspx?display=Print] Hello friends.
    I'm pretty new with PL/SQL.
    I have code that run well on MSSQL and I want to convert it to PL/SQL with no luck.
    The code converts byte array to table of int.
    The byte array is actually array of int that was converted to bytes in C# for sending it as parameter.
    The TSQL code is:
    CREATE FUNCTION dbo.GetTableVarchar(@Data image)
    RETURNS @DataTable TABLE (RowID int primary key IDENTITY ,
    Value Varchar(8000))
    AS
    BEGIN
    --First Test the data is of type Varchar.
    IF(dbo.ValidateExpectedType(103, @Data)<>1) RETURN
    --Loop thru the list inserting each
    -- item into the variable table.
    DECLARE @Ptr int, @Length int,
    @VarcharLength smallint, @Value Varchar(8000)
    SELECT @Length = DataLength(@Data), @Ptr = 2
    WHILE(@Ptr<@Length)
    BEGIN
    --The first 2 bytes of each item is the length of the
    --varchar, a negative number designates a null value.
    SET @VarcharLength = SUBSTRING(@Data, @ptr, 2)
    SET @Ptr = @Ptr + 2
    IF(@VarcharLength<0)
    SET @Value = NULL
    ELSE
    BEGIN
    SET @Value = SUBSTRING(@Data, @ptr, @VarcharLength)
    SET @Ptr = @Ptr + @VarcharLength
    END
    INSERT INTO @DataTable (Value) VALUES(@Value)
    END
    RETURN
    END
    It's taken from http://www.codeproject.com/KB/database/PassingArraysIntoSPs.aspx?display=Print.
    The C# code is:
    public byte[] Convert2Bytes(int[] list)
    if (list == null || list.Length == 0)
    return new byte[0];
    byte[] data = new byte[list.Length * 4];
    int k = 0;
    for (int i = 0; i < list.Length; i++)
    byte[] intBytes = BitConverter.GetBytes(list);
    for (int j = intBytes.Length - 1; j >= 0; j--)
    data[k++] = intBytes[j];
    return data;
    I tryied to convert the TSQL code to PL/SQL and thats what I've got:
    FUNCTION GetTableInt(p_Data blob)
    RETURN t_array --t_array is table of int
    AS
    l_Ptr number;
    l_Length number;
    l_ID number;
    l_data t_array;
    BEGIN
         l_Length := dbms_lob.getlength(p_Data);
    l_Ptr := 1;
         WHILE(l_Ptr<=l_Length)
         loop
              l_ID := to_number( DBMS_LOB.SUBSTR (p_Data, 4, l_ptr));
              IF(l_ID<-2147483646)THEN
                   IF(l_ID=-2147483648)THEN
                        l_ID := NULL;
                   ELSE
                        l_Ptr := l_Ptr + 4;
                        l_ID := to_number( DBMS_LOB.SUBSTR(p_Data, 4,l_ptr));
                   END IF;
                   END IF;
    l_data(l_data.count) := l_ID;
              l_Ptr := l_Ptr + 4;
         END loop;
         RETURN l_data;
    END GetTableInt;
    This isn't work.
    This is the error:
    Error report:
    ORA-06502: PL/SQL: numeric or value error: character to number conversion error
    06502. 00000 - "PL/SQL: numeric or value error%s"
    I think the problem is in this line:
    l_ID := to_number( DBMS_LOB.SUBSTR (p_Data, 4, l_ptr));
    but I don't know how to fix that.
    Thanks,
    MTs.

    I'd found the solution.
    I need to write:
    l_ID := utl_raw.cast_to_binary_integer( DBMS_LOB.SUBSTR(p_Data, 4,l_ptr));
    instead of:
    l_ID := to_number( DBMS_LOB.SUBSTR (p_Data, 4, l_ptr));
    The performance isn't good, it's take 2.8 sec to convert 5000 int, but it's works.

  • Sending command apdu with a byte array as CDATA

    Hi,
    I am learning java card as part of my final year project. So far I think I can do most of the basic things but I have got stuck at one particular point.
    I know that there are different constructors for creating a command apdu object and a number of these constructors take an array of bytes as CDATA values.
    My problem is, how to access this array of data in the card side because apdu.getBuffer() returns an array of integers (bytes)? And what is actually on apdu.getBuffer()[ISO7816.OFFSET_CDATA)] location when you send command apdu object using such a constuctor?
    regards
    Edited by: 992194 on 06-Mar-2013 06:12

    992194 wrote:
    (..) I should have mentioned earlier that my card use jc 2.2.1 version, and i have read from different places that this version does not support ExtendedLength facility.Indeed.
    Also I understand the semantics of apdu.getBuffer()[ISO7816.OFFSET_CDATA] that is the first byte of the command data. My question is, this command data was initially supplied as an array of bytes. Something like this:
    +new CommandAPDU(CLA, INS, P1, P2, DATA_ARRAY, Le)+
    So when you call:
    byte [] buffer = apdu.getBuffer()
    So does this mean that the byte values inside DATA_ARRAY automatically occupy locations +buffer[ISO7816.OFFSET_CDATA]+ onwards inside the buffer?Yes. The length would be<tt> (short)(buffer[ISO7816.OFFSET_LC]&0xFF) </tt>. Notice the<tt> &0xFF </tt> is a must above 127 bytes.
    Or their is a mechanism of extracting the DATA_ARRAY array itself?No.
    In fact, in the interest of performance and portability in environments with little memory, the usual coding style is to pass<tt> buffer </tt>, an offset within that, and the length; rather than making an object, which would require a copy. Welcome to the real world of Java Card.

  • How to put a String into a byte array

    How can i put a String into a byte array byte[]. So that i can send it to the serial port for output to an LCD display. Cheers David

    javadocs for String
    getBytes
    public byte[] getBytes()
    Encodes this String into a sequence of bytes using the platform's default charset, storing the result into a new byte array.
    Returns:
    The resultant byte arraySince:
    JDK1.1

  • Is there a null value that I can put into a byte array?

    I have a byte[] that I'm trying to make smaller, at the moment, in order to do so, i'm writing it byte-by-byte to another byte[] called temp. Both are set to the same size, because I don't know exactly what the initial array will compress to.
    For example, my method will write a single byte that will tell the decompressor to carry out the next instruction 5 times (eg aaaaa = 5a), but after the instruction, I want to set the 4 a's afterwards to an empty value so that I can then iterate through temp, finding out how long to make the output byte[] by counting how many null's there are.
    Eclipse is telling me null is not possible to use, I was just wondering if there is an equivalent I can use?

    That's an idea!
    The only thing is then when I come to iterate through the byte array to write it to my output array, it throws up an error that I'm trying to compare a byte to a byte[]:
              int next = 0;
              byte[] n = new byte[0];
              for (int i = 0; i < temp.length; i++) {
                   if (temp[i] != n) {
                        output[next] = temp;
                        next++;
              return output;

  • How to create a jar having the contents of the jar in a byte array?

    Hi,
    I have a server and client application. My server returns the contents of the jar in the form of byte array to the client on a particluar method call. Now at the client end, i want to reconstruct the jar to be used. How do I do this?
    The server uses the JarInputStream to read the contents of the jar to be returned. I have tried using the JarOutputStream, but looks like this works fine if we have spearate class files to be added to the jar. Now that I have the contents of the jar itself, how do i recreate the jar?
    Can anyone please help me with this?
    Thanks
    Rajani

    Have you ever gotten the raw byte copy to work? If so, how?
    I download a jar via InputStream and save into a jar file via fileoutputstream. It always gets corrupted in the process. The new Jar file has the exact same number of bytes, but doesn't get past the Manifest on a -tvf. In fact, Winzip can open it fine, but can't extract. So close...yet so far.
    Here is a snapshot of my code:
    BufferedInputStream data1=new BufferedInputStream(con.getInputStream());
    DataInputStream data=new DataInputStream(data1);
    StringBuffer buf=new StringBuffer();
    try{
    while((theChar=data.read()) != -1)
    { buf.append((char)theChar); }
    } catch (Exception z){ logger.info("UpdateThread.read Done Reading jar file");}
    data.close();
    File newFile = new File("C:/MyJar.jar");
    FileOutputStream outstream2 = new FileOutputStream(newFile);
    DataOutputStream outstream1 = new DataOutputStream(outstream2);
    BufferedOutputStream outstream = new BufferedOutputStream(outstream1);
    byte [] bytes = buf.toString().getBytes();
    logger.info("Bytes of new Jar file = " + bytes.length);
    int i;
    for(i=0;i<bytes.length;i++){
    outstream.write(bytes);
    outstream1.close();
    outstream.close();
    Any ideas where I'm going wrong?

Maybe you are looking for

  • What program should i use to archive my photos ?

    what program should i use to archive my photos ? i have tried aperture and the mage browsing program that comes with canon, but i just cant find the right program to be fast and efficent ! any suggestions ?

  • Using external clock on sbRIO 9606

    I'm trying to use LTC2170 ADC with sbRIO 9606. The ADC chip has serial data outputs, a frame start output and a data clock output. How can I use the frame start and data clock outputs of the ADC in LabVIEW to read serial data bits from the ADC? The s

  • Does Old imac support External optical drive

    APple says that my imac mid2010 21.5" doesnt support external superdrive but my iMac's built in optical drive has failed so can other external optical drives function on my mac beacuse there seems to be no way of using a disc in a mac whose internal

  • WDR_TEST_ADOBE: popup doesnt work after viewing the form

    Hi, I would need your help in letting me know if there is any additional setting required for correct execution. I tried executing the sample "WDR_TEST_ADOBE" web dynpro component. On execution, on the right hand context area, you will see a button "

  • I got the following error when I try to logon to oracle portal.WWC-41439:

    Hi, I got WWC-41439 error.Message is "You can't logon becuase there is no configuration information stored in ranabler confoguration table. Any solution? Regards, TLN Reddy.