blob: b12d15cc36223bb56f50a07c8efdf28509b4dc25 [file] [log] [blame]
Thomas Vachuska24c849c2014-10-27 09:53:05 -07001/*
Ray Milkey34c95902015-04-15 09:47:53 -07002 * Copyright 2014-2015 Open Networking Laboratory
Thomas Vachuska24c849c2014-10-27 09:53:05 -07003 *
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07004 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
Thomas Vachuska24c849c2014-10-27 09:53:05 -07007 *
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07008 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
Thomas Vachuska24c849c2014-10-27 09:53:05 -070015 */
tom5f38b3a2014-08-27 23:50:54 -070016package org.onlab.util;
17
Madan Jampani2bfa94c2015-04-11 05:03:49 -070018import static java.nio.file.Files.delete;
19import static java.nio.file.Files.walkFileTree;
20import static org.onlab.util.GroupedThreadFactory.groupedThreadFactory;
21import static org.slf4j.LoggerFactory.getLogger;
Yuta HIGUCHI683e9782014-11-25 17:26:36 -080022
tom53efab52014-10-07 17:43:48 -070023import java.io.BufferedReader;
24import java.io.File;
Ray Milkey705d9bc2014-11-18 08:19:00 -080025import java.io.FileInputStream;
tom53efab52014-10-07 17:43:48 -070026import java.io.IOException;
Ray Milkey705d9bc2014-11-18 08:19:00 -080027import java.io.InputStreamReader;
Madan Jampani27b69c62015-05-15 15:49:02 -070028import java.nio.ByteBuffer;
Ray Milkey705d9bc2014-11-18 08:19:00 -080029import java.nio.charset.StandardCharsets;
Thomas Vachuska02aeb032015-01-06 22:36:30 -080030import java.nio.file.FileVisitResult;
Thomas Vachuska90b453f2015-01-30 18:57:14 -080031import java.nio.file.Files;
Thomas Vachuska02aeb032015-01-06 22:36:30 -080032import java.nio.file.Path;
33import java.nio.file.Paths;
34import java.nio.file.SimpleFileVisitor;
Thomas Vachuska90b453f2015-01-30 18:57:14 -080035import java.nio.file.StandardCopyOption;
Thomas Vachuska02aeb032015-01-06 22:36:30 -080036import java.nio.file.attribute.BasicFileAttributes;
tom53efab52014-10-07 17:43:48 -070037import java.util.ArrayList;
Madan Jampani27b69c62015-05-15 15:49:02 -070038import java.util.Arrays;
Brian O'Connore2eac102015-02-12 18:30:22 -080039import java.util.Collection;
Thomas Vachuska6519e6f2015-03-11 02:29:31 -070040import java.util.Dictionary;
tom53efab52014-10-07 17:43:48 -070041import java.util.List;
Thomas Vachuskaadba1522015-06-04 15:08:30 -070042import java.util.Random;
Madan Jampani27b69c62015-05-15 15:49:02 -070043import java.util.concurrent.CompletableFuture;
Madan Jampani2bfa94c2015-04-11 05:03:49 -070044import java.util.concurrent.ExecutionException;
45import java.util.concurrent.Future;
tom5f38b3a2014-08-27 23:50:54 -070046import java.util.concurrent.ThreadFactory;
Madan Jampani2bfa94c2015-04-11 05:03:49 -070047import java.util.concurrent.TimeUnit;
48import java.util.concurrent.TimeoutException;
Madan Jampania29c6772015-08-17 13:17:07 -070049import java.util.function.Function;
50import java.util.function.Supplier;
HIGUCHI Yutabfc8b7a2015-07-01 23:47:43 -070051import java.util.stream.Stream;
52import java.util.stream.StreamSupport;
tom5f38b3a2014-08-27 23:50:54 -070053
Madan Jampani2bfa94c2015-04-11 05:03:49 -070054import org.slf4j.Logger;
55
56import com.google.common.base.Strings;
57import com.google.common.primitives.UnsignedLongs;
58import com.google.common.util.concurrent.ThreadFactoryBuilder;
Ray Milkey705d9bc2014-11-18 08:19:00 -080059
Thomas Vachuskac13b90a2015-02-18 18:19:55 -080060/**
61 * Miscellaneous utility methods.
62 */
tom5f38b3a2014-08-27 23:50:54 -070063public abstract class Tools {
64
65 private Tools() {
66 }
67
Thomas Vachuska02aeb032015-01-06 22:36:30 -080068 private static final Logger log = getLogger(Tools.class);
Yuta HIGUCHI683e9782014-11-25 17:26:36 -080069
Thomas Vachuskaadba1522015-06-04 15:08:30 -070070 private static Random random = new Random();
71
tom5f38b3a2014-08-27 23:50:54 -070072 /**
73 * Returns a thread factory that produces threads named according to the
74 * supplied name pattern.
75 *
76 * @param pattern name pattern
77 * @return thread factory
78 */
79 public static ThreadFactory namedThreads(String pattern) {
Yuta HIGUCHI683e9782014-11-25 17:26:36 -080080 return new ThreadFactoryBuilder()
81 .setNameFormat(pattern)
Thomas Vachuska480adad2015-03-06 10:27:09 -080082 .setUncaughtExceptionHandler((t, e) -> log.error("Uncaught exception on " + t.getName(), e))
83 .build();
Thomas Vachuska9c17a6d2015-02-17 23:36:43 -080084 }
Yuta HIGUCHI683e9782014-11-25 17:26:36 -080085
Thomas Vachuska9c17a6d2015-02-17 23:36:43 -080086 /**
87 * Returns a thread factory that produces threads named according to the
88 * supplied name pattern and from the specified thread-group. The thread
89 * group name is expected to be specified in slash-delimited format, e.g.
Thomas Vachuskac13b90a2015-02-18 18:19:55 -080090 * {@code onos/intent}. The thread names will be produced by converting
91 * the thread group name into dash-delimited format and pre-pended to the
92 * specified pattern.
Thomas Vachuska9c17a6d2015-02-17 23:36:43 -080093 *
94 * @param groupName group name in slash-delimited format to indicate hierarchy
95 * @param pattern name pattern
96 * @return thread factory
97 */
98 public static ThreadFactory groupedThreads(String groupName, String pattern) {
99 return new ThreadFactoryBuilder()
100 .setThreadFactory(groupedThreadFactory(groupName))
Thomas Vachuskac13b90a2015-02-18 18:19:55 -0800101 .setNameFormat(groupName.replace(GroupedThreadFactory.DELIMITER, "-") + "-" + pattern)
Thomas Vachuska480adad2015-03-06 10:27:09 -0800102 .setUncaughtExceptionHandler((t, e) -> log.error("Uncaught exception on " + t.getName(), e))
103 .build();
tom5f38b3a2014-08-27 23:50:54 -0700104 }
105
tom782a7cf2014-09-11 23:58:38 -0700106 /**
Yuta HIGUCHI06586272014-11-25 14:27:03 -0800107 * Returns a thread factory that produces threads with MIN_PRIORITY.
108 *
109 * @param factory backing ThreadFactory
110 * @return thread factory
111 */
112 public static ThreadFactory minPriority(ThreadFactory factory) {
113 return new ThreadFactoryBuilder()
Thomas Vachuska02aeb032015-01-06 22:36:30 -0800114 .setThreadFactory(factory)
115 .setPriority(Thread.MIN_PRIORITY)
116 .build();
Yuta HIGUCHI06586272014-11-25 14:27:03 -0800117 }
118
119 /**
Brian O'Connore2eac102015-02-12 18:30:22 -0800120 * Returns true if the collection is null or is empty.
121 *
122 * @param collection collection to test
123 * @return true if null or empty; false otherwise
124 */
125 public static boolean isNullOrEmpty(Collection collection) {
126 return collection == null || collection.isEmpty();
127 }
128
129 /**
Ray Milkeyd43fe452015-05-29 09:35:12 -0700130 * Returns the specified item if that item is not null; otherwise throws
Thomas Vachuskaca88bb72015-04-08 19:38:02 -0700131 * not found exception.
132 *
133 * @param item item to check
134 * @param message not found message
135 * @param <T> item type
136 * @return item if not null
137 * @throws org.onlab.util.ItemNotFoundException if item is null
138 */
139 public static <T> T nullIsNotFound(T item, String message) {
140 if (item == null) {
141 throw new ItemNotFoundException(message);
142 }
143 return item;
144 }
145
146 /**
Ray Milkeyd43fe452015-05-29 09:35:12 -0700147 * Returns the specified item if that item is not null; otherwise throws
148 * bad argument exception.
149 *
150 * @param item item to check
151 * @param message not found message
152 * @param <T> item type
153 * @return item if not null
154 * @throws IllegalArgumentException if item is null
155 */
156 public static <T> T nullIsIllegal(T item, String message) {
157 if (item == null) {
158 throw new IllegalArgumentException(message);
159 }
160 return item;
161 }
162
163 /**
tom782a7cf2014-09-11 23:58:38 -0700164 * Converts a string from hex to long.
165 *
166 * @param string hex number in string form; sans 0x
167 * @return long value
168 */
169 public static long fromHex(String string) {
170 return UnsignedLongs.parseUnsignedLong(string, 16);
171 }
172
173 /**
174 * Converts a long value to hex string; 16 wide and sans 0x.
175 *
176 * @param value long value
177 * @return hex string
178 */
179 public static String toHex(long value) {
180 return Strings.padStart(UnsignedLongs.toString(value, 16), 16, '0');
181 }
182
183 /**
184 * Converts a long value to hex string; 16 wide and sans 0x.
185 *
186 * @param value long value
187 * @param width string width; zero padded
188 * @return hex string
189 */
190 public static String toHex(long value, int width) {
191 return Strings.padStart(UnsignedLongs.toString(value, 16), width, '0');
192 }
tomf110fff2014-09-26 00:38:18 -0700193
194 /**
Madan Jampani9eb55d12015-08-14 07:47:56 -0700195 * Returns a copy of the input byte array.
196 *
197 * @param original input
198 * @return copy of original
199 */
200 public static byte[] copyOf(byte[] original) {
201 return Arrays.copyOf(original, original.length);
202 }
203
204 /**
Thomas Vachuska6519e6f2015-03-11 02:29:31 -0700205 * Get property as a string value.
206 *
207 * @param properties properties to be looked up
208 * @param propertyName the name of the property to look up
209 * @return value when the propertyName is defined or return null
210 */
211 public static String get(Dictionary<?, ?> properties, String propertyName) {
212 Object v = properties.get(propertyName);
213 String s = (v instanceof String) ? (String) v :
214 v != null ? v.toString() : null;
215 return Strings.isNullOrEmpty(s) ? null : s.trim();
216 }
217
218 /**
tomf110fff2014-09-26 00:38:18 -0700219 * Suspends the current thread for a specified number of millis.
220 *
221 * @param ms number of millis
222 */
223 public static void delay(int ms) {
224 try {
225 Thread.sleep(ms);
226 } catch (InterruptedException e) {
227 throw new RuntimeException("Interrupted", e);
228 }
229 }
230
tom53efab52014-10-07 17:43:48 -0700231 /**
Madan Jampania29c6772015-08-17 13:17:07 -0700232 * Returns a function that retries execution on failure.
233 * @param base base function
234 * @param exceptionClass type of exception for which to retry
235 * @param maxRetries max number of retries before giving up
236 * @param maxDelayBetweenRetries max delay between successive retries. The actual delay is randomly picked from
237 * the interval (0, maxDelayBetweenRetries]
238 * @return function
239 */
240 public static <U, V> Function<U, V> retryable(Function<U, V> base,
241 Class<? extends Throwable> exceptionClass,
242 int maxRetries,
243 int maxDelayBetweenRetries) {
244 return new RetryingFunction<>(base, exceptionClass, maxRetries, maxDelayBetweenRetries);
245 }
246
247 /**
248 * Returns a Supplier that retries execution on failure.
249 * @param base base supplier
250 * @param exceptionClass type of exception for which to retry
251 * @param maxRetries max number of retries before giving up
252 * @param maxDelayBetweenRetries max delay between successive retries. The actual delay is randomly picked from
253 * the interval (0, maxDelayBetweenRetries]
254 * @return supplier
255 */
256 public static <V> Supplier<V> retryable(Supplier<V> base,
257 Class<? extends Throwable> exceptionClass,
258 int maxRetries,
259 int maxDelayBetweenRetries) {
260 return () -> new RetryingFunction<>(v -> base.get(),
261 exceptionClass,
262 maxRetries,
263 maxDelayBetweenRetries).apply(null);
264 }
265
266 /**
Thomas Vachuskaadba1522015-06-04 15:08:30 -0700267 * Suspends the current thread for a random number of millis between 0 and
268 * the indicated limit.
269 *
270 * @param ms max number of millis
271 */
272 public static void randomDelay(int ms) {
273 try {
274 Thread.sleep(random.nextInt(ms));
275 } catch (InterruptedException e) {
276 throw new RuntimeException("Interrupted", e);
277 }
278 }
279
280 /**
Thomas Vachuskac40d4632015-04-09 16:55:03 -0700281 * Suspends the current thread for a specified number of millis and nanos.
282 *
283 * @param ms number of millis
284 * @param nanos number of nanos
285 */
286 public static void delay(int ms, int nanos) {
287 try {
288 Thread.sleep(ms, nanos);
289 } catch (InterruptedException e) {
290 throw new RuntimeException("Interrupted", e);
291 }
292 }
293
294 /**
tom53efab52014-10-07 17:43:48 -0700295 * Slurps the contents of a file into a list of strings, one per line.
296 *
297 * @param path file path
298 * @return file contents
299 */
300 public static List<String> slurp(File path) {
Ray Milkey705d9bc2014-11-18 08:19:00 -0800301 try {
302 BufferedReader br = new BufferedReader(
Thomas Vachuska02aeb032015-01-06 22:36:30 -0800303 new InputStreamReader(new FileInputStream(path), StandardCharsets.UTF_8));
Ray Milkey705d9bc2014-11-18 08:19:00 -0800304
tom53efab52014-10-07 17:43:48 -0700305 List<String> lines = new ArrayList<>();
306 String line;
307 while ((line = br.readLine()) != null) {
308 lines.add(line);
309 }
310 return lines;
311
312 } catch (IOException e) {
313 return null;
314 }
315 }
316
Thomas Vachuska02aeb032015-01-06 22:36:30 -0800317 /**
318 * Purges the specified directory path.&nbsp;Use with great caution since
319 * no attempt is made to check for symbolic links, which could result in
320 * deletion of unintended files.
321 *
322 * @param path directory to be removed
323 * @throws java.io.IOException if unable to remove contents
324 */
325 public static void removeDirectory(String path) throws IOException {
Thomas Vachuska62ad95f2015-02-18 12:11:36 -0800326 DirectoryDeleter visitor = new DirectoryDeleter();
Thomas Vachuskaf9c84362015-04-15 11:20:45 -0700327 File dir = new File(path);
328 if (dir.exists() && dir.isDirectory()) {
329 walkFileTree(Paths.get(path), visitor);
330 if (visitor.exception != null) {
331 throw visitor.exception;
332 }
Thomas Vachuska62ad95f2015-02-18 12:11:36 -0800333 }
Thomas Vachuska02aeb032015-01-06 22:36:30 -0800334 }
335
336 /**
337 * Purges the specified directory path.&nbsp;Use with great caution since
338 * no attempt is made to check for symbolic links, which could result in
339 * deletion of unintended files.
340 *
341 * @param dir directory to be removed
342 * @throws java.io.IOException if unable to remove contents
343 */
344 public static void removeDirectory(File dir) throws IOException {
Thomas Vachuska62ad95f2015-02-18 12:11:36 -0800345 DirectoryDeleter visitor = new DirectoryDeleter();
Thomas Vachuskaf9c84362015-04-15 11:20:45 -0700346 if (dir.exists() && dir.isDirectory()) {
347 walkFileTree(Paths.get(dir.getAbsolutePath()), visitor);
348 if (visitor.exception != null) {
349 throw visitor.exception;
350 }
Thomas Vachuska62ad95f2015-02-18 12:11:36 -0800351 }
Thomas Vachuska02aeb032015-01-06 22:36:30 -0800352 }
353
Thomas Vachuska62ad95f2015-02-18 12:11:36 -0800354 // Auxiliary path visitor for recursive directory structure removal.
Thomas Vachuska02aeb032015-01-06 22:36:30 -0800355 private static class DirectoryDeleter extends SimpleFileVisitor<Path> {
Thomas Vachuska62ad95f2015-02-18 12:11:36 -0800356
357 private IOException exception;
358
Thomas Vachuska02aeb032015-01-06 22:36:30 -0800359 @Override
360 public FileVisitResult visitFile(Path file, BasicFileAttributes attributes)
361 throws IOException {
362 if (attributes.isRegularFile()) {
363 delete(file);
364 }
365 return FileVisitResult.CONTINUE;
366 }
367
368 @Override
369 public FileVisitResult postVisitDirectory(Path directory, IOException ioe)
370 throws IOException {
371 delete(directory);
372 return FileVisitResult.CONTINUE;
373 }
374
375 @Override
376 public FileVisitResult visitFileFailed(Path file, IOException ioe)
377 throws IOException {
Thomas Vachuska62ad95f2015-02-18 12:11:36 -0800378 this.exception = ioe;
379 return FileVisitResult.TERMINATE;
Thomas Vachuska02aeb032015-01-06 22:36:30 -0800380 }
381 }
382
Madan Jampani30a57f82015-03-02 12:19:41 -0800383 /**
384 * Returns a human friendly time ago string for a specified system time.
Thomas Vachuska480adad2015-03-06 10:27:09 -0800385 *
Madan Jampani30a57f82015-03-02 12:19:41 -0800386 * @param unixTime system time in millis
387 * @return human friendly time ago
388 */
389 public static String timeAgo(long unixTime) {
390 long deltaMillis = System.currentTimeMillis() - unixTime;
391 long secondsSince = (long) (deltaMillis / 1000.0);
392 long minsSince = (long) (deltaMillis / (1000.0 * 60));
393 long hoursSince = (long) (deltaMillis / (1000.0 * 60 * 60));
394 long daysSince = (long) (deltaMillis / (1000.0 * 60 * 60 * 24));
395 if (daysSince > 0) {
396 return String.format("%dd ago", daysSince);
397 } else if (hoursSince > 0) {
398 return String.format("%dh ago", hoursSince);
399 } else if (minsSince > 0) {
400 return String.format("%dm ago", minsSince);
401 } else if (secondsSince > 0) {
402 return String.format("%ds ago", secondsSince);
403 } else {
404 return "just now";
405 }
406 }
Thomas Vachuska90b453f2015-01-30 18:57:14 -0800407
408 /**
409 * Copies the specified directory path.&nbsp;Use with great caution since
410 * no attempt is made to check for symbolic links, which could result in
411 * copy of unintended files.
412 *
413 * @param src directory to be copied
414 * @param dst destination directory to be removed
415 * @throws java.io.IOException if unable to remove contents
416 */
417 public static void copyDirectory(String src, String dst) throws IOException {
418 walkFileTree(Paths.get(src), new DirectoryCopier(src, dst));
419 }
420
421 /**
422 * Copies the specified directory path.&nbsp;Use with great caution since
423 * no attempt is made to check for symbolic links, which could result in
424 * copy of unintended files.
425 *
426 * @param src directory to be copied
427 * @param dst destination directory to be removed
428 * @throws java.io.IOException if unable to remove contents
429 */
430 public static void copyDirectory(File src, File dst) throws IOException {
431 walkFileTree(Paths.get(src.getAbsolutePath()),
432 new DirectoryCopier(src.getAbsolutePath(),
433 dst.getAbsolutePath()));
434 }
435
Madan Jampani2bfa94c2015-04-11 05:03:49 -0700436 /**
437 * Returns the future value when complete or if future
438 * completes exceptionally returns the defaultValue.
Thomas Vachuskad894b5d2015-07-30 11:59:07 -0700439 *
Madan Jampani2bfa94c2015-04-11 05:03:49 -0700440 * @param future future
441 * @param defaultValue default value
442 * @param <T> future value type
443 * @return future value when complete or if future
444 * completes exceptionally returns the defaultValue.
445 */
446 public static <T> T futureGetOrElse(Future<T> future, T defaultValue) {
447 try {
448 return future.get();
449 } catch (InterruptedException e) {
450 Thread.currentThread().interrupt();
451 return defaultValue;
452 } catch (ExecutionException e) {
453 return defaultValue;
454 }
455 }
456
457 /**
458 * Returns the future value when complete or if future
459 * completes exceptionally returns the defaultValue.
Thomas Vachuskad894b5d2015-07-30 11:59:07 -0700460 *
Madan Jampani2bfa94c2015-04-11 05:03:49 -0700461 * @param future future
462 * @param timeout time to wait for successful completion
463 * @param timeUnit time unit
464 * @param defaultValue default value
465 * @param <T> future value type
466 * @return future value when complete or if future
467 * completes exceptionally returns the defaultValue.
468 */
469 public static <T> T futureGetOrElse(Future<T> future,
470 long timeout,
471 TimeUnit timeUnit,
472 T defaultValue) {
473 try {
474 return future.get(timeout, timeUnit);
475 } catch (InterruptedException e) {
476 Thread.currentThread().interrupt();
477 return defaultValue;
478 } catch (ExecutionException | TimeoutException e) {
479 return defaultValue;
480 }
481 }
482
Madan Jampani27b69c62015-05-15 15:49:02 -0700483 /**
484 * Returns a future that is completed exceptionally.
Thomas Vachuskad894b5d2015-07-30 11:59:07 -0700485 *
Madan Jampani27b69c62015-05-15 15:49:02 -0700486 * @param t exception
487 * @param <T> future value type
488 * @return future
489 */
490 public static <T> CompletableFuture<T> exceptionalFuture(Throwable t) {
491 CompletableFuture<T> future = new CompletableFuture<>();
492 future.completeExceptionally(t);
493 return future;
494 }
495
496 /**
497 * Returns the contents of {@code ByteBuffer} as byte array.
498 * <p>
499 * WARNING: There is a performance cost due to array copy
500 * when using this method.
Thomas Vachuskad894b5d2015-07-30 11:59:07 -0700501 *
Madan Jampani27b69c62015-05-15 15:49:02 -0700502 * @param buffer byte buffer
503 * @return byte array containing the byte buffer contents
504 */
505 public static byte[] byteBuffertoArray(ByteBuffer buffer) {
506 int length = buffer.remaining();
507 if (buffer.hasArray()) {
508 int offset = buffer.arrayOffset() + buffer.position();
509 return Arrays.copyOfRange(buffer.array(), offset, offset + length);
510 }
511 byte[] bytes = new byte[length];
512 buffer.duplicate().get(bytes);
513 return bytes;
514 }
515
HIGUCHI Yutabfc8b7a2015-07-01 23:47:43 -0700516 /**
Thomas Vachuskad894b5d2015-07-30 11:59:07 -0700517 * Converts an iterable to a stream.
HIGUCHI Yutabfc8b7a2015-07-01 23:47:43 -0700518 *
Thomas Vachuskad894b5d2015-07-30 11:59:07 -0700519 * @param it iterable to convert
520 * @param <T> type if item
521 * @return iterable as a stream
HIGUCHI Yutabfc8b7a2015-07-01 23:47:43 -0700522 */
523 public static <T> Stream<T> stream(Iterable<T> it) {
524 return StreamSupport.stream(it.spliterator(), false);
525 }
526
Thomas Vachuska62ad95f2015-02-18 12:11:36 -0800527 // Auxiliary path visitor for recursive directory structure copying.
528 private static class DirectoryCopier extends SimpleFileVisitor<Path> {
Thomas Vachuska90b453f2015-01-30 18:57:14 -0800529 private Path src;
530 private Path dst;
531 private StandardCopyOption copyOption = StandardCopyOption.REPLACE_EXISTING;
532
533 DirectoryCopier(String src, String dst) {
534 this.src = Paths.get(src);
535 this.dst = Paths.get(dst);
536 }
537
538 @Override
539 public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {
540 Path targetPath = dst.resolve(src.relativize(dir));
541 if (!Files.exists(targetPath)) {
542 Files.createDirectory(targetPath);
543 }
544 return FileVisitResult.CONTINUE;
545 }
546
547 @Override
548 public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
549 Files.copy(file, dst.resolve(src.relativize(file)), copyOption);
550 return FileVisitResult.CONTINUE;
551 }
552 }
553
tom5f38b3a2014-08-27 23:50:54 -0700554}