KickJava   Java API By Example, From Geeks To Geeks.

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


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: ToTextTest.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.StringWriter JavaDoc;
13
14 import org.dom4j.Document;
15 import org.dom4j.io.SAXReader;
16 import org.dom4j.io.XMLWriter;
17
18 /**
19  * Tests the performance of turning a Document into text
20  *
21  * @author <a HREF="mailto:james.strachan@metastuff.com">James Strachan </a>
22  * @version $Revision: 1.4 $
23  */

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

101
Popular Tags