1 19 20 package org.openide.filesystems.xmlfs; 21 22 import java.io.*; 23 import java.net.URL ; 24 25 import org.xml.sax.*; 26 27 import org.openide.filesystems.XMLFileSystem; 28 29 30 31 36 public class XMLFSvsParserTest extends org.netbeans.performance.Benchmark 37 implements EntityResolver { 38 private static final String PUBLIC_ID = "-//NetBeans//DTD Filesystem 1.0//EN"; private static final String DTD_PATH = "/org/openide/filesystems/filesystem.dtd"; 41 private URL url; 42 43 45 public XMLFSvsParserTest (String name) { 46 super (name, new Object [] { 47 new Integer (100), 48 new Integer (1000), 49 new Integer (10000) 50 }); 51 } 52 53 55 public static void main(java.lang.String [] args) { 56 junit.textui.TestRunner.run(new junit.framework.TestSuite (XMLFSvsParserTest.class)); 57 } 58 59 61 protected void setUp () throws Exception { 62 File file = File.createTempFile ("afile", null); 63 file.deleteOnExit (); 64 65 Integer count = (Integer )getArgument (); 66 67 prepareXmlFilesystem (file, count.intValue (), "anyfilewithanyvalues"); 68 69 url = file.toURL (); 70 } 71 72 73 75 public void testXMLParser () throws Exception { 76 int cnt = getIterationCount (); 77 78 while (cnt-- > 0) { 79 org.xml.sax.HandlerBase base = new org.xml.sax.HandlerBase (); 80 javax.xml.parsers.SAXParserFactory factory = javax.xml.parsers.SAXParserFactory.newInstance (); 81 factory.setValidating (false); 82 org.xml.sax.Parser parser = factory.newSAXParser ().getParser (); 83 parser.setEntityResolver(this); 84 parser.setDocumentHandler (base); 85 86 parser.parse (new InputSource (url.openStream ())); 87 } 88 } 89 90 91 93 public void testXMLFS () throws Exception { 94 int cnt = getIterationCount (); 95 while (cnt-- > 0) { 96 XMLFileSystem fs = new XMLFileSystem (url); 97 } 98 } 99 100 102 public InputSource resolveEntity(java.lang.String pid,java.lang.String sid) throws SAXException { 103 if (pid != null && pid.equals(PUBLIC_ID)) 104 return new InputSource (getClass ().getResourceAsStream (DTD_PATH)); 105 106 return new InputSource (sid); 107 } 108 109 110 112 private static void prepareXmlFilesystem( File jar, int count, String prefix ) throws IOException { 113 FileOutputStream stream = new FileOutputStream( jar ); 114 OutputStreamWriter writer = new OutputStreamWriter( stream, "UTF8" ); 115 PrintWriter print = new PrintWriter( writer ); 116 print.println( 117 "<?xml version=\"1.0\"?>" + 118 "<!DOCTYPE filesystem PUBLIC " + 119 "\"-//NetBeans//DTD Filesystem 1.0//EN\" " + 120 "\"http://www.netbeans.org/dtds/filesystem-1_0.dtd\">\n" + 121 "<filesystem>" 122 ); 123 124 for( int i=0; i<count; i++ ) { 125 print.println( "<file name=\"" + prefix + i + "\"/>" ); 126 } 127 print.println( "</filesystem>" ); 128 print.flush(); 129 print.close(); 130 } 131 132 } 133 | Popular Tags |