src/share/classes/org/openjdk/jigsaw/Files.java

Print this page




   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 org.openjdk.jigsaw;
  27 
  28 import java.io.*;
  29 import java.util.*;
  30 import java.util.jar.*;
  31 import java.util.zip.*;
  32 
  33 
  34 public final class Files {
  35 
  36     private Files() { }
  37 
  38     private static void ensureIsDirectory(File path)
  39         throws IOException
  40     {


















  41         if (!path.exists() || !path.isDirectory())
  42             throw new IOException(path + ": Not a directory");
  43     }
  44 
  45     private static void ensureIsFile(File path)
  46         throws IOException
  47     {
  48         if (!path.exists() || !path.isFile())
  49             throw new IOException(path + ": Not a file");
  50     }
  51 
  52     private static String[] list(File dir)
  53         throws IOException
  54     {
  55         ensureIsDirectory(dir);
  56         String[] fs = dir.list();
  57         if (fs == null)
  58             throw new IOException(dir + ": Cannot list directory contents");
  59         return fs;
  60     }




   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 org.openjdk.jigsaw;
  27 
  28 import java.io.*;

  29 import java.util.jar.*;
  30 import java.util.zip.*;
  31 

  32 public final class Files {
  33 
  34     private Files() { }
  35 
  36     // paths are stored with a platform agnostic separator, '/'
  37     static String convertSeparator(String path) {
  38         return path.replace(File.separatorChar, '/');
  39     }
  40     
  41     static String platformSeparator(String path) {
  42         return path.replace('/', File.separatorChar);
  43     }
  44 
  45     static void ensureWriteable(File path) throws IOException {
  46         if (!path.canWrite())
  47             throw new IOException(path + ": is not writeable.");
  48     }
  49 
  50     static String ensureNonAbsolute(String path) throws IOException {
  51         if ((new File(path)).isAbsolute())
  52             throw new IOException("Abolute path instead of relative: " + path);
  53         return path;
  54     }
  55 
  56     static void ensureIsDirectory(File path) throws IOException {
  57         if (!path.exists() || !path.isDirectory())
  58             throw new IOException(path + ": Not a directory");
  59     }
  60 
  61     private static void ensureIsFile(File path)
  62         throws IOException
  63     {
  64         if (!path.exists() || !path.isFile())
  65             throw new IOException(path + ": Not a file");
  66     }
  67 
  68     private static String[] list(File dir)
  69         throws IOException
  70     {
  71         ensureIsDirectory(dir);
  72         String[] fs = dir.list();
  73         if (fs == null)
  74             throw new IOException(dir + ": Cannot list directory contents");
  75         return fs;
  76     }