• Post Reply Bookmark Topic Watch Topic
  • New Topic

Is there a way to open .ser file?

 
Gitesh Ramchandani
Ranch Hand
Posts: 274
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there a way to open/view .ser (Java Serialized Object File (Sun))file so that i can see the contents? I urgently need it, please help.

Thanks,
Gitesh
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There isn't. Do you know the class of the serialized object? If so, what prevents you from writing a piece of code that deserializes it and shows you all the pertinent information?
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Or we could say that yes there is, and that way is by using an ObjectInputStream. From the question, it's not clear if you're familiar with the basics of how to use this.

Once you know the class of the object(s) in the file, you can cast the objects to the correct class and call other methods.

It also might be useful to use XStream to write an XML representation of each object after you read it. This tool does all the work of using reflection to identify all the fields in an object, and writes the object in an easy-to-read format.
 
Gitesh Ramchandani
Ranch Hand
Posts: 274
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually i don;t know about serialization. Also the ser file i got from a simulator for 310-035 exam. If you can help me in deserializing the file/code, it will be helpful for me.

Thanks,
Gitesh
 
Gitesh Ramchandani
Ranch Hand
Posts: 274
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Jim Yingst:
Or we could say that yes there is, and that way is by using an ObjectInputStream. From the question, it's not clear if you're familiar with the basics of how to use this.

Once you know the class of the object(s) in the file, you can cast the objects to the correct class and call other methods.

It also might be useful to use XStream to write an XML representation of each object after you read it. This tool does all the work of using reflection to identify all the fields in an object, and writes the object in an easy-to-read format.


Thanks a lot Jim for replying. I have the jar file for the simulator, which contains all the classes,etc and questions.ser file.

The MANIFEST.MF file gives the class where to start with, so now with this information how can i go ahead and decode the .ser file?

Where and how can i use the code you provided to get the work done?

Here is the url for one such jar file:
http://www.santis.ch/training/java/jcp/selftester/santis_JCP.jar

I hope i'm not sounding like an idiot in asking so many questions, while not knowing anything about serialization

Thanks,
Gitesh
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, you probably need to include the jar file(s) in your class path. Have you tried running the code I showed? What happens?

It may well be helpful to read about serialization at this point. Here is an article that looks good. Many more can be found by googling "java serialization", "java serialization tutorial", etc.
[ March 03, 2008: Message edited by: Jim Yingst ]
 
Gitesh Ramchandani
Ranch Hand
Posts: 274
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Jim Yingst:
Well, you probably need to include the far file(s) in your class path. Have you tried running the code I showed? What happens?

[ March 03, 2008: Message edited by: Jim Yingst ]


ok, after that i create a new java file having the code you given above, replace the filename with the actual .ser file and execute the resulting .java file? what will it result to?



Regards,
Gitesh
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's what I'm asking you. I don't know what's in the ser file. I gave you some code that can help you find out, though. You need to run it and find out.
 
Gitesh Ramchandani
Ranch Hand
Posts: 274
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I placed the jar file in E:\Program Files\Java\jdk1.6.0_02\bin, where my .java files are placed.

I modified the code you have shown to get rid of compiler errors. On running the code it printed B.

How should i proceed further.

Some more information

Contents of MANIFEST.MF:
Manifest-Version: 1.0
Ant-Version: Apache Ant 1.6.5
Created-By: 1.6.0-b105 (Sun Microsystems Inc.)
main-class: fake.MainFrame

Jar
|+--eu
|+--fake
|+--lts
|+--META-INF
|+--Questions.ser

Modified code:



Thanks,
Gitesh
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It prints "B"? What does B mean? It looks like you added some code yourself which is responsible for this message. Perhaps you should print the exception message instead - I usually just use either e.printStackTrace(), or sometimes System.out.println("Error: " + e),
 
Gitesh Ramchandani
Ranch Hand
Posts: 274
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i added


that means it is throwing FileNotFoundException.
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeessssss...

Do you can you guess which file it's unable to find? (Hint: there's only one.) Is there any way you can change the code to specify exactly where that file is located?
 
Gitesh Ramchandani
Ranch Hand
Posts: 274
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok the filename is Questions.ser. Also I modified the code to mention the exact location of the file:




But now i get IOException on running it:



Thats something which is going above my head

What to do next? From little bit what i read and understand is that, there is some problem with the format/conversion i'm doing to the content of Questions.ser file. Please help in this.

Thanks,
Gitesh
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ah, now that's interesting. That tells us that it's not a standard Java serialized object file. I became curious and started looking around the site you're getting this from. They've got the full source code of the application available here (under a GNU license):

JCP_tester_src.jar

You can unjar that with:

jar xfv JCP_tester_src.jar

Looking around the code, I found two things. One is that the questions are available in an XML file at

data/xml/JCP_JSDK1.4.xml

If you want to see them all in one place, that's the easy way to do it. The other thing I found is the code that reads the Questions.ser file. That's at

src/eu/gressly/io/ResourceAnchor.java

in the getObjectInputStream() method. The key lines are:

So, it's not just a serialized file - it's a file that was serialized and then gzipped. If you still want to deserialize it, that code should solve the problem. However if you just want the questions and answers, the XML file takes care of that already.
[ March 04, 2008: Message edited by: Jim Yingst ]
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Keep in mind that serialization may not be compatible between JDK versions. So if you're using (say) Java 1.5 to read a file that was serialized using Java 1.4, it may not work.
 
Gitesh Ramchandani
Ranch Hand
Posts: 274
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But is there a way to know if the serialization was done with 1.4/1.5? :roll:
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Generally you can just try it and see - if there's an incompatibility you'll get an exception, probably an InvalidClassException. For this application the web page tells us the application uses JRE 1.5, although it seems to run fine on 11.6 as well.
 
Philipp Gressly Freimann
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there


There is also a code that reads the XML-File and produces the Questions.ser File. Simply start the ant srcipt using "clean", "compile" and "questions" as targets.

Any help to make Santis JCP Tester better is welcome.


phi
 
Rob Spoor
Sheriff
Posts: 20819
68
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Gitesh hasn't posted in over 18 months, so I doubt he/she is still looking for an answer. http://faq.javaranch.com/java/DontWakeTheZombies
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!