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
3
votes
1 answer

Read different byte[] from ObjectInputStream than written to ObjectOutputStream

I have a strange problem with java. I want to write (amongst others) a byte[] in an ObjectOutputStream and from there to a new file. That byte-array represent an other file read from disk. Later, after writing into the newly created file, I want to…
Ph3n1x
  • 307
  • 7
  • 13
3
votes
6 answers

HashMap saving with ObjectOutputStream

To save teleportation points on command, I have an HashMap: public HashMap mapHomes = new HashMap<>(); Which is accessed like this: if(cmd.getName().equalsIgnoreCase("sethome")){ Location loc = player.getLocation(); …
brotheroftux
  • 87
  • 1
  • 2
  • 9
3
votes
2 answers

ObjectInputStream readObject(): ClassNotFoundException

In both client and server classes, I have an exact same inner class called Data. This Data object is being sent from the server using: ObjectOutputStream output= new ObjectOutputStream(socket.getOutputStream()); output.writeObject(d); (where d is a…
3
votes
2 answers

estimating size of file on disk when using ObjectOutputStream

I am trying to write my spatial data from a table to a file. But I need to know the exact size of the data on disk before writing to disk. As an example, let's say that I am writing to disk using the following code: FileOutputStream fos = new…
reza
  • 1,188
  • 3
  • 17
  • 32
3
votes
3 answers

Java de-serialization: how do I know when I've reached the end of the object when reading from a buffer?

I tried to come up with a good title, but seem to have failed. Here's my problem: I'm reading data in from a socket. The data contained in the buffer is a serialized object. Once the data is completely read, I can then create an ObjectInputStream…
3
votes
2 answers

send changed hashmap but get the same one using ObjectOutputStream and ObjectInputStream

public static void main(String[] args) throws Exception { Socket socket = new Socket("127.0.0.1", 2345); ObjectOutputStream oos = new ObjectOutputStream(socket.getOutputStream()); Map testMap = new HashMap
JustFF
  • 115
  • 1
  • 1
  • 6
2
votes
2 answers

Writing an object to a file in MonoDroid

What is the best way to write an object to a file in MonoDroid so that it can be be reloaded the next time the application runs? I'm running into problem after problem trying to use XmlSerializer, and I have been unable to get Java's…
2
votes
1 answer

Can't verify signature after reading signed file

sign.verify(signature) returns false in the verifySignature method; and I think it has something to do about how I use outputstreams and inputstreams with the signedobject.obj file (certificate passed validity). I can read the message correctly from…
gorn
  • 8,097
  • 5
  • 37
  • 44
2
votes
2 answers

Why does ObjectOutputStream.writeObject() throw IOException?

I'm currently working on an Android app that automatically changes the phones state based on a certain event, such as battery level. I have a Profile class which has 3 main parameters, names, Event and State (Event and State are 2 other custom…
William Stewart
  • 841
  • 1
  • 14
  • 27
2
votes
3 answers

Saving my Serialized Class that have not serialized objects like Rect

I'm trying to save my Serialized object when the activity calls the onDestroy() but when i try to write my object using ObjectOutputStream a java.io.NotSerializableExeption is thrown. Can you please help me. Thanks
2
votes
1 answer

Why I receive NotSerializableException while attempting to Serialize an Object

I have the following class: public class GameWorld implements Serializable { int sumu_dist = 30; public List tileGroup = new ArrayList<>(); public List loadingTiles = new ArrayList<>(); // constructor etc. } in…
2
votes
2 answers

ObjectOutputStream writes same instances differently depending on how i open stream

For the unknown reason, instances written into the same objectOutputStream and instances written separately (If I open objectOutputStream on each iteration) both create two different files. ObjectOutputStream objectOutputStream = new…
wuz1moo
  • 23
  • 1
  • 3
2
votes
1 answer

How to send a string array using sockets and objectoutputstream

I have this to send string or integer but if i want to send a string array what should i use? // A string ("Hello, World"). out.write("Hello, World".getBytes()); // An integer (123). …
drizzom
  • 37
  • 1
  • 7
2
votes
2 answers

How to write serializable object to String without writing to file?

I want to write a class object to the string and then again create an object from it. I searched on the net but all I found is to write an object to file however I want to write in the string, not on file. Below is the example of writing to file…
2
votes
3 answers

Is ObjectOutputStream.writeObject to a file thread safe?

I am working on an application that has to serialize objects to a file for use later. There are multiple threads calling method writeObject (for different objects, same file) concurrently. Is the method thread-safe? Do I have to synchronize the…