KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > dom4j > samples > performance > ParseTest


1 /*
2  * Copyright 2001-2004 (C) MetaStuff, Ltd. All Rights Reserved.
3  *
4  * This software is open source.
5  * See the bottom of this file for the licence.
6  *
7  * $Id: ParseTest.java,v 1.4 2005/01/29 14:53:13 maartenc Exp $
8  */

9
10 package org.dom4j.samples.performance;
11
12 import java.io.BufferedReader JavaDoc;
13 import java.io.FileReader JavaDoc;
14 import java.io.StringReader JavaDoc;
15
16 import org.dom4j.Document;
17 import org.dom4j.io.SAXReader;
18
19 /**
20  * Tests the performance of parsing a Document
21  *
22  * @author <a HREF="mailto:james.strachan@metastuff.com">James Strachan </a>
23  * @version $Revision: 1.4 $
24  */

25 public class ParseTest extends PerformanceSupport {
26
27     private int bufferSize = 128 * 1024;
28
29     private Document document;
30
31     private SAXReader xmlReader;
32
33     private String JavaDoc text;
34
35     public static void main(String JavaDoc[] args) {
36         run(new ParseTest(), args);
37     }
38
39     public ParseTest() {
40     }
41
42     protected void setUp() throws Exception JavaDoc {
43         xmlReader = new SAXReader();
44
45         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc(64 * 1024);
46         BufferedReader JavaDoc reader = new BufferedReader JavaDoc(new FileReader JavaDoc(xmlFile));
47         while (true) {
48             String JavaDoc text = reader.readLine();
49             if (text == null) {
50                 break;
51             }
52             buffer.append(text);
53             buffer.append("\n");
54         }
55         text = buffer.toString();
56     }
57
58     protected void tearDown() throws Exception JavaDoc {
59         println("Created Document: " + document);
60     }
61
62     protected Task createTask() throws Exception JavaDoc {
63         return new Task() {
64             public void run() throws Exception JavaDoc {
65                 document = xmlReader.read(new StringReader JavaDoc(text));
66             }
67         };
68     }
69 }
70
71 /*
72  * Redistribution and use of this software and associated documentation
73  * ("Software"), with or without modification, are permitted provided that the
74  * following conditions are met:
75  *
76  * 1. Redistributions of source code must retain copyright statements and
77  * notices. Redistributions must also contain a copy of this document.
78  *
79  * 2. Redistributions in binary form must reproduce the above copyright notice,
80  * this list of conditions and the following disclaimer in the documentation
81  * and/or other materials provided with the distribution.
82  *
83  * 3. The name "DOM4J" must not be used to endorse or promote products derived
84  * from this Software without prior written permission of MetaStuff, Ltd. For
85  * written permission, please contact dom4j-info@metastuff.com.
86  *
87  * 4. Products derived from this Software may not be called "DOM4J" nor may
88  * "DOM4J" appear in their names without prior written permission of MetaStuff,
89  * Ltd. DOM4J is a registered trademark of MetaStuff, Ltd.
90  *
91  * 5. Due credit should be given to the DOM4J Project - http://www.dom4j.org
92  *
93  * THIS SOFTWARE IS PROVIDED BY METASTUFF, LTD. AND CONTRIBUTORS ``AS IS'' AND
94  * ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
95  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
96  * ARE DISCLAIMED. IN NO EVENT SHALL METASTUFF, LTD. OR ITS CONTRIBUTORS BE
97  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
98  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
99  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
100  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
101  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
102  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
103  * POSSIBILITY OF SUCH DAMAGE.
104  *
105  * Copyright 2001-2004 (C) MetaStuff, Ltd. All Rights Reserved.
106  *
107  * $Id: ParseTest.java,v 1.4 2005/01/29 14:53:13 maartenc Exp $
108  */

109
Popular Tags