FilesUncheck.java

  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. package org.apache.commons.io.file;

  18. import java.io.BufferedReader;
  19. import java.io.BufferedWriter;
  20. import java.io.IOException;
  21. import java.io.InputStream;
  22. import java.io.OutputStream;
  23. import java.io.Reader;
  24. import java.io.UncheckedIOException;
  25. import java.nio.channels.SeekableByteChannel;
  26. import java.nio.charset.Charset;
  27. import java.nio.file.CopyOption;
  28. import java.nio.file.DirectoryStream;
  29. import java.nio.file.FileStore;
  30. import java.nio.file.FileVisitOption;
  31. import java.nio.file.FileVisitor;
  32. import java.nio.file.Files;
  33. import java.nio.file.LinkOption;
  34. import java.nio.file.OpenOption;
  35. import java.nio.file.Path;
  36. import java.nio.file.attribute.BasicFileAttributes;
  37. import java.nio.file.attribute.FileAttribute;
  38. import java.nio.file.attribute.FileTime;
  39. import java.nio.file.attribute.PosixFilePermission;
  40. import java.nio.file.attribute.UserPrincipal;
  41. import java.util.List;
  42. import java.util.Map;
  43. import java.util.Set;
  44. import java.util.function.BiPredicate;
  45. import java.util.stream.Stream;

  46. import org.apache.commons.io.function.Uncheck;

  47. /**
  48.  * Delegates to {@link Files} to uncheck calls by throwing {@link UncheckedIOException} instead of {@link IOException}.
  49.  *
  50.  * @see Files
  51.  * @see IOException
  52.  * @see UncheckedIOException
  53.  * @since 2.12.0
  54.  */
  55. public final class FilesUncheck {

  56.     /**
  57.      * Delegates to {@link Files#copy(InputStream, Path, CopyOption...)} throwing {@link UncheckedIOException} instead of
  58.      * {@link IOException}.
  59.      *
  60.      * @param in See delegate.
  61.      * @param target See delegate.
  62.      * @param options See delegate.
  63.      * @return See delegate.
  64.      * @throws UncheckedIOException Wraps an {@link IOException}.
  65.      * @see Files#copy(InputStream, Path,CopyOption...)
  66.      */
  67.     public static long copy(final InputStream in, final Path target, final CopyOption... options) {
  68.         return Uncheck.apply(Files::copy, in, target, options);
  69.     }

  70.     /**
  71.      * Delegates to {@link Files#copy(Path, OutputStream)} throwing {@link UncheckedIOException} instead of
  72.      * {@link IOException}.
  73.      *
  74.      * @param source See delegate. See delegate.
  75.      * @param out See delegate. See delegate.
  76.      * @return See delegate. See delegate.
  77.      * @throws UncheckedIOException Wraps an {@link IOException}.
  78.      */
  79.     public static long copy(final Path source, final OutputStream out) {
  80.         return Uncheck.apply(Files::copy, source, out);
  81.     }

  82.     /**
  83.      * Delegates to {@link Files#copy(Path, Path, CopyOption...)} throwing {@link UncheckedIOException} instead of
  84.      * {@link IOException}.
  85.      *
  86.      * @param source See delegate.
  87.      * @param target See delegate.
  88.      * @param options See delegate.
  89.      * @return See delegate.
  90.      * @throws UncheckedIOException Wraps an {@link IOException}.
  91.      */
  92.     public static Path copy(final Path source, final Path target, final CopyOption... options) {
  93.         return Uncheck.apply(Files::copy, source, target, options);
  94.     }

  95.     /**
  96.      * Delegates to {@link Files#createDirectories(Path, FileAttribute...)} throwing {@link UncheckedIOException} instead of
  97.      * {@link IOException}.
  98.      *
  99.      * @param dir See delegate.
  100.      * @param attrs See delegate.
  101.      * @return See delegate.
  102.      * @throws UncheckedIOException Wraps an {@link IOException}.
  103.      */
  104.     public static Path createDirectories(final Path dir, final FileAttribute<?>... attrs) {
  105.         return Uncheck.apply(Files::createDirectories, dir, attrs);
  106.     }

  107.     /**
  108.      * Delegates to {@link Files#createDirectory(Path, FileAttribute...)} throwing {@link UncheckedIOException} instead of
  109.      * {@link IOException}.
  110.      *
  111.      * @param dir See delegate.
  112.      * @param attrs See delegate.
  113.      * @return See delegate.
  114.      * @throws UncheckedIOException Wraps an {@link IOException}.
  115.      */
  116.     public static Path createDirectory(final Path dir, final FileAttribute<?>... attrs) {
  117.         return Uncheck.apply(Files::createDirectory, dir, attrs);
  118.     }

  119.     /**
  120.      * Delegates to {@link Files#createFile(Path, FileAttribute...)} throwing {@link UncheckedIOException} instead of
  121.      * {@link IOException}.
  122.      *
  123.      * @param path See delegate.
  124.      * @param attrs See delegate.
  125.      * @return See delegate.
  126.      * @throws UncheckedIOException Wraps an {@link IOException}.
  127.      */
  128.     public static Path createFile(final Path path, final FileAttribute<?>... attrs) {
  129.         return Uncheck.apply(Files::createFile, path, attrs);
  130.     }

  131.     /**
  132.      * Delegates to {@link Files#createLink(Path, Path)} throwing {@link UncheckedIOException} instead of
  133.      * {@link IOException}.
  134.      *
  135.      * @param link See delegate.
  136.      * @param existing See delegate.
  137.      * @return See delegate.
  138.      * @throws UncheckedIOException Wraps an {@link IOException}.
  139.      */
  140.     public static Path createLink(final Path link, final Path existing) {
  141.         return Uncheck.apply(Files::createLink, link, existing);
  142.     }

  143.     /**
  144.      * Delegates to {@link Files#createSymbolicLink(Path, Path, FileAttribute...)} throwing {@link UncheckedIOException}
  145.      * instead of {@link IOException}.
  146.      *
  147.      * @param link See delegate.
  148.      * @param target See delegate.
  149.      * @param attrs See delegate.
  150.      * @return See delegate.
  151.      * @throws UncheckedIOException Wraps an {@link IOException}.
  152.      */
  153.     public static Path createSymbolicLink(final Path link, final Path target, final FileAttribute<?>... attrs) {
  154.         return Uncheck.apply(Files::createSymbolicLink, link, target, attrs);
  155.     }

  156.     /**
  157.      * Delegates to {@link Files#createTempDirectory(Path, String, FileAttribute...)} throwing {@link UncheckedIOException}
  158.      * instead of {@link IOException}.
  159.      *
  160.      * @param dir See delegate.
  161.      * @param prefix See delegate.
  162.      * @param attrs See delegate.
  163.      * @return See delegate.
  164.      * @throws UncheckedIOException Wraps an {@link IOException}.
  165.      */
  166.     public static Path createTempDirectory(final Path dir, final String prefix, final FileAttribute<?>... attrs) {
  167.         return Uncheck.apply(Files::createTempDirectory, dir, prefix, attrs);
  168.     }

  169.     /**
  170.      * Delegates to {@link Files#createTempDirectory(String, FileAttribute...)} throwing {@link UncheckedIOException}
  171.      * instead of {@link IOException}.
  172.      *
  173.      * @param prefix See delegate.
  174.      * @param attrs See delegate.
  175.      * @return See delegate.
  176.      * @throws UncheckedIOException Wraps an {@link IOException}.
  177.      */
  178.     public static Path createTempDirectory(final String prefix, final FileAttribute<?>... attrs) {
  179.         return Uncheck.apply(Files::createTempDirectory, prefix, attrs);
  180.     }

  181.     /**
  182.      * Delegates to {@link Files#createTempFile(Path, String, String, FileAttribute...)} throwing
  183.      * {@link UncheckedIOException} instead of {@link IOException}.
  184.      *
  185.      * @param dir See delegate.
  186.      * @param prefix See delegate.
  187.      * @param suffix See delegate.
  188.      * @param attrs See delegate.
  189.      * @return See delegate.
  190.      * @throws UncheckedIOException Wraps an {@link IOException}.
  191.      */
  192.     public static Path createTempFile(final Path dir, final String prefix, final String suffix, final FileAttribute<?>... attrs) {
  193.         return Uncheck.apply(Files::createTempFile, dir, prefix, suffix, attrs);
  194.     }

  195.     /**
  196.      * Delegates to {@link Files#createTempFile(String, String, FileAttribute...)} throwing {@link UncheckedIOException}
  197.      * instead of {@link IOException}.
  198.      *
  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 String prefix, final String suffix, final FileAttribute<?>... attrs) {
  206.         return Uncheck.apply(Files::createTempFile, prefix, suffix, attrs);
  207.     }

  208.     /**
  209.      * Delegates to {@link Files#delete(Path)} throwing {@link UncheckedIOException} instead of {@link IOException}.
  210.      *
  211.      * @param path See delegate.
  212.      * @throws UncheckedIOException Wraps an {@link IOException}.
  213.      */
  214.     public static void delete(final Path path) {
  215.         Uncheck.accept(Files::delete, path);
  216.     }

  217.     /**
  218.      * Delegates to {@link Files#deleteIfExists(Path)} throwing {@link UncheckedIOException} instead of {@link IOException}.
  219.      *
  220.      * @param path See delegate.
  221.      * @return See delegate.
  222.      * @throws UncheckedIOException Wraps an {@link IOException}.
  223.      */
  224.     public static boolean deleteIfExists(final Path path) {
  225.         return Uncheck.apply(Files::deleteIfExists, path);
  226.     }

  227.     /**
  228.      * Delegates to {@link Files#find(Path, int, BiPredicate, FileVisitOption...)} throwing {@link UncheckedIOException} instead of {@link IOException}.
  229.      * <p>
  230.      * The returned {@link Stream} wraps a {@link DirectoryStream}. When you require timely disposal of file system resources, use a {@code try}-with-resources
  231.      * block to ensure invocation of the stream's {@link Stream#close()} method after the stream operations are completed.
  232.      * </p>
  233.      *
  234.      * @param start    See delegate.
  235.      * @param maxDepth See delegate.
  236.      * @param matcher  See delegate.
  237.      * @param options  See delegate.
  238.      * @return See delegate.
  239.      * @throws UncheckedIOException Wraps an {@link IOException}.
  240.      * @since 2.14.0
  241.      */
  242.     public static Stream<Path> find(final Path start, final int maxDepth, final BiPredicate<Path, BasicFileAttributes> matcher,
  243.             final FileVisitOption... options) {
  244.         return Uncheck.apply(Files::find, start, maxDepth, matcher, options);
  245.     }

  246.     /**
  247.      * Delegates to {@link Files#getAttribute(Path, String, LinkOption...)} throwing {@link UncheckedIOException} instead of
  248.      * {@link IOException}.
  249.      *
  250.      * @param path See delegate.
  251.      * @param attribute See delegate.
  252.      * @param options See delegate.
  253.      * @return See delegate.
  254.      * @throws UncheckedIOException Wraps an {@link IOException}.
  255.      */
  256.     public static Object getAttribute(final Path path, final String attribute, final LinkOption... options) {
  257.         return Uncheck.apply(Files::getAttribute, path, attribute, options);
  258.     }

  259.     /**
  260.      * Delegates to {@link Files#getFileStore(Path)} throwing {@link UncheckedIOException} instead of {@link IOException}.
  261.      *
  262.      * @param path See delegate.
  263.      * @return See delegate.
  264.      * @throws UncheckedIOException Wraps an {@link IOException}.
  265.      */
  266.     public static FileStore getFileStore(final Path path) {
  267.         return Uncheck.apply(Files::getFileStore, path);
  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.      * Delegates to {@link Files#getOwner(Path, LinkOption...)} throwing {@link UncheckedIOException} instead of
  283.      * {@link IOException}.
  284.      *
  285.      * @param path See delegate.
  286.      * @param options See delegate.
  287.      * @return See delegate.
  288.      * @throws UncheckedIOException Wraps an {@link IOException}.
  289.      */
  290.     public static UserPrincipal getOwner(final Path path, final LinkOption... options) {
  291.         return Uncheck.apply(Files::getOwner, path, options);
  292.     }

  293.     /**
  294.      * Delegates to {@link Files#getPosixFilePermissions(Path, LinkOption...)} throwing {@link UncheckedIOException} instead
  295.      * of {@link IOException}.
  296.      *
  297.      * @param path See delegate.
  298.      * @param options See delegate.
  299.      * @return See delegate.
  300.      * @throws UncheckedIOException Wraps an {@link IOException}.
  301.      */
  302.     public static Set<PosixFilePermission> getPosixFilePermissions(final Path path, final LinkOption... options) {
  303.         return Uncheck.apply(Files::getPosixFilePermissions, path, options);
  304.     }

  305.     /**
  306.      * Delegates to {@link Files#isHidden(Path)} throwing {@link UncheckedIOException} instead of {@link IOException}.
  307.      *
  308.      * @param path See delegate.
  309.      * @return See delegate.
  310.      * @throws UncheckedIOException Wraps an {@link IOException}.
  311.      */
  312.     public static boolean isHidden(final Path path) {
  313.         return Uncheck.apply(Files::isHidden, path);
  314.     }

  315.     /**
  316.      * Delegates to {@link Files#isSameFile(Path, Path)} throwing {@link UncheckedIOException} instead of
  317.      * {@link IOException}.
  318.      *
  319.      * @param path See delegate.
  320.      * @param path2 See delegate.
  321.      * @return See delegate.
  322.      * @throws UncheckedIOException Wraps an {@link IOException}.
  323.      */
  324.     public static boolean isSameFile(final Path path, final Path path2) {
  325.         return Uncheck.apply(Files::isSameFile, path, path2);
  326.     }

  327.     /**
  328.      * Delegates to {@link Files#lines(Path)} throwing {@link UncheckedIOException} instead of {@link IOException}.
  329.      * <p>
  330.      * The returned {@link Stream} wraps a {@link Reader}. When you require timely disposal of file system resources, use a {@code try}-with-resources block to
  331.      * ensure invocation of the stream's {@link Stream#close()} method after the stream operations are completed.
  332.      * </p>
  333.      *
  334.      * @param path See delegate.
  335.      * @return See delegate.
  336.      * @throws UncheckedIOException Wraps an {@link IOException}.
  337.      */
  338.     public static Stream<String> lines(final Path path) {
  339.         return Uncheck.apply(Files::lines, path);
  340.     }

  341.     /**
  342.      * Delegates to {@link Files#lines(Path, Charset)} throwing {@link UncheckedIOException} instead of {@link IOException}.
  343.      * <p>
  344.      * The returned {@link Stream} wraps a {@link Reader}. When you require timely disposal of file system resources, use a {@code try}-with-resources block to
  345.      * ensure invocation of the stream's {@link Stream#close()} method after the stream operations are completed.
  346.      * </p>
  347.      *
  348.      * @param path See delegate.
  349.      * @param cs See delegate.
  350.      * @return See delegate.
  351.      * @throws UncheckedIOException Wraps an {@link IOException}.
  352.      */
  353.     public static Stream<String> lines(final Path path, final Charset cs) {
  354.         return Uncheck.apply(Files::lines, path, cs);
  355.     }

  356.     /**
  357.      * Delegates to {@link Files#list(Path)} throwing {@link UncheckedIOException} instead of {@link IOException}.
  358.      * <p>
  359.      * The returned {@link Stream} wraps a {@link DirectoryStream}. When you require timely disposal of file system resources, use a {@code try}-with-resources
  360.      * block to ensure invocation of the stream's {@link Stream#close()} method after the stream operations are completed.
  361.      * </p>
  362.      *
  363.      * @param dir See delegate.
  364.      * @return See delegate.
  365.      * @throws UncheckedIOException Wraps an {@link IOException}.
  366.      */
  367.     public static Stream<Path> list(final Path dir) {
  368.         return Uncheck.apply(Files::list, dir);
  369.     }

  370.     /**
  371.      * Delegates to {@link Files#move(Path, Path, CopyOption...)} throwing {@link UncheckedIOException} instead of
  372.      * {@link IOException}.
  373.      *
  374.      * @param source See delegate.
  375.      * @param target See delegate.
  376.      * @param options See delegate.
  377.      * @return See delegate.
  378.      * @throws UncheckedIOException Wraps an {@link IOException}.
  379.      */
  380.     public static Path move(final Path source, final Path target, final CopyOption... options) {
  381.         return Uncheck.apply(Files::move, source, target, options);
  382.     }

  383.     /**
  384.      * Delegates to {@link Files#newBufferedReader(Path)} throwing {@link UncheckedIOException} instead of
  385.      * {@link IOException}.
  386.      *
  387.      * @param path See delegate.
  388.      * @return See delegate.
  389.      * @throws UncheckedIOException Wraps an {@link IOException}.
  390.      */
  391.     public static BufferedReader newBufferedReader(final Path path) {
  392.         return Uncheck.apply(Files::newBufferedReader, path);
  393.     }

  394.     /**
  395.      * Delegates to {@link Files#newBufferedReader(Path, Charset)} throwing {@link UncheckedIOException} instead of
  396.      * {@link IOException}.
  397.      *
  398.      * @param path See delegate.
  399.      * @param cs See delegate.
  400.      * @return See delegate.
  401.      * @throws UncheckedIOException Wraps an {@link IOException}.
  402.      */
  403.     public static BufferedReader newBufferedReader(final Path path, final Charset cs) {
  404.         return Uncheck.apply(Files::newBufferedReader, path, cs);
  405.     }

  406.     /**
  407.      * Delegates to {@link Files#newBufferedWriter(Path, Charset, OpenOption...)} throwing {@link UncheckedIOException}
  408.      * instead of {@link IOException}.
  409.      *
  410.      * @param path See delegate.
  411.      * @param cs See delegate.
  412.      * @param options See delegate.
  413.      * @return See delegate.
  414.      * @throws UncheckedIOException Wraps an {@link IOException}.
  415.      */
  416.     public static BufferedWriter newBufferedWriter(final Path path, final Charset cs, final OpenOption... options) {
  417.         return Uncheck.apply(Files::newBufferedWriter, path, cs, options);
  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.      * Delegates to {@link Files#newByteChannel(Path, OpenOption...)} throwing {@link UncheckedIOException} instead of
  433.      * {@link IOException}.
  434.      *
  435.      * @param path See delegate.
  436.      * @param options See delegate.
  437.      * @return See delegate.
  438.      * @throws UncheckedIOException Wraps an {@link IOException}.
  439.      */
  440.     public static SeekableByteChannel newByteChannel(final Path path, final OpenOption... options) {
  441.         return Uncheck.apply(Files::newByteChannel, path, options);
  442.     }

  443.     /**
  444.      * Delegates to {@link Files#newByteChannel(Path, Set, FileAttribute...)} throwing {@link UncheckedIOException} instead
  445.      * of {@link IOException}.
  446.      *
  447.      * @param path See delegate.
  448.      * @param options See delegate.
  449.      * @param attrs See delegate.
  450.      * @return See delegate.
  451.      * @throws UncheckedIOException Wraps an {@link IOException}.
  452.      */
  453.     public static SeekableByteChannel newByteChannel(final Path path, final Set<? extends OpenOption> options, final FileAttribute<?>... attrs) {
  454.         return Uncheck.apply(Files::newByteChannel, path, options, attrs);
  455.     }

  456.     /**
  457.      * Delegates to {@link Files#newDirectoryStream(Path)} throwing {@link UncheckedIOException} instead of {@link IOException}.
  458.      * <p>
  459.      * If you don't use the try-with-resources construct, then you must call the stream's {@link Stream#close()} method after iteration is complete to free any
  460.      * resources held for the open directory.
  461.      * </p>
  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.      * Delegates to {@link Files#newDirectoryStream(Path, java.nio.file.DirectoryStream.Filter)} throwing {@link UncheckedIOException} instead of
  471.      * {@link IOException}.
  472.      * <p>
  473.      * If you don't use the try-with-resources construct, then you must call the stream's {@link Stream#close()} method after iteration is complete to free any
  474.      * resources held for the open directory.
  475.      * </p>
  476.      *
  477.      * @param dir    See delegate.
  478.      * @param filter See delegate.
  479.      * @return See delegate.
  480.      */
  481.     public static DirectoryStream<Path> newDirectoryStream(final Path dir, final DirectoryStream.Filter<? super Path> filter) {
  482.         return Uncheck.apply(Files::newDirectoryStream, dir, filter);
  483.     }

  484.     /**
  485.      * Delegates to {@link Files#newDirectoryStream(Path, String)} throwing {@link UncheckedIOException} instead of
  486.      * {@link IOException}.
  487.      * <p>
  488.      * The returned {@link Stream} wraps a {@link DirectoryStream}. When you require timely disposal of file system resources, use a {@code try}-with-resources
  489.      * block to ensure invocation of the stream's {@link Stream#close()} method after the stream operations are completed.
  490.      * </p>
  491.      *
  492.      * @param dir See delegate.
  493.      * @param glob See delegate.
  494.      * @return See delegate.
  495.      */
  496.     public static DirectoryStream<Path> newDirectoryStream(final Path dir, final String glob) {
  497.         return Uncheck.apply(Files::newDirectoryStream, dir, glob);
  498.     }

  499.     /**
  500.      * Delegates to {@link Files#newInputStream(Path, OpenOption...)} throwing {@link UncheckedIOException} instead of
  501.      * {@link IOException}.
  502.      *
  503.      * @param path See delegate.
  504.      * @param options See delegate.
  505.      * @return See delegate.
  506.      */
  507.     public static InputStream newInputStream(final Path path, final OpenOption... options) {
  508.         return Uncheck.apply(Files::newInputStream, path, options);
  509.     }

  510.     /**
  511.      * Delegates to {@link Files#newOutputStream(Path, OpenOption...)} throwing {@link UncheckedIOException} instead of
  512.      * {@link IOException}.
  513.      *
  514.      * @param path See delegate.
  515.      * @param options See delegate.
  516.      * @return See delegate.
  517.      */
  518.     public static OutputStream newOutputStream(final Path path, final OpenOption... options) {
  519.         return Uncheck.apply(Files::newOutputStream, path, options);
  520.     }

  521.     /**
  522.      * Delegates to {@link Files#probeContentType(Path)} throwing {@link UncheckedIOException} instead of
  523.      * {@link IOException}.
  524.      *
  525.      * @param path See delegate.
  526.      * @return See delegate.
  527.      */
  528.     public static String probeContentType(final Path path) {
  529.         return Uncheck.apply(Files::probeContentType, path);
  530.     }

  531.     /**
  532.      * Delegates to {@link Files#readAllBytes(Path)} throwing {@link UncheckedIOException} instead of {@link IOException}.
  533.      *
  534.      * @param path See delegate.
  535.      * @return See delegate.
  536.      */
  537.     public static byte[] readAllBytes(final Path path) {
  538.         return Uncheck.apply(Files::readAllBytes, path);
  539.     }

  540.     /**
  541.      * Delegates to {@link Files#readAllLines(Path)} throwing {@link UncheckedIOException} instead of {@link IOException}.
  542.      *
  543.      * @param path See delegate.
  544.      * @return See delegate.
  545.      */
  546.     public static List<String> readAllLines(final Path path) {
  547.         return Uncheck.apply(Files::readAllLines, path);
  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.      * Delegates to {@link Files#readAttributes(Path, Class, LinkOption...)} throwing {@link UncheckedIOException} instead
  562.      * of {@link IOException}.
  563.      *
  564.      * @param <A> See delegate.
  565.      * @param path See delegate.
  566.      * @param type See delegate.
  567.      * @param options See delegate.
  568.      * @return See delegate.
  569.      */
  570.     public static <A extends BasicFileAttributes> A readAttributes(final Path path, final Class<A> type, final LinkOption... options) {
  571.         return Uncheck.apply(Files::readAttributes, path, type, options);
  572.     }

  573.     /**
  574.      * Delegates to {@link Files#readAttributes(Path, String, LinkOption...)} throwing {@link UncheckedIOException} instead
  575.      * of {@link IOException}.
  576.      *
  577.      * @param path See delegate.
  578.      * @param attributes See delegate.
  579.      * @param options See delegate.
  580.      * @return See delegate.
  581.      */
  582.     public static Map<String, Object> readAttributes(final Path path, final String attributes, final LinkOption... options) {
  583.         return Uncheck.apply(Files::readAttributes, path, attributes, options);
  584.     }

  585.     /**
  586.      * Delegates to {@link Files#readSymbolicLink(Path)} throwing {@link UncheckedIOException} instead of
  587.      * {@link IOException}.
  588.      *
  589.      * @param link See delegate.
  590.      * @return See delegate.
  591.      */
  592.     public static Path readSymbolicLink(final Path link) {
  593.         return Uncheck.apply(Files::readSymbolicLink, link);
  594.     }

  595.     /**
  596.      * Delegates to {@link Files#setAttribute(Path, String, Object, LinkOption...)} throwing {@link UncheckedIOException}
  597.      * instead of {@link IOException}.
  598.      *
  599.      * @param path See delegate.
  600.      * @param attribute See delegate.
  601.      * @param value See delegate.
  602.      * @param options See delegate.
  603.      * @return See delegate.
  604.      */
  605.     public static Path setAttribute(final Path path, final String attribute, final Object value, final LinkOption... options) {
  606.         return Uncheck.apply(Files::setAttribute, path, attribute, value, options);
  607.     }

  608.     /**
  609.      * Delegates to {@link Files#setLastModifiedTime(Path, FileTime)} throwing {@link UncheckedIOException} instead of
  610.      * {@link IOException}.
  611.      *
  612.      * @param path See delegate.
  613.      * @param time See delegate.
  614.      * @return See delegate.
  615.      */
  616.     public static Path setLastModifiedTime(final Path path, final FileTime time) {
  617.         return Uncheck.apply(Files::setLastModifiedTime, path, time);
  618.     }

  619.     /**
  620.      * Delegates to {@link Files#setOwner(Path, UserPrincipal)} throwing {@link UncheckedIOException} instead of
  621.      * {@link IOException}.
  622.      *
  623.      * @param path See delegate.
  624.      * @param owner See delegate.
  625.      * @return See delegate.
  626.      */
  627.     public static Path setOwner(final Path path, final UserPrincipal owner) {
  628.         return Uncheck.apply(Files::setOwner, path, owner);
  629.     }

  630.     /**
  631.      * Delegates to {@link Files#setPosixFilePermissions(Path, Set)} throwing {@link UncheckedIOException} instead of
  632.      * {@link IOException}.
  633.      *
  634.      * @param path See delegate.
  635.      * @param perms See delegate.
  636.      * @return See delegate.
  637.      */
  638.     public static Path setPosixFilePermissions(final Path path, final Set<PosixFilePermission> perms) {
  639.         return Uncheck.apply(Files::setPosixFilePermissions, path, perms);
  640.     }

  641.     /**
  642.      * Delegates to {@link Files#size(Path)} throwing {@link UncheckedIOException} instead of {@link IOException}.
  643.      *
  644.      * @param path See delegate.
  645.      * @return See delegate.
  646.      */
  647.     public static long size(final Path path) {
  648.         return Uncheck.apply(Files::size, path);
  649.     }

  650.     /**
  651.      * Delegates to {@link Files#walk(Path, FileVisitOption...)} throwing {@link UncheckedIOException} instead of {@link IOException}.
  652.      * <p>
  653.      * The returned {@link Stream} may wrap one or more {@link DirectoryStream}s. When you require timely disposal of file system resources, use a
  654.      * {@code try}-with-resources block to ensure invocation of the stream's {@link Stream#close()} method after the stream operations are completed. Calling a
  655.      * closed stream causes a {@link IllegalStateException}.
  656.      * </p>
  657.      *
  658.      * @param start   See delegate.
  659.      * @param options See delegate.
  660.      * @return See delegate.
  661.      */
  662.     public static Stream<Path> walk(final Path start, final FileVisitOption... options) {
  663.         return Uncheck.apply(Files::walk, start, options);
  664.     }

  665.     /**
  666.      * Delegates to {@link Files#walk(Path, int, FileVisitOption...)} throwing {@link UncheckedIOException} instead of {@link IOException}.
  667.      * <p>
  668.      * The returned {@link Stream} may wrap one or more {@link DirectoryStream}s. When you require timely disposal of file system resources, use a
  669.      * {@code try}-with-resources block to ensure invocation of the stream's {@link Stream#close()} method after the stream operations are completed. Calling a
  670.      * closed stream causes a {@link IllegalStateException}.
  671.      * </p>
  672.      *
  673.      * @param start    See delegate.
  674.      * @param maxDepth See delegate.
  675.      * @param options  See delegate.
  676.      * @return See delegate.
  677.      */
  678.     public static Stream<Path> walk(final Path start, final int maxDepth, final FileVisitOption... options) {
  679.         return Uncheck.apply(Files::walk, start, maxDepth, options);
  680.     }

  681.     /**
  682.      * Delegates to {@link Files#walkFileTree(Path, FileVisitor)} throwing {@link UncheckedIOException} instead of
  683.      * {@link IOException}.
  684.      *
  685.      * @param start See delegate.
  686.      * @param visitor See delegate.
  687.      * @return See delegate.
  688.      */
  689.     public static Path walkFileTree(final Path start, final FileVisitor<? super Path> visitor) {
  690.         return Uncheck.apply(Files::walkFileTree, start, visitor);
  691.     }

  692.     /**
  693.      * Delegates to {@link Files#walkFileTree(Path, Set, int, FileVisitor)} throwing {@link UncheckedIOException} instead of
  694.      * {@link IOException}.
  695.      *
  696.      * @param start See delegate.
  697.      * @param options See delegate.
  698.      * @param maxDepth See delegate.
  699.      * @param visitor See delegate.
  700.      * @return See delegate.
  701.      */
  702.     public static Path walkFileTree(final Path start, final Set<FileVisitOption> options, final int maxDepth, final FileVisitor<? super Path> visitor) {
  703.         return Uncheck.apply(Files::walkFileTree, start, options, maxDepth, visitor);
  704.     }

  705.     /**
  706.      * Delegates to {@link Files#write(Path, byte[], OpenOption...)} throwing {@link UncheckedIOException} instead of
  707.      * {@link IOException}.
  708.      *
  709.      * @param path See delegate.
  710.      * @param bytes See delegate.
  711.      * @param options See delegate.
  712.      * @return See delegate.
  713.      */
  714.     public static Path write(final Path path, final byte[] bytes, final OpenOption... options) {
  715.         return Uncheck.apply(Files::write, path, bytes, options);
  716.     }

  717.     /**
  718.      * Delegates to {@link Files#write(Path, Iterable, Charset, OpenOption...)} throwing {@link UncheckedIOException}
  719.      * instead of {@link IOException}.
  720.      *
  721.      * @param path See delegate.
  722.      * @param lines See delegate.
  723.      * @param cs See delegate.
  724.      * @param options See delegate.
  725.      * @return See delegate.
  726.      */
  727.     public static Path write(final Path path, final Iterable<? extends CharSequence> lines, final Charset cs, final OpenOption... options) {
  728.         return Uncheck.apply(Files::write, path, lines, cs, options);
  729.     }

  730.     /**
  731.      * Delegates to {@link Files#write(Path, Iterable, OpenOption...)} throwing {@link UncheckedIOException} instead of
  732.      * {@link IOException}.
  733.      *
  734.      * @param path See delegate.
  735.      * @param lines See delegate.
  736.      * @param options See delegate.
  737.      * @return See delegate.
  738.      */
  739.     public static Path write(final Path path, final Iterable<? extends CharSequence> lines, final OpenOption... options) {
  740.         return Uncheck.apply(Files::write, path, lines, options);
  741.     }

  742.     /**
  743.      * No instances.
  744.      */
  745.     private FilesUncheck() {
  746.         // No instances
  747.     }
  748. }