• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements.  See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License.  You may obtain a copy of the License at
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 package org.apache.commons.io.file;
19 
20 import java.io.BufferedReader;
21 import java.io.BufferedWriter;
22 import java.io.IOException;
23 import java.io.InputStream;
24 import java.io.OutputStream;
25 import java.io.UncheckedIOException;
26 import java.nio.channels.SeekableByteChannel;
27 import java.nio.charset.Charset;
28 import java.nio.file.CopyOption;
29 import java.nio.file.DirectoryStream;
30 import java.nio.file.FileStore;
31 import java.nio.file.FileVisitOption;
32 import java.nio.file.FileVisitor;
33 import java.nio.file.Files;
34 import java.nio.file.LinkOption;
35 import java.nio.file.OpenOption;
36 import java.nio.file.Path;
37 import java.nio.file.attribute.BasicFileAttributes;
38 import java.nio.file.attribute.FileAttribute;
39 import java.nio.file.attribute.FileTime;
40 import java.nio.file.attribute.PosixFilePermission;
41 import java.nio.file.attribute.UserPrincipal;
42 import java.util.List;
43 import java.util.Map;
44 import java.util.Set;
45 import java.util.stream.Stream;
46 
47 import org.apache.commons.io.function.Uncheck;
48 
49 /**
50  * Delegates to {@link Files} to uncheck calls by throwing {@link UncheckedIOException} instead of {@link IOException}.
51  *
52  * @see Files
53  * @see IOException
54  * @see UncheckedIOException
55  * @since 2.12.0
56  */
57 public class FilesUncheck {
58 
59     /**
60      * Delegates to {@link Files#copy(InputStream, Path,CopyOption...)} throwing {@link UncheckedIOException} instead of
61      * {@link IOException}.
62      *
63      * @param in See delegate.
64      * @param target See delegate.
65      * @param options See delegate.
66      * @return See delegate.
67      * @throws UncheckedIOException Wraps an {@link IOException}.
68      * @see Files#copy(InputStream, Path,CopyOption...)
69      */
copy(final InputStream in, final Path target, final CopyOption... options)70     public static long copy(final InputStream in, final Path target, final CopyOption... options) {
71         return Uncheck.apply(Files::copy, in, target, options);
72     }
73 
74     /**
75      * Delegates to {@link Files#copy(Path, OutputStream)} throwing {@link UncheckedIOException} instead of
76      * {@link IOException}.
77      *
78      * @param source See delegate. See delegate.
79      * @param out See delegate. See delegate.
80      * @return See delegate. See delegate.
81      * @throws UncheckedIOException Wraps an {@link IOException}.
82      */
copy(final Path source, final OutputStream out)83     public static long copy(final Path source, final OutputStream out) {
84         return Uncheck.apply(Files::copy, source, out);
85     }
86 
87     /**
88      * Delegates to {@link Files#copy(Path, Path, CopyOption...)} throwing {@link UncheckedIOException} instead of
89      * {@link IOException}.
90      *
91      * @param source See delegate.
92      * @param target See delegate.
93      * @param options See delegate.
94      * @return See delegate.
95      * @throws UncheckedIOException Wraps an {@link IOException}.
96      */
copy(final Path source, final Path target, final CopyOption... options)97     public static Path copy(final Path source, final Path target, final CopyOption... options) {
98         return Uncheck.apply(Files::copy, source, target, options);
99     }
100 
101     /**
102      * Delegates to {@link Files#createDirectories(Path, FileAttribute...)} throwing {@link UncheckedIOException} instead of
103      * {@link IOException}.
104      *
105      * @param dir See delegate.
106      * @param attrs See delegate.
107      * @return See delegate.
108      * @throws UncheckedIOException Wraps an {@link IOException}.
109      */
createDirectories(final Path dir, final FileAttribute<?>... attrs)110     public static Path createDirectories(final Path dir, final FileAttribute<?>... attrs) {
111         return Uncheck.apply(Files::createDirectories, dir, attrs);
112     }
113 
114     /**
115      * Delegates to {@link Files#createDirectory(Path, FileAttribute...)} throwing {@link UncheckedIOException} instead of
116      * {@link IOException}.
117      *
118      * @param dir See delegate.
119      * @param attrs See delegate.
120      * @return See delegate.
121      * @throws UncheckedIOException Wraps an {@link IOException}.
122      */
createDirectory(final Path dir, final FileAttribute<?>... attrs)123     public static Path createDirectory(final Path dir, final FileAttribute<?>... attrs) {
124         return Uncheck.apply(Files::createDirectory, dir, attrs);
125     }
126 
127     /**
128      * Delegates to {@link Files#createFile(Path, FileAttribute...)} throwing {@link UncheckedIOException} instead of
129      * {@link IOException}.
130      *
131      * @param path See delegate.
132      * @param attrs See delegate.
133      * @return See delegate.
134      * @throws UncheckedIOException Wraps an {@link IOException}.
135      */
createFile(final Path path, final FileAttribute<?>... attrs)136     public static Path createFile(final Path path, final FileAttribute<?>... attrs) {
137         return Uncheck.apply(Files::createFile, path, attrs);
138     }
139 
140     /**
141      * Delegates to {@link Files#createLink(Path, Path)} throwing {@link UncheckedIOException} instead of
142      * {@link IOException}.
143      *
144      * @param link See delegate.
145      * @param existing See delegate.
146      * @return See delegate.
147      * @throws UncheckedIOException Wraps an {@link IOException}.
148      */
createLink(final Path link, final Path existing)149     public static Path createLink(final Path link, final Path existing) {
150         return Uncheck.apply(Files::createLink, link, existing);
151     }
152 
153     /**
154      * Delegates to {@link Files#createSymbolicLink(Path, Path, FileAttribute...)} throwing {@link UncheckedIOException}
155      * instead of {@link IOException}.
156      *
157      * @param link See delegate.
158      * @param target See delegate.
159      * @param attrs See delegate.
160      * @return See delegate.
161      * @throws UncheckedIOException Wraps an {@link IOException}.
162      */
createSymbolicLink(final Path link, final Path target, final FileAttribute<?>... attrs)163     public static Path createSymbolicLink(final Path link, final Path target, final FileAttribute<?>... attrs) {
164         return Uncheck.apply(Files::createSymbolicLink, link, target, attrs);
165     }
166 
167     /**
168      * Delegates to {@link Files#createTempDirectory(Path, String, FileAttribute...)} throwing {@link UncheckedIOException}
169      * instead of {@link IOException}.
170      *
171      * @param dir See delegate.
172      * @param prefix See delegate.
173      * @param attrs See delegate.
174      * @return See delegate.
175      * @throws UncheckedIOException Wraps an {@link IOException}.
176      */
createTempDirectory(final Path dir, final String prefix, final FileAttribute<?>... attrs)177     public static Path createTempDirectory(final Path dir, final String prefix, final FileAttribute<?>... attrs) {
178         return Uncheck.apply(Files::createTempDirectory, dir, prefix, attrs);
179     }
180 
181     /**
182      * Delegates to {@link Files#createTempDirectory(String, FileAttribute...)} throwing {@link UncheckedIOException}
183      * instead of {@link IOException}.
184      *
185      * @param prefix See delegate.
186      * @param attrs See delegate.
187      * @return See delegate.
188      * @throws UncheckedIOException Wraps an {@link IOException}.
189      */
createTempDirectory(final String prefix, final FileAttribute<?>... attrs)190     public static Path createTempDirectory(final String prefix, final FileAttribute<?>... attrs) {
191         return Uncheck.apply(Files::createTempDirectory, prefix, attrs);
192     }
193 
194     /**
195      * Delegates to {@link Files#createTempFile(Path, String, String, FileAttribute...)} throwing
196      * {@link UncheckedIOException} instead of {@link IOException}.
197      *
198      * @param dir See delegate.
199      * @param prefix See delegate.
200      * @param suffix See delegate.
201      * @param attrs See delegate.
202      * @return See delegate.
203      * @throws UncheckedIOException Wraps an {@link IOException}.
204      */
createTempFile(final Path dir, final String prefix, final String suffix, final FileAttribute<?>... attrs)205     public static Path createTempFile(final Path dir, final String prefix, final String suffix, final FileAttribute<?>... attrs) {
206         return Uncheck.apply(Files::createTempFile, dir, prefix, suffix, attrs);
207     }
208 
209     /**
210      * Delegates to {@link Files#createTempFile(String, String, FileAttribute...)} throwing {@link UncheckedIOException}
211      * instead of {@link IOException}.
212      *
213      * @param prefix See delegate.
214      * @param suffix See delegate.
215      * @param attrs See delegate.
216      * @return See delegate.
217      * @throws UncheckedIOException Wraps an {@link IOException}.
218      */
createTempFile(final String prefix, final String suffix, final FileAttribute<?>... attrs)219     public static Path createTempFile(final String prefix, final String suffix, final FileAttribute<?>... attrs) {
220         return Uncheck.apply(Files::createTempFile, prefix, suffix, attrs);
221     }
222 
223     /**
224      * Delegates to {@link Files#delete(Path)} throwing {@link UncheckedIOException} instead of {@link IOException}.
225      *
226      * @param path See delegate.
227      * @throws UncheckedIOException Wraps an {@link IOException}.
228      */
delete(final Path path)229     public static void delete(final Path path) {
230         Uncheck.accept(Files::delete, path);
231     }
232 
233     /**
234      * Delegates to {@link Files#deleteIfExists(Path)} throwing {@link UncheckedIOException} instead of {@link IOException}.
235      *
236      * @param path See delegate.
237      * @return See delegate.
238      * @throws UncheckedIOException Wraps an {@link IOException}.
239      */
deleteIfExists(final Path path)240     public static boolean deleteIfExists(final Path path) {
241         return Uncheck.apply(Files::deleteIfExists, path);
242     }
243 
244     /**
245      * Delegates to {@link Files#getAttribute(Path, String, LinkOption...)} throwing {@link UncheckedIOException} instead of
246      * {@link IOException}.
247      *
248      * @param path See delegate.
249      * @param attribute See delegate.
250      * @param options See delegate.
251      * @return See delegate.
252      * @throws UncheckedIOException Wraps an {@link IOException}.
253      */
getAttribute(final Path path, final String attribute, final LinkOption... options)254     public static Object getAttribute(final Path path, final String attribute, final LinkOption... options) {
255         return Uncheck.apply(Files::getAttribute, path, attribute, options);
256     }
257 
258     /**
259      * Delegates to {@link Files#getFileStore(Path)} throwing {@link UncheckedIOException} instead of {@link IOException}.
260      *
261      * @param path See delegate.
262      * @return See delegate.
263      * @throws UncheckedIOException Wraps an {@link IOException}.
264      */
getFileStore(final Path path)265     public static FileStore getFileStore(final Path path) {
266         return Uncheck.apply(Files::getFileStore, path);
267     }
268 
269     /**
270      * Delegates to {@link Files#getLastModifiedTime(Path, LinkOption...)} throwing {@link UncheckedIOException} instead of
271      * {@link IOException}.
272      *
273      * @param path See delegate.
274      * @param options See delegate.
275      * @return See delegate.
276      * @throws UncheckedIOException Wraps an {@link IOException}.
277      */
getLastModifiedTime(final Path path, final LinkOption... options)278     public static FileTime getLastModifiedTime(final Path path, final LinkOption... options) {
279         return Uncheck.apply(Files::getLastModifiedTime, path, options);
280     }
281 
282     /**
283      * Delegates to {@link Files#getOwner(Path, LinkOption...)} throwing {@link UncheckedIOException} instead of
284      * {@link IOException}.
285      *
286      * @param path See delegate.
287      * @param options See delegate.
288      * @return See delegate.
289      * @throws UncheckedIOException Wraps an {@link IOException}.
290      */
getOwner(final Path path, final LinkOption... options)291     public static UserPrincipal getOwner(final Path path, final LinkOption... options) {
292         return Uncheck.apply(Files::getOwner, path, options);
293     }
294 
295     /**
296      * Delegates to {@link Files#getPosixFilePermissions(Path, LinkOption...)} throwing {@link UncheckedIOException} instead
297      * of {@link IOException}.
298      *
299      * @param path See delegate.
300      * @param options See delegate.
301      * @return See delegate.
302      * @throws UncheckedIOException Wraps an {@link IOException}.
303      */
getPosixFilePermissions(final Path path, final LinkOption... options)304     public static Set<PosixFilePermission> getPosixFilePermissions(final Path path, final LinkOption... options) {
305         return Uncheck.apply(Files::getPosixFilePermissions, path, options);
306     }
307 
308     /**
309      * Delegates to {@link Files#isHidden(Path)} throwing {@link UncheckedIOException} instead of {@link IOException}.
310      *
311      * @param path See delegate.
312      * @return See delegate.
313      * @throws UncheckedIOException Wraps an {@link IOException}.
314      */
isHidden(final Path path)315     public static boolean isHidden(final Path path) {
316         return Uncheck.apply(Files::isHidden, path);
317     }
318 
319     /**
320      * Delegates to {@link Files#isSameFile(Path, Path)} throwing {@link UncheckedIOException} instead of
321      * {@link IOException}.
322      *
323      * @param path See delegate.
324      * @param path2 See delegate.
325      * @return See delegate.
326      * @throws UncheckedIOException Wraps an {@link IOException}.
327      */
isSameFile(final Path path, final Path path2)328     public static boolean isSameFile(final Path path, final Path path2) {
329         return Uncheck.apply(Files::isSameFile, path, path2);
330     }
331 
332     /**
333      * Delegates to {@link Files#lines(Path)} throwing {@link UncheckedIOException} instead of {@link IOException}.
334      *
335      * @param path See delegate.
336      * @return See delegate.
337      * @throws UncheckedIOException Wraps an {@link IOException}.
338      */
lines(final Path path)339     public static Stream<String> lines(final Path path) {
340         return Uncheck.apply(Files::lines, path);
341     }
342 
343     /**
344      * Delegates to {@link Files#lines(Path, Charset)} throwing {@link UncheckedIOException} instead of {@link IOException}.
345      *
346      * @param path See delegate.
347      * @param cs See delegate.
348      * @return See delegate.
349      * @throws UncheckedIOException Wraps an {@link IOException}.
350      */
lines(final Path path, final Charset cs)351     public static Stream<String> lines(final Path path, final Charset cs) {
352         return Uncheck.apply(Files::lines, path, cs);
353     }
354 
355     /**
356      * Delegates to {@link Files#list(Path)} throwing {@link UncheckedIOException} instead of {@link IOException}.
357      *
358      * @param dir See delegate.
359      * @return See delegate.
360      * @throws UncheckedIOException Wraps an {@link IOException}.
361      */
list(final Path dir)362     public static Stream<Path> list(final Path dir) {
363         return Uncheck.apply(Files::list, dir);
364     }
365 
366     /**
367      * Delegates to {@link Files#move(Path, Path, CopyOption...)} throwing {@link UncheckedIOException} instead of
368      * {@link IOException}.
369      *
370      * @param source See delegate.
371      * @param target See delegate.
372      * @param options See delegate.
373      * @return See delegate.
374      * @throws UncheckedIOException Wraps an {@link IOException}.
375      */
move(final Path source, final Path target, final CopyOption... options)376     public static Path move(final Path source, final Path target, final CopyOption... options) {
377         return Uncheck.apply(Files::move, source, target, options);
378     }
379 
380     /**
381      * Delegates to {@link Files#newBufferedReader(Path)} throwing {@link UncheckedIOException} instead of
382      * {@link IOException}.
383      *
384      * @param path See delegate.
385      * @return See delegate.
386      * @throws UncheckedIOException Wraps an {@link IOException}.
387      */
newBufferedReader(final Path path)388     public static BufferedReader newBufferedReader(final Path path) {
389         return Uncheck.apply(Files::newBufferedReader, path);
390     }
391 
392     /**
393      * Delegates to {@link Files#newBufferedReader(Path, Charset)} throwing {@link UncheckedIOException} instead of
394      * {@link IOException}.
395      *
396      * @param path See delegate.
397      * @param cs See delegate.
398      * @return See delegate.
399      * @throws UncheckedIOException Wraps an {@link IOException}.
400      */
newBufferedReader(final Path path, final Charset cs)401     public static BufferedReader newBufferedReader(final Path path, final Charset cs) {
402         return Uncheck.apply(Files::newBufferedReader, path, cs);
403     }
404 
405     /**
406      * Delegates to {@link Files#newBufferedWriter(Path, Charset, OpenOption...)} throwing {@link UncheckedIOException}
407      * instead of {@link IOException}.
408      *
409      * @param path See delegate.
410      * @param cs See delegate.
411      * @param options See delegate.
412      * @return See delegate.
413      * @throws UncheckedIOException Wraps an {@link IOException}.
414      */
newBufferedWriter(final Path path, final Charset cs, final OpenOption... options)415     public static BufferedWriter newBufferedWriter(final Path path, final Charset cs, final OpenOption... options) {
416         return Uncheck.apply(Files::newBufferedWriter, path, cs, options);
417     }
418 
419     /**
420      * Delegates to {@link Files#newBufferedWriter(Path, OpenOption...)} throwing {@link UncheckedIOException} instead of
421      * {@link IOException}.
422      *
423      * @param path See delegate.
424      * @param options See delegate.
425      * @return See delegate.
426      * @throws UncheckedIOException Wraps an {@link IOException}.
427      */
newBufferedWriter(final Path path, final OpenOption... options)428     public static BufferedWriter newBufferedWriter(final Path path, final OpenOption... options) {
429         return Uncheck.apply(Files::newBufferedWriter, path, options);
430     }
431 
432     /**
433      * Delegates to {@link Files#newByteChannel(Path, OpenOption...)} throwing {@link UncheckedIOException} instead of
434      * {@link IOException}.
435      *
436      * @param path See delegate.
437      * @param options See delegate.
438      * @return See delegate.
439      * @throws UncheckedIOException Wraps an {@link IOException}.
440      */
newByteChannel(final Path path, final OpenOption... options)441     public static SeekableByteChannel newByteChannel(final Path path, final OpenOption... options) {
442         return Uncheck.apply(Files::newByteChannel, path, options);
443     }
444 
445     /**
446      * Delegates to {@link Files#newByteChannel(Path, Set, FileAttribute...)} throwing {@link UncheckedIOException} instead
447      * of {@link IOException}.
448      *
449      * @param path See delegate.
450      * @param options See delegate.
451      * @param attrs See delegate.
452      * @return See delegate.
453      * @throws UncheckedIOException Wraps an {@link IOException}.
454      */
newByteChannel(final Path path, final Set<? extends OpenOption> options, final FileAttribute<?>... attrs)455     public static SeekableByteChannel newByteChannel(final Path path, final Set<? extends OpenOption> options, final FileAttribute<?>... attrs) {
456         return Uncheck.apply(Files::newByteChannel, path, options, attrs);
457     }
458 
459     /**
460      * Delegates to {@link Files#newDirectoryStream(Path)} throwing {@link UncheckedIOException} instead of
461      * {@link IOException}.
462      *
463      * @param dir See delegate.
464      * @return See delegate.
465      */
newDirectoryStream(final Path dir)466     public static DirectoryStream<Path> newDirectoryStream(final Path dir) {
467         return Uncheck.apply(Files::newDirectoryStream, dir);
468     }
469 
470     /**
471      * Delegates to {@link Files#newDirectoryStream(Path, java.nio.file.DirectoryStream.Filter)} throwing
472      * {@link UncheckedIOException} instead of {@link IOException}.
473      *
474      * @param dir See delegate.
475      * @param filter See delegate.
476      * @return See delegate.
477      */
newDirectoryStream(final Path dir, final DirectoryStream.Filter<? super Path> filter)478     public static DirectoryStream<Path> newDirectoryStream(final Path dir, final DirectoryStream.Filter<? super Path> filter) {
479         return Uncheck.apply(Files::newDirectoryStream, dir, filter);
480     }
481 
482     /**
483      * Delegates to {@link Files#newDirectoryStream(Path, String)} throwing {@link UncheckedIOException} instead of
484      * {@link IOException}.
485      *
486      * @param dir See delegate.
487      * @param glob See delegate.
488      * @return See delegate.
489      */
newDirectoryStream(final Path dir, final String glob)490     public static DirectoryStream<Path> newDirectoryStream(final Path dir, final String glob) {
491         return Uncheck.apply(Files::newDirectoryStream, dir, glob);
492     }
493 
494     /**
495      * Delegates to {@link Files#newInputStream(Path, OpenOption...)} throwing {@link UncheckedIOException} instead of
496      * {@link IOException}.
497      *
498      * @param path See delegate.
499      * @param options See delegate.
500      * @return See delegate.
501      */
newInputStream(final Path path, final OpenOption... options)502     public static InputStream newInputStream(final Path path, final OpenOption... options) {
503         return Uncheck.apply(Files::newInputStream, path, options);
504     }
505 
506     /**
507      * Delegates to {@link Files#newOutputStream(Path, OpenOption...)} throwing {@link UncheckedIOException} instead of
508      * {@link IOException}.
509      *
510      * @param path See delegate.
511      * @param options See delegate.
512      * @return See delegate.
513      */
newOutputStream(final Path path, final OpenOption... options)514     public static OutputStream newOutputStream(final Path path, final OpenOption... options) {
515         return Uncheck.apply(Files::newOutputStream, path, options);
516     }
517 
518     /**
519      * Delegates to {@link Files#probeContentType(Path)} throwing {@link UncheckedIOException} instead of
520      * {@link IOException}.
521      *
522      * @param path See delegate.
523      * @return See delegate.
524      */
probeContentType(final Path path)525     public static String probeContentType(final Path path) {
526         return Uncheck.apply(Files::probeContentType, path);
527     }
528 
529     /**
530      * Delegates to {@link Files#readAllBytes(Path)} throwing {@link UncheckedIOException} instead of {@link IOException}.
531      *
532      * @param path See delegate.
533      * @return See delegate.
534      */
readAllBytes(final Path path)535     public static byte[] readAllBytes(final Path path) {
536         return Uncheck.apply(Files::readAllBytes, path);
537     }
538 
539     /**
540      * Delegates to {@link Files#readAllLines(Path)} throwing {@link UncheckedIOException} instead of {@link IOException}.
541      *
542      * @param path See delegate.
543      * @return See delegate.
544      */
readAllLines(final Path path)545     public static List<String> readAllLines(final Path path) {
546         return Uncheck.apply(Files::readAllLines, path);
547     }
548 
549     /**
550      * Delegates to {@link Files#readAllLines(Path, Charset)} throwing {@link UncheckedIOException} instead of
551      * {@link IOException}.
552      *
553      * @param path See delegate.
554      * @param cs See delegate.
555      * @return See delegate.
556      */
readAllLines(final Path path, final Charset cs)557     public static List<String> readAllLines(final Path path, final Charset cs) {
558         return Uncheck.apply(Files::readAllLines, path, cs);
559     }
560 
561     /**
562      * Delegates to {@link Files#readAttributes(Path, Class, LinkOption...)} throwing {@link UncheckedIOException} instead
563      * of {@link IOException}.
564      *
565      * @param <A> See delegate.
566      * @param path See delegate.
567      * @param type See delegate.
568      * @param options See delegate.
569      * @return See delegate.
570      */
readAttributes(final Path path, final Class<A> type, final LinkOption... options)571     public static <A extends BasicFileAttributes> A readAttributes(final Path path, final Class<A> type, final LinkOption... options) {
572         return Uncheck.apply(Files::readAttributes, path, type, options);
573     }
574 
575     /**
576      * Delegates to {@link Files#readAttributes(Path, String, LinkOption...)} throwing {@link UncheckedIOException} instead
577      * of {@link IOException}.
578      *
579      * @param path See delegate.
580      * @param attributes See delegate.
581      * @param options See delegate.
582      * @return See delegate.
583      */
readAttributes(final Path path, final String attributes, final LinkOption... options)584     public static Map<String, Object> readAttributes(final Path path, final String attributes, final LinkOption... options) {
585         return Uncheck.apply(Files::readAttributes, path, attributes, options);
586     }
587 
588     /**
589      * Delegates to {@link Files#readSymbolicLink(Path)} throwing {@link UncheckedIOException} instead of
590      * {@link IOException}.
591      *
592      * @param link See delegate.
593      * @return See delegate.
594      */
readSymbolicLink(final Path link)595     public static Path readSymbolicLink(final Path link) {
596         return Uncheck.apply(Files::readSymbolicLink, link);
597     }
598 
599     /**
600      * Delegates to {@link Files#setAttribute(Path, String, Object, LinkOption...)} throwing {@link UncheckedIOException}
601      * instead of {@link IOException}.
602      *
603      * @param path See delegate.
604      * @param attribute See delegate.
605      * @param value See delegate.
606      * @param options See delegate.
607      * @return See delegate.
608      */
setAttribute(final Path path, final String attribute, final Object value, final LinkOption... options)609     public static Path setAttribute(final Path path, final String attribute, final Object value, final LinkOption... options) {
610         return Uncheck.apply(Files::setAttribute, path, attribute, value, options);
611     }
612 
613     /**
614      * Delegates to {@link Files#setLastModifiedTime(Path, FileTime)} throwing {@link UncheckedIOException} instead of
615      * {@link IOException}.
616      *
617      * @param path See delegate.
618      * @param time See delegate.
619      * @return See delegate.
620      */
setLastModifiedTime(final Path path, final FileTime time)621     public static Path setLastModifiedTime(final Path path, final FileTime time) {
622         return Uncheck.apply(Files::setLastModifiedTime, path, time);
623     }
624 
625     /**
626      * Delegates to {@link Files#setOwner(Path, UserPrincipal)} throwing {@link UncheckedIOException} instead of
627      * {@link IOException}.
628      *
629      * @param path See delegate.
630      * @param owner See delegate.
631      * @return See delegate.
632      */
setOwner(final Path path, final UserPrincipal owner)633     public static Path setOwner(final Path path, final UserPrincipal owner) {
634         return Uncheck.apply(Files::setOwner, path, owner);
635     }
636 
637     /**
638      * Delegates to {@link Files#setPosixFilePermissions(Path, Set)} throwing {@link UncheckedIOException} instead of
639      * {@link IOException}.
640      *
641      * @param path See delegate.
642      * @param perms See delegate.
643      * @return See delegate.
644      */
setPosixFilePermissions(final Path path, final Set<PosixFilePermission> perms)645     public static Path setPosixFilePermissions(final Path path, final Set<PosixFilePermission> perms) {
646         return Uncheck.apply(Files::setPosixFilePermissions, path, perms);
647     }
648 
649     /**
650      * Delegates to {@link Files#size(Path)} throwing {@link UncheckedIOException} instead of {@link IOException}.
651      *
652      * @param path See delegate.
653      * @return See delegate.
654      */
size(final Path path)655     public static long size(final Path path) {
656         return Uncheck.apply(Files::size, path);
657     }
658 
659     /**
660      * Delegates to {@link Files#walk(Path, FileVisitOption...)} throwing {@link UncheckedIOException} instead of
661      * {@link IOException}.
662      *
663      * @param start See delegate.
664      * @param options See delegate.
665      * @return See delegate.
666      */
walk(final Path start, final FileVisitOption... options)667     public static Stream<Path> walk(final Path start, final FileVisitOption... options) {
668         return Uncheck.apply(Files::walk, start, options);
669     }
670 
671     /**
672      * Delegates to {@link Files#walk(Path, int, FileVisitOption...)} throwing {@link UncheckedIOException} instead of
673      * {@link IOException}.
674      *
675      * @param start See delegate.
676      * @param maxDepth See delegate.
677      * @param options See delegate.
678      * @return See delegate.
679      */
walk(final Path start, final int maxDepth, final FileVisitOption... options)680     public static Stream<Path> walk(final Path start, final int maxDepth, final FileVisitOption... options) {
681         return Uncheck.apply(Files::walk, start, maxDepth, options);
682     }
683 
684     /**
685      * Delegates to {@link Files#walkFileTree(Path, FileVisitor)} throwing {@link UncheckedIOException} instead of
686      * {@link IOException}.
687      *
688      * @param start See delegate.
689      * @param visitor See delegate.
690      * @return See delegate.
691      */
walkFileTree(final Path start, final FileVisitor<? super Path> visitor)692     public static Path walkFileTree(final Path start, final FileVisitor<? super Path> visitor) {
693         return Uncheck.apply(Files::walkFileTree, start, visitor);
694     }
695 
696     /**
697      * Delegates to {@link Files#walkFileTree(Path, Set, int, FileVisitor)} throwing {@link UncheckedIOException} instead of
698      * {@link IOException}.
699      *
700      * @param start See delegate.
701      * @param options See delegate.
702      * @param maxDepth See delegate.
703      * @param visitor See delegate.
704      * @return See delegate.
705      */
walkFileTree(final Path start, final Set<FileVisitOption> options, final int maxDepth, final FileVisitor<? super Path> visitor)706     public static Path walkFileTree(final Path start, final Set<FileVisitOption> options, final int maxDepth, final FileVisitor<? super Path> visitor) {
707         return Uncheck.apply(Files::walkFileTree, start, options, maxDepth, visitor);
708     }
709 
710     /**
711      * Delegates to {@link Files#write(Path, byte[], OpenOption...)} throwing {@link UncheckedIOException} instead of
712      * {@link IOException}.
713      *
714      * @param path See delegate.
715      * @param bytes See delegate.
716      * @param options See delegate.
717      * @return See delegate.
718      */
write(final Path path, final byte[] bytes, final OpenOption... options)719     public static Path write(final Path path, final byte[] bytes, final OpenOption... options) {
720         return Uncheck.apply(Files::write, path, bytes, options);
721     }
722 
723     /**
724      * Delegates to {@link Files#write(Path, Iterable, Charset, OpenOption...)} throwing {@link UncheckedIOException}
725      * instead of {@link IOException}.
726      *
727      * @param path See delegate.
728      * @param lines See delegate.
729      * @param cs See delegate.
730      * @param options See delegate.
731      * @return See delegate.
732      */
write(final Path path, final Iterable<? extends CharSequence> lines, final Charset cs, final OpenOption... options)733     public static Path write(final Path path, final Iterable<? extends CharSequence> lines, final Charset cs, final OpenOption... options) {
734         return Uncheck.apply(Files::write, path, lines, cs, options);
735     }
736 
737     /**
738      * Delegates to {@link Files#write(Path, Iterable, OpenOption...)} throwing {@link UncheckedIOException} instead of
739      * {@link IOException}.
740      *
741      * @param path See delegate.
742      * @param lines See delegate.
743      * @param options See delegate.
744      * @return See delegate.
745      */
write(final Path path, final Iterable<? extends CharSequence> lines, final OpenOption... options)746     public static Path write(final Path path, final Iterable<? extends CharSequence> lines, final OpenOption... options) {
747         return Uncheck.apply(Files::write, path, lines, options);
748     }
749 
750     /**
751      * No instances.
752      */
FilesUncheck()753     private FilesUncheck() {
754         // No instances
755     }
756 }
757