This repository has been archived by the owner on Mar 27, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 55
/
LocalFileHandler.java
91 lines (78 loc) · 2.7 KB
/
LocalFileHandler.java
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/*******************************************************************************
* Copyright (c) 2019- UT-Battelle, LLC.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Initial API and implementation and/or initial documentation -
* Jay Jay Billings, Joe Osborn
*******************************************************************************/
package org.eclipse.ice.commands;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
/**
* This class inherits from FileHandler and deals with the processing of local
* file transfer commands
*
* @author Joe Osborn
*
*/
public class LocalFileHandler extends FileHandler {
/**
* Default constructor
*/
public LocalFileHandler() {
}
/**
* See {@link org.eclipse.ice.commands.FileHandler#setConfiguration(String, String)}
*/
@Override
protected void configureMoveCommand(final String source, final String destination) {
command = new LocalMoveFileCommand();
// Cast the Command as a LocalMoveFileCommand to set the source and destination paths
((LocalMoveFileCommand) command).setConfiguration(source, destination);
}
/**
* See {@link org.eclipse.ice.commands.FileHandler#setConfiguration(String, String)}
*/
@Override
protected void configureCopyCommand(final String source, final String destination) {
command = new LocalCopyFileCommand();
// Cast the Command as a LocalCopyFileCommand to set the source and destination paths
((LocalCopyFileCommand) command).setConfiguration(source, destination);
}
/**
* See {@link org.eclipse.ice.commands.FileHandler#exists(String)}
*/
@Override
public boolean exists(final String file) throws IOException {
// Get the path from the passed string
Path path = Paths.get(file);
// Check if the path exists or not. Symbolic links are followed
// by default, see {@link java.nio.file.Files#exists}
return Files.exists(path);
}
/**
* See
* {@link org.eclipse.ice.commands.FileHandler#checkExistence(String, String)}
*/
@Override
public void checkExistence(final String source, final String destination) throws IOException {
if (!exists(source)) {
logger.error("Source doesn't exist! Exiting.");
throw new IOException();
}
// If the destination doesn't exist, make a new directory
if (!exists(destination)) {
// If directory can't be made, throw an exception
if (!createDirectories(destination)) {
logger.error("Destination doesn't exist! Exiting.");
throw new IOException();
}
}
}
}