private static String fixupWindows(String fn) { if ( Sys.isWindows && fn.length() >= 3 && fn.charAt(0) == '/' && windowsDrive(fn, 1)) fn = fn.substring(1) ; return fn; }
private static String fixupWindows(String fn) { if ( Sys.isWindows && fn.length() >= 3 && fn.charAt(0) == '/' && windowsDrive(fn, 1)) fn = fn.substring(1) ; return fn; }
/** Convert a plain file name (no file:) to a file: URL */ private static String plainFilenameToURL(String fn) { // No "file:" // Make Absolute filename. boolean trailingSlash = fn.endsWith("/") ; // To get Path.toAbsolutePath to work, we need to convert /C:/ to C:/ // then back again. fn = fixupWindows(fn) ; fn = Paths.get(fn).toAbsolutePath().normalize().toString() ; if ( trailingSlash && ! fn.endsWith("/") ) fn = fn + "/" ; if ( Sys.isWindows ) { // C:\ => file:///C:/... if ( windowsDrive(fn, 0) ) // Windows drive letter - already absolute path. // Make "URI" absolute path fn = "/"+fn ; // Convert \ to / // Maybe should do this on all platforms? i.e consistency. fn = fn.replace('\\', '/' ) ; } fn = encodeFileURL(fn) ; return "file://"+fn ; }
/** Convert a plain file name (no file:) to a file: URL */ private static String plainFilenameToURL(String fn) { // No "file:" // Make Absolute filename. boolean trailingSlash = fn.endsWith("/") ; // To get Path.toAbsolutePath to work, we need to convert /C:/ to C:/ // then back again. fn = fixupWindows(fn) ; fn = Paths.get(fn).toAbsolutePath().normalize().toString() ; if ( trailingSlash && ! fn.endsWith("/") ) fn = fn + "/" ; if ( Sys.isWindows ) { // C:\ => file:///C:/... if ( windowsDrive(fn, 0) ) // Windows drive letter - already absolute path. // Make "URI" absolute path fn = "/"+fn ; // Convert \ to / // Maybe should do this on all platforms? i.e consistency. fn = fn.replace('\\', '/' ) ; } fn = encodeFileURL(fn) ; return "file://"+fn ; }