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.

566 questions
6
votes
1 answer

Send an Anonymous class over sockets? (Object..Stream in Java)

So right now, I have a server that is running with ObjectInputStream and ObjectOutputStream. The problem I am having is that I have a custom (anonymous) class that extends java.lang.Date that I am trying to send to the client and then compile. So…
6
votes
4 answers

Reading Objects from Random Access File

I wrote a file using Java's FileChannel class that uses RandomAccessFiles. I wrote objects at various locations in the file. The objects were of variable sizes but all of the same class. I wrote the objects using the following idea…
AnkurVj
  • 7,958
  • 10
  • 43
  • 55
6
votes
2 answers

When would one use ObjectInputStream.readUnshared() vs .readObject()?

There are two similar methods in the Java ObjectInputStream: readUnshared() and readObject() The documentation states: public Object readUnshared() throws IOException, ClassNotFoundException Reads an "unshared" object from the ObjectInputStream.…
E.S.
  • 2,733
  • 6
  • 36
  • 71
6
votes
2 answers

ObjectInputStream from file causing memory leaks

I have a huge file with a list of objects written by ObjectOutputStream, one after another. for (Object obj : currentList){ oos.writeUnshared(obj); } Now I want to read this file using ObjectInputStream. However, I need to read multiple files…
copperhead
  • 647
  • 1
  • 9
  • 15
5
votes
3 answers

ObjectInputStream Error

I am using ObjectOutputStream to create a file of serialized objects. I then use an ObjectInputStream to with the readObject() method to get the objects back out of the file. It works great the first time. Meaning that if the file does not exist…
JavaDunce
5
votes
4 answers

Overhead in java ObjectOutputStream?

I am puzzled by the behavior of ObjectOutputStream. It seems like it has an overhead of 9 bytes when writing data. Consider the code below: float[] speeds = new float[96]; float[] flows = new float[96]; //.. do some stuff here to fill the arrays…
hinsbergen
  • 147
  • 2
  • 11
5
votes
5 answers

Java ObjectOutputStream on Socket not flush()ing

I'm working on a network app written in Java, using ObjectOutputStream and ObjectInputStream on top of Sockets to exchange messages. My code looks like this: Sender: ObjectOutputStream out; ObjectInputStream in; try{ Socket socket=new…
user597474
5
votes
3 answers

What character encoding does ObjectOutputStream 's writeObject method use?

I read that Java uses UTF-16 encoding internally. i.e. I understand that if I have like: String var = "जनमत"; then the "जनमत" will be encoded in UTF-16 internally. So, If I dump this variable to some file such as below: fileOut = new…
5
votes
5 answers

Java: Use ObjectOutputStream without serializable

Sometimes, I want to use an ObjectOutputStream to write something to a file or sending a little image over the network. But BufferedImage and many other classes don't implement java.io.Serializable and then the Stream cancels writing. Is there a way…
Martijn Courteaux
  • 67,591
  • 47
  • 198
  • 287
5
votes
4 answers

What's the difference between Serialization and simply store the object on disk?

I am confused about this. Since when doing implementation of Serializable class, we need to use classes like FileOutputStream, ObjectOutputStream or something like that. Then why not we just use those classes to do things like output a object to a…
5
votes
4 answers

How to override ObjectOutputStream.writeStreamHeader()?

The method ObjectOutputStream.writeStreamHeader() can be overridden to prepend or append data to the header. However, if that data is based on an argument passed to the derived class's constructor like: public class MyObjectOutputStream extends…
Paul J. Lucas
  • 6,895
  • 6
  • 44
  • 88
4
votes
2 answers

Should streams be closed after every use?

I am currently working on a UDP server for a game. In this server use a ByteArrayInputStream and a ObjectInputStream every tick to convert serialized bytes to objects. Is it more efficient to create one variable for the streams and close them once…
4
votes
2 answers

ObjectStream: is there a way to read serialized object as properties map?

Is there any standard way or any utility library to read/navigate through serialized (via ObjectOutputStream) object's properties? The problem I'm trying to solve is to upgrade data which was serialized using ObjectOutputStream (legacy) and stored…
4
votes
2 answers

Why this strange behaviour of ObjectOutputStream and ObjectInputStream throwing EOFException?

I wrote a custom serializing/de-serializing logic for persisting some of the data as Java default serialization turned out to be both time and memory expensive. For this purpose I wrote readObject(ObjectInput in) and writeObject(ObjectOutput out)…
madteapot
  • 2,208
  • 2
  • 19
  • 32
4
votes
2 answers

Why does ObjectOutputStream.readObject() access MyClass.readObject()

I was going through the basics of Java IO and I saw that, in order to use a custom writeObject function in a class, it has to be declared private. private void writeObject(ObjectOutputStream oos); Then, when we…
Aswin Murugesh
  • 10,831
  • 10
  • 40
  • 69
1
2
3
37 38