Path: blob/master/src/java.base/windows/classes/jdk/internal/loader/ClassLoaderHelper.java
41137 views
/*1* Copyright (c) 2012, 2020, 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 jdk.internal.loader;2627import java.io.File;2829class ClassLoaderHelper {3031private ClassLoaderHelper() {}3233/**34* Returns an alternate path name for the given file35* such that if the original pathname did not exist, then the36* file may be located at the alternate location.37* For most platforms, this behavior is not supported and returns null.38*/39static File mapAlternativeName(File lib) {40return null;41}4243/**44* Parse a PATH env variable. Windows allows quoted elements in a PATH,45* so special care needs to be taken.46*47* Empty elements will be replaced by dot.48*/49static String[] parsePath(String ldPath) {50int ldLen = ldPath.length();51char ps = File.pathSeparatorChar;52int psCount = 0;5354if (ldPath.indexOf('\"') >= 0) {55// First, remove quotes put around quoted parts of paths.56// Second, use a quotation mark as a new path separator.57// This will preserve any quoted old path separators.58char[] buf = new char[ldLen];59int bufLen = 0;60for (int i = 0; i < ldLen; ++i) {61char ch = ldPath.charAt(i);62if (ch == '\"') {63while (++i < ldLen &&64(ch = ldPath.charAt(i)) != '\"') {65buf[bufLen++] = ch;66}67} else {68if (ch == ps) {69psCount++;70ch = '\"';71}72buf[bufLen++] = ch;73}74}75ldPath = new String(buf, 0, bufLen);76ldLen = bufLen;77ps = '\"';78} else {79for (int i = ldPath.indexOf(ps); i >= 0;80i = ldPath.indexOf(ps, i + 1)) {81psCount++;82}83}8485String[] paths = new String[psCount + 1];86int pathStart = 0;87for (int j = 0; j < psCount; ++j) {88int pathEnd = ldPath.indexOf(ps, pathStart);89paths[j] = (pathStart < pathEnd) ?90ldPath.substring(pathStart, pathEnd) : ".";91pathStart = pathEnd + 1;92}93paths[psCount] = (pathStart < ldLen) ?94ldPath.substring(pathStart, ldLen) : ".";95return paths;96}97}9899100