org.apache.commons.io_2.0.1.v201105210651

16:41:01.301 INFO  jd.cli.Main - Decompiling org.apache.commons.io_2.0.1.v201105210651.jar
package org.apache.commons.io;

import java.io.Serializable;

public class ByteOrderMark
  implements Serializable
{
  private static final long serialVersionUID = 1L;
  public static final ByteOrderMark UTF_8 = new ByteOrderMark("UTF-8", new int[] { 239, 187, 191 });
  public static final ByteOrderMark UTF_16BE = new ByteOrderMark("UTF-16BE", new int[] { 254, 255 });
  public static final ByteOrderMark UTF_16LE = new ByteOrderMark("UTF-16LE", new int[] { 255, 254 });
  private final String charsetName;
  private final int[] bytes;
  
  public ByteOrderMark(String charsetName, int... bytes)
  {
    if ((charsetName == null) || (charsetName.length() == 0)) {
      throw new IllegalArgumentException("No charsetName specified");
    }
    if ((bytes == null) || (bytes.length == 0)) {
      throw new IllegalArgumentException("No bytes specified");
    }
    this.charsetName = charsetName;
    this.bytes = new int[bytes.length];
    System.arraycopy(bytes, 0, this.bytes, 0, bytes.length);
  }
  
  public String getCharsetName()
  {
    return charsetName;
  }
  
  public int length()
  {
    return bytes.length;
  }
  
  public int get(int pos)
  {
    return bytes[pos];
  }
  
  public byte[] getBytes()
  {
    byte[] copy = new byte[bytes.length];
    for (int i = 0; i < bytes.length; i++) {
      copy[i] = ((byte)bytes[i]);
    }
    return copy;
  }
  
  public boolean equals(Object obj)
  {
    if (!(obj instanceof ByteOrderMark)) {
      return false;
    }
    ByteOrderMark bom = (ByteOrderMark)obj;
    if (bytes.length != bom.length()) {
      return false;
    }
    for (int i = 0; i < bytes.length; i++) {
      if (bytes[i] != bom.get(i)) {
        return false;
      }
    }
    return true;
  }
  
  public int hashCode()
  {
    int hashCode = getClass().hashCode();
    for (int b : bytes) {
      hashCode += b;
    }
    return hashCode;
  }
  
  public String toString()
  {
    StringBuilder builder = new StringBuilder();
    builder.append(getClass().getSimpleName());
    builder.append('[');
    builder.append(charsetName);
    builder.append(": ");
    for (int i = 0; i < bytes.length; i++)
    {
      if (i > 0) {
        builder.append(",");
      }
      builder.append("0x");
      builder.append(Integer.toHexString(0xFF & bytes[i]).toUpperCase());
    }
    builder.append(']');
    return builder.toString();
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.io.ByteOrderMark
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.io;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.Reader;
import java.io.StringReader;
import java.io.Writer;

@Deprecated
public class CopyUtils
{
  private static final int DEFAULT_BUFFER_SIZE = 4096;
  
  public static void copy(byte[] input, OutputStream output)
    throws IOException
  {
    output.write(input);
  }
  
  public static void copy(byte[] input, Writer output)
    throws IOException
  {
    ByteArrayInputStream in = new ByteArrayInputStream(input);
    copy(in, output);
  }
  
  public static void copy(byte[] input, Writer output, String encoding)
    throws IOException
  {
    ByteArrayInputStream in = new ByteArrayInputStream(input);
    copy(in, output, encoding);
  }
  
  public static int copy(InputStream input, OutputStream output)
    throws IOException
  {
    byte[] buffer = new byte['?'];
    int count = 0;
    int n = 0;
    while (-1 != (n = input.read(buffer)))
    {
      output.write(buffer, 0, n);
      count += n;
    }
    return count;
  }
  
  public static int copy(Reader input, Writer output)
    throws IOException
  {
    char[] buffer = new char['?'];
    int count = 0;
    int n = 0;
    while (-1 != (n = input.read(buffer)))
    {
      output.write(buffer, 0, n);
      count += n;
    }
    return count;
  }
  
  public static void copy(InputStream input, Writer output)
    throws IOException
  {
    InputStreamReader in = new InputStreamReader(input);
    copy(in, output);
  }
  
  public static void copy(InputStream input, Writer output, String encoding)
    throws IOException
  {
    InputStreamReader in = new InputStreamReader(input, encoding);
    copy(in, output);
  }
  
  public static void copy(Reader input, OutputStream output)
    throws IOException
  {
    OutputStreamWriter out = new OutputStreamWriter(output);
    copy(input, out);
    
    out.flush();
  }
  
  public static void copy(String input, OutputStream output)
    throws IOException
  {
    StringReader in = new StringReader(input);
    OutputStreamWriter out = new OutputStreamWriter(output);
    copy(in, out);
    
    out.flush();
  }
  
  public static void copy(String input, Writer output)
    throws IOException
  {
    output.write(input);
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.io.CopyUtils
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.io;

import java.io.File;
import java.io.IOException;

public class DirectoryWalker$CancelException
  extends IOException
{
  private static final long serialVersionUID = 1347339620135041008L;
  private final File file;
  private final int depth;
  
  public DirectoryWalker$CancelException(File file, int depth)
  {
    this("Operation Cancelled", file, depth);
  }
  
  public DirectoryWalker$CancelException(String message, File file, int depth)
  {
    super(message);
    this.file = file;
    this.depth = depth;
  }
  
  public File getFile()
  {
    return file;
  }
  
  public int getDepth()
  {
    return depth;
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.io.DirectoryWalker.CancelException
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.io;

import java.io.File;
import java.io.FileFilter;
import java.io.IOException;
import java.util.Collection;
import org.apache.commons.io.filefilter.FileFilterUtils;
import org.apache.commons.io.filefilter.IOFileFilter;
import org.apache.commons.io.filefilter.TrueFileFilter;

public abstract class DirectoryWalker<T>
{
  private final FileFilter filter;
  private final int depthLimit;
  
  protected DirectoryWalker()
  {
    this(null, -1);
  }
  
  protected DirectoryWalker(FileFilter filter, int depthLimit)
  {
    this.filter = filter;
    this.depthLimit = depthLimit;
  }
  
  protected DirectoryWalker(IOFileFilter directoryFilter, IOFileFilter fileFilter, int depthLimit)
  {
    if ((directoryFilter == null) && (fileFilter == null))
    {
      filter = null;
    }
    else
    {
      directoryFilter = directoryFilter != null ? directoryFilter : TrueFileFilter.TRUE;
      fileFilter = fileFilter != null ? fileFilter : TrueFileFilter.TRUE;
      directoryFilter = FileFilterUtils.makeDirectoryOnly(directoryFilter);
      fileFilter = FileFilterUtils.makeFileOnly(fileFilter);
      filter = FileFilterUtils.or(new IOFileFilter[] { directoryFilter, fileFilter });
    }
    this.depthLimit = depthLimit;
  }
  
  protected final void walk(File startDirectory, Collection<T> results)
    throws IOException
  {
    if (startDirectory == null) {
      throw new NullPointerException("Start Directory is null");
    }
    try
    {
      handleStart(startDirectory, results);
      walk(startDirectory, 0, results);
      handleEnd(results);
    }
    catch (CancelException cancel)
    {
      handleCancelled(startDirectory, results, cancel);
    }
  }
  
  private void walk(File directory, int depth, Collection<T> results)
    throws IOException
  {
    checkIfCancelled(directory, depth, results);
    if (handleDirectory(directory, depth, results))
    {
      handleDirectoryStart(directory, depth, results);
      int childDepth = depth + 1;
      if ((depthLimit < 0) || (childDepth <= depthLimit))
      {
        checkIfCancelled(directory, depth, results);
        File[] childFiles = filter == null ? directory.listFiles() : directory.listFiles(filter);
        childFiles = filterDirectoryContents(directory, depth, childFiles);
        if (childFiles == null) {
          handleRestricted(directory, childDepth, results);
        } else {
          for (File childFile : childFiles) {
            if (childFile.isDirectory())
            {
              walk(childFile, childDepth, results);
            }
            else
            {
              checkIfCancelled(childFile, childDepth, results);
              handleFile(childFile, childDepth, results);
              checkIfCancelled(childFile, childDepth, results);
            }
          }
        }
      }
      handleDirectoryEnd(directory, depth, results);
    }
    checkIfCancelled(directory, depth, results);
  }
  
  protected final void checkIfCancelled(File file, int depth, Collection<T> results)
    throws IOException
  {
    if (handleIsCancelled(file, depth, results)) {
      throw new CancelException(file, depth);
    }
  }
  
  protected boolean handleIsCancelled(File file, int depth, Collection<T> results)
    throws IOException
  {
    return false;
  }
  
  protected void handleCancelled(File startDirectory, Collection<T> results, CancelException cancel)
    throws IOException
  {
    throw cancel;
  }
  
  protected void handleStart(File startDirectory, Collection<T> results)
    throws IOException
  {}
  
  protected boolean handleDirectory(File directory, int depth, Collection<T> results)
    throws IOException
  {
    return true;
  }
  
  protected void handleDirectoryStart(File directory, int depth, Collection<T> results)
    throws IOException
  {}
  
  protected File[] filterDirectoryContents(File directory, int depth, File[] files)
    throws IOException
  {
    return files;
  }
  
  protected void handleFile(File file, int depth, Collection<T> results)
    throws IOException
  {}
  
  protected void handleRestricted(File directory, int depth, Collection<T> results)
    throws IOException
  {}
  
  protected void handleDirectoryEnd(File directory, int depth, Collection<T> results)
    throws IOException
  {}
  
  protected void handleEnd(Collection<T> results)
    throws IOException
  {}
  
  public static class CancelException
    extends IOException
  {
    private static final long serialVersionUID = 1347339620135041008L;
    private final File file;
    private final int depth;
    
    public CancelException(File file, int depth)
    {
      this("Operation Cancelled", file, depth);
    }
    
    public CancelException(String message, File file, int depth)
    {
      super();
      this.file = file;
      this.depth = depth;
    }
    
    public File getFile()
    {
      return file;
    }
    
    public int getDepth()
    {
      return depth;
    }
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.io.DirectoryWalker
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.io;

import java.io.EOFException;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

public class EndianUtils
{
  public static short swapShort(short value)
  {
    return (short)(((value >> 0 & 0xFF) << 8) + ((value >> 8 & 0xFF) << 0));
  }
  
  public static int swapInteger(int value)
  {
    return ((value >> 0 & 0xFF) << 24) + ((value >> 8 & 0xFF) << 16) + ((value >> 16 & 0xFF) << 8) + ((value >> 24 & 0xFF) << 0);
  }
  
  public static long swapLong(long value)
  {
    return ((value >> 0 & 0xFF) << 56) + ((value >> 8 & 0xFF) << 48) + ((value >> 16 & 0xFF) << 40) + ((value >> 24 & 0xFF) << 32) + ((value >> 32 & 0xFF) << 24) + ((value >> 40 & 0xFF) << 16) + ((value >> 48 & 0xFF) << 8) + ((value >> 56 & 0xFF) << 0);
  }
  
  public static float swapFloat(float value)
  {
    return Float.intBitsToFloat(swapInteger(Float.floatToIntBits(value)));
  }
  
  public static double swapDouble(double value)
  {
    return Double.longBitsToDouble(swapLong(Double.doubleToLongBits(value)));
  }
  
  public static void writeSwappedShort(byte[] data, int offset, short value)
  {
    data[(offset + 0)] = ((byte)(value >> 0 & 0xFF));
    data[(offset + 1)] = ((byte)(value >> 8 & 0xFF));
  }
  
  public static short readSwappedShort(byte[] data, int offset)
  {
    return (short)(((data[(offset + 0)] & 0xFF) << 0) + ((data[(offset + 1)] & 0xFF) << 8));
  }
  
  public static int readSwappedUnsignedShort(byte[] data, int offset)
  {
    return ((data[(offset + 0)] & 0xFF) << 0) + ((data[(offset + 1)] & 0xFF) << 8);
  }
  
  public static void writeSwappedInteger(byte[] data, int offset, int value)
  {
    data[(offset + 0)] = ((byte)(value >> 0 & 0xFF));
    data[(offset + 1)] = ((byte)(value >> 8 & 0xFF));
    data[(offset + 2)] = ((byte)(value >> 16 & 0xFF));
    data[(offset + 3)] = ((byte)(value >> 24 & 0xFF));
  }
  
  public static int readSwappedInteger(byte[] data, int offset)
  {
    return ((data[(offset + 0)] & 0xFF) << 0) + ((data[(offset + 1)] & 0xFF) << 8) + ((data[(offset + 2)] & 0xFF) << 16) + ((data[(offset + 3)] & 0xFF) << 24);
  }
  
  public static long readSwappedUnsignedInteger(byte[] data, int offset)
  {
    long low = ((data[(offset + 0)] & 0xFF) << 0) + ((data[(offset + 1)] & 0xFF) << 8) + ((data[(offset + 2)] & 0xFF) << 16);
    
    long high = data[(offset + 3)] & 0xFF;
    
    return (high << 24) + (0xFFFFFFFF & low);
  }
  
  public static void writeSwappedLong(byte[] data, int offset, long value)
  {
    data[(offset + 0)] = ((byte)(int)(value >> 0 & 0xFF));
    data[(offset + 1)] = ((byte)(int)(value >> 8 & 0xFF));
    data[(offset + 2)] = ((byte)(int)(value >> 16 & 0xFF));
    data[(offset + 3)] = ((byte)(int)(value >> 24 & 0xFF));
    data[(offset + 4)] = ((byte)(int)(value >> 32 & 0xFF));
    data[(offset + 5)] = ((byte)(int)(value >> 40 & 0xFF));
    data[(offset + 6)] = ((byte)(int)(value >> 48 & 0xFF));
    data[(offset + 7)] = ((byte)(int)(value >> 56 & 0xFF));
  }
  
  public static long readSwappedLong(byte[] data, int offset)
  {
    long low = ((data[(offset + 0)] & 0xFF) << 0) + ((data[(offset + 1)] & 0xFF) << 8) + ((data[(offset + 2)] & 0xFF) << 16) + ((data[(offset + 3)] & 0xFF) << 24);
    
    long high = ((data[(offset + 4)] & 0xFF) << 0) + ((data[(offset + 5)] & 0xFF) << 8) + ((data[(offset + 6)] & 0xFF) << 16) + ((data[(offset + 7)] & 0xFF) << 24);
    
    return (high << 32) + (0xFFFFFFFF & low);
  }
  
  public static void writeSwappedFloat(byte[] data, int offset, float value)
  {
    writeSwappedInteger(data, offset, Float.floatToIntBits(value));
  }
  
  public static float readSwappedFloat(byte[] data, int offset)
  {
    return Float.intBitsToFloat(readSwappedInteger(data, offset));
  }
  
  public static void writeSwappedDouble(byte[] data, int offset, double value)
  {
    writeSwappedLong(data, offset, Double.doubleToLongBits(value));
  }
  
  public static double readSwappedDouble(byte[] data, int offset)
  {
    return Double.longBitsToDouble(readSwappedLong(data, offset));
  }
  
  public static void writeSwappedShort(OutputStream output, short value)
    throws IOException
  {
    output.write((byte)(value >> 0 & 0xFF));
    output.write((byte)(value >> 8 & 0xFF));
  }
  
  public static short readSwappedShort(InputStream input)
    throws IOException
  {
    return (short)(((read(input) & 0xFF) << 0) + ((read(input) & 0xFF) << 8));
  }
  
  public static int readSwappedUnsignedShort(InputStream input)
    throws IOException
  {
    int value1 = read(input);
    int value2 = read(input);
    
    return ((value1 & 0xFF) << 0) + ((value2 & 0xFF) << 8);
  }
  
  public static void writeSwappedInteger(OutputStream output, int value)
    throws IOException
  {
    output.write((byte)(value >> 0 & 0xFF));
    output.write((byte)(value >> 8 & 0xFF));
    output.write((byte)(value >> 16 & 0xFF));
    output.write((byte)(value >> 24 & 0xFF));
  }
  
  public static int readSwappedInteger(InputStream input)
    throws IOException
  {
    int value1 = read(input);
    int value2 = read(input);
    int value3 = read(input);
    int value4 = read(input);
    
    return ((value1 & 0xFF) << 0) + ((value2 & 0xFF) << 8) + ((value3 & 0xFF) << 16) + ((value4 & 0xFF) << 24);
  }
  
  public static long readSwappedUnsignedInteger(InputStream input)
    throws IOException
  {
    int value1 = read(input);
    int value2 = read(input);
    int value3 = read(input);
    int value4 = read(input);
    
    long low = ((value1 & 0xFF) << 0) + ((value2 & 0xFF) << 8) + ((value3 & 0xFF) << 16);
    
    long high = value4 & 0xFF;
    
    return (high << 24) + (0xFFFFFFFF & low);
  }
  
  public static void writeSwappedLong(OutputStream output, long value)
    throws IOException
  {
    output.write((byte)(int)(value >> 0 & 0xFF));
    output.write((byte)(int)(value >> 8 & 0xFF));
    output.write((byte)(int)(value >> 16 & 0xFF));
    output.write((byte)(int)(value >> 24 & 0xFF));
    output.write((byte)(int)(value >> 32 & 0xFF));
    output.write((byte)(int)(value >> 40 & 0xFF));
    output.write((byte)(int)(value >> 48 & 0xFF));
    output.write((byte)(int)(value >> 56 & 0xFF));
  }
  
  public static long readSwappedLong(InputStream input)
    throws IOException
  {
    byte[] bytes = new byte[8];
    for (int i = 0; i < 8; i++) {
      bytes[i] = ((byte)read(input));
    }
    return readSwappedLong(bytes, 0);
  }
  
  public static void writeSwappedFloat(OutputStream output, float value)
    throws IOException
  {
    writeSwappedInteger(output, Float.floatToIntBits(value));
  }
  
  public static float readSwappedFloat(InputStream input)
    throws IOException
  {
    return Float.intBitsToFloat(readSwappedInteger(input));
  }
  
  public static void writeSwappedDouble(OutputStream output, double value)
    throws IOException
  {
    writeSwappedLong(output, Double.doubleToLongBits(value));
  }
  
  public static double readSwappedDouble(InputStream input)
    throws IOException
  {
    return Double.longBitsToDouble(readSwappedLong(input));
  }
  
  private static int read(InputStream input)
    throws IOException
  {
    int value = input.read();
    if (-1 == value) {
      throw new EOFException("Unexpected EOF reached");
    }
    return value;
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.io.EndianUtils
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.io;

import java.io.File;

@Deprecated
public class FileCleaner
{
  static final FileCleaningTracker theInstance = new FileCleaningTracker();
  
  @Deprecated
  public static void track(File file, Object marker)
  {
    theInstance.track(file, marker);
  }
  
  @Deprecated
  public static void track(File file, Object marker, FileDeleteStrategy deleteStrategy)
  {
    theInstance.track(file, marker, deleteStrategy);
  }
  
  @Deprecated
  public static void track(String path, Object marker)
  {
    theInstance.track(path, marker);
  }
  
  @Deprecated
  public static void track(String path, Object marker, FileDeleteStrategy deleteStrategy)
  {
    theInstance.track(path, marker, deleteStrategy);
  }
  
  @Deprecated
  public static int getTrackCount()
  {
    return theInstance.getTrackCount();
  }
  
  @Deprecated
  public static synchronized void exitWhenFinished()
  {
    theInstance.exitWhenFinished();
  }
  
  public static FileCleaningTracker getInstance()
  {
    return theInstance;
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.io.FileCleaner
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.io;

import java.lang.ref.ReferenceQueue;
import java.util.Collection;
import java.util.List;

final class FileCleaningTracker$Reaper
  extends Thread
{
  FileCleaningTracker$Reaper(FileCleaningTracker paramFileCleaningTracker)
  {
    super("File Reaper");
    setPriority(10);
    setDaemon(true);
  }
  
  public void run()
  {
    while ((!this$0.exitWhenFinished) || (this$0.trackers.size() > 0)) {
      try
      {
        FileCleaningTracker.Tracker tracker = (FileCleaningTracker.Tracker)this$0.q.remove();
        this$0.trackers.remove(tracker);
        if (!tracker.delete()) {
          this$0.deleteFailures.add(tracker.getPath());
        }
        tracker.clear();
      }
      catch (InterruptedException e) {}
    }
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.io.FileCleaningTracker.Reaper
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.io;

import java.io.File;
import java.lang.ref.PhantomReference;
import java.lang.ref.ReferenceQueue;

final class FileCleaningTracker$Tracker
  extends PhantomReference<Object>
{
  private final String path;
  private final FileDeleteStrategy deleteStrategy;
  
  FileCleaningTracker$Tracker(String path, FileDeleteStrategy deleteStrategy, Object marker, ReferenceQueue<? super Object> queue)
  {
    super(marker, queue);
    this.path = path;
    this.deleteStrategy = (deleteStrategy == null ? FileDeleteStrategy.NORMAL : deleteStrategy);
  }
  
  public String getPath()
  {
    return path;
  }
  
  public boolean delete()
  {
    return deleteStrategy.deleteQuietly(new File(path));
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.io.FileCleaningTracker.Tracker
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.io;

import java.io.File;
import java.lang.ref.PhantomReference;
import java.lang.ref.ReferenceQueue;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;

public class FileCleaningTracker
{
  ReferenceQueue<Object> q;
  final Collection<Tracker> trackers;
  final List<String> deleteFailures;
  volatile boolean exitWhenFinished;
  Thread reaper;
  
  public FileCleaningTracker()
  {
    q = new ReferenceQueue();
    
    trackers = Collections.synchronizedSet(new HashSet());
    
    deleteFailures = Collections.synchronizedList(new ArrayList());
    
    exitWhenFinished = false;
  }
  
  public void track(File file, Object marker)
  {
    track(file, marker, (FileDeleteStrategy)null);
  }
  
  public void track(File file, Object marker, FileDeleteStrategy deleteStrategy)
  {
    if (file == null) {
      throw new NullPointerException("The file must not be null");
    }
    addTracker(file.getPath(), marker, deleteStrategy);
  }
  
  public void track(String path, Object marker)
  {
    track(path, marker, (FileDeleteStrategy)null);
  }
  
  public void track(String path, Object marker, FileDeleteStrategy deleteStrategy)
  {
    if (path == null) {
      throw new NullPointerException("The path must not be null");
    }
    addTracker(path, marker, deleteStrategy);
  }
  
  private synchronized void addTracker(String path, Object marker, FileDeleteStrategy deleteStrategy)
  {
    if (exitWhenFinished) {
      throw new IllegalStateException("No new trackers can be added once exitWhenFinished() is called");
    }
    if (reaper == null)
    {
      reaper = new Reaper();
      reaper.start();
    }
    trackers.add(new Tracker(path, deleteStrategy, marker, q));
  }
  
  public int getTrackCount()
  {
    return trackers.size();
  }
  
  public List<String> getDeleteFailures()
  {
    return deleteFailures;
  }
  
  public synchronized void exitWhenFinished()
  {
    exitWhenFinished = true;
    if (reaper != null) {
      synchronized (reaper)
      {
        reaper.interrupt();
      }
    }
  }
  
  private final class Reaper
    extends Thread
  {
    Reaper()
    {
      super();
      setPriority(10);
      setDaemon(true);
    }
    
    public void run()
    {
      while ((!exitWhenFinished) || (trackers.size() > 0)) {
        try
        {
          FileCleaningTracker.Tracker tracker = (FileCleaningTracker.Tracker)q.remove();
          trackers.remove(tracker);
          if (!tracker.delete()) {
            deleteFailures.add(tracker.getPath());
          }
          tracker.clear();
        }
        catch (InterruptedException e) {}
      }
    }
  }
  
  private static final class Tracker
    extends PhantomReference<Object>
  {
    private final String path;
    private final FileDeleteStrategy deleteStrategy;
    
    Tracker(String path, FileDeleteStrategy deleteStrategy, Object marker, ReferenceQueue<? super Object> queue)
    {
      super(queue);
      this.path = path;
      this.deleteStrategy = (deleteStrategy == null ? FileDeleteStrategy.NORMAL : deleteStrategy);
    }
    
    public String getPath()
    {
      return path;
    }
    
    public boolean delete()
    {
      return deleteStrategy.deleteQuietly(new File(path));
    }
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.io.FileCleaningTracker
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.io;

import java.io.File;
import java.io.IOException;

class FileDeleteStrategy$ForceFileDeleteStrategy
  extends FileDeleteStrategy
{
  FileDeleteStrategy$ForceFileDeleteStrategy()
  {
    super("Force");
  }
  
  protected boolean doDelete(File fileToDelete)
    throws IOException
  {
    FileUtils.forceDelete(fileToDelete);
    return true;
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.io.FileDeleteStrategy.ForceFileDeleteStrategy
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.io;

import java.io.File;
import java.io.IOException;

public class FileDeleteStrategy
{
  public static final FileDeleteStrategy NORMAL = new FileDeleteStrategy("Normal");
  public static final FileDeleteStrategy FORCE = new ForceFileDeleteStrategy();
  private final String name;
  
  protected FileDeleteStrategy(String name)
  {
    this.name = name;
  }
  
  public boolean deleteQuietly(File fileToDelete)
  {
    if ((fileToDelete == null) || (!fileToDelete.exists())) {
      return true;
    }
    try
    {
      return doDelete(fileToDelete);
    }
    catch (IOException ex) {}
    return false;
  }
  
  public void delete(File fileToDelete)
    throws IOException
  {
    if ((fileToDelete.exists()) && (!doDelete(fileToDelete))) {
      throw new IOException("Deletion failed: " + fileToDelete);
    }
  }
  
  protected boolean doDelete(File fileToDelete)
    throws IOException
  {
    return fileToDelete.delete();
  }
  
  public String toString()
  {
    return "FileDeleteStrategy[" + name + "]";
  }
  
  static class ForceFileDeleteStrategy
    extends FileDeleteStrategy
  {
    ForceFileDeleteStrategy()
    {
      super();
    }
    
    protected boolean doDelete(File fileToDelete)
      throws IOException
    {
      FileUtils.forceDelete(fileToDelete);
      return true;
    }
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.io.FileDeleteStrategy
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.io;

import java.io.File;
import java.io.IOException;

public class FileExistsException
  extends IOException
{
  private static final long serialVersionUID = 1L;
  
  public FileExistsException() {}
  
  public FileExistsException(String message)
  {
    super(message);
  }
  
  public FileExistsException(File file)
  {
    super("File " + file + " exists");
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.io.FileExistsException
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.io;

import java.io.BufferedReader;
import java.io.File;
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.Locale;
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;
  private static final String DF;
  
  static
  {
    int os = 0;
    String dfPath = "df";
    try
    {
      String osName = System.getProperty("os.name");
      if (osName == null) {
        throw new IOException("os.name not found");
      }
      osName = osName.toLowerCase(Locale.ENGLISH);
      if (osName.indexOf("windows") != -1)
      {
        os = 1;
      }
      else if ((osName.indexOf("linux") != -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("sun os") != -1) || (osName.indexOf("sunos") != -1) || (osName.indexOf("solaris") != -1))
      {
        os = 3;
        dfPath = "/usr/xpg4/bin/df";
      }
      else if ((osName.indexOf("hp-ux") != -1) || (osName.indexOf("aix") != -1))
      {
        os = 3;
      }
      else
      {
        os = 0;
      }
    }
    catch (Exception ex)
    {
      os = -1;
    }
    OS = os;
    DF = dfPath;
  }
  
  @Deprecated
  public static long freeSpace(String path)
    throws IOException
  {
    return INSTANCE.freeSpaceOS(path, OS, false, -1L);
  }
  
  public static long freeSpaceKb(String path)
    throws IOException
  {
    return freeSpaceKb(path, -1L);
  }
  
  public static long freeSpaceKb(String path, long timeout)
    throws IOException
  {
    return INSTANCE.freeSpaceOS(path, OS, true, timeout);
  }
  
  public static long freeSpaceKb()
    throws IOException
  {
    return freeSpaceKb(-1L);
  }
  
  public static long freeSpaceKb(long timeout)
    throws IOException
  {
    return freeSpaceKb(new File(".").getAbsolutePath(), timeout);
  }
  
  long freeSpaceOS(String path, int os, boolean kb, long timeout)
    throws IOException
  {
    if (path == null) {
      throw new IllegalArgumentException("Path must not be empty");
    }
    switch (os)
    {
    case 1: 
      return kb ? freeSpaceWindows(path, timeout) / 1024L : freeSpaceWindows(path, timeout);
    case 2: 
      return freeSpaceUnix(path, kb, false, timeout);
    case 3: 
      return freeSpaceUnix(path, kb, true, timeout);
    case 0: 
      throw new IllegalStateException("Unsupported operating system");
    }
    throw new IllegalStateException("Exception caught when determining operating system");
  }
  
  long freeSpaceWindows(String path, long timeout)
    throws IOException
  {
    path = FilenameUtils.normalize(path, false);
    if ((path.length() > 0) && (path.charAt(0) != '"')) {
      path = "\"" + path + "\"";
    }
    String[] cmdAttribs = { "cmd.exe", "/C", "dir /-c " + path };
    
    List<String> lines = performCommand(cmdAttribs, Integer.MAX_VALUE, timeout);
    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 + "'");
    }
    StringBuilder buf = new StringBuilder(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, long timeout)
    throws IOException
  {
    if (path.length() == 0) {
      throw new IllegalArgumentException("Path must not be empty");
    }
    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<String> lines = performCommand(cmdAttribs, 3, timeout);
    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 IOExceptionWithCause("Command line '" + DF + "' did not return numeric data as expected " + "for path '" + path + "'- check path is valid", ex);
    }
  }
  
  List<String> performCommand(String[] cmdAttribs, int max, long timeout)
    throws IOException
  {
    List<String> lines = new ArrayList(20);
    Process proc = null;
    InputStream in = null;
    OutputStream out = null;
    InputStream err = null;
    BufferedReader inr = null;
    try
    {
      Thread monitor = ThreadMonitor.start(timeout);
      
      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(Locale.ENGLISH).trim();
        lines.add(line);
        line = inr.readLine();
      }
      proc.waitFor();
      
      ThreadMonitor.stop(monitor);
      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 IOExceptionWithCause("Command line threw an InterruptedException for command " + Arrays.asList(cmdAttribs) + " timeout=" + timeout, ex);
    }
    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: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.io;

import java.io.File;
import java.io.FileFilter;
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.URI;
import java.net.URL;
import java.net.URLConnection;
import java.nio.ByteBuffer;
import java.nio.CharBuffer;
import java.nio.channels.FileChannel;
import java.nio.charset.Charset;
import java.util.ArrayList;
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;
  private static final long FIFTY_MB = 52428800L;
  public static final long ONE_GB = 1073741824L;
  public static final File[] EMPTY_FILE_ARRAY = new File[0];
  private static final Charset UTF8 = Charset.forName("UTF-8");
  
  public static String getTempDirectoryPath()
  {
    return System.getProperty("java.io.tmpdir");
  }
  
  public static File getTempDirectory()
  {
    return new File(getTempDirectoryPath());
  }
  
  public static String getUserDirectoryPath()
  {
    return System.getProperty("user.home");
  }
  
  public static File getUserDirectory()
  {
    return new File(getUserDirectoryPath());
  }
  
  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<File> files)
 
1 2 3 4 5 6 7

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-2017. Infinite Loop Ltd