Skip to content

Commit 68ac698

Browse files
committed
Replace File with Path
1 parent 68bac42 commit 68ac698

File tree

1 file changed

+32
-32
lines changed

1 file changed

+32
-32
lines changed

exist-ant/src/main/java/org/exist/ant/XMLDBExtractTask.java

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@
5353
*/
5454
public class XMLDBExtractTask extends AbstractXMLDBTask {
5555
private String resource = null;
56-
private File destFile = null;
57-
private File destDir = null;
56+
private Path destFile = null;
57+
private Path destDir = null;
5858
private boolean createdirectories = false;
5959
private boolean subcollections = false;
6060
private boolean overwrite = false;
@@ -81,7 +81,7 @@ public void execute() throws BuildException {
8181
if ((resource != null) && (destDir == null)) {
8282

8383
// extraction of a single resource
84-
log("Extracting resource: " + resource + " to " + destFile.getAbsolutePath(), Project.MSG_INFO);
84+
log("Extracting resource: " + resource + " to " + destFile.toAbsolutePath().toString(), Project.MSG_INFO);
8585
final Resource res = base.getResource(resource);
8686

8787
if (res == null) {
@@ -139,23 +139,23 @@ public void execute() throws BuildException {
139139
private void extractResources(final Collection base, final String path) throws XMLDBException, IOException {
140140
final String[] resources = base.listResources();
141141
if (resources != null) {
142-
File dir = destDir;
142+
Path dir = destDir;
143143

144-
log("Extracting to directory " + destDir.getAbsolutePath(), Project.MSG_DEBUG);
144+
log("Extracting to directory " + destFile.toAbsolutePath().toString(), Project.MSG_DEBUG);
145145

146146
if (path != null) {
147-
dir = new File(destDir, path);
147+
dir = destDir.resolve(path);
148148
}
149149

150150
for (final String resource : resources) {
151151
final Resource res = base.getResource(resource);
152152
log("Extracting resource: " + res.getId(), Project.MSG_DEBUG);
153153

154-
if (!dir.exists() && createdirectories) {
155-
dir.mkdirs();
154+
if (Files.notExists(dir) && createdirectories) {
155+
Files.createDirectories(dir);
156156
}
157157

158-
if (dir.exists()) {
158+
if (Files.exists(dir)) {
159159
writeResource(res, dir);
160160
}
161161

@@ -181,11 +181,11 @@ private void extractSubCollections(final Collection base, final String path) thr
181181

182182
if (col != null) {
183183
log("Extracting collection: " + col.getName(), Project.MSG_DEBUG);
184-
File dir = destDir;
184+
File dir = destDir.toFile();
185185
final String subdir;
186186

187187
if (path != null) {
188-
dir = new File(destDir, path + File.separator + childCol);
188+
dir = new File(destDir.toFile(), path + File.separator + childCol);
189189
subdir = path + File.separator + childCol;
190190
} else {
191191
subdir = childCol;
@@ -214,7 +214,7 @@ private void extractSubCollections(final Collection base, final String path) thr
214214
* @throws XMLDBException if a database error occurs
215215
* @throws IOException if an I/O error occurs
216216
*/
217-
private void writeResource(final Resource res, final File dest) throws XMLDBException, IOException {
217+
private void writeResource(final Resource res, final Path dest) throws XMLDBException, IOException {
218218
if (res instanceof XMLResource) {
219219
writeXMLResource((XMLResource) res, dest);
220220
} else if (res instanceof ExtendedResource) {
@@ -231,11 +231,11 @@ private void writeResource(final Resource res, final File dest) throws XMLDBExce
231231
* @throws XMLDBException if a database error occurs
232232
* @throws IOException if an I/O error occurs
233233
*/
234-
private void writeXMLResource(final XMLResource res, final File dest) throws IOException, XMLDBException {
234+
private void writeXMLResource(final XMLResource res, final Path dest) throws IOException, XMLDBException {
235235
if (createdirectories) {
236-
final File parentDir = new File(dest.getParent());
237-
if (!parentDir.exists()) {
238-
parentDir.mkdirs();
236+
final Path parentDir = dest.getParent();
237+
if (Files.notExists(parentDir)) {
238+
Files.createDirectories(parentDir);
239239
}
240240
}
241241

@@ -245,14 +245,14 @@ private void writeXMLResource(final XMLResource res, final File dest) throws IOE
245245
final SAXSerializer serializer = (SAXSerializer) SerializerPool.getInstance().borrowObject(SAXSerializer.class);
246246

247247
try (final Writer writer = getWriter(res, dest)) {
248-
log("Writing resource " + res.getId() + " to destination " + dest.getAbsolutePath(), Project.MSG_DEBUG);
248+
log("Writing resource " + res.getId() + " to destination " + dest.toAbsolutePath().toString(), Project.MSG_DEBUG);
249249
serializer.setOutput(writer, outputProperties);
250250
res.getContentAsSAX(serializer);
251251
SerializerPool.getInstance().returnObject(serializer);
252252
}
253253

254254
} else {
255-
final String msg = "Destination xml file " + ((dest != null) ? (dest.getAbsolutePath() + " ") : "") + "exists. Use " + "overwrite property to overwrite this file.";
255+
final String msg = "Destination xml file " + ((dest != null) ? (dest.toAbsolutePath().toString() + " ") : "") + "exists. Use " + "overwrite property to overwrite this file.";
256256

257257
if (failonerror) {
258258
throw (new BuildException(msg));
@@ -262,14 +262,14 @@ private void writeXMLResource(final XMLResource res, final File dest) throws IOE
262262
}
263263
}
264264

265-
private Writer getWriter(XMLResource res, File dest) throws XMLDBException, IOException {
265+
private Writer getWriter(XMLResource res, Path dest) throws XMLDBException, IOException {
266266
final Writer writer;
267-
if (dest.isDirectory()) {
268-
final Path file = dest.toPath().resolve(res.getId());
267+
if (Files.isDirectory(dest)) {
268+
final Path file = dest.resolve(res.getId());
269269
writer = Files.newBufferedWriter(file, UTF_8);
270270

271271
} else {
272-
writer = Files.newBufferedWriter(destFile.toPath(), UTF_8);
272+
writer = Files.newBufferedWriter(destFile, UTF_8);
273273
}
274274
return writer;
275275
}
@@ -283,27 +283,27 @@ private Writer getWriter(XMLResource res, File dest) throws XMLDBException, IOEx
283283
* @throws XMLDBException if a database error occurs
284284
* @throws IOException if an I/O error occurs
285285
*/
286-
private void writeBinaryResource(final Resource res, File dest) throws XMLDBException, IOException {
286+
private void writeBinaryResource(final Resource res, Path dest) throws XMLDBException, IOException {
287287
if (createdirectories == true) {
288-
final File parentDir = new File(dest.getParent());
289-
if (!parentDir.exists()) {
290-
parentDir.mkdirs();
288+
final Path parentDir = dest.getParent();
289+
if (Files.notExists(parentDir)) {
290+
Files.createDirectories(parentDir);
291291
}
292292
}
293293

294294
//dest != null && ( !dest.exists() ||
295295
if (dest != null || overwrite == true) {
296-
if (dest.isDirectory()) {
296+
if (Files.isDirectory(dest)) {
297297
final String fname = res.getId();
298-
dest = new File(dest, fname);
298+
dest = dest.resolve(fname);
299299
}
300300

301-
try(final OutputStream os = Files.newOutputStream(dest.toPath())) {
301+
try(final OutputStream os = Files.newOutputStream(dest)) {
302302
((ExtendedResource) res).getContentIntoAStream(os);
303303
}
304304

305305
} else {
306-
final String msg = "Dest binary file " + ((dest != null) ? (dest.getAbsolutePath() + " ") : "") + "exists. Use " + "overwrite property to overwrite file.";
306+
final String msg = "Dest binary file " + ((dest != null) ? (dest.toAbsolutePath().toString() + " ") : "") + "exists. Use " + "overwrite property to overwrite file.";
307307

308308
if (failonerror) {
309309
throw (new BuildException(msg));
@@ -318,11 +318,11 @@ public void setResource(final String resource) {
318318
}
319319

320320
public void setDestFile(final File destFile) {
321-
this.destFile = destFile;
321+
this.destFile = destFile.toPath();
322322
}
323323

324324
public void setDestDir(final File destDir) {
325-
this.destDir = destDir;
325+
this.destDir = destDir.toPath();
326326
}
327327

328328

0 commit comments

Comments
 (0)