Questions tagged [objectoutputstream]

The Java ObjectOutputStream serialization class from the Java standard library.

ObjectOutputStream is a class from the Java standard library that can be used to serialize and write objects previously that can later be read and deserialized by an ObjectInputStream instance.

544 questions
61
votes
6 answers

Appending to an ObjectOutputStream

Is it not possible to append to an ObjectOutputStream? I am trying to append to a list of objects. Following snippet is a function that is called whenever a job is finished. FileOutputStream fos = new FileOutputStream …
Hamza Yerlikaya
  • 47,689
  • 37
  • 135
  • 231
33
votes
1 answer

How can I convert an Object to Inputstream

How can I convert the java Object into a InputStream?
SRy
  • 2,743
  • 7
  • 33
  • 54
24
votes
3 answers

Why can I only read 1024 bytes at a time with ObjectInputStream?

I have written the following code which writes 4000 bytes of 0s to a file test.txt. Then, I read the same file in chunks of 1000 bytes at a time. FileOutputStream output = new FileOutputStream("test.txt"); ObjectOutputStream stream = new…
Zsw
  • 3,312
  • 3
  • 21
  • 41
21
votes
3 answers

Sending the same but modifed object over ObjectOutputStream

I have the following code that shows either a bug or a misunderstanding on my part. I sent the same list, but modified over an ObjectOutputStream. Once as [0] and other as [1]. But when I read it, I get [0] twice. I think this is caused by the…
Pyrolistical
  • 26,088
  • 21
  • 78
  • 104
14
votes
2 answers

How do I write multiple objects to the serializable file and read them when the program is used again?

I want to maintain database of users of a Bank for my project. I am able to save the number of users in one serializable file. But when I try to save the user to database it adds only the latest one to database. Below is the sneak peak of code which…
12
votes
4 answers

JSONObject Not Serializable?

I am trying to serialize an ArrayList of JSONObjects. But I get the error: 05-07 01:04:24.130: WARN/System.err(913): java.io.NotSerializableException: org.json.JSONObject 05-07 01:04:24.130: WARN/System.err(913): at…
Sheehan Alam
  • 57,155
  • 123
  • 348
  • 546
12
votes
6 answers

java.io.StreamCorruptedException: invalid type code: 00

So basically im writing a client-server multiplayer game. I have a SeverCommunicationThread that creates a gameThread if he receives a RequestForGame creates a gameThread. When i send a RequestForGame exception is thrown…
user1420273
  • 121
  • 1
  • 1
  • 4
10
votes
5 answers

Performance issue using Javas Object streams with Sockets

I'm trying to do local IPC using Sockets and Object streams in Java however I'm seeing poor performance. I am testing the ping time of sending an object via an ObjectOutputStream to receiving a reply via an ObjectInputStream over a Socket. Here's…
10
votes
0 answers

Why ObjectOutputStream.writeObject(Object o); but not ObjectOutputStream.writeObject(Serializable o)

In Java, we use the writeObject(Object obj) method of ObjectOutputStream to serialize an Object. But since the method only takes object that implements the java.io.Serializable interface (or it will throw NotSerializableException), why does it…
8
votes
3 answers

Cannot create ObjectInputStream with InputStream for a Bluetooth Socket on the Android Platform

I am writing a multiplayer game for Android phones. Communication is via Bluetooth. I have managed to send bytes from one phone to the other using the input / output stream. Since I need to be able to transfer objects I want objectstreams. However,…
Alexander
  • 1,493
  • 4
  • 18
  • 24
8
votes
3 answers

create object output stream from an object

I want to create on ObjectOutputStream, but I don't want to persist the object in a file, so how to do that? All the tutorials(that I found) say only about the file way: FileOutputStream fos = new FileOutputStream("t.tmp"); …
coubeatczech
  • 5,892
  • 7
  • 43
  • 71
8
votes
1 answer

How to send Json object through java sockets?

How do you send Json object's through sockets preferable through ObjectOutputStream class in java this is what I got so far s = new Socket("192.168.0.100", 7777); ObjectOutputStream out = new ObjectOutputStream(s.getOutputStream()); …
user3339626
  • 81
  • 1
  • 1
  • 2
8
votes
2 answers

What's the difference between writeUTF and writeChars?

What's the difference between writeUTF and writeChars? (methods of ObjectOutputStream) Further I have not found the corresponding readChars in ObjectInputStream.
Indeed ItIs
  • 227
  • 2
  • 9
7
votes
1 answer

Android Socket + ObjectOutputStream not working correctly

I am developing a client/server program where the client is an android device. The server has a listener class that reads an object from the input stream. I created a client software for another COMPUTER that sends a small object over a local…
7
votes
4 answers

writing a BitSet to a file in java

I have a BitSet and want to write it to a file- I came across a solution to use a ObjectOutputStream using the writeObject method. I looked at the ObjectOutputStream in the java API and saw that you can write other things (byte, int, short etc) I…
Avner
  • 215
  • 7
  • 13
1
2 3
36 37