<commit_before>/*
 * Copyright  2000-2004 The Apache Software Foundation
 *
 *  Licensed under the Apache License, Version 2.0 (the "License"); 
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License. 
 *
 */ 
package org.apache.bcel.util;


import java.util.*;
import java.util.zip.*;
import java.io.*;

/**
 * Responsible for loading (class) files from the CLASSPATH. Inspired by
 * sun.tools.ClassPath.
 *
 * @version $Id$
 * @author  <A HREF="mailto:<EMAIL>"><NAME></A>
 */
public class ClassPath implements Serializable {
  public static final ClassPath SYSTEM_CLASS_PATH = new ClassPath();

  private PathEntry[] paths;
  private String      class_path;

  /**
   * Search for classes in given path.
   */
  public ClassPath(String class_path) {
    this.class_path = class_path;

    ArrayList vec = new ArrayList();

    for(StringTokenizer tok=new StringTokenizer(class_path,
						System.getProperty("path.separator"));
	tok.hasMoreTokens();)
    {
      String path = tok.nextToken();
      
      if(!path.equals("")) {
	File file = new File(path);

	try {
	  if(file.exists()) {
	    if(file.isDirectory())
	      vec.add(new Dir(path));
	    else
	      vec.add(new Zip(new ZipFile(file)));
	  }
	} catch(IOException e) {
	  System.err.println("CLASSPATH component " + file + ": " + e);
	}
      }
    }

    paths = new PathEntry[vec.size()];
    vec.toArray(paths);
  }

  /**
   * Search for classes in CLASSPATH.
   * @deprecated Use SYSTEM_CLASS_PATH constant
   */
  public ClassPath() {
    this(getClassPath());
  }

  /** @return used class path string
   */
  public String toString() {
    return class_path;
  }
  
  public int hashCode() {
    return class_path.hashCode();
  }

  public boolean equals(Object o) {
    if(o instanceof ClassPath) {
      return class_path.equals(((ClassPath)o).class_path);
    }

    return false;
  }

  private static final void getPathComponents(String path, ArrayList list) {
    if(path != null) {
      StringTokenizer tok = new StringTokenizer(path, File.pathSeparator);

      while(tok.hasMoreTokens()) {
        String name = tok.nextToken();
        File   file = new File(name);

	if(file.exists())
	  list.add(name);
      }
    }
  }

  /** Checks for class path components in the following properties:
   * "java.class.path", "sun.boot.class.path", "java.ext.dirs"
   *
   * @return class path as used by default by BCEL
   */
  public static final String getClassPath() {
    String class_path = System.getProperty("java.class.path");
    String boot_path  = System.getProperty("sun.boot.class.path");
    String ext_path   = System.getProperty("java.ext.dirs");

    ArrayList list = new ArrayList();

    getPathComponents(class_path, list);
    getPathComponents(boot_path, list);

    ArrayList dirs = new ArrayList();
    getPathComponents(ext_path, dirs);

    for(Iterator e = dirs.iterator(); e.hasNext(); ) {
      File     ext_dir    = new File((String)e.next());
      String[] extensions = ext_dir.list(new FilenameFilter() {
	public boolean accept(File dir, String name) {
	  name = name.toLowerCase();
	  return name.endsWith(".zip") || name.endsWith(".jar");
	}
      });

      if(extensions != null)
	for(int i=0; i < extensions.length; i++)
	  list.add(ext_path + File.separatorChar + extensions[i]);
    }

    StringBuffer buf = new StringBuffer();

    for(Iterator e = list.iterator(); e.hasNext(); ) {
      buf.append((String)e.next());

      if(e.hasNext())
	buf.append(File.pathSeparatorChar);
    }

    return buf.toString().intern();
  }

  /**
   * @param name fully qualified class name, e.g. java.lang.String
   * @return input stream for class
   */
  public InputStream getInputStream(String name) throws IOException {
    return getInputStream(name, ".class");
  }
    
  /**
   * Return stream for class or resource on CLASSPATH.
   *
   * @param name fully qualified file name, e.g. java/lang/String
   * @param suffix file name ends with suff, e.g. .java
   * @return input stream for file on class path
   */
  public InputStream getInputStream(String name, String suffix) throws IOException {
    InputStream is = null;<commit_msg>Apply Patch 31630 from <NAME>. Fix parsing problems is java.ext.dirs contain multiple paths. This shows up (at least) on the mac.<commit_after>/*
 * Copyright  2000-2004 The Apache Software Foundation
 *
 *  Licensed under the Apache License, Version 2.0 (the "License"); 
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License. 
 *
 */ 
package org.apache.bcel.util;


import java.util.*;
import java.util.zip.*;
import java.io.*;

/**
 * Responsible for loading (class) files from the CLASSPATH. Inspired by
 * sun.tools.ClassPath.
 *
 * @version $Id$
 * @author  <A HREF="mailto:<EMAIL>"><NAME></A>
 */
public class ClassPath implements Serializable {
  public static final ClassPath SYSTEM_CLASS_PATH = new ClassPath();

  private PathEntry[] paths;
  private String      class_path;

  /**
   * Search for classes in given path.
   */
  public ClassPath(String class_path) {
    this.class_path = class_path;

    ArrayList vec = new ArrayList();

    for(StringTokenizer tok=new StringTokenizer(class_path,
						System.getProperty("path.separator"));
	tok.hasMoreTokens();)
    {
      String path = tok.nextToken();
      
      if(!path.equals("")) {
	File file = new File(path);

	try {
	  if(file.exists()) {
	    if(file.isDirectory())
	      vec.add(new Dir(path));
	    else
	      vec.add(new Zip(new ZipFile(file)));
	  }
	} catch(IOException e) {
	  System.err.println("CLASSPATH component " + file + ": " + e);
	}
      }
    }

    paths = new PathEntry[vec.size()];
    vec.toArray(paths);
  }

  /**
   * Search for classes in CLASSPATH.
   * @deprecated Use SYSTEM_CLASS_PATH constant
   */
  public ClassPath() {
    this(getClassPath());
  }

  /** @return used class path string
   */
  public String toString() {
    return class_path;
  }
  
  public int hashCode() {
    return class_path.hashCode();
  }

  public boolean equals(Object o) {
    if(o instanceof ClassPath) {
      return class_path.equals(((ClassPath)o).class_path);
    }

    return false;
  }

  private static final void getPathComponents(String path, ArrayList list) {
    if(path != null) {
      StringTokenizer tok = new StringTokenizer(path, File.pathSeparator);

      while(tok.hasMoreTokens()) {
        String name = tok.nextToken();
        File   file = new File(name);

	if(file.exists())
	  list.add(name);
      }
    }
  }

  /** Checks for class path components in the following properties:
   * "java.class.path", "sun.boot.class.path", "java.ext.dirs"
   *
   * @return class path as used by default by BCEL
   */
  public static final String getClassPath() {
    String class_path = System.getProperty("java.class.path");
    String boot_path  = System.getProperty("sun.boot.class.path");
    String ext_path   = System.getProperty("java.ext.dirs");

    ArrayList list = new ArrayList();

    getPathComponents(class_path, list);
    getPathComponents(boot_path, list);

    ArrayList dirs = new ArrayList();
    getPathComponents(ext_path, dirs);

    for(Iterator e = dirs.iterator(); e.hasNext(); ) {
      File     ext_dir    = new File((String)e.next());
      String[] extensions = ext_dir.list(new FilenameFilter() {
	public boolean accept(File dir, String name) {
	  name = name.toLowerCase();
	  return name.endsWith(".zip") || name.endsWith(".jar");
	}
      });

      if(extensions != null)
        for(int i=0; i < extensions.length; i++)
          list.add(ext_dir.getPath() + File.separatorChar + extensions[i]);
    }

    StringBuffer buf = new StringBuffer();

    for(Iterator e = list.iterator(); e.hasNext(); ) {
      buf.append((String)e.next());

      if(e.hasNext())
	buf.append(File.pathSeparatorChar);
    }

    return buf.toString().intern();
  }

  /**
   * @param name fully qualified class name, e.g. java.lang.String
   * @return input stream for class
   */
  public InputStream getInputStream(String name) throws IOException {
    return getInputStream(name, ".class");
  }
    
  /**
   * Return stream for class or resource on CLASSPATH.
   *
   * @param name fully qualified file name, e.g. java/lang/String
   * @param suffix file name ends with suff, e.g. .java
   * @return input stream for file on class path
   */
  public InputStream getInputStream(String name, String suffix) throws IOException {
    InputStream is = null;
{'fraction_non_alphanumeric': 0.12321562734785875, 'fraction_numerical': 0.0033272512611355587, 'mean_word_length': 3.0636720453554296, 'pattern_counts': {'":': 2, '<': 14, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3860788', 'n_tokens_mistral': 2871, 'n_tokens_neox': 2786, 'n_words': 815}