|
|||||||||||||||||||
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover | |||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
WritableFile.java | 0% | 0% | 0% | 0% |
|
1 |
/*
|
|
2 |
* $Id: WritableFile.java,v 1.2 2004/07/11 19:41:10 glaforge Exp $
|
|
3 |
*
|
|
4 |
* Copyright 2003 (C) John Wilson. All Rights Reserved.
|
|
5 |
*
|
|
6 |
* Redistribution and use of this software and associated documentation
|
|
7 |
* ("Software"), with or without modification, are permitted provided that the
|
|
8 |
* following conditions are met:
|
|
9 |
* 1. Redistributions of source code must retain copyright statements and
|
|
10 |
* notices. Redistributions must also contain a copy of this document.
|
|
11 |
* 2. Redistributions in binary form must reproduce the above copyright
|
|
12 |
* notice, this list of conditions and the following disclaimer in the
|
|
13 |
* documentation and/or other materials provided with the distribution.
|
|
14 |
* 3. The name "groovy" must not be used to endorse or promote products
|
|
15 |
* derived from this Software without prior written permission of The Codehaus.
|
|
16 |
* For written permission, please contact info@codehaus.org.
|
|
17 |
* 4. Products derived from this Software may not be called "groovy" nor may
|
|
18 |
* "groovy" appear in their names without prior written permission of The
|
|
19 |
* Codehaus. "groovy" is a registered trademark of The Codehaus.
|
|
20 |
* 5. Due credit should be given to The Codehaus - http://groovy.codehaus.org/
|
|
21 |
*
|
|
22 |
* THIS SOFTWARE IS PROVIDED BY THE CODEHAUS AND CONTRIBUTORS ``AS IS'' AND ANY
|
|
23 |
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
24 |
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
25 |
* DISCLAIMED. IN NO EVENT SHALL THE CODEHAUS OR ITS CONTRIBUTORS BE LIABLE FOR
|
|
26 |
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
27 |
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
28 |
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
29 |
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
30 |
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
31 |
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
|
|
32 |
* DAMAGE.
|
|
33 |
*
|
|
34 |
*/
|
|
35 |
|
|
36 |
package org.codehaus.groovy.runtime;
|
|
37 |
|
|
38 |
import groovy.lang.Writable;
|
|
39 |
|
|
40 |
import java.io.File;
|
|
41 |
import java.io.Writer;
|
|
42 |
import java.io.IOException;
|
|
43 |
import java.io.Reader;
|
|
44 |
import java.io.FilenameFilter;
|
|
45 |
import java.io.FileFilter;
|
|
46 |
import java.net.URI;
|
|
47 |
import java.net.URL;
|
|
48 |
import java.net.MalformedURLException;
|
|
49 |
|
|
50 |
/**
|
|
51 |
* A Writable File.
|
|
52 |
*
|
|
53 |
* @author John Wilson
|
|
54 |
*
|
|
55 |
*/
|
|
56 |
public class WritableFile extends File implements Writable { |
|
57 |
private final File delegate;
|
|
58 |
private final String encoding;
|
|
59 |
|
|
60 | 0 |
public WritableFile(File delegate) {
|
61 | 0 |
this(delegate, null); |
62 |
} |
|
63 |
|
|
64 | 0 |
public WritableFile(File delegate, String encoding) {
|
65 | 0 |
super(""); |
66 | 0 |
this.delegate = delegate;
|
67 | 0 |
this.encoding = encoding;
|
68 |
} |
|
69 |
|
|
70 | 0 |
public Writer writeTo(Writer out) throws IOException { |
71 | 0 |
final Reader reader = |
72 | 0 |
(this.encoding == null) |
73 |
? DefaultGroovyMethods.newReader(this.delegate)
|
|
74 |
: DefaultGroovyMethods.newReader(this.delegate, this.encoding); |
|
75 |
|
|
76 | 0 |
try {
|
77 | 0 |
int c = reader.read();
|
78 |
|
|
79 | 0 |
while (c != -1) {
|
80 | 0 |
out.write(c); |
81 | 0 |
c = reader.read(); |
82 |
} |
|
83 |
} |
|
84 |
finally {
|
|
85 | 0 |
reader.close(); |
86 |
} |
|
87 | 0 |
return out;
|
88 |
} |
|
89 |
|
|
90 | 0 |
public boolean canRead() { |
91 | 0 |
return delegate.canRead();
|
92 |
} |
|
93 |
|
|
94 | 0 |
public boolean canWrite() { |
95 | 0 |
return delegate.canWrite();
|
96 |
} |
|
97 |
|
|
98 | 0 |
public int compareTo(File arg0) { |
99 | 0 |
return delegate.compareTo(arg0);
|
100 |
} |
|
101 |
|
|
102 | 0 |
public int compareTo(Object arg0) { |
103 | 0 |
return delegate.compareTo(arg0);
|
104 |
} |
|
105 |
|
|
106 | 0 |
public boolean createNewFile() throws IOException { |
107 | 0 |
return delegate.createNewFile();
|
108 |
} |
|
109 |
|
|
110 | 0 |
public boolean delete() { |
111 | 0 |
return delegate.delete();
|
112 |
} |
|
113 |
|
|
114 | 0 |
public void deleteOnExit() { |
115 | 0 |
delegate.deleteOnExit(); |
116 |
} |
|
117 |
|
|
118 | 0 |
public boolean equals(Object arg0) { |
119 | 0 |
return delegate.equals(arg0);
|
120 |
} |
|
121 |
|
|
122 | 0 |
public boolean exists() { |
123 | 0 |
return delegate.exists();
|
124 |
} |
|
125 |
|
|
126 | 0 |
public File getAbsoluteFile() {
|
127 | 0 |
return delegate.getAbsoluteFile();
|
128 |
} |
|
129 |
|
|
130 | 0 |
public String getAbsolutePath() {
|
131 | 0 |
return delegate.getAbsolutePath();
|
132 |
} |
|
133 |
|
|
134 | 0 |
public File getCanonicalFile() throws IOException { |
135 | 0 |
return delegate.getCanonicalFile();
|
136 |
} |
|
137 |
|
|
138 | 0 |
public String getCanonicalPath() throws IOException { |
139 | 0 |
return delegate.getCanonicalPath();
|
140 |
} |
|
141 |
|
|
142 | 0 |
public String getName() {
|
143 | 0 |
return delegate.getName();
|
144 |
} |
|
145 |
|
|
146 | 0 |
public String getParent() {
|
147 | 0 |
return delegate.getParent();
|
148 |
} |
|
149 |
|
|
150 | 0 |
public File getParentFile() {
|
151 | 0 |
return delegate.getParentFile();
|
152 |
} |
|
153 |
|
|
154 | 0 |
public String getPath() {
|
155 | 0 |
return delegate.getPath();
|
156 |
} |
|
157 |
|
|
158 | 0 |
public int hashCode() { |
159 | 0 |
return delegate.hashCode();
|
160 |
} |
|
161 |
|
|
162 | 0 |
public boolean isAbsolute() { |
163 | 0 |
return delegate.isAbsolute();
|
164 |
} |
|
165 |
|
|
166 | 0 |
public boolean isDirectory() { |
167 | 0 |
return delegate.isDirectory();
|
168 |
} |
|
169 |
|
|
170 | 0 |
public boolean isFile() { |
171 | 0 |
return delegate.isFile();
|
172 |
} |
|
173 |
|
|
174 |
/* (non-Javadoc)
|
|
175 |
* @see java.io.File#isHidden()
|
|
176 |
*/
|
|
177 | 0 |
public boolean isHidden() { |
178 | 0 |
return delegate.isHidden();
|
179 |
} |
|
180 |
|
|
181 |
/* (non-Javadoc)
|
|
182 |
* @see java.io.File#lastModified()
|
|
183 |
*/
|
|
184 | 0 |
public long lastModified() { |
185 | 0 |
return delegate.lastModified();
|
186 |
} |
|
187 |
|
|
188 |
/* (non-Javadoc)
|
|
189 |
* @see java.io.File#length()
|
|
190 |
*/
|
|
191 | 0 |
public long length() { |
192 | 0 |
return delegate.length();
|
193 |
} |
|
194 |
|
|
195 |
/* (non-Javadoc)
|
|
196 |
* @see java.io.File#list()
|
|
197 |
*/
|
|
198 | 0 |
public String[] list() {
|
199 | 0 |
return delegate.list();
|
200 |
} |
|
201 |
|
|
202 |
/* (non-Javadoc)
|
|
203 |
* @see java.io.File#list(java.io.FilenameFilter)
|
|
204 |
*/
|
|
205 | 0 |
public String[] list(FilenameFilter arg0) {
|
206 | 0 |
return delegate.list(arg0);
|
207 |
} |
|
208 |
|
|
209 |
/* (non-Javadoc)
|
|
210 |
* @see java.io.File#listFiles()
|
|
211 |
*/
|
|
212 | 0 |
public File[] listFiles() {
|
213 | 0 |
return delegate.listFiles();
|
214 |
} |
|
215 |
|
|
216 |
/* (non-Javadoc)
|
|
217 |
* @see java.io.File#listFiles(java.io.FileFilter)
|
|
218 |
*/
|
|
219 | 0 |
public File[] listFiles(FileFilter arg0) {
|
220 | 0 |
return delegate.listFiles(arg0);
|
221 |
} |
|
222 |
|
|
223 |
/* (non-Javadoc)
|
|
224 |
* @see java.io.File#listFiles(java.io.FilenameFilter)
|
|
225 |
*/
|
|
226 | 0 |
public File[] listFiles(FilenameFilter arg0) {
|
227 | 0 |
return delegate.listFiles(arg0);
|
228 |
} |
|
229 |
|
|
230 |
/* (non-Javadoc)
|
|
231 |
* @see java.io.File#mkdir()
|
|
232 |
*/
|
|
233 | 0 |
public boolean mkdir() { |
234 | 0 |
return delegate.mkdir();
|
235 |
} |
|
236 |
|
|
237 |
/* (non-Javadoc)
|
|
238 |
* @see java.io.File#mkdirs()
|
|
239 |
*/
|
|
240 | 0 |
public boolean mkdirs() { |
241 | 0 |
return delegate.mkdirs();
|
242 |
} |
|
243 |
|
|
244 |
/* (non-Javadoc)
|
|
245 |
* @see java.io.File#renameTo(java.io.File)
|
|
246 |
*/
|
|
247 | 0 |
public boolean renameTo(File arg0) { |
248 | 0 |
return delegate.renameTo(arg0);
|
249 |
} |
|
250 |
|
|
251 |
/* (non-Javadoc)
|
|
252 |
* @see java.io.File#setLastModified(long)
|
|
253 |
*/
|
|
254 | 0 |
public boolean setLastModified(long arg0) { |
255 | 0 |
return delegate.setLastModified(arg0);
|
256 |
} |
|
257 |
|
|
258 |
/* (non-Javadoc)
|
|
259 |
* @see java.io.File#setReadOnly()
|
|
260 |
*/
|
|
261 | 0 |
public boolean setReadOnly() { |
262 | 0 |
return delegate.setReadOnly();
|
263 |
} |
|
264 |
|
|
265 |
/* (non-Javadoc)
|
|
266 |
* @see java.io.File#toString()
|
|
267 |
*/
|
|
268 | 0 |
public String toString() {
|
269 | 0 |
return delegate.toString();
|
270 |
} |
|
271 |
|
|
272 |
/* (non-Javadoc)
|
|
273 |
* @see java.io.File#toURI()
|
|
274 |
*/
|
|
275 | 0 |
public URI toURI() {
|
276 | 0 |
return delegate.toURI();
|
277 |
} |
|
278 |
|
|
279 |
/* (non-Javadoc)
|
|
280 |
* @see java.io.File#toURL()
|
|
281 |
*/
|
|
282 | 0 |
public URL toURL() throws MalformedURLException { |
283 | 0 |
return delegate.toURL();
|
284 |
} |
|
285 |
|
|
286 |
} |
|
287 |
|
|