Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/solaris/classes/sun/misc/FileURLMapper.java
32287 views
/*1* Copyright (c) 2002, 2003, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package sun.misc;2627import java.net.URL;28import java.io.File;29import sun.net.www.ParseUtil;3031/**32* (Solaris) platform specific handling for file: URLs .33* urls must not contain a hostname in the authority field34* other than "localhost".35*36* This implementation could be updated to map such URLs37* on to /net/host/...38*39* @author Michael McMahon40*/4142public class FileURLMapper {4344URL url;45String path;4647public FileURLMapper (URL url) {48this.url = url;49}5051/**52* @returns the platform specific path corresponding to the URL53* so long as the URL does not contain a hostname in the authority field.54*/5556public String getPath () {57if (path != null) {58return path;59}60String host = url.getHost();61if (host == null || "".equals(host) || "localhost".equalsIgnoreCase (host)) {62path = url.getFile();63path = ParseUtil.decode (path);64}65return path;66}6768/**69* Checks whether the file identified by the URL exists.70*/71public boolean exists () {72String s = getPath ();73if (s == null) {74return false;75} else {76File f = new File (s);77return f.exists();78}79}80}818283