1 package parser.stax; 2 40 41 import java.io.*; 42 import javax.xml.parsers.*; 43 import com.sun.xml.fastinfoset.stax.StAXDocumentParser; 44 45 import com.sun.japex.*; 46 import com.sun.xml.fastinfoset.sax.SAXDocumentSerializer; 47 48 public class FastInfosetStAXDriver extends JapexDriverBase { 49 50 String _xmlFile; 51 InputStream _inputStream; 52 53 StAXDocumentParser _staxParser = null; 54 55 public void initializeDriver() { 56 _staxParser = new StAXDocumentParser(); 57 } 58 59 public void prepare(TestCase testCase) { 60 _xmlFile = testCase.getParam("xmlfile"); 61 if (_xmlFile == null) { 62 throw new RuntimeException ("xmlfile not specified"); 63 } 64 65 try { 67 SAXParserFactory spf = SAXParserFactory.newInstance(); 68 spf.setNamespaceAware(true); 69 SAXParser parser = spf.newSAXParser(); 70 71 ByteArrayOutputStream baos = new ByteArrayOutputStream(); 72 SAXDocumentSerializer ds = new SAXDocumentSerializer(); 73 74 ds.setOutputStream(baos); 75 76 FileInputStream fis = new FileInputStream(new File(_xmlFile)); 78 parser.parse(fis, ds); 79 fis.close(); 80 81 _inputStream = new ByteArrayInputStream(baos.toByteArray()); 82 } 83 catch (Exception e) { 84 e.printStackTrace(); 85 } 86 } 87 88 public void warmup(TestCase testCase) { 89 try { 90 _inputStream.reset(); 91 _staxParser.setInputStream(_inputStream); 92 while (_staxParser.hasNext()) { 93 _staxParser.next(); 94 } 95 } 96 catch (Exception e) { 97 e.printStackTrace(); 98 } 99 } 100 101 public void run(TestCase testCase) { 102 try { 103 _inputStream.reset(); 104 _staxParser.setInputStream(_inputStream); 105 while (_staxParser.hasNext()) { 106 _staxParser.next(); 107 } 108 } 109 catch (Exception e) { 110 e.printStackTrace(); 111 } 112 } 113 114 public void finish(TestCase testCase) { 115 } 116 117 public void terminateDriver() { 118 } 119 } 120 | Popular Tags |