my dog learned polymorphism*
The moose likes Servlets and the fly likes java.io.StreamCorruptedException Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "java.io.StreamCorruptedException" Watch "java.io.StreamCorruptedException" New topic
Author

java.io.StreamCorruptedException

bujji adapa
Greenhorn

Joined: Oct 17, 2001
Posts: 11
Iam trying to load applet which calls servlet for a random number.
When i run my applet iam getting an error message as follows:
Error inflating object: java.io.StreamCorruptedException: Caught EOFException wh
ile reading the stream header Caught EOFException while reading the stream heade
r
Exception occurred during event dispatching:
java.lang.NullPointerException
at testapplet.drawAxes(testapplet.java:90)
at testapplet.paint(testapplet.java:111)
at sun.awt.RepaintArea.paint(RepaintArea.java:298)
at sun.awt.windows.WComponentPeer.handleEvent(WComponentPeer.java:199)
at java.awt.Component.dispatchEventImpl(Component.java:2665)
at java.awt.Container.dispatchEventImpl(Container.java:1216)
at java.awt.Component.dispatchEvent(Component.java:2499)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:336)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchTh
read.java:134)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThre
ad.java:101)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:96)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:88)
Can anyone tell me why this is happening?
Please answer to my question....
I also posted a topic two days back for which i did not get any reply.
I expect some positive response this time.
regards
bujji
Kyle Brown
author
Ranch Hand

Joined: Aug 10, 2001
Posts: 3892
    
    5
Could you possibly post a short snippet of code from your applet showing how you are receiving the information from the servlet and a corresponding piece of code from the servlet side?
Kyle
------------------
Kyle Brown,
Author of Enterprise Java (tm) Programming with IBM Websphere
See my homepage at http://members.aol.com/kgb1001001 for other WebSphere information.


Kyle Brown, Author of Persistence in the Enterprise and Enterprise Java Programming with IBM Websphere, 2nd Edition
See my homepage at http://www.kyle-brown.com/ for other WebSphere information.
bujji adapa
Greenhorn

Joined: Oct 17, 2001
Posts: 11
Here is my applet code:
public Integer getNumberFromServlet() {
URL url = null;
try{
// Create the URL
String urlStr = "http://localhost:8080/servlet/RandomServlet";
url = new URL( urlStr + "?");
} catch( MalformedURLException e) {
System.out.println(" URL: " + e.toString());
e.printStackTrace();
return null;
}
// Open the stream -- this starts the service() method in the servlet
InputStream inStream = null;
try{
inStream = url.openStream();
} catch( IOException e){
System.out.println("RandomApplet Exception: " + e.toString());
e.printStackTrace();
return null;
}
// Get random number...
Integer randomnum = null;
// Inflage Random number Object
randomnum =
(Integer) inflate( inStream);
return randomnum;
}
Object inflate( InputStream in){
Object obj = null;

try{
ObjectInputStream objIn = new ObjectInputStream( in);
obj = objIn.readObject();
} catch( IOException e){
System.out.println("Error inflating object: " + e + " " + e.getMessage());
} catch( ClassNotFoundException e){
System.out.println("Error finding class: " + e.getMessage());
}
return obj;
}
And my servlet code is:
public void service(javax.servlet.ServletRequest req,javax.servlet.ServletResponse res) throws IOException, ServletException
{
// Create the output stream for communicating with the Applet
FilterOutputStream objOut = new FilterOutputStream( res.getOutputStream());
byte[] errorDeflatedExam = null;
ServletContext context = getServletContext();
if (context != null) {
context.log("LOG:ReqInfoServlet:service START");
}
Integer randomnum= rangen.getRandomVal();
// Get a deflated random number Object
byte[] aDeflatedRandomNumber = (byte[]) buildDeflatedRandomNumber(randomnum);
//Write it to the applet
//objOut.write(aDeflatedRandomNumber);
//objOut.close();
}
private byte[] buildDeflatedRandomNumber(Integer aint)
{
//Long randomnum= rangen.getRandomVal();
// Deflate the object to an output stream
ObjectOutputStream objOut = null;
ByteArrayOutputStream bOut = null;
try {
bOut = new ByteArrayOutputStream();
objOut = new ObjectOutputStream(bOut);
objOut.writeObject(aint);
objOut.close();
} catch (java.io.IOException e) {
e.printStackTrace();
return null;
}
return bOut.toByteArray();
}

Thanks for the response.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: java.io.StreamCorruptedException