StreamCorruptedException无效的流标头 [英] StreamCorruptedException invalid stream header
问题描述
我发送了一个字符串数组,最初是一个序列化的对象类到我的php服务器端,这样我就可以把它作为文本保存到我的mysql数据库中
String temp = new 字符串(facetemplate,Charset.forName( UTF-8));
字符串 feat = new 字符串(facefeatures,Charset.forName( UTF-8));
我将String转换回字节数组但是当我想将它转换回一个对象时它会给我
java.io.StreamCorruptedException:无效的流标题:3F3F0573
这就是我转换回对象的方式
/ * *
*将字节数组转换为对象
* @param byteobject
* @return byte [] byte
* @throws IOException
* @throws ClassNotFoundException
** /
public static 对象 DeSerialise( byte [] byteobject)抛出IOException,ClassNotFoundException
{
ByteArrayInputStream in = new ByteArrayInputStream(byteobject);
ObjectInputStream = new ObjectInputStream( in < /跨度>);
return 是 .readObject();
}
序列化我的对象类
/ * *
*将对象序列化为文件
*
* @param< T>
*
* @param obj
* @throws FileNotFoundException
* /
public 静态< T> void SerializeObject(Context context,T obj)
throws FileNotFoundException,IOException {
File cache = new 文件(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();
}
但是有关我如何上课的更多信息到字节请看下面的链接
http://stackoverflow.com/questions/28673243/object-to-byte-arrray-conversion-and-byte-array-to-string-conversion [ ^ ]
我不知道为什么,但我猜它是因为我在发送之前最初做的字符串转换。不是真正的专家,所以任何帮助将不胜感激。谢谢
我认为toString导致问题。在上面给出的链接中,您提到要将字节对象保存在mysql DB的文本列中。而不是存储BLOB类型列中的值,并且不将字节对象转换为tostring。
问候,
Panduranga。
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
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
java.io.StreamCorruptedException: invalid stream header: 3F3F0573
This is how i did my conversion back to an object
/**
* 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
/**
* 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
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.
这篇关于StreamCorruptedException无效的流标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!