i have this relatively simple piece of Java (for Android) code which i have stripped down for this question.
int number = 42;
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutputStream os = new ObjectOutputStream(bos);
os.writeObject(number);
String serial = bos.toString("UTF-8");
os.close();
ByteArrayInputStream bis = new ByteArrayInputStream(serial.getBytes("UTF-8"));
ObjectInputStream is = new ObjectInputStream(bis); // <<<< Exception Here
The last line, initializing the ObjectInputStream, throws a StreamCorruptedException and i have no idea why.
(i am planning to use this to serialize a few small objects to Strings and store them in SharedPreferences and read them back later. But i am using just an integer now because that isolates the problem)