001: /*
002: * Copyright (c) 2000 Silvere Martin-Michiellot All Rights Reserved.
003: *
004: * Silvere Martin-Michiellot grants you ("Licensee") a non-exclusive,
005: * royalty free, license to use, modify and redistribute this
006: * software in source and binary code form,
007: * provided that i) this copyright notice and license appear on all copies of
008: * the software; and ii) Licensee does not utilize the software in a manner
009: * which is disparaging to Silvere Martin-Michiellot.
010: *
011: * This software is provided "AS IS," without a warranty of any kind. ALL
012: * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY
013: * IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
014: * NON-INFRINGEMENT, ARE HEREBY EXCLUDED. Silvere Martin-Michiellot
015: * AND ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES
016: * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
017: * OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL
018: * Silvere Martin-Michiellot OR ITS LICENSORS BE LIABLE
019: * FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT,
020: * INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER
021: * CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF
022: * OR INABILITY TO USE SOFTWARE, EVEN IF Silvere Martin-Michiellot HAS BEEN
023: * ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
024: *
025: * This software is not designed or intended for use in on-line control of
026: * aircraft, air traffic, aircraft navigation or aircraft communications; or in
027: * the design, construction, operation or maintenance of any nuclear
028: * facility. Licensee represents and warrants that it will not use or
029: * redistribute the Software for such purposes.
030: *
031: */
032:
033: package com.db.utils;
034:
035: // This code is repackaged after the Autoupdater
036: // Site http://sourceforge.net/projects/autoupdater/
037: // Email wurp@users.sourceforge.net
038:
039: import java.io.*;
040: import java.net.URL;
041: import java.util.*;
042: import java.util.zip.CRC32;
043: import java.util.zip.CheckedInputStream;
044:
045: public class IOUtil {
046:
047: public static final int BUFFER_SIZE = 8192;
048: public static final byte THROWAWAY_BUFFER[] = new byte[8192];
049:
050: public IOUtil() {
051: }
052:
053: public static void copy(Reader reader, Writer writer)
054: throws IOException {
055:
056: char ac[] = new char[8192];
057: int i;
058: while ((i = reader.read(ac)) != -1)
059: writer.write(ac, 0, i);
060:
061: }
062:
063: public static void copy(InputStream inputstream,
064: OutputStream outputstream) throws IOException {
065:
066: byte abyte0[] = new byte[8192];
067: int i;
068: while ((i = inputstream.read(abyte0)) != -1)
069: outputstream.write(abyte0, 0, i);
070:
071: }
072:
073: public static void copy(String s, String s1) throws IOException {
074:
075: BufferedFileInputStream bufferedfileinputstream = new BufferedFileInputStream(
076: s);
077: BufferedFileOutputStream bufferedfileoutputstream = new BufferedFileOutputStream(
078: s1);
079: copy(((InputStream) (bufferedfileinputstream)),
080: ((OutputStream) (bufferedfileoutputstream)));
081: bufferedfileinputstream.close();
082: bufferedfileoutputstream.close();
083:
084: }
085:
086: public static String[] getLines(String s) throws IOException {
087:
088: BufferedReader bufferedreader = new BufferedReader(
089: new FileReader(s));
090: ArrayList arraylist = new ArrayList();
091: String s1;
092: while ((s1 = bufferedreader.readLine()) != null)
093: arraylist.add(s1);
094: Iterator iterator = arraylist.iterator();
095: int i = 0;
096: String as[] = new String[arraylist.size()];
097: while (iterator.hasNext())
098: as[i++] = iterator.next().toString();
099: bufferedreader.close();
100:
101: return as;
102:
103: }
104:
105: public static long getCRC32(InputStream inputstream)
106: throws IOException {
107:
108: CRC32 crc32 = new CRC32();
109: CheckedInputStream checkedinputstream;
110: for (checkedinputstream = new CheckedInputStream(inputstream,
111: crc32); checkedinputstream.read(THROWAWAY_BUFFER, 0,
112: THROWAWAY_BUFFER.length) != -1;)
113: ;
114: checkedinputstream.close();
115:
116: return crc32.getValue();
117:
118: }
119:
120: public static String trimLeadingFileSeparator(String s) {
121:
122: for (; s.endsWith("/") || s.endsWith("\\")
123: || s.endsWith(File.separator); s = s.substring(0, s
124: .length() - 1))
125: ;
126:
127: return s;
128:
129: }
130:
131: public static String trimTrailingFileSeparator(String s) {
132:
133: for (; s.startsWith("/") || s.startsWith("\\")
134: || s.startsWith(File.separator); s = s.substring(1))
135: ;
136:
137: return s;
138:
139: }
140:
141: public static String trimFileSeparator(String s) {
142:
143: s = trimLeadingFileSeparator(s);
144: s = trimTrailingFileSeparator(s);
145:
146: return s;
147:
148: }
149:
150: public static void removeDirectoriesBetween(File file, File file1) {
151:
152: for (; file1.getAbsolutePath().startsWith(
153: file.getAbsolutePath())
154: && !file1.equals(file); file1 = new File(file1
155: .getParent()))
156: file1.delete();
157:
158: }
159:
160: public static List getTree(File file) {
161:
162: ArrayList arraylist = new ArrayList();
163: getTree(file, ((List) (arraylist)));
164:
165: return arraylist;
166:
167: }
168:
169: public static void getTree(File file, List list) {
170:
171: list.add(file);
172: File afile[] = file.listFiles();
173: if (afile != null) {
174: for (int i = 0; i < afile.length; i++)
175: getTree(afile[i], list);
176: }
177:
178: }
179:
180: public static String[] parseJarURL(String s) {
181:
182: ArrayList arraylist = new ArrayList();
183: for (StringTokenizer stringtokenizer = new StringTokenizer(s,
184: "!"); stringtokenizer.hasMoreTokens(); arraylist
185: .add(stringtokenizer.nextToken()))
186: ;
187: String as[] = new String[arraylist.size()];
188: for (int i = 0; i < as.length; i++)
189: as[i] = (String) arraylist.get(i);
190:
191: return as;
192:
193: }
194:
195: public static String fixJarURL(String s) {
196:
197: if (s.indexOf("!") != -1 && !s.startsWith("jar:"))
198: s = "jar:" + s;
199:
200: return s;
201:
202: }
203:
204: public static void main(String args[]) throws Exception {
205:
206: copy(new BufferedInputStream((new URL(args[0])).openStream()),
207: new FileOutputStream(args[1]));
208:
209: }
210:
211: }
|