001: /* Copyright (c) 2001-2005, The HSQL Development Group
002: * All rights reserved.
003: *
004: * Redistribution and use in source and binary forms, with or without
005: * modification, are permitted provided that the following conditions are met:
006: *
007: * Redistributions of source code must retain the above copyright notice, this
008: * list of conditions and the following disclaimer.
009: *
010: * Redistributions in binary form must reproduce the above copyright notice,
011: * this list of conditions and the following disclaimer in the documentation
012: * and/or other materials provided with the distribution.
013: *
014: * Neither the name of the HSQL Development Group nor the names of its
015: * contributors may be used to endorse or promote products derived from this
016: * software without specific prior written permission.
017: *
018: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
019: * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
020: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
021: * ARE DISCLAIMED. IN NO EVENT SHALL HSQL DEVELOPMENT GROUP, HSQLDB.ORG,
022: * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
023: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
024: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
025: * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
026: * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
027: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
028: * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
029: */
030:
031: package org.hsqldb.lib.java;
032:
033: import java.io.File;
034: import java.io.FileNotFoundException;
035: import java.io.FileOutputStream;
036: import java.io.IOException;
037: import java.io.OutputStream;
038: import java.io.PrintStream;
039: import java.io.PrintWriter;
040: import java.math.BigDecimal;
041: import java.math.BigInteger;
042: import java.sql.DriverManager;
043: import java.util.Properties;
044: import java.text.Collator;
045: import java.io.RandomAccessFile;
046:
047: // fredt@users 20020320 - patch 1.7.0 - JDBC 2 support and error trapping
048: // fredt@users 20021030 - patch 1.7.2 - updates
049:
050: /**
051: * Handles the differences between JDK 1.1.x and 1.2.x and above
052: *
053: * @author fredt@users
054: * @version 1.8.0
055: */
056: public class JavaSystem {
057:
058: // variables to track rough count on object creation, to use in gc
059: public static int gcFrequency;
060: public static int memoryRecords;
061:
062: // Garbage Collection
063: public static void gc() {
064:
065: if ((gcFrequency > 0) && (memoryRecords > gcFrequency)) {
066: memoryRecords = 0;
067:
068: System.gc();
069: }
070: }
071:
072: /**
073: * Arguments are never null.
074: */
075: public static int CompareIngnoreCase(String a, String b) {
076:
077: //#ifdef JAVA1TARGET
078: /*
079: return a.toUpperCase().compareTo(b.toUpperCase());
080: */
081:
082: //#else
083: return a.compareToIgnoreCase(b);
084:
085: //#endif
086: }
087:
088: public static double parseDouble(String s) {
089:
090: //#ifdef JAVA1TARGET
091: /*
092: return new Double(s).doubleValue();
093: */
094:
095: //#else
096: return Double.parseDouble(s);
097:
098: //#endif JAVA1TARGET
099: }
100:
101: public static BigInteger getUnscaledValue(BigDecimal o) {
102:
103: //#ifdef JAVA1TARGET
104: /*
105: int scale = o.scale();
106: return o.movePointRight(scale).toBigInteger();
107: */
108:
109: //#else
110: return o.unscaledValue();
111:
112: //#endif
113: }
114:
115: public static void setLogToSystem(boolean value) {
116:
117: //#ifdef JAVA1TARGET
118: /*
119: try {
120: PrintStream newOutStream = (value) ? System.out
121: : null;
122: DriverManager.setLogStream(newOutStream);
123: } catch (Exception e){}
124: */
125:
126: //#else
127: try {
128: PrintWriter newPrintWriter = (value) ? new PrintWriter(
129: System.out) : null;
130:
131: DriverManager.setLogWriter(newPrintWriter);
132: } catch (Exception e) {
133: }
134:
135: //#endif
136: }
137:
138: public static void deleteOnExit(File f) {
139:
140: //#ifdef JAVA1TARGET
141: /*
142: */
143:
144: //#else
145: f.deleteOnExit();
146:
147: //#endif
148: }
149:
150: public static void saveProperties(Properties props, String name,
151: OutputStream os) throws IOException {
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 file) {
175:
176: //#ifdef JAVA1TARGET
177: /*
178: */
179:
180: //#else
181: try {
182: return file.createNewFile();
183: } catch (IOException e) {
184: }
185:
186: return false;
187:
188: //#endif
189: }
190:
191: public static void setRAFileLength(RandomAccessFile raFile,
192: long length) throws IOException {
193: //#ifdef JAVA1TARGET
194: /*
195: */
196:
197: //#else
198: raFile.setLength(length);
199: //#endif
200: }
201: }
|