User: user57  
  Date: 02/02/14 22:14:22

  Added:       src/main/org/jboss/util/file FilePrefixFilter.java
                        FileSuffixFilter.java FilenamePrefixFilter.java
                        FilenameSuffixFilter.java Files.java package.html
  Log:
   o importing the useful bits from the bliss cl.
   o plus some bits from server/*/util/* have been moved to util.jmx
  
  Revision  Changes    Path
  1.1                  jboss-common/src/main/org/jboss/util/file/FilePrefixFilter.java
  
  Index: FilePrefixFilter.java
  ===================================================================
  /***************************************
   *                                     *
   *  JBoss: The OpenSource J2EE WebOS   *
   *                                     *
   *  Distributable under LGPL license.  *
   *  See terms of license at gnu.org.   *
   *                                     *
   ***************************************/
  
  package org.jboss.util.file;
  
  import java.io.File;
  import java.io.FileFilter;
  
  /**
   * A <em>prefix</em> based file filter.
   *
   * @version <tt>$Revision: 1.1 $</tt>
   * @author  <a href="mailto:[EMAIL PROTECTED]";>Jason Dillon</a>
   */
  public class FilePrefixFilter
     implements FileFilter
  {
     /** The prefix which files must have to be accepted. */
     protected final String prefix;
  
     /** Flag to signal that we want to ignore the case. */
     protected final boolean ignoreCase;
  
     /**
      * Construct a <tt>FilePrefixFilter</tt>.
      *
      * @param prefix     The prefix which files must have to be accepted.
      * @param ignoreCase <tt>True</tt> if the filter should be case-insensitive.
      */
     public FilePrefixFilter(final String prefix,
                             final boolean ignoreCase)
     {
        this.ignoreCase = ignoreCase;
        this.prefix = (ignoreCase ? prefix.toLowerCase() : prefix);
     }
  
     /**
      * Construct a case sensitive <tt>FilePrefixFilter</tt>.
      *
      * @param prefix  The prefix which files must have to be accepted.
      */
     public FilePrefixFilter(final String prefix) {
        this(prefix, false);
     }
  
     /**
      * Check if a file is acceptible.
      *
      * @param file    The file to check.
      * @return        <tt>true</tt> if the file is acceptable.
      */
     public boolean accept(final File file) {
        if (ignoreCase) {
           return file.getName().toLowerCase().startsWith(prefix);
        }
        else {
           return file.getName().startsWith(prefix);
        }
     }
  }
  
  
  
  1.1                  jboss-common/src/main/org/jboss/util/file/FileSuffixFilter.java
  
  Index: FileSuffixFilter.java
  ===================================================================
  /***************************************
   *                                     *
   *  JBoss: The OpenSource J2EE WebOS   *
   *                                     *
   *  Distributable under LGPL license.  *
   *  See terms of license at gnu.org.   *
   *                                     *
   ***************************************/
  
  package org.jboss.util.file;
  
  import java.io.File;
  import java.io.FileFilter;
  
  /**
   * A <em>suffix</em> based file filter.
   *
   * @version <tt>$Revision: 1.1 $</tt>
   * @author  <a href="mailto:[EMAIL PROTECTED]";>Jason Dillon</a>
   */
  public class FileSuffixFilter
     implements FileFilter
  {
     /** A list of suffixes which files must have to be accepted. */
     protected final String suffixes[];
  
     /** Flag to signal that we want to ignore the case. */
     protected final boolean ignoreCase;
  
     /**
      * Construct a <tt>FileSuffixFilter</tt>.
      *
      * @param suffixes   A list of suffixes which files mut have to be accepted.
      * @param ignoreCase <tt>True</tt> if the filter should be case-insensitive.
      */
     public FileSuffixFilter(final String suffixes[],
                             final boolean ignoreCase)
     {
        this.ignoreCase = ignoreCase;
        if (ignoreCase) {
           this.suffixes = new String[suffixes.length];
           for (int i=0; i<suffixes.length; i++) {
              this.suffixes[i] = suffixes[i].toLowerCase();
           }
        }
        else {
           this.suffixes = suffixes;
        }
     }
  
     /**
      * Construct a <tt>FileSuffixFilter</tt>.
      *
      * @param suffixes   A list of suffixes which files mut have to be accepted.
      */
     public FileSuffixFilter(final String suffixes[])
     {
        this(suffixes, false);
     }
  
     /**
      * Construct a <tt>FileSuffixFilter</tt>.
      *
      * @param suffix     The suffix which files must have to be accepted.
      * @param ignoreCase <tt>True</tt> if the filter should be case-insensitive.
      */
     public FileSuffixFilter(final String suffix,
                             final boolean ignoreCase)
     {
        this(new String[] { suffix }, ignoreCase);
     }
  
     /**
      * Construct a case sensitive <tt>FileSuffixFilter</tt>.
      *
      * @param suffix  The suffix which files must have to be accepted.
      */
     public FileSuffixFilter(final String suffix) {
        this(suffix, false);
     }
  
     /**
      * Check if a file is acceptible.
      *
      * @param file    The file to check.
      * @return        <tt>true</tt> if the file is acceptable.
      */
     public boolean accept(final File file) {
        boolean success = false;
  
        for (int i=0; i<suffixes.length && !success; i++) {
           if (ignoreCase)
              success = file.getName().toLowerCase().endsWith(suffixes[i]);
           else
              success = file.getName().endsWith(suffixes[i]);
        }
  
        return success;
     }
  }
  
  
  
  1.1                  
jboss-common/src/main/org/jboss/util/file/FilenamePrefixFilter.java
  
  Index: FilenamePrefixFilter.java
  ===================================================================
  /***************************************
   *                                     *
   *  JBoss: The OpenSource J2EE WebOS   *
   *                                     *
   *  Distributable under LGPL license.  *
   *  See terms of license at gnu.org.   *
   *                                     *
   ***************************************/
  
  package org.jboss.util.file;
  
  import java.io.File;
  import java.io.FilenameFilter;
  
  /**
   * A <em>prefix</em> based filename filter.
   *
   * @version <tt>$Revision: 1.1 $</tt>
   * @author  <a href="mailto:[EMAIL PROTECTED]";>Jason Dillon</a>
   */
  public class FilenamePrefixFilter
     implements FilenameFilter
  {
     /** The prefix which files must have to be accepted. */
     protected final String prefix;
  
     /** Flag to signal that we want to ignore the case. */
     protected final boolean ignoreCase;
  
     /**
      * Construct a <tt>FilenamePrefixFilter</tt>.
      *
      * @param prefix     The prefix which files must have to be accepted.
      * @param ignoreCase <tt>True</tt> if the filter should be case-insensitive.
      */
     public FilenamePrefixFilter(final String prefix,
                                 final boolean ignoreCase)
     {
        this.ignoreCase = ignoreCase;
        this.prefix = (ignoreCase ? prefix.toLowerCase() : prefix);
     }
  
     /**
      * Construct a case sensitive <tt>FilenamePrefixFilter</tt>.
      *
      * @param prefix  The prefix which files must have to be accepted.
      */
     public FilenamePrefixFilter(final String prefix) {
        this(prefix, false);
     }
  
     /**
      * Check if a file is acceptible.
      *
      * @param dir  The directory the file resides in.
      * @param name The name of the file.
      * @return     <tt>true</tt> if the file is acceptable.
      */
     public boolean accept(final File dir, final String name) {
        if (ignoreCase) {
           return name.toLowerCase().startsWith(prefix);
        }
        else {
           return name.startsWith(prefix);
        }
     }
  }
  
  
  
  1.1                  
jboss-common/src/main/org/jboss/util/file/FilenameSuffixFilter.java
  
  Index: FilenameSuffixFilter.java
  ===================================================================
  /***************************************
   *                                     *
   *  JBoss: The OpenSource J2EE WebOS   *
   *                                     *
   *  Distributable under LGPL license.  *
   *  See terms of license at gnu.org.   *
   *                                     *
   ***************************************/
  
  package org.jboss.util.file;
  
  import java.io.File;
  import java.io.FilenameFilter;
  
  /**
   * A <em>suffix</em> based filename filter.
   *
   * @version <tt>$Revision: 1.1 $</tt>
   * @author  <a href="mailto:[EMAIL PROTECTED]";>Jason Dillon</a>
   */
  public class FilenameSuffixFilter
     implements FilenameFilter
  {
     /** The suffix which files must have to be accepted. */
     protected final String suffix;
  
     /** Flag to signal that we want to ignore the case. */
     protected final boolean ignoreCase;
  
     /**
      * Construct a <tt>FilenameSuffixFilter</tt>.
      *
      * @param suffix     The suffix which files must have to be accepted.
      * @param ignoreCase <tt>True</tt> if the filter should be case-insensitive.
      */
     public FilenameSuffixFilter(final String suffix,
                                 final boolean ignoreCase)
     {
        this.ignoreCase = ignoreCase;
        this.suffix = (ignoreCase ? suffix.toLowerCase() : suffix);
     }
  
     /**
      * Construct a case sensitive <tt>FilenameSuffixFilter</tt>.
      *
      * @param suffix  The suffix which files must have to be accepted.
      */
     public FilenameSuffixFilter(final String suffix) {
        this(suffix, false);
     }
  
     /**
      * Check if a file is acceptible.
      *
      * @param dir  The directory the file resides in.
      * @param name The name of the file.
      * @return     <tt>true</tt> if the file is acceptable.
      */
     public boolean accept(final File dir, final String name) {
        if (ignoreCase) {
           return name.toLowerCase().endsWith(suffix);
        }
        else {
           return name.endsWith(suffix);
        }
     }
  }
  
  
  
  1.1                  jboss-common/src/main/org/jboss/util/file/Files.java
  
  Index: Files.java
  ===================================================================
  /***************************************
   *                                     *
   *  JBoss: The OpenSource J2EE WebOS   *
   *                                     *
   *  Distributable under LGPL license.  *
   *  See terms of license at gnu.org.   *
   *                                     *
   ***************************************/
  
  package org.jboss.util.file;
  
  import java.io.File;
  import java.io.IOException;
  import java.io.FileInputStream;
  import java.io.FileOutputStream;
  import java.io.DataInputStream;
  import java.io.DataOutputStream;
  import java.io.BufferedInputStream;
  import java.io.BufferedOutputStream;
  
  import org.jboss.util.stream.Streams;
  
  /**
   * A collection of file utilities.
   *
   * @version <tt>$Revision: 1.1 $</tt>
   * @author  <a href="mailto:[EMAIL PROTECTED]";>Jason Dillon</a>
   */
  public final class Files
  {
     /**
      * Delete a directory and all of its contents.
      *
      * @param dir  The directory to delete.
      *
      * @throws IOException  Failed to delete directory.
      */
     public static void delete(File dir) throws IOException {
        File files[] = dir.listFiles();
        if (files != null) {
           for (int i=0; i<files.length; i++) {
              if (files[i].isDirectory()) {
                 // delete the directory and all of its contents.
                 delete(files[i]);
              }
  
              // delete each file in the directory
              files[i].delete();
           }
        }
  
        // finally delete the directory
        dir.delete();
     }
  
     /** The default size of the copy buffer. */
     public static final int DEFAULT_BUFFER_SIZE = 8192; // 8k
  
     /**
      * Copy a file.
      *
      * @param source  Source file to copy.
      * @param target  Destination target file.
      * @param buff    The copy buffer.
      *
      * @throws IOException  Failed to copy file.
      */
     public static void copy(final File source,
                             final File target,
                             final byte buff[])
        throws IOException
     {
        DataInputStream in = new DataInputStream
           (new BufferedInputStream(new FileInputStream(source)));
  
        DataOutputStream out = new DataOutputStream
           (new BufferedOutputStream(new FileOutputStream(target)));
  
        int read;
  
        try {
           while ((read = in.read(buff)) != -1) {
              out.write(buff, 0, read);
           }
        }
        finally {
           Streams.flush(out);
           Streams.close(in);
           Streams.close(out);
        }
     }
  
     /**
      * Copy a file.
      *
      * @param source  Source file to copy.
      * @param target  Destination target file.
      * @param size    The size of the copy buffer.
      *
      * @throws IOException  Failed to copy file.
      */
     public static void copy(final File source,
                             final File target,
                             final int size)
        throws IOException
     {
        copy(source, target, new byte[size]);
     }
  
     /**
      * Copy a file.
      *
      * @param source  Source file to copy.
      * @param target  Destination target file.
      *
      * @throws IOException  Failed to copy file.
      */
     public static void copy(final File source, final File target)
        throws IOException
     {
        copy(source, target, DEFAULT_BUFFER_SIZE);
     }
  }
  
  
  
  1.1                  jboss-common/src/main/org/jboss/util/file/package.html
  
  Index: package.html
  ===================================================================
  <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  <html>
    <head>
      <!-- $Id: package.html,v 1.1 2002/02/15 06:14:22 user57 Exp $ -->
      <!--
  
      JBoss: The OpenSource J2EE WebOS 
  
      Distributable under LGPL license.
      See terms of license at gnu.org.
  
      -->
    </head>
  
    <body bgcolor="white">
      <p>File related classes.</p>
  
      <h2>Package Specification</h2>
      <ul>
        <li><a href="javascript: alert('not available')">Not Available</a>
      </ul>
        
      <h2>Related Documentation</h2>
      <ul>
        <li><a href="javascript: alert('not available')">Not Available</a>
      </ul>
  
      <h2>Package Status</h2>
      <ul>
        <li><font color="green"><b>STABLE</b></font>
      </ul>
  
      <h2>Todo</h2>
      <ul>
        <li>???
      </ul>
  
      <!-- Put @see and @since tags down here. -->
  
    </body>
  </html>
  
  
  
  

_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development

Reply via email to