1 /*
   2  * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package java.nio.file;
  27 
  28 import java.nio.file.spi.FileSystemProvider;
  29 import java.net.URI;
  30 
  31 /**
  32  * This class consists exclusively of static methods that return a {@link Path}
  33  * by converting a path string or {@link URI}.
  34  *
  35  * @apiNote
  36  * It is recommended to obtain a {@code Path} via the {@code Path.of} methods
  37  * instead of via the {@code get} methods defined in this class as this class
  38  * may be deprecated in a future release.
  39  *
  40  * @since 1.7
  41  * @see Path
  42  */
  43 
  44 public final class Paths {
  45     private Paths() { }
  46 
  47     /**
  48      * Converts a path string, or a sequence of strings that when joined form
  49      * a path string, to a {@code Path}.
  50      *
  51      * @implSpec
  52      * This method simply invokes {@link Path#of(String,String...)
  53      * Path.of(String, String...)} with the given parameters.
  54      *
  55      * @param   first
  56      *          the path string or initial part of the path string
  57      * @param   more
  58      *          additional strings to be joined to form the path string
  59      *
  60      * @return  the resulting {@code Path}
  61      *
  62      * @throws  InvalidPathException
  63      *          if the path string cannot be converted to a {@code Path}
  64      *
  65      * @see FileSystem#getPath
  66      * @see Path#of(String,String...)
  67      */
  68     public static Path get(String first, String... more) {
  69         return Path.of(first, more);
  70     }
  71 
  72     /**
  73      * Converts the given URI to a {@link Path} object.
  74      *
  75      * @implSpec
  76      * This method simply invokes {@link Path#of(URI) * Path.of(URI)} with the given parameter.
  77      *
  78      * @param   uri
  79      *          the URI to convert
  80      *
  81      * @return  the resulting {@code Path}
  82      *
  83      * @throws  IllegalArgumentException
  84      *          if preconditions on the {@code uri} parameter do not hold. The
  85      *          format of the URI is provider specific.
  86      * @throws  FileSystemNotFoundException
  87      *          The file system, identified by the URI, does not exist and
  88      *          cannot be created automatically, or the provider identified by
  89      *          the URI's scheme component is not installed
  90      * @throws  SecurityException
  91      *          if a security manager is installed and it denies an unspecified
  92      *          permission to access the file system
  93      *
  94      * @see Path#of(URI)
  95      */
  96     public static Path get(URI uri) {
  97         return Path.of(uri);
  98     }
  99 }