objectoutputstream

How to store a class object into Internal Memory Storage using serializable?

陌路散爱 提交于 2019-12-03 15:06:11
问题 I need to store this object into the internal storage memory of the phone, and i have the <uses-permission android:name="android.permission.WRITE_INTERNAL_STORAGE"></uses-permission> set on the manifest. The object itself haves two static methods for store and reload it from the internal memory: public class SaveState implements Serializable { static public List<FullMagazine> fms = new ArrayList<FullMagazine>(); static SaveState instance=null; public static SaveState getInstance(){ if(

SocketException: Connection reset on server with ObjectInputStream

别来无恙 提交于 2019-12-02 13:10:32
问题 I'm trying to get my head around the ObjectInputStream/ObjectOutputStream , so I create a very simple server-client application where the client sends a HashMap object over the created stream and the server receives that and prints it out. This my server code: import java.io.*; import java.net.*; public class Server { public static void main(String[] args) throws IOException, ClassNotFoundException { ServerSocket server = new ServerSocket(4444); while (true) { Socket socket = server.accept();

SocketException: Connection reset on server with ObjectInputStream

夙愿已清 提交于 2019-12-02 04:14:18
I'm trying to get my head around the ObjectInputStream/ObjectOutputStream , so I create a very simple server-client application where the client sends a HashMap object over the created stream and the server receives that and prints it out. This my server code: import java.io.*; import java.net.*; public class Server { public static void main(String[] args) throws IOException, ClassNotFoundException { ServerSocket server = new ServerSocket(4444); while (true) { Socket socket = server.accept(); ObjectInputStream objIn = new ObjectInputStream(socket.getInputStream()); if (objIn.readObject() !=

ObjectInputStream readObject(): ClassNotFoundException

橙三吉。 提交于 2019-12-01 21:06:53
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 Data object) This object is received on the client side and cast to a Data object: ObjectInputStream input = new ObjectInputStream(socket.getInputStream()); Object receiveObject = input.readObject(); if (receiveObject instanceof Data){ Data receiveData = (Data) receiveObject; // some code here... } I'm getting a java.lang.ClassNotFoundException:

How can I convert an Object to Inputstream

久未见 提交于 2019-11-30 05:56:46
How can I convert the java Object into a InputStream? You can use ObjectOutputStream You write the object (obj in the code below) to the ObjectOutputStream , your object you want to convert to an input stream must implement Serializable . ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(baos); oos.writeObject(obj); oos.flush(); oos.close(); InputStream is = new ByteArrayInputStream(baos.toByteArray()); 来源: https://stackoverflow.com/questions/9264162/how-can-i-convert-an-object-to-inputstream

Performance issue using Javas Object streams with Sockets

蹲街弑〆低调 提交于 2019-11-29 09:43:30
I'm trying to do local IPC using Sockets and Object streams in Java however I'm seeing poor performance. I am testing the ping time of sending an object via an ObjectOutputStream to receiving a reply via an ObjectInputStream over a Socket. Here's the Requestor: public SocketTest(){ int iterations = 100; try { Socket socket = new Socket("localhost", 1212); ObjectInputStream objectInputStream = new ObjectInputStream(socket.getInputStream()); ObjectOutputStream objectOutputStream = new ObjectOutputStream(socket.getOutputStream()); double start = System.currentTimeMillis(); for (int i = 0; i <

Object property change is not saved after streaming in java

懵懂的女人 提交于 2019-11-28 12:45:23
Update: OK so I've grayed out parts of code and found what was causing the problem. I've added here 3 lines of code with the comment "this is the added code that causes the problem". But I still don't understand why it affects the result. I am working on a client-server application that sends data objects via ObjectOutputStream and ObjectInputStream. I noticed something strange that made me think I might not fully understand object referencing. On the client side I have a method that creates and returns a User object: private static User createNewUser() { User newUser = new User(); newUser

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

∥☆過路亽.° 提交于 2019-11-28 11:49:12
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 the reason for this? and is there a formal API spec for it? Yes. I see how this might happen. The

java.io.EOFException while writing and reading froma servlet

被刻印的时光 ゝ 提交于 2019-11-28 11:40:55
I have the following code on the applet side: URL servlet = new URL(appletCodeBase, "FormsServlet?form=requestRoom"); URLConnection con = servlet.openConnection(); con.setDoOutput(true); con.setDoInput(true); con.setUseCaches(false); con.setRequestProperty("Content-Type", "application/octet-stream"); ObjectOutputStream out = new ObjectOutputStream(con.getOutputStream()); out.writeObject(user);//user is an object of a serializable class out.flush(); out.close(); ObjectInputStream in = new ObjectInputStream(con.getInputStream()); status = (String)in.readObject(); in.close(); if("success".equals(

ObjectInputStream/ObjectOutputStream work not right

余生长醉 提交于 2019-11-27 08:35:52
问题 I have classes: Client, Server and Background is working with Player class. I really don't understand why my Client class with ObjectInputStream / ObjectOutputStream doesn't work right. What i'm doing bad? Where's my mistake? package Shooter2Dv27082013; public class Player implements Serializable{ .... public int x=10; public int y=10; .... } package Shooter2Dv27082013; public class Background extends JPanel implements ActionListener, Serializable { public int countCollisions=0; private int