< prev index next >

src/java.base/unix/classes/sun/nio/fs/UnixFileSystemProvider.java

Print this page
8213406: (fs) More than one instance of built-in FileSystem observed in heap
Reviewed-by: alanb, cushon, weijun
   1 /*
   2  * Copyright (c) 2008, 2013, 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


  37 import java.security.AccessController;
  38 
  39 import sun.nio.ch.ThreadPool;
  40 import sun.security.util.SecurityConstants;
  41 import static sun.nio.fs.UnixNativeDispatcher.*;
  42 import static sun.nio.fs.UnixConstants.*;
  43 
  44 /**
  45  * Base implementation of FileSystemProvider
  46  */
  47 
  48 public abstract class UnixFileSystemProvider
  49     extends AbstractFileSystemProvider
  50 {
  51     private static final String USER_DIR = "user.dir";
  52     private final UnixFileSystem theFileSystem;
  53 
  54     public UnixFileSystemProvider() {
  55         String userDir = System.getProperty(USER_DIR);
  56         theFileSystem = newFileSystem(userDir);




  57     }
  58 
  59     /**
  60      * Constructs a new file system using the given default directory.
  61      */
  62     abstract UnixFileSystem newFileSystem(String dir);
  63 
  64     @Override
  65     public final String getScheme() {
  66         return "file";
  67     }
  68 
  69     private void checkUri(URI uri) {
  70         if (!uri.getScheme().equalsIgnoreCase(getScheme()))
  71             throw new IllegalArgumentException("URI does not match this provider");
  72         if (uri.getRawAuthority() != null)
  73             throw new IllegalArgumentException("Authority component present");
  74         String path = uri.getPath();
  75         if (path == null)
  76             throw new IllegalArgumentException("Path component is undefined");


   1 /*
   2  * Copyright (c) 2008, 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


  37 import java.security.AccessController;
  38 
  39 import sun.nio.ch.ThreadPool;
  40 import sun.security.util.SecurityConstants;
  41 import static sun.nio.fs.UnixNativeDispatcher.*;
  42 import static sun.nio.fs.UnixConstants.*;
  43 
  44 /**
  45  * Base implementation of FileSystemProvider
  46  */
  47 
  48 public abstract class UnixFileSystemProvider
  49     extends AbstractFileSystemProvider
  50 {
  51     private static final String USER_DIR = "user.dir";
  52     private final UnixFileSystem theFileSystem;
  53 
  54     public UnixFileSystemProvider() {
  55         String userDir = System.getProperty(USER_DIR);
  56         theFileSystem = newFileSystem(userDir);
  57     }
  58 
  59     UnixFileSystem theFileSystem() {
  60         return theFileSystem;
  61     }
  62 
  63     /**
  64      * Constructs a new file system using the given default directory.
  65      */
  66     abstract UnixFileSystem newFileSystem(String dir);
  67 
  68     @Override
  69     public final String getScheme() {
  70         return "file";
  71     }
  72 
  73     private void checkUri(URI uri) {
  74         if (!uri.getScheme().equalsIgnoreCase(getScheme()))
  75             throw new IllegalArgumentException("URI does not match this provider");
  76         if (uri.getRawAuthority() != null)
  77             throw new IllegalArgumentException("Authority component present");
  78         String path = uri.getPath();
  79         if (path == null)
  80             throw new IllegalArgumentException("Path component is undefined");


< prev index next >