Questions tagged [objectinputstream]

The Java `ObjectInputStream` deserialization class from the Java standard library.

ObjectInputStream is a class from the Java standard library that can be used to read and deserialize objects previously serialized by an ObjectOutputStream instance.

619 questions
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
1 answer

Android convert string to ObjectInputStream

I'm trying to construct an ObjectInputStream from a string but I'm getting a java.io.StreamCorruptedException: My code: public static final String PUBLIC_KEY = "-----BEGIN PUBLIC…
giorgos.nl
  • 2,704
  • 27
  • 36
4
votes
3 answers

Receive an object over TCP/IP

I am going to write a program over TCP/IP and I should send objects by client or by server, It is going right when I want to send or receive strings but when I am trying to read an object: private Socket client; public ThreadedClient(Socket client)…
Naeem Baghi
  • 811
  • 2
  • 14
  • 29
4
votes
5 answers

When I run the given code I get A B A as output. I don't understand why it prints A again

Tha code mentioned below returns A B A as output but I didnt understand the logic why A has been printed again after B. class A1 { public A1() { System.out.println("A"); } } class B extends A1 implements Serializable { public…
4
votes
3 answers

ObjectInputStream gives me an empty object (but the readed file is not empty)

I have this serializable class, wich i use to store on a binary file an ArrayList of Strings. public class SaveState implements Serializable{ public static ArrayList favoriteBusStopNumbers = new ArrayList(); public static…
3
votes
0 answers

Problems with I/O with android (Mostly ObjectInputStream)

First time posting on here so go easy on me! Trying to create a method that reads in omw.data, checks to see if SavedSession object already exists in the file. If it does then ignore it otherwise append it to the end of the file. I am able to add…
Mat
  • 31
  • 5
3
votes
0 answers

Android ObjectInputStream(openFileInput) always throws IOException

I'm trying to read from internal storage (a file) however i'm having issues. I get a FileInputStream for a file using FileInputStream fis = context.openFileInput(filename). The call is successful, nothing fails. Next I try to create an…
Sababado
  • 2,524
  • 5
  • 33
  • 51
3
votes
3 answers

program hangs on ObjectInputStream readObject method .

I want to share object of type Stuff which contains ( String name,address,title, ... and byte[] picture ) when connection is established after that my code hangs on objectinputstream readObject() function . No streaming occurs. Can anyone please…
Ahmed
  • 814
  • 2
  • 19
  • 38
3
votes
2 answers

Unable to send Object through ObjectInputStream in Java

I am writing an app that makes use of Object Output and Input Streams. However I have a problem, because I am not able to send my object properly. I write it to stream, and server gives me a class not found exception, even though both client and…
BartoszCichecki
  • 2,227
  • 4
  • 28
  • 41
3
votes
0 answers

readObject returns same object every time

I am writing objects as needed to a file using ObjectOutputStream. However, I am only able to read the first object that is written to the file, even though several objects are added to the file. This means that it just loops, because the user…
Raggen96
  • 49
  • 3
3
votes
2 answers

Java SocketServer with multiple clients - StreamCorruptException

The Application I'm writing a client/server application in Java, that communicates by sending objects over sockets using the ObjectStream classes. Each node in the application looks approximately like this: class Node { SocketServer server; …
wen
  • 3,782
  • 9
  • 34
  • 54
3
votes
2 answers

Java reading different variables with ObjectInputStream

I have an ObjectInputStream which needs to read two different inputs which are a String and my own created object. I have a thread which constantly waits for an input and depending on the input be it a string or object it will process the result. I…
bubblebath
  • 939
  • 4
  • 18
  • 45
3
votes
2 answers

Deserialization using Externalizable interface in Java

I'm learning about Serializable and Externalizable interface and I see that, when an Externalizable object is reconstructed, an instance is created first using the public no-arg constructor, then the readExternal method is called. If the object does…
3
votes
1 answer

ObjectInputStream java.io.StreamCorruptedException: Wrong format: 0 lollipop and marshmalow

im a beginner at java and android, i get the follow: "java.io.StreamCorruptedException: Wrong format: 0" when i try to read back the object. but i only get it on lollipop and marshmallow devices, when i run this at Nougat(7.1) i have no problem at…
3
votes
3 answers

Mocking an ObjectInputStream

When i try to mock ObjectInputStream object i get a NullPointerException. More precisely, when this line is called: when(inputStream.readObject()).thenReturn(new Person("Doe", "John", "123")); Code fragment: @RunWith(MockitoJUnitRunner.class) public…
sidzej
  • 31
  • 3
1 2
3
41 42