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
/
LocalCopyFileCommand.java
124 lines (105 loc) · 3 KB
/
LocalCopyFileCommand.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/**
* /*******************************************************************************
* 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 static java.nio.file.StandardCopyOption.REPLACE_EXISTING;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
/**
* Child class for locally copying a file without a remote connection
*
* @author Joe Osborn
*
*/
public class LocalCopyFileCommand extends LocalCommand {
/**
* The path to the source file which is to be copied
*/
Path source;
/**
* The path of the destination for which the source file will be copied to
*/
Path destination;
/**
* Default constructor
*/
public LocalCopyFileCommand() {
}
/**
* This function actually executes the copy file command. It checks that the
* copy was completed successfully. It returns a CommandStatus indicating
* whether or not the move was successful.
*
* @return CommandStatus
*/
@Override
public CommandStatus execute() {
// Run the copying
status = run();
return status;
}
/**
* This function contains the command to actually copy the file. Returns a
* CommandStatus indicating that the command is currently running and needs to
* be checked that it completed correctly.
*
* @return CommandStatus
*/
@Override
protected CommandStatus run() {
// Try to copy from source to destination, overwriting if the file already
// exists at the destination. If it can't, complain.
try {
Files.copy(source, destination.resolve(source.getFileName()), REPLACE_EXISTING);
} catch (IOException e) {
e.printStackTrace();
}
return CommandStatus.RUNNING;
}
/**
* This function cancels the command when called. See also
* {@link org.eclipse.ice.commands.Command#cancel()}
*/
@Override
public CommandStatus cancel() {
status = CommandStatus.CANCELED;
return CommandStatus.CANCELED;
}
/**
* This function sets the Paths for source and destination to the given strings
* @param src - string corresponding to the source file
* @param dest - string corresponding to the destination file
*/
public void setConfiguration(String src, String dest) {
source = Paths.get(src);
destination = Paths.get(dest);
return;
}
/**
* A function that returns the source path in string form
*
* @return - String
*/
public String getSource() {
return source.toString();
}
/**
* A function that returns the destination path in string form
*
* @return - String
*/
public String getDestination() {
return destination.toString();
}
}