KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jodd > io > FileEx


1 // Copyright (c) 2003-2007, Jodd Team (jodd.sf.net). All Rights Reserved.
2

3 package jodd.io;
4
5 import java.io.File JavaDoc;
6 import java.io.IOException JavaDoc;
7 import java.net.URI JavaDoc;
8
9 /**
10  * Extended File object that adapts {@link FileUtil}s.
11  */

12 public class FileEx extends File JavaDoc {
13
14     // ---------------------------------------------------------------- constructors
15

16     public FileEx(String JavaDoc pathname) {
17         super(pathname);
18     }
19
20     public FileEx(String JavaDoc parent, String JavaDoc child) {
21         super(parent, child);
22     }
23
24     public FileEx(File JavaDoc parent, String JavaDoc child) {
25         super(parent, child);
26     }
27
28     public FileEx(URI JavaDoc uri) {
29         super(uri);
30     }
31
32
33     // ---------------------------------------------------------------- settings
34

35     protected FileUtil.Settings settings = FileUtil.cloneSettings();
36
37     public void setPreserveDate(boolean value) {
38         settings.preserveDate = value;
39     }
40     public boolean isPreserveDate() {
41         return settings.preserveDate;
42     }
43
44     public void setOverwriteExisting(boolean value) {
45         settings.overwriteExisting = value;
46     }
47     public boolean isOverwriteExisting() {
48         return settings.overwriteExisting;
49     }
50
51     public void setCreateDirs(boolean value) {
52         settings.createDirs = value;
53     }
54     public boolean isCreateDirs() {
55         return settings.createDirs;
56     }
57
58     public void setRecursive(boolean value) {
59         settings.recursive = value;
60     }
61     public boolean isRecursive() {
62         return settings.recursive;
63     }
64
65     public boolean isContinueOnError() {
66         return settings.continueOnError;
67     }
68     public void setContinueOnError(boolean continueOnError) {
69         settings.continueOnError = continueOnError;
70     }
71
72     public String JavaDoc getEncoding() {
73         return settings.encoding;
74     }
75     public void setEncoding(String JavaDoc encoding) {
76         settings.encoding = encoding;
77     }
78
79     // ---------------------------------------------------------------- operations
80

81     public void touch() throws IOException JavaDoc {
82         FileUtil.touch(this);
83     }
84
85     public void copyFile(File JavaDoc dest) throws IOException JavaDoc {
86         FileUtil.copyFile(this, dest, settings);
87     }
88     public void copyToDir(File JavaDoc dest) throws IOException JavaDoc {
89         FileUtil.copyFileToDir(this, dest, settings);
90     }
91     public void copyDir(File JavaDoc dest) throws IOException JavaDoc {
92         FileUtil.copyDir(this, dest, settings);
93     }
94
95     public void moveFile(File JavaDoc dest) throws IOException JavaDoc {
96         FileUtil.moveFile(this, dest, settings);
97     }
98     public void moveToDir(File JavaDoc dest) throws IOException JavaDoc {
99         FileUtil.moveFileToDir(this, dest, settings);
100     }
101     public void moveDir(File JavaDoc dest) throws IOException JavaDoc {
102         FileUtil.moveDir(this, dest);
103     }
104
105     public void deleteFile() throws IOException JavaDoc {
106         FileUtil.deleteFile(this);
107     }
108     public void deleteDir() throws IOException JavaDoc {
109         FileUtil.deleteDir(this, settings);
110     }
111     public void cleanDir() throws IOException JavaDoc {
112         FileUtil.cleanDir(this, settings);
113     }
114
115     public String JavaDoc readString() throws IOException JavaDoc {
116         return FileUtil.readString(this);
117     }
118     public String JavaDoc readString(String JavaDoc encoding) throws IOException JavaDoc {
119         return FileUtil.readString(this, encoding);
120     }
121     public void writeString(String JavaDoc data) throws IOException JavaDoc {
122         FileUtil.writeString(this, data);
123     }
124     public void writeString(String JavaDoc data, String JavaDoc encoding) throws IOException JavaDoc {
125         FileUtil.writeString(this, data, encoding);
126     }
127
128     public byte[] readBytes() throws IOException JavaDoc {
129         return FileUtil.readBytes(this);
130     }
131     public void writeBytes(byte[] data) throws IOException JavaDoc {
132         FileUtil.writeBytes(this, data);
133     }
134
135     public boolean compare(File JavaDoc dest) throws IOException JavaDoc {
136         return FileUtil.compare(this, dest);
137     }
138
139     public boolean isNewer(File JavaDoc reference) {
140         return FileUtil.isNewer(this, reference);
141     }
142     public boolean isNewer(long timeMillis) {
143         return FileUtil.isNewer(this, timeMillis);
144     }
145     public boolean isOlder(File JavaDoc reference) {
146         return FileUtil.isOlder(this, reference);
147     }
148     public boolean isOlder(long timeMillis) {
149         return FileUtil.isOlder(this, timeMillis);
150     }
151
152
153     public void copy(File JavaDoc dest) throws IOException JavaDoc {
154         FileUtil.copy(this, dest, settings);
155     }
156     public void move(File JavaDoc dest) throws IOException JavaDoc {
157         FileUtil.move(this, dest, settings);
158     }
159     public void delete(File JavaDoc dest) throws IOException JavaDoc {
160         FileUtil.delete(this, settings);
161     }
162
163 }
164
Popular Tags