• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Trying to read an XML file, getting java.io.StreamCorruptedException
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Trying to read an XML file, getting java.io.StreamCorruptedException


  • Subject: Trying to read an XML file, getting java.io.StreamCorruptedException
  • From: Denis Stanton <email@hidden>
  • Date: Thu, 25 Sep 2003 20:04:29 +1200

Hi

I'm trying to add the ability to read an XML file into my WebObjects
application and I'm stumbling at the first hurdle.  I wonder if anyone
can tell if I'm doing the right thing.

My application needs to read an XML file that has been exported from
FileMaker. The first few line of the file are:

<?xml version="1.0" encoding="UTF-8" ?>
<FMPXMLRESULT xmlns="http://www.filemaker.com/fmpxmlresult";>
	<ERRORCODE>0</ERRORCODE>
	<PRODUCT BUILD="11/13/2002" NAME="FileMaker Pro" VERSION="6.0v4"/>
	<DATABASE DATEFORMAT="d/M/yyyy" LAYOUT="" NAME="04_inquiriesfp5"
RECORDS="1" TIMEFORMAT="k:mm:ss "/>
	<METADATA>
		<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="accommodation" TYPE="TEXT"/>
		<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="Action_ID" TYPE="NUMBER"/>
and so on ......

I have copied some code from Apple's XML Serialization documentation,
but the application fails while trying to read the above data file.
The exception message reads:
java.io.StreamCorruptedException: Caught EOFException while reading the
stream header
	at
java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:840)
	at java.io.ObjectInputStream.<init>(ObjectInputStream.java:163)
	at
com.webobjects.foundation.xml.NSXMLInputStream.<init>(NSXMLInputStream.j
ava:290)
	at Import.deserialize(Import.java:118)

"Import" is the name of my WOComponent.  The message appears to say
that it struck End Of File while reading the header.  What's wrong with
the header?  Does this mean that the NSXMLInputStream class cannot cope
with an XML file produced by FileMaker?  The documentation refers to
"transformation" of XML.  Is it saying that XML files produced by third
parties (FileMaker), need to be reformatted before they can be read by
NSXMLInputStream?

Here is the code I copied:

import java.util.*;
import java.io.*;
import com.webobjects.appserver.xml.WOXMLDecoder;
import com.webobjects.foundation.xml.NSXMLInputStream;

     public void deserialize() {
         // Filename of the input file.
         String filename = "/Library/WebObjects/enquiries.xml";

         try {
             // Create a stream from the input file.
             FileInputStream input_stream = new
FileInputStream(filename);

             // Create an XML-input stream.
             NSXMLInputStream xml_stream = new
NSXMLInputStream(input_stream); <------- fails on this line

             // Read the data.
             String theString = (String)xml_stream.readObject();
             int theInt = xml_stream.readInt();

             // Close the streams.
             xml_stream.close();
             input_stream.close();
         }

         catch (IOException e) {
             e.printStackTrace();
         }

         catch (ClassNotFoundException e) {
             e.printStackTrace();
         }
     }

Denis Stanton
email@hidden
Home:  (09) 533 0391
mobile: 021 1433622
_______________________________________________
webobjects-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/webobjects-dev
Do not post admin requests to the list. They will be ignored.

References: 
 >Java Client xml framework (From: "Shantanu Wadodkar" <email@hidden>)

  • Prev by Date: OpenEJB failure
  • Next by Date: Using NSArray for Lists and WODisplayGroup for Batches
  • Previous by thread: Java Client xml framework
  • Next by thread: Must an EOEnterpriseObject be inserted into EOEditingContext to use?
  • Index(es):
    • Date
    • Thread