commons-io-1.3.2

   return !filter.accept(file, name);
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.io.filefilter.NotFileFilter
 * Java Class Version: 1.3 (47.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.io.filefilter;

import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;

public class OrFileFilter
  extends AbstractFileFilter
  implements ConditionalFileFilter
{
  private List fileFilters;
  
  public OrFileFilter()
  {
    fileFilters = new ArrayList();
  }
  
  public OrFileFilter(List fileFilters)
  {
    if (fileFilters == null) {
      this.fileFilters = new ArrayList();
    } else {
      this.fileFilters = new ArrayList(fileFilters);
    }
  }
  
  public OrFileFilter(IOFileFilter filter1, IOFileFilter filter2)
  {
    if ((filter1 == null) || (filter2 == null)) {
      throw new IllegalArgumentException("The filters must not be null");
    }
    fileFilters = new ArrayList();
    addFileFilter(filter1);
    addFileFilter(filter2);
  }
  
  public void addFileFilter(IOFileFilter ioFileFilter)
  {
    fileFilters.add(ioFileFilter);
  }
  
  public List getFileFilters()
  {
    return Collections.unmodifiableList(fileFilters);
  }
  
  public boolean removeFileFilter(IOFileFilter ioFileFilter)
  {
    return fileFilters.remove(ioFileFilter);
  }
  
  public void setFileFilters(List fileFilters)
  {
    this.fileFilters = fileFilters;
  }
  
  public boolean accept(File file)
  {
    for (Iterator iter = fileFilters.iterator(); iter.hasNext();)
    {
      IOFileFilter fileFilter = (IOFileFilter)iter.next();
      if (fileFilter.accept(file)) {
        return true;
      }
    }
    return false;
  }
  
  public boolean accept(File file, String name)
  {
    for (Iterator iter = fileFilters.iterator(); iter.hasNext();)
    {
      IOFileFilter fileFilter = (IOFileFilter)iter.next();
      if (fileFilter.accept(file, name)) {
        return true;
      }
    }
    return false;
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.io.filefilter.OrFileFilter
 * Java Class Version: 1.3 (47.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.io.filefilter;

import java.io.File;
import java.util.List;

public class PrefixFileFilter
  extends AbstractFileFilter
{
  private String[] prefixes;
  
  public PrefixFileFilter(String prefix)
  {
    if (prefix == null) {
      throw new IllegalArgumentException("The prefix must not be null");
    }
    prefixes = new String[] { prefix };
  }
  
  public PrefixFileFilter(String[] prefixes)
  {
    if (prefixes == null) {
      throw new IllegalArgumentException("The array of prefixes must not be null");
    }
    this.prefixes = prefixes;
  }
  
  public PrefixFileFilter(List prefixes)
  {
    if (prefixes == null) {
      throw new IllegalArgumentException("The list of prefixes must not be null");
    }
    this.prefixes = ((String[])prefixes.toArray(new String[prefixes.size()]));
  }
  
  public boolean accept(File file)
  {
    String name = file.getName();
    for (int i = 0; i < prefixes.length; i++) {
      if (name.startsWith(prefixes[i])) {
        return true;
      }
    }
    return false;
  }
  
  public boolean accept(File file, String name)
  {
    for (int i = 0; i < prefixes.length; i++) {
      if (name.startsWith(prefixes[i])) {
        return true;
      }
    }
    return false;
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.io.filefilter.PrefixFileFilter
 * Java Class Version: 1.3 (47.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.io.filefilter;

import java.io.File;

public class SizeFileFilter
  extends AbstractFileFilter
{
  private long size;
  private boolean acceptLarger;
  
  public SizeFileFilter(long size)
  {
    this(size, true);
  }
  
  public SizeFileFilter(long size, boolean acceptLarger)
  {
    if (size < 0L) {
      throw new IllegalArgumentException("The size must be non-negative");
    }
    this.size = size;
    this.acceptLarger = acceptLarger;
  }
  
  public boolean accept(File file)
  {
    boolean smaller = file.length() < size;
    return acceptLarger ? false : !smaller ? true : smaller;
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.io.filefilter.SizeFileFilter
 * Java Class Version: 1.3 (47.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.io.filefilter;

import java.io.File;
import java.util.List;

public class SuffixFileFilter
  extends AbstractFileFilter
{
  private String[] suffixes;
  
  public SuffixFileFilter(String suffix)
  {
    if (suffix == null) {
      throw new IllegalArgumentException("The suffix must not be null");
    }
    suffixes = new String[] { suffix };
  }
  
  public SuffixFileFilter(String[] suffixes)
  {
    if (suffixes == null) {
      throw new IllegalArgumentException("The array of suffixes must not be null");
    }
    this.suffixes = suffixes;
  }
  
  public SuffixFileFilter(List suffixes)
  {
    if (suffixes == null) {
      throw new IllegalArgumentException("The list of suffixes must not be null");
    }
    this.suffixes = ((String[])suffixes.toArray(new String[suffixes.size()]));
  }
  
  public boolean accept(File file)
  {
    String name = file.getName();
    for (int i = 0; i < suffixes.length; i++) {
      if (name.endsWith(suffixes[i])) {
        return true;
      }
    }
    return false;
  }
  
  public boolean accept(File file, String name)
  {
    for (int i = 0; i < suffixes.length; i++) {
      if (name.endsWith(suffixes[i])) {
        return true;
      }
    }
    return false;
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.io.filefilter.SuffixFileFilter
 * Java Class Version: 1.3 (47.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.io.filefilter;

import java.io.File;

public class TrueFileFilter
  implements IOFileFilter
{
  public static final IOFileFilter TRUE = new TrueFileFilter();
  public static final IOFileFilter INSTANCE = TRUE;
  
  public boolean accept(File file)
  {
    return true;
  }
  
  public boolean accept(File dir, String name)
  {
    return true;
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.io.filefilter.TrueFileFilter
 * Java Class Version: 1.3 (47.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.io.filefilter;

import java.io.File;
import java.util.List;
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.io.IOCase;

public class WildcardFileFilter
  extends AbstractFileFilter
{
  private String[] wildcards;
  private IOCase caseSensitivity;
  
  public WildcardFileFilter(String wildcard)
  {
    this(wildcard, null);
  }
  
  public WildcardFileFilter(String wildcard, IOCase caseSensitivity)
  {
    if (wildcard == null) {
      throw new IllegalArgumentException("The wildcard must not be null");
    }
    wildcards = new String[] { wildcard };
    this.caseSensitivity = (caseSensitivity == null ? IOCase.SENSITIVE : caseSensitivity);
  }
  
  public WildcardFileFilter(String[] wildcards)
  {
    this(wildcards, null);
  }
  
  public WildcardFileFilter(String[] wildcards, IOCase caseSensitivity)
  {
    if (wildcards == null) {
      throw new IllegalArgumentException("The wildcard array must not be null");
    }
    this.wildcards = wildcards;
    this.caseSensitivity = (caseSensitivity == null ? IOCase.SENSITIVE : caseSensitivity);
  }
  
  public WildcardFileFilter(List wildcards)
  {
    this(wildcards, null);
  }
  
  public WildcardFileFilter(List wildcards, IOCase caseSensitivity)
  {
    if (wildcards == null) {
      throw new IllegalArgumentException("The wildcard list must not be null");
    }
    this.wildcards = ((String[])wildcards.toArray(new String[wildcards.size()]));
    this.caseSensitivity = (caseSensitivity == null ? IOCase.SENSITIVE : caseSensitivity);
  }
  
  public boolean accept(File dir, String name)
  {
    for (int i = 0; i < wildcards.length; i++) {
      if (FilenameUtils.wildcardMatch(name, wildcards[i], caseSensitivity)) {
        return true;
      }
    }
    return false;
  }
  
  public boolean accept(File file)
  {
    String name = file.getName();
    for (int i = 0; i < wildcards.length; i++) {
      if (FilenameUtils.wildcardMatch(name, wildcards[i], caseSensitivity)) {
        return true;
      }
    }
    return false;
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.io.filefilter.WildcardFileFilter
 * Java Class Version: 1.3 (47.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.io.filefilter;

import java.io.File;
import java.util.List;
import org.apache.commons.io.FilenameUtils;

/**
 * @deprecated
 */
public class WildcardFilter
  extends AbstractFileFilter
{
  private String[] wildcards;
  
  public WildcardFilter(String wildcard)
  {
    if (wildcard == null) {
      throw new IllegalArgumentException("The wildcard must not be null");
    }
    wildcards = new String[] { wildcard };
  }
  
  public WildcardFilter(String[] wildcards)
  {
    if (wildcards == null) {
      throw new IllegalArgumentException("The wildcard array must not be null");
    }
    this.wildcards = wildcards;
  }
  
  public WildcardFilter(List wildcards)
  {
    if (wildcards == null) {
      throw new IllegalArgumentException("The wildcard list must not be null");
    }
    this.wildcards = ((String[])wildcards.toArray(new String[wildcards.size()]));
  }
  
  public boolean accept(File dir, String name)
  {
    if ((dir != null) && (new File(dir, name).isDirectory())) {
      return false;
    }
    for (int i = 0; i < wildcards.length; i++) {
      if (FilenameUtils.wildcardMatch(name, wildcards[i])) {
        return true;
      }
    }
    return false;
  }
  
  public boolean accept(File file)
  {
    if (file.isDirectory()) {
      return false;
    }
    for (int i = 0; i < wildcards.length; i++) {
      if (FilenameUtils.wildcardMatch(file.getName(), wildcards[i])) {
        return true;
      }
    }
    return false;
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.io.filefilter.WildcardFilter
 * Java Class Version: 1.3 (47.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.io;

import java.io.File;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.Stack;

public class FilenameUtils
{
  private static final char EXTENSION_SEPARATOR = '.';
  private static final char UNIX_SEPARATOR = '/';
  private static final char WINDOWS_SEPARATOR = '\\';
  private static final char SYSTEM_SEPARATOR = File.separatorChar;
  private static final char OTHER_SEPARATOR;
  
  static
  {
    if (isSystemWindows()) {
      OTHER_SEPARATOR = '/';
    } else {
      OTHER_SEPARATOR = '\\';
    }
  }
  
  static boolean isSystemWindows()
  {
    return SYSTEM_SEPARATOR == '\\';
  }
  
  private static boolean isSeparator(char ch)
  {
    return (ch == '/') || (ch == '\\');
  }
  
  public static String normalize(String filename)
  {
    return doNormalize(filename, true);
  }
  
  public static String normalizeNoEndSeparator(String filename)
  {
    return doNormalize(filename, false);
  }
  
  private static String doNormalize(String filename, boolean keepSeparator)
  {
    if (filename == null) {
      return null;
    }
    int size = filename.length();
    if (size == 0) {
      return filename;
    }
    int prefix = getPrefixLength(filename);
    if (prefix < 0) {
      return null;
    }
    char[] array = new char[size + 2];
    filename.getChars(0, filename.length(), array, 0);
    for (int i = 0; i < array.length; i++) {
      if (array[i] == OTHER_SEPARATOR) {
        array[i] = SYSTEM_SEPARATOR;
      }
    }
    boolean lastIsDirectory = true;
    if (array[(size - 1)] != SYSTEM_SEPARATOR)
    {
      array[(size++)] = SYSTEM_SEPARATOR;
      lastIsDirectory = false;
    }
    for (int i = prefix + 1; i < size; i++) {
      if ((array[i] == SYSTEM_SEPARATOR) && (array[(i - 1)] == SYSTEM_SEPARATOR))
      {
        System.arraycopy(array, i, array, i - 1, size - i);
        size--;
        i--;
      }
    }
    for (int i = prefix + 1; i < size; i++) {
      if ((array[i] == SYSTEM_SEPARATOR) && (array[(i - 1)] == '.') && ((i == prefix + 1) || (array[(i - 2)] == SYSTEM_SEPARATOR)))
      {
        if (i == size - 1) {
          lastIsDirectory = true;
        }
        System.arraycopy(array, i + 1, array, i - 1, size - i);
        size -= 2;
        i--;
      }
    }
    label455:
    for (int i = prefix + 2; i < size; i++) {
      if ((array[i] == SYSTEM_SEPARATOR) && (array[(i - 1)] == '.') && (array[(i - 2)] == '.') && ((i == prefix + 2) || (array[(i - 3)] == SYSTEM_SEPARATOR)))
      {
        if (i == prefix + 2) {
          return null;
        }
        if (i == size - 1) {
          lastIsDirectory = true;
        }
        for (int j = i - 4; j >= prefix; j--) {
          if (array[j] == SYSTEM_SEPARATOR)
          {
            System.arraycopy(array, i + 1, array, j + 1, size - i);
            size -= i - j;
            i = j + 1;
            break label455;
          }
        }
        System.arraycopy(array, i + 1, array, prefix, size - i);
        size -= i + 1 - prefix;
        i = prefix + 1;
      }
    }
    if (size <= 0) {
      return "";
    }
    if (size <= prefix) {
      return new String(array, 0, size);
    }
    if ((lastIsDirectory) && (keepSeparator)) {
      return new String(array, 0, size);
    }
    return new String(array, 0, size - 1);
  }
  
  public static String concat(String basePath, String fullFilenameToAdd)
  {
    int prefix = getPrefixLength(fullFilenameToAdd);
    if (prefix < 0) {
      return null;
    }
    if (prefix > 0) {
      return normalize(fullFilenameToAdd);
    }
    if (basePath == null) {
      return null;
    }
    int len = basePath.length();
    if (len == 0) {
      return normalize(fullFilenameToAdd);
    }
    char ch = basePath.charAt(len - 1);
    if (isSeparator(ch)) {
      return normalize(basePath + fullFilenameToAdd);
    }
    return normalize(basePath + '/' + fullFilenameToAdd);
  }
  
  public static String separatorsToUnix(String path)
  {
    if ((path == null) || (path.indexOf('\\') == -1)) {
      return path;
    }
    return path.replace('\\', '/');
  }
  
  public static String separatorsToWindows(String path)
  {
    if ((path == null) || (path.indexOf('/') == -1)) {
      return path;
    }
    return path.replace('/', '\\');
  }
  
  public static String separatorsToSystem(String path)
  {
    if (path == null) {
      return null;
    }
    if (isSystemWindows()) {
      return separatorsToWindows(path);
    }
    return separatorsToUnix(path);
  }
  
  public static int getPrefixLength(String filename)
  {
    if (filename == null) {
      return -1;
    }
    int len = filename.length();
    if (len == 0) {
      return 0;
    }
    char ch0 = filename.charAt(0);
    if (ch0 == ':') {
      return -1;
    }
    if (len == 1)
    {
      if (ch0 == '~') {
        return 2;
      }
      return isSeparator(ch0) ? 1 : 0;
    }
    if (ch0 == '~')
    {
      int posUnix = filename.indexOf('/', 1);
      int posWin = filename.indexOf('\\', 1);
      if ((posUnix == -1) && (posWin == -1)) {
        return len + 1;
      }
      posUnix = posUnix == -1 ? posWin : posUnix;
      posWin = posWin == -1 ? posUnix : posWin;
      return Math.min(posUnix, posWin) + 1;
    }
    char ch1 = filename.charAt(1);
    if (ch1 == ':')
    {
      ch0 = Character.toUpperCase(ch0);
      if ((ch0 >= 'A') && (ch0 <= 'Z'))
      {
        if ((len == 2) || (!isSeparator(filename.charAt(2)))) {
          return 2;
        }
        return 3;
      }
      return -1;
    }
    if ((isSeparator(ch0)) && (isSeparator(ch1)))
    {
      int posUnix = filename.indexOf('/', 2);
      int posWin = filename.indexOf('\\', 2);
      if (((posUnix == -1) && (posWin == -1)) || (posUnix == 2) || (posWin == 2)) {
        return -1;
      }
      posUnix = posUnix == -1 ? posWin : posUnix;
      posWin = posWin == -1 ? posUnix : posWin;
      return Math.min(posUnix, posWin) + 1;
    }
    return isSeparator(ch0) ? 1 : 0;
  }
  
  public static int indexOfLastSeparator(String filename)
  {
    if (filename == null) {
      return -1;
    }
    int lastUnixPos = filename.lastIndexOf('/');
    int lastWindowsPos = filename.lastIndexOf('\\');
    return Math.max(lastUnixPos, lastWindowsPos);
  }
  
  public static int indexOfExtension(String filename)
  {
    if (filename == null) {
      return -1;
    }
    int extensionPos = filename.lastIndexOf('.');
    int lastSeparator = indexOfLastSeparator(filename);
    return lastSeparator > extensionPos ? -1 : extensionPos;
  }
  
  public static String getPrefix(String filename)
  {
    if (filename == null) {
      return null;
    }
    int len = getPrefixLength(filename);
    if (len < 0) {
      return null;
    }
    if (len > filename.length()) {
      return filename + '/';
    }
    return filename.substring(0, len);
  }
  
  public static String getPath(String filename)
  {
    return doGetPath(filename, 1);
  }
  
  public static String getPathNoEndSeparator(String filename)
  {
    return doGetPath(filename, 0);
  }
  
  private static String doGetPath(String filename, int separatorAdd)
  {
    if (filename == null) {
      return null;
    }
    int prefix = getPrefixLength(filename);
    if (prefix < 0) {
      return null;
    }
    int index = indexOfLastSeparator(filename);
    if ((prefix >= filename.length()) || (index < 0)) {
      return "";
    }
    return filename.substring(prefix, index + separatorAdd);
  }
  
  public static String getFullPath(String filename)
  {
    return doGetFullPath(filename, true);
  }
  
  public static String getFullPathNoEndSeparator(String filename)
  {
    return doGetFullPath(filename, false);
  }
  
  private static String doGetFullPath(String filename, boolean includeSeparator)
  {
    if (filename == null) {
      return null;
    }
    int prefix = getPrefixLength(filename);
    if (prefix < 0) {
      return null;
    }
    if (prefix >= filename.length())
    {
      if (includeSeparator) {
        return getPrefix(filename);
      }
      return filename;
    }
    int index = indexOfLastSeparator(filename);
    if (index < 0) {
      return filename.substring(0, prefix);
    }
    int end = index + (includeSeparator ? 1 : 0);
    return filename.substring(0, end);
  }
  
  public static String getName(String filename)
  {
    if (filename == null) {
      return null;
    }
    int index = indexOfLastSeparator(filename);
    return filename.substring(index + 1);
  }
  
  public static String getBaseName(String filename)
  {
    return removeExtension(getName(filename));
  }
  
  public static String getExtension(String filename)
  {
    if (filename == null) {
      return null;
    }
    int index = indexOfExtension(filename);
    if (index == -1) {
      return "";
    }
    return filename.substring(index + 1);
  }
  
  public static String removeExtension(String filename)
  {
    if (filename == null) {
      return null;
    }
    int index = indexOfExtension(filename);
    if (index == -1) {
      return filename;
    }
    return filename.substring(0, index);
  }
  
  public static boolean equals(String filename1, String filename2)
  {
    return equals(filename1, filename2, false, IOCase.SENSITIVE);
  }
  
  public static boolean equalsOnSystem(String filename1, String filename2)
  {
    return equals(filename1, filename2, false, IOCase.SYSTEM);
  }
  
  public static boolean equalsNormalized(String filename1, String filename2)
  {
    return equals(filename1, filename2, true, IOCase.SENSITIVE);
  }
  
  public static boolean equalsNormalizedOnSystem(String filename1, String filename2)
  {
    return equals(filename1, filename2, true, IOCase.SYSTEM);
  }
  
  public static boolean equals(String filename1, String filename2, boolean normalized, IOCase caseSensitivity)
  {
    if ((filename1 == null) || (filename2 == null)) {
      return filename1 == filename2;
    }
    if (normalized)
    {
      filename1 = normalize(filename1);
      filename2 = normalize(filename2);
    }
    if (caseSensitivity == null) {
      caseSensitivity = IOCase.SENSITIVE;
    }
    return caseSensitivity.checkEquals(filename1, filename2);
  }
  
  public static boolean isExtension(String filename, String extension)
  {
    if (filename == null) {
      return false;
    }
    if ((extension == null) || (extension.length() == 0)) {
      return indexOfExtension(filename) == -1;
    }
    String fileExt = getExtension(filename);
    return fileExt.equals(extension);
  }
  
  public static boolean isExtension(String filename, String[] extensions)
  {
    if (filename == null) {
      return false;
    }
    if ((extensions == null) || (extensions.length == 0)) {
      return indexOfExtension(filename) == -1;
    }
    String fileExt = getExtension(filename);
    for (int i = 0; i < extensions.length; i++) {
      if (fileExt.equals(extensions[i])) {
        return true;
      }
    }
    return false;
  }
  
  public static boolean isExtension(String filename, Collection extensions)
  {
    if (filename == null) {
      return false;
    }
    if ((extensions == null) || (extensions.isEmpty())) {
      return indexOfExtension(filename) == -1;
    }
    String fileExt = getExtension(filename);
    for (Iterator it = extensions.iterator(); it.hasNext();) {
      if (fileExt.equals(it.next())) {
        return true;
      }
    }
    return false;
  }
  
  public static boolean wildcardMatch(String filename, String wildcardMatcher)
  {
    return wildcardMatch(filename, wildcardMatcher, IOCase.SENSITIVE);
  }
  
  public static boolean wildcardMatchOnSystem(String filename, String wildcardMatcher)
  {
    return wildcardMatch(filename, wildcardMatcher, IOCase.SYSTEM);
  }
  
  public static boolean wildcardMatch(String filename, String wildcardMatcher, IOCase caseSensitivity)
  {
    if ((filename == null) && (wildcardMatcher == null)) {
      return true;
    }
    if ((filename == null) || (wildcardMatcher == null)) {
      return false;
    }
    if (caseSensitivity == null) {
      caseSensitivity = IOCase.SENSITIVE;
    }
    filename = caseSensitivity.convertCase(filename);
    wildcardMatcher = caseSensitivity.convertCase(wildcardMatcher);
    String[] wcs = splitOnTokens(wildcardMatcher);
    boolean anyChars = false;
    int textIdx = 0;
    int wcsIdx = 0;
    Stack backtrack = new Stack();
    do
    {
      if (backtrack.size() > 0)
      {
        int[] array = (int[])backtrack.pop();
        wcsIdx = array[0];
        textIdx = array[1];
        anyChars = true;
      }
      while (wcsIdx < wcs.length)
      {
        if (wcs[wcsIdx].equals("?"))
        {
          textIdx++;
          anyChars = false;
        }
        else if (wcs[wcsIdx].equals("*"))
        {
          anyChars = true;
          if (wcsIdx == wcs.length - 1) {
            textIdx = filename.length();
          }
        }
        else
        {
          if (anyChars)
          {
            textIdx = filename.indexOf(wcs[wcsIdx], textIdx);
            if (textIdx == -1) {
              break;
            }
            int repeat = filename.indexOf(wcs[wcsIdx], textIdx + 1);
            if (repeat >= 0) {
              backtrack.push(new int[] { wcsIdx, repeat });
            }
          }
          else
          {
            if (!filename.startsWith(wcs[wcsIdx], textIdx)) {
              break;
            }
          }
          textIdx += wcs[wcsIdx].length();
          anyChars = false;
        }
        wcsIdx++;
      }
      if ((wcsIdx == wcs.length) && (textIdx == filename.length())) {
        return true;
      }
    } while (backtrack.size() > 0);
    return false;
  }
  
  static String[] splitOnTokens(String text)
  {
    if ((text.indexOf("?") == -1) && (text.indexOf("*") == -1)) {
      return new String[] { text };
    }
    char[] array = text.toCharArray();
    ArrayList list = new ArrayList();
    StringBuffer buffer = new StringBuffer();
    for (int i = 0; i < array.length; i++) {
      if ((array[i] == '?') || (array[i] == '*'))
      {
        if (buffer.length() != 0)
        {
          list.add(buffer.toString());
          buffer.setLength(0);
        }
        if (array[i] == '?') {
          list.add("?");
        } else if ((list.size() == 0) || ((i > 0) && (!list.get(list.size() - 1).equals("*")))) {
          list.add("*");
        }
      }
      else
      {
        buffer.append(array[i]);
      }
    }
    if (buffer.length() != 0) {
      list.add(buffer.toString());
    }
    return (String[])list.toArray(new String[list.size()]);
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.io.FilenameUtils
 * Java Class Version: 1.3 (47.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.io;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.StringTokenizer;

public class FileSystemUtils
{
  private static final FileSystemUtils INSTANCE = new FileSystemUtils();
  private static final int INIT_PROBLEM = -1;
  private static final int OTHER = 0;
  private static final int WINDOWS = 1;
  private static final int UNIX = 2;
  private static final int POSIX_UNIX = 3;
  private static final int OS;
  
  static
  {
    int os = 0;
    try
    {
      String osName = System.getProperty("os.name");
      if (osName == null) {
        throw new IOException("os.name not found");
      }
      osName = osName.toLowerCase();
      if (osName.indexOf("windows") != -1) {
        os = 1;
      } else if ((osName.indexOf("linux") != -1) || (osName.indexOf("sun os") != -1) || (osName.indexOf("sunos") != -1) || (osName.indexOf("solaris") != -1) || (osName.indexOf("mpe/ix") != -1) || (osName.indexOf("freebsd") != -1) || (osName.indexOf("irix") != -1) || (osName.indexOf("digital unix") != -1) || (osName.indexOf("unix") != -1) || (osName.indexOf("mac os x") != -1)) {
        os = 2;
      } else if ((osName.indexOf("hp-ux") != -1) || (osName.indexOf("aix") != -1)) {
        os = 3;
      } else {
        os = 0;
      }
    }
    catch (Exception ex)
    {
      os = -1;
    }
    OS = os;
  }
  
  /**
   * @deprecated
   */
  public static long freeSpace(String path)
    throws IOException
  {
    return INSTANCE.freeSpaceOS(path, OS, false);
  }
  
  public static long freeSpaceKb(String path)
    throws IOException
  {
    return INSTANCE.freeSpaceOS(path, OS, true);
  }
  
  long freeSpaceOS(String path, int os, boolean kb)
    throws IOException
  {
    if (path == null) {
      throw new IllegalArgumentException("Path must not be empty");
    }
    switch (os)
    {
    case 1: 
      return kb ? freeSpaceWindows(path) / 1024L : freeSpaceWindows(path);
    case 2: 
      return freeSpaceUnix(path, kb, false);
    case 3: 
      return freeSpaceUnix(path, kb, true);
    case 0: 
      throw new IllegalStateException("Unsupported operating system");
    }
    throw new IllegalStateException("Exception caught when determining operating system");
  }
  
  long freeSpaceWindows(String path)
    throws IOException
  {
    path = FilenameUtils.normalize(path);
    if ((path.length() > 2) && (path.charAt(1) == ':')) {
      path = path.substring(0, 2);
    }
    String[] cmdAttribs = { "cmd.exe", "/C", "dir /-c " + path };
    
    List lines = performCommand(cmdAttribs, Integer.MAX_VALUE);
    for (int i = lines.size() - 1; i >= 0; i--)
    {
      String line = (String)lines.get(i);
      if (line.length() > 0) {
        return parseDir(line, path);
      }
    }
    throw new IOException("Command line 'dir /-c' did not return any info for path '" + path + "'");
  }
  
  long parseDir(String line, String path)
    throws IOException
  {
    int bytesStart = 0;
    int bytesEnd = 0;
    int j = line.length() - 1;
    while (j >= 0)
    {
      char c = line.charAt(j);
      if (Character.isDigit(c))
      {
        bytesEnd = j + 1;
        break;
      }
      j--;
    }
    while (j >= 0)
    {
      char c = line.charAt(j);
      if ((!Character.isDigit(c)) && (c != ',') && (c != '.'))
      {
        bytesStart = j + 1;
        break;
      }
      j--;
    }
    if (j < 0) {
      throw new IOException("Command line 'dir /-c' did not return valid info for path '" + path + "'");
    }
    StringBuffer buf = new StringBuffer(line.substring(bytesStart, bytesEnd));
    for (int k = 0; k < buf.length(); k++) {
      if ((buf.charAt(k) == ',') || (buf.charAt(k) == '.')) {
        buf.deleteCharAt(k--);
      }
    }
    return parseBytes(buf.toString(), path);
  }
  
  long freeSpaceUnix(String path, boolean kb, boolean posix)
    throws IOException
  {
    if (path.length() == 0) {
      throw new IllegalArgumentException("Path must not be empty");
    }
    path = FilenameUtils.normalize(path);
    
    String flags = "-";
    if (kb) {
      flags = flags + "k";
    }
    if (posix) {
      flags = flags + "P";
    }
    String[] cmdAttribs = { "df", flags.length() > 1 ? new String[] { "df", flags, path } : path };
    
    List lines = performCommand(cmdAttribs, 3);
    if (lines.size() < 2) {
      throw new IOException("Command line 'df' did not return info as expected for path '" + path + "'- response was " + lines);
    }
    String line2 = (String)lines.get(1);
    
    StringTokenizer tok = new StringTokenizer(line2, " ");
    if (tok.countTokens() < 4)
    {
      if ((tok.countTokens() == 1) && (lines.size() >= 3))
      {
        String line3 = (String)lines.get(2);
        tok = new StringTokenizer(line3, " ");
      }
      else
      {
        throw new IOException("Command line 'df' did not return data as expected for path '" + path + "'- check path is valid");
      }
    }
    else {
      tok.nextToken();
    }
    tok.nextToken();
    tok.nextToken();
    String freeSpace = tok.nextToken();
    return parseBytes(freeSpace, path);
  }
  
  long parseBytes(String freeSpace, String path)
    throws IOException
  {
    try
    {
      long bytes = Long.parseLong(freeSpace);
      if (bytes < 0L) {
        throw new IOException("Command line 'df' did not find free space in response for path '" + path + "'- check path is valid");
      }
      return bytes;
    }
    catch (NumberFormatException ex)
    {
      throw new IOException("Command line 'df' did not return numeric data as expected for path '" + path + "'- check path is valid");
    }
  }
  
  List performCommand(String[] cmdAttribs, int max)
    throws IOException
  {
    List lines = new ArrayList(20);
    Process proc = null;
    InputStream in = null;
    OutputStream out = null;
    InputStream err = null;
    BufferedReader inr = null;
    try
    {
      proc = openProcess(cmdAttribs);
      in = proc.getInputStream();
      out = proc.getOutputStream();
      err = proc.getErrorStream();
      inr = new BufferedReader(new InputStreamReader(in));
      String line = inr.readLine();
      while ((line != null) && (lines.size() < max))
      {
        line = line.toLowerCase().trim();
        lines.add(line);
        line = inr.readLine();
      }
      proc.waitFor();
      if (proc.exitValue() != 0) {
        throw new IOException("Command line returned OS error code '" + proc.exitValue() + "' for command " + Arrays.asList(cmdAttribs));
      }
      if (lines.size() == 0) {
        throw new IOException("Command line did not return any info for command " + Arrays.asList(cmdAttribs));
      }
      return lines;
    }
    catch (InterruptedException ex)
    {
      throw new IOException("Command line threw an InterruptedException '" + ex.getMessage() + "' for command " + Arrays.asList(cmdAttribs));
    }
    finally
    {
      IOUtils.closeQuietly(in);
      IOUtils.closeQuietly(out);
      IOUtils.closeQuietly(err);
      IOUtils.closeQuietly(inr);
      if (proc != null) {
        proc.destroy();
      }
    }
  }
  
  Process openProcess(String[] cmdAttribs)
    throws IOException
  {
    return Runtime.getRuntime().exec(cmdAttribs);
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.io.FileSystemUtils
 * Java Class Version: 1.3 (47.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.io;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URL;
import java.util.Collection;
import java.util.Date;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.zip.CRC32;
import java.util.zip.CheckedInputStream;
import java.util.zip.Checksum;
import org.apache.commons.io.filefilter.DirectoryFileFilter;
import org.apache.commons.io.filefilter.FalseFileFilter;
import org.apache.commons.io.filefilter.FileFilterUtils;
import org.apache.commons.io.filefilter.IOFileFilter;
import org.apache.commons.io.filefilter.SuffixFileFilter;
import org.apache.commons.io.filefilter.TrueFileFilter;
import org.apache.commons.io.output.NullOutputStream;

public class FileUtils
{
  public static final long ONE_KB = 1024L;
  public static final long ONE_MB = 1048576L;
  public static final long ONE_GB = 1073741824L;
  public static final File[] EMPTY_FILE_ARRAY = new File[0];
  
  public static FileInputStream openInputStream(File file)
    throws IOException
  {
    if (file.exists())
    {
      if (file.isDirectory()) {
        throw new IOException("File '" + file + "' exists but is a directory");
      }
      if (!file.canRead()) {
        throw new IOException("File '" + file + "' cannot be read");
      }
    }
    else
    {
      throw new FileNotFoundException("File '" + file + "' does not exist");
    }
    return new FileInputStream(file);
  }
  
  public static FileOutputStream openOutputStream(File file)
    throws IOException
  {
    if (file.exists())
    {
      if (file.isDirectory()) {
        throw new IOException("File '" + file + "' exists but is a directory");
      }
      if (!file.canWrite()) {
        throw new IOException("File '" + file + "' cannot be written to");
      }
    }
    else
    {
      File parent = file.getParentFile();
      if ((parent != null) && (!parent.exists()) && 
        (!parent.mkdirs())) {
        throw new IOException("File '" + file + "' could not be created");
      }
    }
    return new FileOutputStream(file);
  }
  
  public static String byteCountToDisplaySize(long size)
  {
    String displaySize;
    String displaySize;
    if (size / 1073741824L > 0L)
    {
      displaySize = String.valueOf(size / 1073741824L) + " GB";
    }
    else
    {
      String displaySize;
      if (size / 1048576L > 0L)
      {
        displaySize = String.valueOf(size / 1048576L) + " MB";
      }
      else
      {
        String displaySize;
        if (size / 1024L > 0L) {
          displaySize = String.valueOf(size / 1024L) + " KB";
        } else {
          displaySize = String.valueOf(size) + " bytes";
        }
      }
    }
    return displaySize;
  }
  
  public static void touch(File file)
    throws IOException
  {
    if (!file.exists())
    {
      OutputStream out = openOutputStream(file);
      IOUtils.closeQuietly(out);
    }
    boolean success = file.setLastModified(System.currentTimeMillis());
    if (!success) {
      throw new IOException("Unable to set the last modification time for " + file);
    }
  }
  
  public static File[] convertFileCollectionToFileArray(Collection files)
  {
    return (File[])files.toArray(new File[files.size()]);
  }
  
  private static void innerListFiles(Collection files, File directory, IOFileFilter filter)
  {
    File[] found = directory.listFiles(filter);
    if (found != null) {
      for (int i = 0; i < found.length; i++) {
        if (found[i].isDirectory()) {
          innerListFiles(files, found[i], filter);
        } else {
          files.add(found[i]);
        }
      }
    }
  }
  
  public static Collection listFiles(File directory, IOFileFilter fileFilter, IOFileFilter dirFilter)
  {
    if (!directory.isDirectory()) {
      throw new IllegalArgumentException("Parameter 'directory' is not a directory");
    }
    if (fileFilter == null) {
      throw new NullPointerException("Parameter 'fileFilter' is null");
    }
    IOFileFilter effFileFilter = FileFilterUtils.andFileFilter(fileFilter, FileFilterUtils.notFileFilter(DirectoryFileFilter.INSTANCE));
    IOFileFilter effDirFilter;
    IOFileFilter effDirFilter;
    if (dirFilter == null) {
      effDirFilter = FalseFileFilter.INSTANCE;
    } else {
      effDirFilter = FileFilterUtils.andFileFilter(dirFilter, DirectoryFileFilter.INSTANCE);
    }
    Collection files = new LinkedList();
    innerListFiles(files, directory, FileFilterUtils.orFileFilter(effFileFilter, effDirFilter));
    
    return files;
  }
  
  public static Iterator iterateFiles(File directory, IOFileFilter fileFilter, IOFileFilter dirFilter)
  {
    return listFiles(directory, fileFilter, dirFilter).iterator();
  }
  
  private static String[] toSuffixes(String[] extensions)
  {
    String[] suffixes = new String[extensions.length];
    for (int i = 0; i < extensions.length; i++) {
      suffixes[i] = ("." + extensions[i]);
    }
    return suffixes;
  }
  
  public static Collection listFiles(File directory, String[] extensions, boolean recursive)
  {
    IOFileFilter filter;
    IOFileFilter filter;
    if (extensions == null)
    {
      filter = TrueFileFilter.INSTANCE;
    }
    else
    {
      String[] suffixes = toSuffixes(extensions);
      filter = new SuffixFileFilter(suffixes);
    }
    return listFiles(directory, filter, recursive ? TrueFileFilter.INSTANCE : FalseFileFilter.INSTANCE);
  }
  
  public static Iterator iterateFiles(File directory, String[] extensions, boolean recursive)
  {
    return listFiles(directory, extensions, recursive).iterator();
  }
  
  public static boolean contentEquals(File file1, File file2)
    throws IOException
  {
    boolean file1Exists = file1.exists();
    if (file1Exists != file2.exists()) {
      return false;
    }
    if (!file1Exists) {
      return true;
    }
    if ((file1.isDirectory()) || (file2.isDirectory())) {
      throw new IOException("Can't compare directories, only files");
    }
    if (file1.length() != file2.length()) {
      return false;
    }
    if (file1.getCanonicalFile().equals(file2.getCanonicalFile())) {
      return true;
    }
    InputStream input1 = null;
    InputStream input2 = null;
    try
    {
      input1 = new FileInputStream(file1);
      input2 = new FileInputStream(file2);
      return IOUtils.contentEquals(input1, input2);
    }
    finally
    {
      IOUtils.closeQuietly(input1);
      IOUtils.closeQuietly(input2);
    }
  }
  
  public static File toFile(URL url)
  {
    if ((url == null) || (!url.getProtocol().equals("file"))) {
      return null;
    }
    String filename = url.getFile().replace('/', File.separatorChar);
    int pos = 0;
    while ((pos = filename.indexOf('%', pos)) >= 0) {
      if (pos + 2 < filename.length())
      {
        String hexStr = filename.substring(pos + 1, pos + 3);
        char ch = (char)Integer.parseInt(hexStr, 16);
        filename = filename.substring(0, pos) + ch + filename.substring(pos + 3);
      }
    }
    return new File(filename);
  }
  
  public static File[] toFiles(URL[] urls)
  {
    if ((urls == null) || (urls.length == 0)) {
      return EMPTY_FILE_ARRAY;
    }
    File[] files = new File[urls.length];
    for (int i = 0; i < urls.length; i++)
    {
      URL url = urls[i];
      if (url != null)
      {
        if (!url.getProtocol().equals("file")) {
          throw new IllegalArgumentException("URL could not be converted to a File: " + url);
        }
        files[i] = t
1 2 3 4

Further reading...

For more information on Java 1.5 Tiger, you may find Java 1.5 Tiger, A developer's Notebook by D. Flanagan and B. McLaughlin from O'Reilly of interest.

New!JAR listings


Copyright 2006-2019. Infinite Loop Ltd