MCPcopy Create free account
hub / github.com/apache/tomcat / copy

Method copy

java/org/apache/catalina/startup/ExpandWar.java:233–276  ·  view source on GitHub ↗

Copy the specified file or directory to the destination. @param src File object representing the source @param dest File object representing the destination @return true if the copy was successful

(File src, File dest)

Source from the content-addressed store, hash-verified

231 * @return <code>true</code> if the copy was successful
232 */
233 public static boolean copy(File src, File dest) {
234
235 boolean result = true;
236
237 String[] files;
238 if (src.isDirectory()) {
239 files = src.list();
240 result = dest.isDirectory() || dest.mkdir();
241 } else {
242 files = new String[1];
243 files[0] = "";
244 }
245 if (files == null) {
246 files = new String[0];
247 }
248 for (int i = 0; (i < files.length) && result; i++) {
249 File fileSrc = new File(src, files[i]);
250 File fileDest = new File(dest, files[i]);
251 if (fileSrc.isDirectory()) {
252 result = copy(fileSrc, fileDest);
253 } else {
254 try (FileInputStream fis = new FileInputStream(fileSrc);
255 FileChannel ic = (fis).getChannel();
256 FileOutputStream fos = new FileOutputStream(fileDest);
257 FileChannel oc = (fos).getChannel()) {
258 long size = ic.size();
259 long position = 0;
260 while (size > 0) {
261 long count = ic.transferTo(position, size, oc);
262 if (count > 0) {
263 position += count;
264 size -= count;
265 } else {
266 throw new EOFException();
267 }
268 }
269 } catch (IOException ioe) {
270 log.error(sm.getString("expandWar.copy", fileSrc, fileDest), ioe);
271 result = false;
272 }
273 }
274 }
275 return result;
276 }
277
278
279 /**

Callers 2

antiLockingMethod · 0.95
deployMethod · 0.95

Calls 7

isDirectoryMethod · 0.65
listMethod · 0.65
mkdirMethod · 0.65
getChannelMethod · 0.65
errorMethod · 0.65
getStringMethod · 0.65
sizeMethod · 0.45

Tested by

no test coverage detected