< prev index next >

src/java.base/windows/classes/sun/misc/FileURLMapper.java

Print this page




  29 import java.io.File;
  30 import sun.net.www.ParseUtil;
  31 
  32 /**
  33  * (Windows) Platform specific handling for file: URLs . In particular deals
  34  * with network paths mapping them to UNCs.
  35  *
  36  * @author      Michael McMahon
  37  */
  38 
  39 public class FileURLMapper {
  40 
  41     URL url;
  42     String file;
  43 
  44     public FileURLMapper (URL url) {
  45         this.url = url;
  46     }
  47 
  48     /**
  49      * @returns the platform specific path corresponding to the URL, and in particular
  50      *  returns a UNC when the authority contains a hostname
  51      */
  52 
  53     public String getPath () {
  54         if (file != null) {
  55             return file;
  56         }
  57         String host = url.getHost();
  58         if (host != null && !host.equals("") &&
  59             !"localhost".equalsIgnoreCase(host)) {
  60             String rest = url.getFile();
  61             String s = host + ParseUtil.decode (url.getFile());
  62             file = "\\\\"+ s.replace('/', '\\');
  63             return file;
  64         }
  65         String path = url.getFile().replace('/', '\\');
  66         file = ParseUtil.decode(path);
  67         return file;
  68     }
  69 


  29 import java.io.File;
  30 import sun.net.www.ParseUtil;
  31 
  32 /**
  33  * (Windows) Platform specific handling for file: URLs . In particular deals
  34  * with network paths mapping them to UNCs.
  35  *
  36  * @author      Michael McMahon
  37  */
  38 
  39 public class FileURLMapper {
  40 
  41     URL url;
  42     String file;
  43 
  44     public FileURLMapper (URL url) {
  45         this.url = url;
  46     }
  47 
  48     /**
  49      * @return the platform specific path corresponding to the URL, and in particular
  50      *  returns a UNC when the authority contains a hostname
  51      */
  52 
  53     public String getPath () {
  54         if (file != null) {
  55             return file;
  56         }
  57         String host = url.getHost();
  58         if (host != null && !host.equals("") &&
  59             !"localhost".equalsIgnoreCase(host)) {
  60             String rest = url.getFile();
  61             String s = host + ParseUtil.decode (url.getFile());
  62             file = "\\\\"+ s.replace('/', '\\');
  63             return file;
  64         }
  65         String path = url.getFile().replace('/', '\\');
  66         file = ParseUtil.decode(path);
  67         return file;
  68     }
  69 
< prev index next >