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.

589 questions
4
votes
1 answer

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,301
  • 6
  • 26
  • 52
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
  • 673
  • 1
  • 11
  • 26
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,454
  • 5
  • 27
  • 50
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
  • 1,936
  • 3
  • 26
  • 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,712
  • 8
  • 32
  • 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
  • 829
  • 4
  • 15
  • 40
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
6 answers

Java Socket Programming

I am building a simple client/server application using java sockets and experimenting with the ObjectOutputStream etc. I have been following the tutorial at this url http://java.sun.com/developer/technicalArticles/ALT/sockets starting half way down…
Malachi
  • 30,486
  • 16
  • 60
  • 96
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

Android/Java: How to track progress of InputStream

I have the following code in my Android app, and not sure whether it is my Googling skills, but am not able to find a good tutorial on how to monitor progress of InputStream. private void restoreFromUri(Uri uri) { try { InputStream is =…
Shahid Thaika
  • 1,633
  • 3
  • 16
  • 48
3
votes
1 answer

How to read different Object using ObjectInputStream in Java

Note: it's not a duplicate, because here we want to write not only Objects, but also a whole file, then read it back. I have created a single File with 3 Objects using ObjectOutputStream, String String File ( size is between [1 to 1.5]GB ) Below…
1 2
3
39 40