1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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 public WritableFile(File delegate) {
61 this(delegate, null);
62 }
63
64 public WritableFile(File delegate, String encoding) {
65 super("");
66 this.delegate = delegate;
67 this.encoding = encoding;
68 }
69
70 public Writer writeTo(Writer out) throws IOException {
71 final Reader reader =
72 (this.encoding == null)
73 ? DefaultGroovyMethods.newReader(this.delegate)
74 : DefaultGroovyMethods.newReader(this.delegate, this.encoding);
75
76 try {
77 int c = reader.read();
78
79 while (c != -1) {
80 out.write(c);
81 c = reader.read();
82 }
83 }
84 finally {
85 reader.close();
86 }
87 return out;
88 }
89
90 public boolean canRead() {
91 return delegate.canRead();
92 }
93
94 public boolean canWrite() {
95 return delegate.canWrite();
96 }
97
98 public int compareTo(File arg0) {
99 return delegate.compareTo(arg0);
100 }
101
102 public int compareTo(Object arg0) {
103 return delegate.compareTo(arg0);
104 }
105
106 public boolean createNewFile() throws IOException {
107 return delegate.createNewFile();
108 }
109
110 public boolean delete() {
111 return delegate.delete();
112 }
113
114 public void deleteOnExit() {
115 delegate.deleteOnExit();
116 }
117
118 public boolean equals(Object arg0) {
119 return delegate.equals(arg0);
120 }
121
122 public boolean exists() {
123 return delegate.exists();
124 }
125
126 public File getAbsoluteFile() {
127 return delegate.getAbsoluteFile();
128 }
129
130 public String getAbsolutePath() {
131 return delegate.getAbsolutePath();
132 }
133
134 public File getCanonicalFile() throws IOException {
135 return delegate.getCanonicalFile();
136 }
137
138 public String getCanonicalPath() throws IOException {
139 return delegate.getCanonicalPath();
140 }
141
142 public String getName() {
143 return delegate.getName();
144 }
145
146 public String getParent() {
147 return delegate.getParent();
148 }
149
150 public File getParentFile() {
151 return delegate.getParentFile();
152 }
153
154 public String getPath() {
155 return delegate.getPath();
156 }
157
158 public int hashCode() {
159 return delegate.hashCode();
160 }
161
162 public boolean isAbsolute() {
163 return delegate.isAbsolute();
164 }
165
166 public boolean isDirectory() {
167 return delegate.isDirectory();
168 }
169
170 public boolean isFile() {
171 return delegate.isFile();
172 }
173
174
175
176
177 public boolean isHidden() {
178 return delegate.isHidden();
179 }
180
181
182
183
184 public long lastModified() {
185 return delegate.lastModified();
186 }
187
188
189
190
191 public long length() {
192 return delegate.length();
193 }
194
195
196
197
198 public String[] list() {
199 return delegate.list();
200 }
201
202
203
204
205 public String[] list(FilenameFilter arg0) {
206 return delegate.list(arg0);
207 }
208
209
210
211
212 public File[] listFiles() {
213 return delegate.listFiles();
214 }
215
216
217
218
219 public File[] listFiles(FileFilter arg0) {
220 return delegate.listFiles(arg0);
221 }
222
223
224
225
226 public File[] listFiles(FilenameFilter arg0) {
227 return delegate.listFiles(arg0);
228 }
229
230
231
232
233 public boolean mkdir() {
234 return delegate.mkdir();
235 }
236
237
238
239
240 public boolean mkdirs() {
241 return delegate.mkdirs();
242 }
243
244
245
246
247 public boolean renameTo(File arg0) {
248 return delegate.renameTo(arg0);
249 }
250
251
252
253
254 public boolean setLastModified(long arg0) {
255 return delegate.setLastModified(arg0);
256 }
257
258
259
260
261 public boolean setReadOnly() {
262 return delegate.setReadOnly();
263 }
264
265
266
267
268 public String toString() {
269 return delegate.toString();
270 }
271
272
273
274
275 public URI toURI() {
276 return delegate.toURI();
277 }
278
279
280
281
282 public URL toURL() throws MalformedURLException {
283 return delegate.toURL();
284 }
285
286 }