objectinputstream

Java ClassNotFoundException when reading object from a stream

雨燕双飞 提交于 2019-12-23 22:07:06
问题 I am getting a ClassNotFoundException when reading an Object from an ObjectInputStream. The object that is being sent is subclassing "WorkUnit" which the reading code has a reference to. It would seem that the receiving end is complaining because it doesn't know about the specific implementation. Why would it care about that when I'm only referencing the object's superclass: "WorkUnit" on the side that is receiving? Code to read from Stream: private Object readObject() { Object object = null;

ObjectInputStream Error [duplicate]

故事扮演 提交于 2019-12-23 09:55:22
问题 This question already has an answer here : StreamCorruptedException: invalid type code: AC (1 answer) Closed 2 years ago . 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 and I open it then append any number of objects, I can open the ObjectInputStream object and access all the objects. However, if

Restore previously serialized JFrame-object, how?

五迷三道 提交于 2019-12-19 09:57:41
问题 I have managed to serialize my very basic GUI-object containing a JTextArea and a few buttons to a file 'test.ser'. Now, I would like to completely restore the previously saved state from 'test.ser', but seem to have a misconception of how to properly deserialize an objects state. The class MyFrame creates the JFrame and serializes it. public class MyFrame extends JFrame implements ActionListener { // Fields JTextArea textArea; String title; static MyFrame gui = new MyFrame(); private static

Changing instance state does not get reflected in serialized object

自作多情 提交于 2019-12-19 09:53:46
问题 I wrote following simple code public static void main(String args[]) throws FileNotFoundException, IOException, ClassNotFoundException { ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(new File("data.txt"))); Human human = new Human(); human.setAge(21); human.setName("Test"); System.out.println("Human : " + human); oos.writeObject(human); human.setName("Test123"); oos.writeObject(human); ObjectInputStream ois = new ObjectInputStream(new FileInputStream(new File("data.txt"

Exception.getCause() returning null when trying to find the source of an exception

倖福魔咒の 提交于 2019-12-18 17:05:49
问题 why does System.out.println(e.getCause()); gives null ? And can store whole HashSet collection like this? private void saving() throws IOException, ClassNotFoundException { ObjectOutputStream out = null; try { out = new ObjectOutputStream(new BufferedOutputStream(new FileOutputStream(dataFile))); out.writeObject(c); } catch (java.io.NotSerializableException e) { System.out.println(e.getCause()); } finally { out.close(); } } Used printStackTrace() instead of getCause() java.io

Continuously read objects from an ObjectInputStream in Java

你离开我真会死。 提交于 2019-12-17 21:34:54
问题 I have a problem using an ObjectInputStream and I have been struggling with it for 2 days now. I tried to search for a solution but unfortunately found no fitting answer. I am trying to write a client/server application in which the client sends objects (in this case a configuration class) to the server. The idea is that connection keeps alive after sending the object so it is possible to send a new object if necessary. Here are the important parts of my client code: mSocket = new Socket("192

Must server & client have reverse sequence of claiming ObjectOutputStream & ObjectInputStream?

徘徊边缘 提交于 2019-12-17 21:28:57
问题 In my experiment, if Server has this: ObjectInputStream objectInputStream = new ObjectInputStream(socket.getInputStream()); ObjectOutputStream objectOutputStream = new ObjectOutputStream(socket.getOutputStream()); then client side has to do this, in the opposite order: ObjectOutputStream objectOutputStream = new ObjectOutputStream(socket.getOutputStream()); ObjectInputStream objectInputStream = new ObjectInputStream(socket.getInputStream()); Otherwise server and client will deadlock. What's

Java FileInputStream ObjectInputStream reaches end of file EOF

让人想犯罪 __ 提交于 2019-12-17 04:06:09
问题 I am trying to read the number of line in a binary file using readObject, but I get IOException EOF. Am I doing this the right way? FileInputStream istream = new FileInputStream(fileName); ObjectInputStream ois = new ObjectInputStream(istream); /** calculate number of items **/ int line_count = 0; while( (String)ois.readObject() != null){ line_count++; } 回答1: readObject() doesn't return null at EOF. You could catch the EOFException and interpret it as EOF, but this would fail to detect

Load files bigger than 1M from assets folder

和自甴很熟 提交于 2019-12-16 20:18:35
问题 I'm going crazy, I created a file object, so it can be read with ObjectInputStream, and I placed the assets folder. The method works with a file smaller than 1M, and give error with larger files. I read that is a limit of Android platform, but I also know that can be "easily" avoided. Those who have downloaded the game Reging Thunder, for example, can easily see that in their assets folder is a file 18.9M large. This is my code for read 1 object from a ObjecInputStream File f = File

java.net.SocketTimeoutException: Read timed out

爱⌒轻易说出口 提交于 2019-12-14 03:39:47
问题 I have an application with client server architecture. The client use Java Web Start with Java Swing / AWT and the sert uses HTTP server / Servlet with Tomcat. The communication is made from the serialization of objects, create a ObjectOutput serializes a byte array and send to the server respectively called the ObjectInputStream and deserializes. The application follows communicating correctly to a certain time of concurrency where starting to show error "SocketException read timeout". The