KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hsqldb > lib > java > JavaSystem


1 /* Copyright (c) 2001-2005, The HSQL Development Group
2  * All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are met:
6  *
7  * Redistributions of source code must retain the above copyright notice, this
8  * list of conditions and the following disclaimer.
9  *
10  * Redistributions in binary form must reproduce the above copyright notice,
11  * this list of conditions and the following disclaimer in the documentation
12  * and/or other materials provided with the distribution.
13  *
14  * Neither the name of the HSQL Development Group nor the names of its
15  * contributors may be used to endorse or promote products derived from this
16  * software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21  * ARE DISCLAIMED. IN NO EVENT SHALL HSQL DEVELOPMENT GROUP, HSQLDB.ORG,
22  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
26  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */

30
31
32 package org.hsqldb.lib.java;
33
34 import java.io.File JavaDoc;
35 import java.io.FileNotFoundException JavaDoc;
36 import java.io.FileOutputStream JavaDoc;
37 import java.io.IOException JavaDoc;
38 import java.io.OutputStream JavaDoc;
39 import java.io.PrintStream JavaDoc;
40 import java.io.PrintWriter JavaDoc;
41 import java.math.BigDecimal JavaDoc;
42 import java.math.BigInteger JavaDoc;
43 import java.sql.DriverManager JavaDoc;
44 import java.util.Properties JavaDoc;
45 import java.text.Collator JavaDoc;
46 import java.io.RandomAccessFile JavaDoc;
47
48 // fredt@users 20020320 - patch 1.7.0 - JDBC 2 support and error trapping
49
// fredt@users 20021030 - patch 1.7.2 - updates
50

51 /**
52  * Handles the differences between JDK 1.1.x and 1.2.x and above
53  *
54  * @author fredt@users
55  * @version 1.8.0
56  */

57 public class JavaSystem {
58
59     // variables to track rough count on object creation, to use in gc
60
public static int gcFrequency;
61     public static int memoryRecords;
62
63     // Garbage Collection
64
public static void gc() {
65
66         if ((gcFrequency > 0) && (memoryRecords > gcFrequency)) {
67             memoryRecords = 0;
68
69             System.gc();
70         }
71     }
72
73     /**
74      * Arguments are never null.
75      */

76     public static int CompareIngnoreCase(String JavaDoc a, String JavaDoc b) {
77
78 //#ifdef JAVA1TARGET
79
/*
80         return a.toUpperCase().compareTo(b.toUpperCase());
81 */

82
83 //#else
84
return a.compareToIgnoreCase(b);
85
86 //#endif
87
}
88
89     public static double parseDouble(String JavaDoc s) {
90
91 //#ifdef JAVA1TARGET
92
/*
93         return new Double(s).doubleValue();
94 */

95
96 //#else
97
return Double.parseDouble(s);
98
99 //#endif JAVA1TARGET
100
}
101
102     public static BigInteger JavaDoc getUnscaledValue(BigDecimal JavaDoc o) {
103
104 //#ifdef JAVA1TARGET
105
/*
106         int scale = o.scale();
107         return o.movePointRight(scale).toBigInteger();
108 */

109
110 //#else
111
return o.unscaledValue();
112
113 //#endif
114
}
115
116     public static void setLogToSystem(boolean value) {
117
118 //#ifdef JAVA1TARGET
119
/*
120         try {
121             PrintStream newOutStream = (value) ? System.out
122                                                : null;
123             DriverManager.setLogStream(newOutStream);
124         } catch (Exception e){}
125 */

126
127 //#else
128
try {
129             PrintWriter JavaDoc newPrintWriter = (value) ? new PrintWriter JavaDoc(System.out)
130                                                  : null;
131
132             DriverManager.setLogWriter(newPrintWriter);
133         } catch (Exception JavaDoc e) {}
134
135 //#endif
136
}
137
138     public static void deleteOnExit(File JavaDoc f) {
139
140 //#ifdef JAVA1TARGET
141
/*
142 */

143
144 //#else
145
f.deleteOnExit();
146
147 //#endif
148
}
149
150     public static void saveProperties(Properties JavaDoc props, String JavaDoc name,
151                                       OutputStream JavaDoc os) throws IOException JavaDoc {
152
153 //#ifdef JAVA1TARGET
154
/*
155     props.save(os, name);
156 */

157
158 //#else
159
props.store(os, name);
160
161 //#endif
162
}
163
164     public static void runFinalizers() {
165
166 //#ifdef JAVA1TARGET
167
/*
168         System.runFinalizersOnExit(true);
169 */

170
171 //#endif
172
}
173
174     public static boolean createNewFile(File JavaDoc file) {
175
176 //#ifdef JAVA1TARGET
177
/*
178 */

179
180 //#else
181
try {
182             return file.createNewFile();
183         } catch (IOException JavaDoc e) {}
184
185         return false;
186
187 //#endif
188
}
189
190     public static void setRAFileLength(RandomAccessFile JavaDoc raFile,
191                                        long length) throws IOException JavaDoc {
192 //#ifdef JAVA1TARGET
193
/*
194 */

195
196 //#else
197
raFile.setLength(length);
198 //#endif
199
}
200 }
201
Popular Tags