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
1
vote
2 answers

java.io.EOFException: Unexpected end of ZLIB input stream when using ByteArrayOutputStream in try-with-resources

I am trying to read the contents of byte array created by gzipping an object, however when I try to unzip the contents of the byte array I get an error stating : java.io.EOFException: Unexpected end of ZLIB input stream I am trying to use the…
1
vote
1 answer

Is making no attribute using inheritance proper design? Causing trouble in Serialization. Java

I'm new to programming and I just learned inheritance a week ago, and have a question for how to design proper class that extends other class. Code below is the Bank Class that stored all the bank account object into ArrayList, which is why I'm…
XYZ
  • 83
  • 11
1
vote
1 answer

NotSerializableException with java.awt.geom.Area

I'm creating a game where all locations of 'blocks' are stored in the variable block_area - an object of class Area. My game has been running correctly for a week now, and I've decided to implement a save and load feature where I save block_area to…
Robo Mop
  • 3,485
  • 1
  • 10
  • 23
1
vote
0 answers

readObject() throws EOFException although no data is written yet

I'm currently writing a client-server application where data should be transferred to the server to process the data. For building the connection I use ServerSocket and Socket and for sending the data I use OutputStream + ObjectOutputStream on the…
Samaranth
  • 385
  • 3
  • 16
1
vote
0 answers

ObjectOutputStream, ObjectInputStream write and read permanently

Im trying to write sample data to a .txt file via an ObjectOutputStream. Afterwards i want to read the written result and show it in my application. Works perfect. But when i try to read the result after reopen the application it shows me only null…
1
vote
0 answers

StreamCorruptedException: invalid stream header: 79737200 when reading objects from a file

I create a client similarity, where clients register an account (an object is created) which is stored in a file. Objects are written to the file as required, I override the writeStreamHeader() method. But when I try to read them all, their file…
WolF Ram
  • 11
  • 4
1
vote
1 answer

Unexpected behavior sending object through socket in java

I'm sending a POJO through a socket in Java using ObjectOutputStream the POJO is below import java.io.Serializable; public class Game implements Serializable { private static final long serialVersionUID = 4367518221873521320L; private…
1
vote
1 answer

Reading Object from Socket Stream Isn't Getting Correct Values

So I am trying to do this project for a class, where I simulate a distributed network of computers using sockets. And then each computer will write an event object that contains its ID and timestamp, and each computer will also read incoming event…
1
vote
0 answers

Shared ArrayList between socket Java

I have 2 sockets: a client socket (Client class) and a concurrent server socket (ServerC Class) that can handle more clients at same time. The thread server sends an array to the client when it connects. If I update the array inside the thread…
1
vote
1 answer

Why does ObjectOutputStream write 14 bytes instead of 8 with DataOutputStream?

The same method (writeInt()) in ObjectOutputStream and DataOutputStream writes different data? Isn't it supposed to be equal for primitive types? // Output: 14 bytes file ObjectOutputStream out = new ObjectOutputStream(new…
1
vote
1 answer

TreeMap Map.Entry NotSerializableException in Java

I am trying to serialize a TreeMap to a text file but I cannot get it to work. I have tried printing/debugging and reading Javadocs. My Record and Table class both implement serializable and I've also built a custom comparator which also implements…
Javabytes
  • 11
  • 3
1
vote
1 answer

How can objects be updated rather than completely written anew when sending through ObjectInputStream

The following achieves updating objects sent through ObjectOutputStream (in this case using sockets) but it has to completely rewrite the object every time to update the object on the other end because otherwise the object uses a back-reference…
1
vote
1 answer

ObjectOutputStream is causing memory leak and reset() throws error

This problem really has me stumped. I'm sending images from a client to a server using ObjectOutputStream, but over time the java heap keeps growing. This eventually causes an OutOfMemoryError exception. After some online research, the reset method…
1
vote
1 answer

ObjectInputStream always retrieves a empty List

I'm working on a Client-Server project (you can call it "Broadcast Chat") but I got a problem with ObjectInputStream. It always retrieves me a an empty List, I found a solution but I don't know why it works... This is the bugged code (check the…
1
vote
0 answers

Send and receive an object via DatagramChannels

I have a problem with ByteArrayInputStream + ObjectInputStream (and corresponding output streams). I want to write some (different) instances of the class Pair over an UDP channel, and I've managed to this way: For writing (this.scores is a…