Click here to Skip to main content
15,886,873 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I sent a stringed byte array which was initially a serialized object class to my php server side so that i can save it into my mysql database as a TEXT

C#
String temp = new String(facetemplate, Charset.forName("UTF-8"));
String feat = new String(facefeatures, Charset.forName("UTF-8"));


I convert the String back to a byte array but when i wan to convert it back to an object it gives me
C#
java.io.StreamCorruptedException: invalid stream header: 3F3F0573


This is how i did my conversion back to an object

C#
 /**
 * Converts byte array to object
 * @param byteobject
 * @return byte[] byte
 * @throws IOException
 * @throws ClassNotFoundException
 **/
public static Object DeSerialise(byte[] byteobject) throws IOException, ClassNotFoundException
{
    ByteArrayInputStream in = new ByteArrayInputStream(byteobject);
    ObjectInputStream is = new ObjectInputStream(in);
    return is.readObject();
}


Serializing my object class

C#
/**
     * Serialises an object to a file
     *
     * @param <T>
     *
     * @param obj
     * @throws FileNotFoundException
     */

    public static <T> void SerializeObject(Context context, T obj)
            throws FileNotFoundException, IOException {
        File cache = new File(context.getCacheDir(), config.FILE_NAME);

        if (!cache.exists())
            cache.createNewFile();
        FileOutputStream fos = new FileOutputStream(cache);

        ObjectOutputStream out = new ObjectOutputStream(fos);

        out.writeObject(obj);
        out.close();

    }



but for further information on how i turned my class to bytes please see the link below
http://stackoverflow.com/questions/28673243/object-to-byte-arrray-conversion-and-byte-array-to-string-conversion[^]

am not sure why but i am guessing it is because of the string conversion i did initially before sending it. Not really an expert so any help would be greatly appreciated. Thanks
Posted
Updated 24-Feb-15 3:45am
v2
Comments
Fredrik Bornander 24-Feb-15 9:33am    
How are you serializing it?
daviestobialex 24-Feb-15 9:46am    
please check the question again i made some changes so you can fully understand my problem. Thanks
Fredrik Bornander 24-Feb-15 9:54am    
How are you getting the content out of the file and into the byte array you pass to DeSerailise?
daviestobialex 24-Feb-15 9:59am    
its in the link please check the link i added when i edited my question
daviestobialex 24-Feb-15 11:11am    
@Fredrik-Bornander can you help please?

1 solution

I think the toString is causing the problem. And in the above given link you mentioned that you are saving the byte object in a text column of mysql DB. Instead of that store the value in BLOB type column and don't convert byte object to tostring.

Regards,
Panduranga.
 
Share this answer
 
Comments
daviestobialex 25-Feb-15 5:01am    
I understand but how can i send an array of bytes from android to the server without using `BasicValuePair`which has to be String Key and Value.
Pandu Rang 26-Feb-15 2:07am    
Could you please explain the architecture of the present application. I want to know hoe the data is flowing.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900