com.crashlytics.tools.android_2.1.0

ir, File destDir, FileFilter filter, boolean preserveFileDate, List<String> exclusionList)
    throws IOException
  {
    File[] srcFiles = filter == null ? srcDir.listFiles() : srcDir.listFiles(filter);
    if (srcFiles == null) {
      throw new IOException("Failed to list contents of " + srcDir);
    }
    if (destDir.exists())
    {
      if (!destDir.isDirectory()) {
        throw new IOException("Destination '" + destDir + "' exists but is not a directory");
      }
    }
    else if ((!destDir.mkdirs()) && (!destDir.isDirectory())) {
      throw new IOException("Destination '" + destDir + "' directory cannot be created");
    }
    if (!destDir.canWrite()) {
      throw new IOException("Destination '" + destDir + "' cannot be written to");
    }
    for (File srcFile : srcFiles)
    {
      File dstFile = new File(destDir, srcFile.getName());
      if ((exclusionList == null) || (!exclusionList.contains(srcFile.getCanonicalPath()))) {
        if (srcFile.isDirectory()) {
          doCopyDirectory(srcFile, dstFile, filter, preserveFileDate, exclusionList);
        } else {
          doCopyFile(srcFile, dstFile, preserveFileDate);
        }
      }
    }
    if (preserveFileDate) {
      destDir.setLastModified(srcDir.lastModified());
    }
  }
  
  public static void copyURLToFile(URL source, File destination)
    throws IOException
  {
    InputStream input = source.openStream();
    copyInputStreamToFile(input, destination);
  }
  
  public static void copyURLToFile(URL source, File destination, int connectionTimeout, int readTimeout)
    throws IOException
  {
    URLConnection connection = source.openConnection();
    connection.setConnectTimeout(connectionTimeout);
    connection.setReadTimeout(readTimeout);
    InputStream input = connection.getInputStream();
    copyInputStreamToFile(input, destination);
  }
  
  public static void copyInputStreamToFile(InputStream source, File destination)
    throws IOException
  {
    try
    {
      FileOutputStream output = openOutputStream(destination);
      try
      {
        IOUtils.copy(source, output);
        output.close();
      }
      finally {}
    }
    finally
    {
      IOUtils.closeQuietly(source);
    }
  }
  
  public static void deleteDirectory(File directory)
    throws IOException
  {
    if (!directory.exists()) {
      return;
    }
    if (!isSymlink(directory)) {
      cleanDirectory(directory);
    }
    if (!directory.delete())
    {
      String message = "Unable to delete directory " + directory + ".";
      
      throw new IOException(message);
    }
  }
  
  public static boolean deleteQuietly(File file)
  {
    if (file == null) {
      return false;
    }
    try
    {
      if (file.isDirectory()) {
        cleanDirectory(file);
      }
    }
    catch (Exception ignored) {}
    try
    {
      return file.delete();
    }
    catch (Exception ignored) {}
    return false;
  }
  
  public static boolean directoryContains(File directory, File child)
    throws IOException
  {
    if (directory == null) {
      throw new IllegalArgumentException("Directory must not be null");
    }
    if (!directory.isDirectory()) {
      throw new IllegalArgumentException("Not a directory: " + directory);
    }
    if (child == null) {
      return false;
    }
    if ((!directory.exists()) || (!child.exists())) {
      return false;
    }
    String canonicalParent = directory.getCanonicalPath();
    String canonicalChild = child.getCanonicalPath();
    
    return FilenameUtils.directoryContains(canonicalParent, canonicalChild);
  }
  
  public static void cleanDirectory(File directory)
    throws IOException
  {
    if (!directory.exists())
    {
      String message = directory + " does not exist";
      throw new IllegalArgumentException(message);
    }
    if (!directory.isDirectory())
    {
      String message = directory + " is not a directory";
      throw new IllegalArgumentException(message);
    }
    File[] files = directory.listFiles();
    if (files == null) {
      throw new IOException("Failed to list contents of " + directory);
    }
    IOException exception = null;
    for (File file : files) {
      try
      {
        forceDelete(file);
      }
      catch (IOException ioe)
      {
        exception = ioe;
      }
    }
    if (null != exception) {
      throw exception;
    }
  }
  
  public static boolean waitFor(File file, int seconds)
  {
    int timeout = 0;
    int tick = 0;
    for (;;)
    {
      if (!file.exists())
      {
        if (tick++ >= 10)
        {
          tick = 0;
          if (timeout++ > seconds) {
            return false;
          }
        }
        try
        {
          Thread.sleep(100L);
        }
        catch (InterruptedException ignore) {}catch (Exception ex) {}
      }
    }
    return true;
  }
  
  public static String readFileToString(File file, Charset encoding)
    throws IOException
  {
    InputStream in = null;
    try
    {
      in = openInputStream(file);
      return IOUtils.toString(in, Charsets.toCharset(encoding));
    }
    finally
    {
      IOUtils.closeQuietly(in);
    }
  }
  
  public static String readFileToString(File file, String encoding)
    throws IOException
  {
    return readFileToString(file, Charsets.toCharset(encoding));
  }
  
  public static String readFileToString(File file)
    throws IOException
  {
    return readFileToString(file, Charset.defaultCharset());
  }
  
  public static byte[] readFileToByteArray(File file)
    throws IOException
  {
    InputStream in = null;
    try
    {
      in = openInputStream(file);
      return IOUtils.toByteArray(in, file.length());
    }
    finally
    {
      IOUtils.closeQuietly(in);
    }
  }
  
  public static List<String> readLines(File file, Charset encoding)
    throws IOException
  {
    InputStream in = null;
    try
    {
      in = openInputStream(file);
      return IOUtils.readLines(in, Charsets.toCharset(encoding));
    }
    finally
    {
      IOUtils.closeQuietly(in);
    }
  }
  
  public static List<String> readLines(File file, String encoding)
    throws IOException
  {
    return readLines(file, Charsets.toCharset(encoding));
  }
  
  public static List<String> readLines(File file)
    throws IOException
  {
    return readLines(file, Charset.defaultCharset());
  }
  
  public static LineIterator lineIterator(File file, String encoding)
    throws IOException
  {
    InputStream in = null;
    try
    {
      in = openInputStream(file);
      return IOUtils.lineIterator(in, encoding);
    }
    catch (IOException ex)
    {
      IOUtils.closeQuietly(in);
      throw ex;
    }
    catch (RuntimeException ex)
    {
      IOUtils.closeQuietly(in);
      throw ex;
    }
  }
  
  public static LineIterator lineIterator(File file)
    throws IOException
  {
    return lineIterator(file, null);
  }
  
  public static void writeStringToFile(File file, String data, Charset encoding)
    throws IOException
  {
    writeStringToFile(file, data, encoding, false);
  }
  
  public static void writeStringToFile(File file, String data, String encoding)
    throws IOException
  {
    writeStringToFile(file, data, encoding, false);
  }
  
  public static void writeStringToFile(File file, String data, Charset encoding, boolean append)
    throws IOException
  {
    OutputStream out = null;
    try
    {
      out = openOutputStream(file, append);
      IOUtils.write(data, out, encoding);
      out.close();
    }
    finally
    {
      IOUtils.closeQuietly(out);
    }
  }
  
  public static void writeStringToFile(File file, String data, String encoding, boolean append)
    throws IOException
  {
    writeStringToFile(file, data, Charsets.toCharset(encoding), append);
  }
  
  public static void writeStringToFile(File file, String data)
    throws IOException
  {
    writeStringToFile(file, data, Charset.defaultCharset(), false);
  }
  
  public static void writeStringToFile(File file, String data, boolean append)
    throws IOException
  {
    writeStringToFile(file, data, Charset.defaultCharset(), append);
  }
  
  public static void write(File file, CharSequence data)
    throws IOException
  {
    write(file, data, Charset.defaultCharset(), false);
  }
  
  public static void write(File file, CharSequence data, boolean append)
    throws IOException
  {
    write(file, data, Charset.defaultCharset(), append);
  }
  
  public static void write(File file, CharSequence data, Charset encoding)
    throws IOException
  {
    write(file, data, encoding, false);
  }
  
  public static void write(File file, CharSequence data, String encoding)
    throws IOException
  {
    write(file, data, encoding, false);
  }
  
  public static void write(File file, CharSequence data, Charset encoding, boolean append)
    throws IOException
  {
    String str = data == null ? null : data.toString();
    writeStringToFile(file, str, encoding, append);
  }
  
  public static void write(File file, CharSequence data, String encoding, boolean append)
    throws IOException
  {
    write(file, data, Charsets.toCharset(encoding), append);
  }
  
  public static void writeByteArrayToFile(File file, byte[] data)
    throws IOException
  {
    writeByteArrayToFile(file, data, false);
  }
  
  public static void writeByteArrayToFile(File file, byte[] data, boolean append)
    throws IOException
  {
    OutputStream out = null;
    try
    {
      out = openOutputStream(file, append);
      out.write(data);
      out.close();
    }
    finally
    {
      IOUtils.closeQuietly(out);
    }
  }
  
  public static void writeLines(File file, String encoding, Collection<?> lines)
    throws IOException
  {
    writeLines(file, encoding, lines, null, false);
  }
  
  public static void writeLines(File file, String encoding, Collection<?> lines, boolean append)
    throws IOException
  {
    writeLines(file, encoding, lines, null, append);
  }
  
  public static void writeLines(File file, Collection<?> lines)
    throws IOException
  {
    writeLines(file, null, lines, null, false);
  }
  
  public static void writeLines(File file, Collection<?> lines, boolean append)
    throws IOException
  {
    writeLines(file, null, lines, null, append);
  }
  
  public static void writeLines(File file, String encoding, Collection<?> lines, String lineEnding)
    throws IOException
  {
    writeLines(file, encoding, lines, lineEnding, false);
  }
  
  public static void writeLines(File file, String encoding, Collection<?> lines, String lineEnding, boolean append)
    throws IOException
  {
    FileOutputStream out = null;
    try
    {
      out = openOutputStream(file, append);
      BufferedOutputStream buffer = new BufferedOutputStream(out);
      IOUtils.writeLines(lines, lineEnding, buffer, encoding);
      buffer.flush();
      out.close();
    }
    finally
    {
      IOUtils.closeQuietly(out);
    }
  }
  
  public static void writeLines(File file, Collection<?> lines, String lineEnding)
    throws IOException
  {
    writeLines(file, null, lines, lineEnding, false);
  }
  
  public static void writeLines(File file, Collection<?> lines, String lineEnding, boolean append)
    throws IOException
  {
    writeLines(file, null, lines, lineEnding, append);
  }
  
  public static void forceDelete(File file)
    throws IOException
  {
    if (file.isDirectory())
    {
      deleteDirectory(file);
    }
    else
    {
      boolean filePresent = file.exists();
      if (!file.delete())
      {
        if (!filePresent) {
          throw new FileNotFoundException("File does not exist: " + file);
        }
        String message = "Unable to delete file: " + file;
        
        throw new IOException(message);
      }
    }
  }
  
  public static void forceDeleteOnExit(File file)
    throws IOException
  {
    if (file.isDirectory()) {
      deleteDirectoryOnExit(file);
    } else {
      file.deleteOnExit();
    }
  }
  
  private static void deleteDirectoryOnExit(File directory)
    throws IOException
  {
    if (!directory.exists()) {
      return;
    }
    directory.deleteOnExit();
    if (!isSymlink(directory)) {
      cleanDirectoryOnExit(directory);
    }
  }
  
  private static void cleanDirectoryOnExit(File directory)
    throws IOException
  {
    if (!directory.exists())
    {
      String message = directory + " does not exist";
      throw new IllegalArgumentException(message);
    }
    if (!directory.isDirectory())
    {
      String message = directory + " is not a directory";
      throw new IllegalArgumentException(message);
    }
    File[] files = directory.listFiles();
    if (files == null) {
      throw new IOException("Failed to list contents of " + directory);
    }
    IOException exception = null;
    for (File file : files) {
      try
      {
        forceDeleteOnExit(file);
      }
      catch (IOException ioe)
      {
        exception = ioe;
      }
    }
    if (null != exception) {
      throw exception;
    }
  }
  
  public static void forceMkdir(File directory)
    throws IOException
  {
    if (directory.exists())
    {
      if (!directory.isDirectory())
      {
        String message = "File " + directory + " exists and is " + "not a directory. Unable to create directory.";
        
        throw new IOException(message);
      }
    }
    else if (!directory.mkdirs()) {
      if (!directory.isDirectory())
      {
        String message = "Unable to create directory " + directory;
        
        throw new IOException(message);
      }
    }
  }
  
  public static long sizeOf(File file)
  {
    if (!file.exists())
    {
      String message = file + " does not exist";
      throw new IllegalArgumentException(message);
    }
    if (file.isDirectory()) {
      return sizeOfDirectory(file);
    }
    return file.length();
  }
  
  public static BigInteger sizeOfAsBigInteger(File file)
  {
    if (!file.exists())
    {
      String message = file + " does not exist";
      throw new IllegalArgumentException(message);
    }
    if (file.isDirectory()) {
      return sizeOfDirectoryAsBigInteger(file);
    }
    return BigInteger.valueOf(file.length());
  }
  
  public static long sizeOfDirectory(File directory)
  {
    checkDirectory(directory);
    
    File[] files = directory.listFiles();
    if (files == null) {
      return 0L;
    }
    long size = 0L;
    for (File file : files) {
      try
      {
        if (!isSymlink(file))
        {
          size += sizeOf(file);
          if (size < 0L) {
            break;
          }
        }
      }
      catch (IOException ioe) {}
    }
    return size;
  }
  
  public static BigInteger sizeOfDirectoryAsBigInteger(File directory)
  {
    checkDirectory(directory);
    
    File[] files = directory.listFiles();
    if (files == null) {
      return BigInteger.ZERO;
    }
    BigInteger size = BigInteger.ZERO;
    for (File file : files) {
      try
      {
        if (!isSymlink(file)) {
          size = size.add(BigInteger.valueOf(sizeOf(file)));
        }
      }
      catch (IOException ioe) {}
    }
    return size;
  }
  
  private static void checkDirectory(File directory)
  {
    if (!directory.exists()) {
      throw new IllegalArgumentException(directory + " does not exist");
    }
    if (!directory.isDirectory()) {
      throw new IllegalArgumentException(directory + " is not a directory");
    }
  }
  
  public static boolean isFileNewer(File file, File reference)
  {
    if (reference == null) {
      throw new IllegalArgumentException("No specified reference file");
    }
    if (!reference.exists()) {
      throw new IllegalArgumentException("The reference file '" + reference + "' doesn't exist");
    }
    return isFileNewer(file, reference.lastModified());
  }
  
  public static boolean isFileNewer(File file, Date date)
  {
    if (date == null) {
      throw new IllegalArgumentException("No specified date");
    }
    return isFileNewer(file, date.getTime());
  }
  
  public static boolean isFileNewer(File file, long timeMillis)
  {
    if (file == null) {
      throw new IllegalArgumentException("No specified file");
    }
    if (!file.exists()) {
      return false;
    }
    return file.lastModified() > timeMillis;
  }
  
  public static boolean isFileOlder(File file, File reference)
  {
    if (reference == null) {
      throw new IllegalArgumentException("No specified reference file");
    }
    if (!reference.exists()) {
      throw new IllegalArgumentException("The reference file '" + reference + "' doesn't exist");
    }
    return isFileOlder(file, reference.lastModified());
  }
  
  public static boolean isFileOlder(File file, Date date)
  {
    if (date == null) {
      throw new IllegalArgumentException("No specified date");
    }
    return isFileOlder(file, date.getTime());
  }
  
  public static boolean isFileOlder(File file, long timeMillis)
  {
    if (file == null) {
      throw new IllegalArgumentException("No specified file");
    }
    if (!file.exists()) {
      return false;
    }
    return file.lastModified() < timeMillis;
  }
  
  public static long checksumCRC32(File file)
    throws IOException
  {
    CRC32 crc = new CRC32();
    checksum(file, crc);
    return crc.getValue();
  }
  
  public static Checksum checksum(File file, Checksum checksum)
    throws IOException
  {
    if (file.isDirectory()) {
      throw new IllegalArgumentException("Checksums can't be computed on directories");
    }
    InputStream in = null;
    try
    {
      in = new CheckedInputStream(new FileInputStream(file), checksum);
      IOUtils.copy(in, new NullOutputStream());
    }
    finally
    {
      IOUtils.closeQuietly(in);
    }
    return checksum;
  }
  
  public static void moveDirectory(File srcDir, File destDir)
    throws IOException
  {
    if (srcDir == null) {
      throw new NullPointerException("Source must not be null");
    }
    if (destDir == null) {
      throw new NullPointerException("Destination must not be null");
    }
    if (!srcDir.exists()) {
      throw new FileNotFoundException("Source '" + srcDir + "' does not exist");
    }
    if (!srcDir.isDirectory()) {
      throw new IOException("Source '" + srcDir + "' is not a directory");
    }
    if (destDir.exists()) {
      throw new FileExistsException("Destination '" + destDir + "' already exists");
    }
    boolean rename = srcDir.renameTo(destDir);
    if (!rename)
    {
      if (destDir.getCanonicalPath().startsWith(srcDir.getCanonicalPath())) {
        throw new IOException("Cannot move directory: " + srcDir + " to a subdirectory of itself: " + destDir);
      }
      copyDirectory(srcDir, destDir);
      deleteDirectory(srcDir);
      if (srcDir.exists()) {
        throw new IOException("Failed to delete original directory '" + srcDir + "' after copy to '" + destDir + "'");
      }
    }
  }
  
  public static void moveDirectoryToDirectory(File src, File destDir, boolean createDestDir)
    throws IOException
  {
    if (src == null) {
      throw new NullPointerException("Source must not be null");
    }
    if (destDir == null) {
      throw new NullPointerException("Destination directory must not be null");
    }
    if ((!destDir.exists()) && (createDestDir)) {
      destDir.mkdirs();
    }
    if (!destDir.exists()) {
      throw new FileNotFoundException("Destination directory '" + destDir + "' does not exist [createDestDir=" + createDestDir + "]");
    }
    if (!destDir.isDirectory()) {
      throw new IOException("Destination '" + destDir + "' is not a directory");
    }
    moveDirectory(src, new File(destDir, src.getName()));
  }
  
  public static void moveFile(File srcFile, File destFile)
    throws IOException
  {
    if (srcFile == null) {
      throw new NullPointerException("Source must not be null");
    }
    if (destFile == null) {
      throw new NullPointerException("Destination must not be null");
    }
    if (!srcFile.exists()) {
      throw new FileNotFoundException("Source '" + srcFile + "' does not exist");
    }
    if (srcFile.isDirectory()) {
      throw new IOException("Source '" + srcFile + "' is a directory");
    }
    if (destFile.exists()) {
      throw new FileExistsException("Destination '" + destFile + "' already exists");
    }
    if (destFile.isDirectory()) {
      throw new IOException("Destination '" + destFile + "' is a directory");
    }
    boolean rename = srcFile.renameTo(destFile);
    if (!rename)
    {
      copyFile(srcFile, destFile);
      if (!srcFile.delete())
      {
        deleteQuietly(destFile);
        throw new IOException("Failed to delete original file '" + srcFile + "' after copy to '" + destFile + "'");
      }
    }
  }
  
  public static void moveFileToDirectory(File srcFile, File destDir, boolean createDestDir)
    throws IOException
  {
    if (srcFile == null) {
      throw new NullPointerException("Source must not be null");
    }
    if (destDir == null) {
      throw new NullPointerException("Destination directory must not be null");
    }
    if ((!destDir.exists()) && (createDestDir)) {
      destDir.mkdirs();
    }
    if (!destDir.exists()) {
      throw new FileNotFoundException("Destination directory '" + destDir + "' does not exist [createDestDir=" + createDestDir + "]");
    }
    if (!destDir.isDirectory()) {
      throw new IOException("Destination '" + destDir + "' is not a directory");
    }
    moveFile(srcFile, new File(destDir, srcFile.getName()));
  }
  
  public static void moveToDirectory(File src, File destDir, boolean createDestDir)
    throws IOException
  {
    if (src == null) {
      throw new NullPointerException("Source must not be null");
    }
    if (destDir == null) {
      throw new NullPointerException("Destination must not be null");
    }
    if (!src.exists()) {
      throw new FileNotFoundException("Source '" + src + "' does not exist");
    }
    if (src.isDirectory()) {
      moveDirectoryToDirectory(src, destDir, createDestDir);
    } else {
      moveFileToDirectory(src, destDir, createDestDir);
    }
  }
  
  public static boolean isSymlink(File file)
    throws IOException
  {
    if (file == null) {
      throw new NullPointerException("File must not be null");
    }
    if (FilenameUtils.isSystemWindows()) {
      return false;
    }
    File fileInCanonicalDir = null;
    if (file.getParent() == null)
    {
      fileInCanonicalDir = file;
    }
    else
    {
      File canonicalDir = file.getParentFile().getCanonicalFile();
      fileInCanonicalDir = new File(canonicalDir, file.getName());
    }
    if (fileInCanonicalDir.getCanonicalFile().equals(fileInCanonicalDir.getAbsoluteFile())) {
      return false;
    }
    return true;
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.io.FileUtils
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.io;

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

public class FilenameUtils
{
  public static final char EXTENSION_SEPARATOR = '.';
  public static final String EXTENSION_SEPARATOR_STR = Character.toString('.');
  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, SYSTEM_SEPARATOR, true);
  }
  
  public static String normalize(String filename, boolean unixSeparator)
  {
    char separator = unixSeparator ? '/' : '\\';
    return doNormalize(filename, separator, true);
  }
  
  public static String normalizeNoEndSeparator(String filename)
  {
    return doNormalize(filename, SYSTEM_SEPARATOR, false);
  }
  
  public static String normalizeNoEndSeparator(String filename, boolean unixSeparator)
  {
    char separator = unixSeparator ? '/' : '\\';
    return doNormalize(filename, separator, false);
  }
  
  private static String doNormalize(String filename, char separator, 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);
    
    char otherSeparator = separator == SYSTEM_SEPARATOR ? OTHER_SEPARATOR : SYSTEM_SEPARATOR;
    for (int i = 0; i < array.length; i++) {
      if (array[i] == otherSeparator) {
        array[i] = separator;
      }
    }
    boolean lastIsDirectory = true;
    if (array[(size - 1)] != separator)
    {
      array[(size++)] = separator;
      lastIsDirectory = false;
    }
    for (int i = prefix + 1; i < size; i++) {
      if ((array[i] == separator) && (array[(i - 1)] == separator))
      {
        System.arraycopy(array, i, array, i - 1, size - i);
        size--;
        i--;
      }
    }
    for (int i = prefix + 1; i < size; i++) {
      if ((array[i] == separator) && (array[(i - 1)] == '.') && ((i == prefix + 1) || (array[(i - 2)] == separator)))
      {
        if (i == size - 1) {
          lastIsDirectory = true;
        }
        System.arraycopy(array, i + 1, array, i - 1, size - i);
        size -= 2;
        i--;
      }
    }
    label464:
    for (int i = prefix + 2; i < size; i++) {
      if ((array[i] == separator) && (array[(i - 1)] == '.') && (array[(i - 2)] == '.') && ((i == prefix + 2) || (array[(i - 3)] == separator)))
      {
        if (i == prefix + 2) {
          return null;
        }
        if (i == size - 1) {
          lastIsDirectory = true;
        }
        for (int j = i - 4; j >= prefix; j--) {
          if (array[j] == separator)
          {
            System.arraycopy(array, i + 1, array, j + 1, size - i);
            size -= i - j;
            i = j + 1;
            break label464;
          }
        }
        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 boolean directoryContains(String canonicalParent, String canonicalChild)
    throws IOException
  {
    if (canonicalParent == null) {
      throw new IllegalArgumentException("Directory must not be null");
    }
    if (canonicalChild == null) {
      return false;
    }
    if (IOCase.SYSTEM.checkEquals(canonicalParent, canonicalChild)) {
      return false;
    }
    return IOCase.SYSTEM.checkStartsWith(canonicalChild, canonicalParent);
  }
  
  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);
    int endIndex = index + separatorAdd;
    if ((prefix >= filename.length()) || (index < 0) || (prefix >= endIndex)) {
      return "";
    }
    return filename.substring(prefix, endIndex);
  }
  
  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);
    if (end == 0) {
      end++;
    }
    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 == null) && (filename2 == null);
    }
    if (normalized)
    {
      filename1 = normalize(filename1);
      filename2 = normalize(filename2);
      if ((filename1 == null) || (filename2 == null)) {
        throw new NullPointerException("Error normalizing one or both of the file names");
      }
    }
    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 (String extension : extensions) {
      if (fileExt.equals(extension)) {
        return true;
      }
    }
    return false;
  }
  
  public static boolean isExtension(String filename, Collection<String> extensions)
  {
    if (filename == null) {
      return false;
    }
    if ((extensions == null) || (extensions.isEmpty())) {
      return indexOfExtension(filename) == -1;
    }
    String fileExt = getExtension(filename);
    for (String extension : extensions) {
      if (fileExt.equals(extension)) {
        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;
    }
    String[] wcs = splitOnTokens(wildcardMatcher);
    boolean anyChars = false;
    int textIdx = 0;
    int wcsIdx = 0;
    Stack<int[]> 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++;
          if (textIdx > filename.length()) {
            break;
          }
          anyChars = false;
        }
        else if (wcs[wcsIdx].equals("*"))
        {
          anyChars = true;
          if (wcsIdx == wcs.length - 1) {
            textIdx = filename.length();
          }
        }
        else
        {
          if (anyChars)
          {
            textIdx = caseSensitivity.checkIndexOf(filename, textIdx, wcs[wcsIdx]);
            if (textIdx == -1) {
              break;
            }
            int repeat = caseSensitivity.checkIndexOf(filename, textIdx + 1, wcs[wcsIdx]);
            if (repeat >= 0) {
              backtrack.push(new int[] { wcsIdx, repeat });
            }
          }
          else
          {
            if (!caseSensitivity.checkRegionMatches(filename, textIdx, wcs[wcsIdx])) {
              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<String> list = new ArrayList();
    StringBuilder buffer = new StringBuilder();
    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.isEmpty()) || ((i > 0) && (!((String)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: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.io;

import java.io.IOException;
import java.io.OutputStream;

public class HexDump
{
  public static void dump(byte[] data, long offset, OutputStream stream, int index)
    throws IOException, ArrayIndexOutOfBoundsException, IllegalArgumentException
  {
    if ((index < 0) || (index >= data.length)) {
      throw new ArrayIndexOutOfBoundsException("illegal index: " + index + " into array of length " + data.length);
    }
    if (stream == null) {
      throw new IllegalArgumentException("cannot write to nullstream");
    }
    long display_offset = offset + index;
    StringBuilder buffer = new StringBuilder(74);
    for (int j = index; j < data.length; j += 16)
    {
      int chars_read = data.length - j;
      if (chars_read > 16) {
        chars_read = 16;
      }
      dump(buffer, display_offset).append(' ');
      for (int k = 0; k < 16; k++)
      {
        if (k < chars_read) {
          dump(buffer, data[(k + j)]);
        } else {
          buffer.append("  ");
        }
        buffer.append(' ');
      }
      for (int k = 0; k < chars_read; k++) {
        if ((data[(k + j)] >= 32) && (data[(k + j)] < Byte.MAX_VALUE)) {
        
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109

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