objectinputstream

ObjectInputStream happy with FileInputStream, not happy with getResourceAsStream

三世轮回 提交于 2019-11-28 10:56:02
I have some pretty standard code which takes in a serialized object from a stream, which bascially looks like this: Object getObjectFromStream(InputStream is) { ObjectInputStream ois = new ObjectInputStream(is); return ois.readObject(); } I then have a file in my resources folder, so on my development machine, I can either reference it as a File, or as a JarResource: InputStream is = new FileInputStream("/home/.../src/main/resources/serializedObjects/testObject"); InputStream is = this.getClass().getResourceAsStream("/serializedObjects/testObject"); In my head, both should do the exact same

The type java.io.ObjectInputStream cannot be resolved. It is indirectly referenced from required .class files

本秂侑毒 提交于 2019-11-28 09:36:12
I have downloaded Eclipse and tried to create a sample servlet program but I got following error The type java.io.ObjectInputStream cannot be resolved. It is indirectly referenced from required .class files I have configured build path correctly. I am using Java 8 and Apache Tomcat 7 and libraries for both are referenced correctly. Problem is specifically for Java EE only. Ordinarily Java SE projects are running fine. mzjn Something happened in Java 8 Update 91 that broke existing JSP code. That seems pretty clear. Here is a sample of similar questions and bug reports: Unable to compile JSP

Java Socket Programming

回眸只為那壹抹淺笑 提交于 2019-11-27 21:28:18
问题 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 when it talks about transporting objects over sockets. See my code for the client http://pastebin.com/m37e4c577 However this doesn't seem to work and i cannot figure out what's not working. The code commented out at the bottom is directly copied

How can I append to an existing java.io.ObjectStream? [duplicate]

元气小坏坏 提交于 2019-11-27 18:03:14
问题 This question already has answers here : Appending to an ObjectOutputStream (6 answers) Closed 5 years ago . As for now I will get java.io.StreamCorruptedException when I try to append an Object. I have searched the Internet for a way to overcome that. The answer I found so far is it can't be done. A way around this problem is to write the objects into a list and then write the list to the file. But I have to overwrite that file everytime when I add new objects. It seems not to be the optimal

new ObjectInputStream() blocks

感情迁移 提交于 2019-11-27 14:11:10
public class SerProg { static ServerSocket ser=null; static Socket cli=null; static ObjectInputStream ins=null; static ObjectOutputStream outs=null; public static void main(String[] args) { try { ser=new ServerSocket(9000,10); cli=ser.accept(); System.out.println("Connected to :"+cli.getInetAddress().getHostAddress()+" At Port :"+cli.getLocalPort()); ins=new ObjectInputStream(cli.getInputStream()); outs=new ObjectOutputStream(cli.getOutputStream()); String str=(String)ins.readObject(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } } And the Client public

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

(java) ObjectInputStream deserializing wrong version of object [duplicate]

血红的双手。 提交于 2019-11-27 07:46:10
问题 This question already has answers here : Java socket/serialization, object won't update (2 answers) Closed 4 years ago . I'm just learning networking from a java book, so I'm a bit of a noob. I couldn't find this problem in the book or online so I decided to ask the internet. The book says to use the ObjectOutputStream and ObjectInputStream to send and receive objects to different consoles. Now, I'm able to successfully receive the objects I send-- but only once. When I send different objects

java.io.EOFException while writing and reading froma servlet

两盒软妹~` 提交于 2019-11-27 06:24:45
问题 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 happy with FileInputStream, not happy with getResourceAsStream

余生长醉 提交于 2019-11-27 05:57:01
问题 I have some pretty standard code which takes in a serialized object from a stream, which bascially looks like this: Object getObjectFromStream(InputStream is) { ObjectInputStream ois = new ObjectInputStream(is); return ois.readObject(); } I then have a file in my resources folder, so on my development machine, I can either reference it as a File, or as a JarResource: InputStream is = new FileInputStream("/home/.../src/main/resources/serializedObjects/testObject"); InputStream is = this

The type java.io.ObjectInputStream cannot be resolved. It is indirectly referenced from required .class files

左心房为你撑大大i 提交于 2019-11-27 03:03:08
问题 I have downloaded Eclipse and tried to create a sample servlet program but I got following error The type java.io.ObjectInputStream cannot be resolved. It is indirectly referenced from required .class files I have configured build path correctly. I am using Java 8 and Apache Tomcat 7 and libraries for both are referenced correctly. Problem is specifically for Java EE only. Ordinarily Java SE projects are running fine. 回答1: Something happened in Java 8 Update 91 that broke existing JSP code.