X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=unused%2Fxml%2Fsax%2Fdemo%2FByteStreamDemo.java;fp=unused%2Fxml%2Fsax%2Fdemo%2FByteStreamDemo.java;h=5da34b97511e6fb66e2bbc652bfc6b947ee46571;hb=8a43b8353b89a47002ef17c959ed61281fc4d826;hp=0000000000000000000000000000000000000000;hpb=55bfdb07355198ae1a1a8b5e14933b4669113ca6;p=jalview.git diff --git a/unused/xml/sax/demo/ByteStreamDemo.java b/unused/xml/sax/demo/ByteStreamDemo.java new file mode 100644 index 0000000..5da34b9 --- /dev/null +++ b/unused/xml/sax/demo/ByteStreamDemo.java @@ -0,0 +1,78 @@ +package org.xml.sax.demo; +// SAX demonstration for parsing from a raw byte stream. +// No warranty; no copyright -- use this as you will. +// $Id: ByteStreamDemo.java,v 1.4 1998/05/01 20:38:19 david Exp $ + +import org.xml.sax.Parser; +import org.xml.sax.InputSource; +import org.xml.sax.SAXException; + +import org.xml.sax.helpers.ParserFactory; + +import java.io.FileInputStream; + + + +/** + * Demonstrate parsing from a byte stream. + * + *

Usage: java -Dorg.xml.sax.parser=CLASSNAME ByteStreamDemo + * FILE

+ * + *

The SAX parser will open a byte stream to the file name + * provided. Note the use of the InputStreamAdapter class to allow a + * Java InputStream to serve as a SAX ByteStream.

+ * + * @see DemoHandler + */ +public class ByteStreamDemo { + + + /** + * Main entry point. + */ + public static void main (String args[]) + throws Exception + { + Parser parser; + InputSource source; + DemoHandler handler; + FileInputStream input; + + // First, check the command-line usage. + if (args.length != 1) { + System.err.println("Usage: java -Dorg.xml.sax.parser= " + + "SystemIdDemo "); + System.exit(2); + } + + // Allocate a SAX Parser object, using + // the class name provided in the + // org.xml.sax.parser property. + parser = ParserFactory.makeParser(); + + // Allocate an event handler, and register + // it with the SAX parser for all four + // types of events (we could use a + // separate object for each). + handler = new DemoHandler(); + parser.setEntityResolver(handler); + parser.setDTDHandler(handler); + parser.setDocumentHandler(handler); + parser.setErrorHandler(handler); + + // Create a Java FileInputStream from + // the file: note that SAX cannot + // use this directly. + input = new FileInputStream(args[0]); + + // Create the input source. + source = new InputSource(input); + source.setSystemId(args[0]); + + // Parse the document from the + // ByteStream. + parser.parse(source); + } + +}