Coverage Report - org.jaudiotagger.audio.AudioFileFilter
 
Classes in this File Line Coverage Branch Coverage Complexity
AudioFileFilter
67%
8/12
50%
4/8
9
 
 1  
 /*
 2  
  * Entagged Audio Tag library
 3  
  * Copyright (c) 2003-2005 Rapha�l Slinckx <raphael@slinckx.net>
 4  
  * 
 5  
  * This library is free software; you can redistribute it and/or
 6  
  * modify it under the terms of the GNU Lesser General Public
 7  
  * License as published by the Free Software Foundation; either
 8  
  * version 2.1 of the License, or (at your option) any later version.
 9  
  *  
 10  
  * This library is distributed in the hope that it will be useful,
 11  
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 12  
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 13  
  * Lesser General Public License for more details.
 14  
  * 
 15  
  * You should have received a copy of the GNU Lesser General Public
 16  
  * License along with this library; if not, write to the Free Software
 17  
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 18  
  */
 19  
 package org.jaudiotagger.audio;
 20  
 
 21  
 import org.jaudiotagger.audio.generic.Utils;
 22  
 
 23  
 import java.io.FileFilter;
 24  
 import java.io.File;
 25  
 
 26  
 /**
 27  
  * <p>This is a simple FileFilter that will only allow the file supported by this library.</p>
 28  
  * <p>It will also accept directories. An additional condition is that file must be readable (read permission) and
 29  
  * are not hidden (dot files, or hidden files)</p>
 30  
  *
 31  
  * @author Raphael Slinckx
 32  
  * @version $Id: AudioFileFilter.java,v 1.3 2008/02/11 14:35:51 paultaylor Exp $
 33  
  * @since v0.01
 34  
  */
 35  1
 public class AudioFileFilter implements FileFilter
 36  
 {
 37  
     /**
 38  
      * <p>Check whether the given file meet the required conditions (supported by the library OR directory).
 39  
      * The File must also be readable and not hidden.</p>
 40  
      *
 41  
      * @param    f    The file to test
 42  
      * @return a boolean indicating if the file is accepted or not
 43  
      */
 44  
     public boolean accept(File f)
 45  
     {
 46  10
         if (f.isHidden() || !f.canRead())
 47  
         {
 48  0
             return false;
 49  
         }
 50  
 
 51  10
         if (f.isDirectory())
 52  
         {
 53  0
             return true;
 54  
         }
 55  
 
 56  10
         String ext = Utils.getExtension(f);
 57  
 
 58  
         try
 59  
         {
 60  10
             if (SupportedFileFormat.valueOf(ext.toUpperCase()) != null)
 61  
             {
 62  8
                 return true;
 63  
             }
 64  
         }
 65  2
         catch(IllegalArgumentException iae)
 66  
         {
 67  
             //Not known enum value
 68  2
             return false;    
 69  0
         }
 70  0
         return false;
 71  
         }
 72  
 }