1 package size; 2 40 41 import java.io.*; 42 import org.xml.sax.InputSource ; 43 import javax.xml.parsers.*; 44 import java.util.Properties ; 45 46 import com.sun.xml.fastinfoset.sax.*; 47 import com.sun.xml.fastinfoset.vocab.*; 48 49 import com.sun.japex.*; 50 51 public class FastInfosetSizeDriver extends JapexDriverBase { 52 53 protected String _xmlFile; 54 protected byte[] _fastInfosetByteArray; 55 56 public FastInfosetSizeDriver() { 57 } 58 59 public void initializeDriver() { 60 } 61 62 public void prepare(TestCase testCase) { 63 _xmlFile = testCase.getParam("xmlfile"); 64 if (_xmlFile == null) { 65 throw new RuntimeException ("xmlfile not specified"); 66 } 67 68 try { 70 SAXParserFactory spf = SAXParserFactory.newInstance(); 71 spf.setNamespaceAware(true); 72 SAXParser parser = spf.newSAXParser(); 73 74 ByteArrayOutputStream baos = new ByteArrayOutputStream(); 75 SAXDocumentSerializer ds = new SAXDocumentSerializer(); 76 77 ds.setOutputStream(baos); 78 79 FileInputStream fis = new FileInputStream(new File(_xmlFile)); 81 parser.parse(fis, ds); 82 fis.close(); 83 84 _fastInfosetByteArray = baos.toByteArray(); 85 } 86 catch (Exception e) { 87 e.printStackTrace(); 88 } 89 } 90 91 public void warmup(TestCase testCase) { 92 } 93 94 public void run(TestCase testCase) { 95 } 96 97 public void finish(TestCase testCase) { 98 testCase.setDoubleParam(Constants.RESULT_VALUE, 99 _fastInfosetByteArray.length / 1024.0); 100 } 101 102 public void terminateDriver() { 103 } 104 } 105 | Popular Tags |