    001/*
    002 * Licensed to the Apache Software Foundation (ASF) under one or more
    003 * contributor license agreements.  See the NOTICE file distributed with
    004 * this work for additional information regarding copyright ownership.
    005 * The ASF licenses this file to You under the Apache License, Version 2.0
    006 * (the "License"); you may not use this file except in compliance with
    007 * the License.  You may obtain a copy of the License at
    008 *
    009 *      http://www.apache.org/licenses/LICENSE-2.0
    010 *
    011 * Unless required by applicable law or agreed to in writing, software
    012 * distributed under the License is distributed on an "AS IS" BASIS,
    013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    014 * See the License for the specific language governing permissions and
    015 * limitations under the License.
    016 */
    017
    018package org.apache.commons.io.file;
    019
    020import java.io.BufferedReader;
    021import java.io.BufferedWriter;
    022import java.io.IOException;
    023import java.io.InputStream;
    024import java.io.OutputStream;
    025import java.io.UncheckedIOException;
    026import java.nio.channels.SeekableByteChannel;
    027import java.nio.charset.Charset;
    028import java.nio.file.CopyOption;
    029import java.nio.file.DirectoryStream;
    030import java.nio.file.FileStore;
    031import java.nio.file.FileVisitOption;
    032import java.nio.file.FileVisitor;
    033import java.nio.file.Files;
    034import java.nio.file.LinkOption;
    035import java.nio.file.OpenOption;
    036import java.nio.file.Path;
    037import java.nio.file.attribute.BasicFileAttributes;
    038import java.nio.file.attribute.FileAttribute;
    039import java.nio.file.attribute.FileTime;
    040import java.nio.file.attribute.PosixFilePermission;
    041import java.nio.file.attribute.UserPrincipal;
    042import java.util.List;
    043import java.util.Map;
    044import java.util.Set;
    045import java.util.stream.Stream;
    046
    047import org.apache.commons.io.function.Uncheck;
    048
    049/**
    050 * Delegates to {@link Files} to uncheck calls by throwing {@link UncheckedIOException} instead of {@link IOException}.
    051 *
    052 * @see Files
    053 * @see IOException
    054 * @see UncheckedIOException
    055 * @since 2.12.0
    056 */
    057public final class FilesUncheck {
    058
    059    /**
    060     * Delegates to {@link Files#copy(InputStream, Path, CopyOption...)} throwing {@link UncheckedIOException} instead of
    061     * {@link IOException}.
    062     *
    063     * @param in See delegate.
    064     * @param target See delegate.
    065     * @param options See delegate.
    066     * @return See delegate.
    067     * @throws UncheckedIOException Wraps an {@link IOException}.
    068     * @see Files#copy(InputStream, Path,CopyOption...)
    069     */
    070    public static long copy(final InputStream in, final Path target, final CopyOption... options) {
    071        return Uncheck.apply(Files::copy, in, target, options);
    072    }
    073
    074    /**
    075     * Delegates to {@link Files#copy(Path, OutputStream)} throwing {@link UncheckedIOException} instead of
    076     * {@link IOException}.
    077     *
    078     * @param source See delegate. See delegate.
    079     * @param out See delegate. See delegate.
    080     * @return See delegate. See delegate.
    081     * @throws UncheckedIOException Wraps an {@link IOException}.
    082     */
    083    public static long copy(final Path source, final OutputStream out) {
    084        return Uncheck.apply(Files::copy, source, out);
    085    }
    086
    087    /**
    088     * Delegates to {@link Files#copy(Path, Path, CopyOption...)} throwing {@link UncheckedIOException} instead of
    089     * {@link IOException}.
    090     *
    091     * @param source See delegate.
    092     * @param target See delegate.
    093     * @param options See delegate.
    094     * @return See delegate.
    095     * @throws UncheckedIOException Wraps an {@link IOException}.
    096     */
    097    public static Path copy(final Path source, final Path target, final CopyOption... options) {
    098        return Uncheck.apply(Files::copy, source, target, options);
    099    }
    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     */
    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     */
    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     */
    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     */
    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     */
    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     */
    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     */
    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     */
    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     */
    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     */
    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     */
    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     */
    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     */
    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     */
    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     */
    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     */
    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     */
    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     */
    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     */
    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     */
    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     */
    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     */
    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     */
    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     */
    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     */
    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     */
    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     */
    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     */
    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     */
    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     */
    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     */
    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     */
    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     */
    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     */
    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     */
    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     */
    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     */
    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     */
    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     */
    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     */
    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     */
    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     */
    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     */
    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     */
    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     */
    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     */
    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     */
    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     */
    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     */
    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     */
    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     */
    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     */
    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     */
    753    private FilesUncheck() {
    754        // No instances
    755    }
    756}