KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > benchmark > util > ResultPrinter


1 /*====================================================================
2
3 OpenCCM: The Open CORBA Component Model Platform
4 Copyright (C) 2000-2004 INRIA - USTL - LIFL - GOAL
5 Contact: openccm@objectweb.org
6
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or any later version.
11
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public
18 License along with this library; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20 USA
21
22 Initial developer(s): Christophe Demarey.
23 Contributor(s): ______________________________________.
24
25 ====================================================================*/

26
27 package org.objectweb.benchmark.util;
28
29 //Package dependencies.
30
import java.io.File JavaDoc;
31 import java.io.FileOutputStream JavaDoc;
32 import java.io.IOException JavaDoc;
33 import java.io.PrintStream JavaDoc;
34
35
36 /**
37  * This class is used to easily write benchmark results in a file.
38  *
39  * @author <a HREF="mailto:Christophe.Demarey@lifl.fr">Christophe Demarey</a>
40  *
41  * @version 0.1
42  */

43 public class ResultPrinter
44 {
45     // ==================================================================
46
//
47
// Internal states.
48
//
49
// ==================================================================
50

51     /** The file to store results in. */
52     private PrintStream JavaDoc file = null;
53
54     // ==================================================================
55
//
56
// Constructors.
57
//
58
// ==================================================================
59

60     /**
61      * The default constructor.
62      *
63      * @param filename - The name of the results file.
64      */

65     public ResultPrinter(String JavaDoc filename)
66     {
67        file = openFile( new File JavaDoc(filename) );
68     }
69
70     // ==================================================================
71
//
72
// Internal methods.
73
//
74
// ==================================================================
75

76     /**
77      * Create the file if it does'nt exist, else open it.
78      *
79      * @param f - The file to open.
80      *
81      * @return A data output stream.
82      */

83     private PrintStream JavaDoc
84     openFile(File JavaDoc f)
85     {
86         FileOutputStream JavaDoc fos = null;
87         
88         try
89         {
90             // Create the file if it doesn't exists
91
f.createNewFile();
92             // Open the file for append
93
fos = new FileOutputStream JavaDoc(f, true);
94         } catch (IOException JavaDoc e) {
95             e.printStackTrace();
96         }
97         
98         return new PrintStream JavaDoc(fos);
99     }
100     
101     // ==================================================================
102
//
103
// Public methods.
104
//
105
// ==================================================================
106

107     /**
108      * Prints a long to file.
109      *
110      * @param l - The long to write.
111      */

112     public void write(long l)
113     {
114         file.println(l);
115     }
116     
117     /**
118      * Close the file.
119      */

120     public void close()
121     {
122         file.close();
123     }
124     
125 }
126
Popular Tags