Source Code Cross Referenced for IO.java in  » Database-DBMS » Quadcap-Embeddable-Database » com » quadcap » io » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Database DBMS » Quadcap Embeddable Database » com.quadcap.io 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package com.quadcap.io;
002:
003:        /* Copyright 1997 - 2003 Quadcap Software.  All rights reserved.
004:         *
005:         * This software is distributed under the Quadcap Free Software License.
006:         * This software may be used or modified for any purpose, personal or
007:         * commercial.  Open Source redistributions are permitted.  Commercial
008:         * redistribution of larger works derived from, or works which bundle
009:         * this software requires a "Commercial Redistribution License"; see
010:         * http://www.quadcap.com/purchase.
011:         *
012:         * Redistributions qualify as "Open Source" under  one of the following terms:
013:         *   
014:         *    Redistributions are made at no charge beyond the reasonable cost of
015:         *    materials and delivery.
016:         *
017:         *    Redistributions are accompanied by a copy of the Source Code or by an
018:         *    irrevocable offer to provide a copy of the Source Code for up to three
019:         *    years at the cost of materials and delivery.  Such redistributions
020:         *    must allow further use, modification, and redistribution of the Source
021:         *    Code under substantially the same terms as this license.
022:         *
023:         * Redistributions of source code must retain the copyright notices as they
024:         * appear in each source code file, these license terms, and the
025:         * disclaimer/limitation of liability set forth as paragraph 6 below.
026:         *
027:         * Redistributions in binary form must reproduce this Copyright Notice,
028:         * these license terms, and the disclaimer/limitation of liability set
029:         * forth as paragraph 6 below, in the documentation and/or other materials
030:         * provided with the distribution.
031:         *
032:         * The Software is provided on an "AS IS" basis.  No warranty is
033:         * provided that the Software is free of defects, or fit for a
034:         * particular purpose.  
035:         *
036:         * Limitation of Liability. Quadcap Software shall not be liable
037:         * for any damages suffered by the Licensee or any third party resulting
038:         * from use of the Software.
039:         */
040:
041:        import java.io.BufferedInputStream;
042:        import java.io.File;
043:        import java.io.FileInputStream;
044:        import java.io.FileOutputStream;
045:        import java.io.IOException;
046:        import java.io.InputStream;
047:        import java.io.OutputStream;
048:        import java.io.Reader;
049:        import java.io.Writer;
050:
051:        import com.quadcap.util.Util;
052:
053:        /**
054:         * 
055:         *
056:         * @author Stan Bailes
057:         */
058:        public class IO {
059:            /**
060:             * Diff two files, return true if the file contents are the same
061:             */
062:            public static boolean cmpFile(File a, File b) throws IOException {
063:                FileInputStream fa = null;
064:                FileInputStream fb = null;
065:                try {
066:                    fa = new FileInputStream(a);
067:                    BufferedInputStream sa = new BufferedInputStream(fa);
068:                    fb = new FileInputStream(b);
069:                    BufferedInputStream sb = new BufferedInputStream(fb);
070:                    int ca = sa.read();
071:                    int cb = sb.read();
072:                    while (ca >= 0 && cb >= 0 && ca == cb) {
073:                        ca = sa.read();
074:                        cb = sb.read();
075:                    }
076:                    return ca == cb;
077:                } finally {
078:                    if (fa != null)
079:                        try {
080:                            fa.close();
081:                        } catch (IOException e) {
082:                        }
083:                    if (fb != null)
084:                        try {
085:                            fb.close();
086:                        } catch (IOException e) {
087:                        }
088:                }
089:
090:            }
091:
092:            /**
093:             * Copy a file
094:             */
095:            public static final void copyFile(File from, File to)
096:                    throws IOException {
097:                FileOutputStream fos = new FileOutputStream(to);
098:                try {
099:                    FileInputStream fis = new FileInputStream(from);
100:                    try {
101:                        copyStream(fis, fos);
102:                    } finally {
103:                        fis.close();
104:                    }
105:                } finally {
106:                    fos.close();
107:                }
108:            }
109:
110:            /**
111:             * Copy 'is' to 'os' until EOF
112:             */
113:            public static final void copyStream(InputStream is, OutputStream os)
114:                    throws IOException {
115:                byte[] buf = new byte[4096];
116:                int cnt;
117:                while ((cnt = is.read(buf)) > 0) {
118:                    os.write(buf, 0, cnt);
119:                }
120:            }
121:
122:            /**
123:             * Rate limited stream copy.  Copy the input stream to the output
124:             * until EOF.  An initial series of "buffered" bytes is sent with
125:             * no rate limit, thereafter, bytes are streamed (in 4Kbyte buffers) at
126:             * the rate limit "bps" bytes per/sec.
127:             * No particular effort is made to buffer the incoming stream.
128:             */
129:            public static final void copyStream(InputStream is,
130:                    OutputStream os, int bps, int buffered) throws IOException {
131:                byte[] buf = new byte[4096];
132:                int cnt;
133:                int amt = 0;
134:                long interval = (buf.length * 1000) / bps;
135:                long wait = 0;
136:                long start = System.currentTimeMillis();
137:                while ((cnt = is.read(buf)) > 0) {
138:                    amt += cnt;
139:                    if (wait > 0)
140:                        Util.sleep(wait);
141:                    os.write(buf, 0, cnt);
142:                    long done = System.currentTimeMillis();
143:                    if (amt > buffered) {
144:                        long elap = done - start;
145:                        wait = interval - elap;
146:                    }
147:                    start = done;
148:                }
149:            }
150:
151:            /**
152:             * Copy 'r' to 'w' until EOF
153:             */
154:            public static final void copyStream(Reader r, Writer w)
155:                    throws IOException {
156:                char[] buf = new char[4096];
157:                int cnt;
158:                while ((cnt = r.read(buf)) > 0) {
159:                    w.write(buf, 0, cnt);
160:                }
161:            }
162:
163:            /**
164:             * Copy 'is' to 'os' until EOF, or <b>limit</b> bytes are copied.
165:             */
166:            public static final void copyStream(InputStream is,
167:                    OutputStream os, int limit) throws IOException {
168:                byte[] buf = new byte[4096];
169:                int cnt;
170:                while (limit > buf.length) {
171:                    if ((cnt = is.read(buf)) > 0) {
172:                        os.write(buf, 0, cnt);
173:                        limit -= cnt;
174:                    } else {
175:                        limit = 0;
176:                    }
177:                }
178:                if ((cnt = is.read(buf, 0, limit)) > 0) {
179:                    os.write(buf, 0, cnt);
180:                }
181:            }
182:
183:            /**
184:             * Write a string to an outputstream using the brutal low-byte extraction
185:             * encoding technique.  Works great for ISO-8859-1.
186:             */
187:            public static void write(OutputStream os, String s)
188:                    throws IOException {
189:                final int len = s.length();
190:                for (int i = 0; i < len; i++)
191:                    os.write(s.charAt(i));
192:            }
193:
194:            /**
195:             * Read an inputstream into a byte buffer
196:             */
197:            public static void readFully(InputStream is, byte[] buf)
198:                    throws IOException {
199:                int pos = 0;
200:                int len = buf.length;
201:                do {
202:                    int cnt = is.read(buf, pos, len);
203:                    if (cnt <= 0)
204:                        throw new IOException("unexpected EOF");
205:                    len -= cnt;
206:                    pos += cnt;
207:                } while (len > 0);
208:            }
209:
210:            /**
211:             * Recursively delete an entire directory.  Be careful!
212:             */
213:            public static void deleteDirectory(File f) throws IOException {
214:                File[] files = f.listFiles();
215:                if (files != null) {
216:                    for (int i = 0; i < files.length; i++) {
217:                        File file = files[i];
218:                        if (file.isDirectory()) {
219:                            deleteDirectory(f);
220:                        } else {
221:                            file.delete();
222:                        }
223:                    }
224:                }
225:                f.delete();
226:            }
227:
228:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.