Path: blob/master/src/java.base/windows/classes/jdk/internal/loader/ClassLoaderHelper.java
67769 views
/*1* Copyright (c) 2012, 2021, 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 true if loading a native library only if35* it's present on the file system.36*/37static boolean loadLibraryOnlyIfPresent() {38return true;39}4041/**42* Returns an alternate path name for the given file43* such that if the original pathname did not exist, then the44* file may be located at the alternate location.45* For most platforms, this behavior is not supported and returns null.46*/47static File mapAlternativeName(File lib) {48return null;49}5051/**52* Parse a PATH env variable. Windows allows quoted elements in a PATH,53* so special care needs to be taken.54*55* Empty elements will be replaced by dot.56*/57static String[] parsePath(String ldPath) {58int ldLen = ldPath.length();59char ps = File.pathSeparatorChar;60int psCount = 0;6162if (ldPath.indexOf('\"') >= 0) {63// First, remove quotes put around quoted parts of paths.64// Second, use a quotation mark as a new path separator.65// This will preserve any quoted old path separators.66char[] buf = new char[ldLen];67int bufLen = 0;68for (int i = 0; i < ldLen; ++i) {69char ch = ldPath.charAt(i);70if (ch == '\"') {71while (++i < ldLen &&72(ch = ldPath.charAt(i)) != '\"') {73buf[bufLen++] = ch;74}75} else {76if (ch == ps) {77psCount++;78ch = '\"';79}80buf[bufLen++] = ch;81}82}83ldPath = new String(buf, 0, bufLen);84ldLen = bufLen;85ps = '\"';86} else {87for (int i = ldPath.indexOf(ps); i >= 0;88i = ldPath.indexOf(ps, i + 1)) {89psCount++;90}91}9293String[] paths = new String[psCount + 1];94int pathStart = 0;95for (int j = 0; j < psCount; ++j) {96int pathEnd = ldPath.indexOf(ps, pathStart);97paths[j] = (pathStart < pathEnd) ?98ldPath.substring(pathStart, pathEnd) : ".";99pathStart = pathEnd + 1;100}101paths[psCount] = (pathStart < ldLen) ?102ldPath.substring(pathStart, ldLen) : ".";103return paths;104}105}106107108