Coverage Report - org.jaudiotagger.test.TestAudioTagger
 
Classes in this File Line Coverage Branch Coverage Complexity
TestAudioTagger
0%
0/43
0%
0/14
3
TestAudioTagger$DirFilter
0%
0/3
N/A
3
 
 1  
 /**
 2  
  * @author : Paul Taylor
 3  
  * <p/>
 4  
  * Version @version:$Id: TestAudioTagger.java 832 2009-11-12 13:25:38Z paultaylor $
 5  
  * <p/>
 6  
  * Jaudiotagger Copyright (C)2004,2005
 7  
  * <p/>
 8  
  * This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser
 9  
  * General Public  License as published by the Free Software Foundation; either version 2.1 of the License,
 10  
  * or (at your option) any later version.
 11  
  * <p/>
 12  
  * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
 13  
  * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 14  
  * See the GNU Lesser General Public License for more details.
 15  
  * <p/>
 16  
  * You should have received a copy of the GNU Lesser General Public License along with this library; if not,
 17  
  * you can get a copy from http://www.opensource.org/licenses/lgpl-license.php or write to the Free Software
 18  
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 19  
  * <p/>
 20  
  * Description:
 21  
  */
 22  
 package org.jaudiotagger.test;
 23  
 
 24  
 import org.jaudiotagger.audio.AudioFileFilter;
 25  
 import org.jaudiotagger.audio.AudioFileIO;
 26  
 
 27  
 import java.io.File;
 28  
 import java.text.DateFormat;
 29  
 import java.util.Date;
 30  
 
 31  
 /**
 32  
  * Simple class that will attempt to recusively read all files within a directory, flags
 33  
  * errors that occur.
 34  
  */
 35  0
 public class TestAudioTagger
 36  
 {
 37  
 
 38  
     public static void main(final String[] args)
 39  
     {
 40  0
         TestAudioTagger test = new TestAudioTagger();
 41  
 
 42  0
         if (args.length == 0)
 43  
         {
 44  0
             System.err.println("usage TestAudioTagger Dirname");
 45  0
             System.err.println("      You must enter the root directory");
 46  0
             System.exit(1);
 47  
         }
 48  0
         else if (args.length > 1)
 49  
         {
 50  0
             System.err.println("usage TestAudioTagger Dirname");
 51  0
             System.err.println("      Only one parameter accepted");
 52  0
             System.exit(1);
 53  
         }
 54  0
         File rootDir = new File(args[0]);
 55  0
         if (!rootDir.isDirectory())
 56  
         {
 57  0
             System.err.println("usage TestAudioTagger Dirname");
 58  0
             System.err.println("      Directory " + args[0] + " could not be found");
 59  0
             System.exit(1);
 60  
         }
 61  0
         Date start = new Date();
 62  0
         System.out.println("Started to read from:" + rootDir.getPath() + " at " + DateFormat.getTimeInstance().format(start));
 63  0
         test.scanSingleDir(rootDir);
 64  0
         Date finish = new Date();
 65  0
         System.out.println("Started to read from:" + rootDir.getPath() + " at " + DateFormat.getTimeInstance().format(start));
 66  0
         System.out.println("Finished to read from:" + rootDir.getPath() + DateFormat.getTimeInstance().format(finish));
 67  0
         System.out.println("Attempted  to read:" + count);
 68  0
         System.out.println("Successful to read:" + (count - failed));
 69  0
         System.out.println("Failed     to read:" + failed);
 70  
 
 71  0
     }
 72  
 
 73  
 
 74  0
     private static int count = 0;
 75  0
     private static int failed = 0;
 76  
 
 77  
     /**
 78  
      * Recursive function to scan directory
 79  
      * @param dir
 80  
      */
 81  
     private void scanSingleDir(final File dir)
 82  
     {
 83  
 
 84  0
         final File[] audioFiles = dir.listFiles(new AudioFileFilter(false));
 85  0
         if (audioFiles.length > 0)
 86  
         {
 87  0
             for (File audioFile : audioFiles)
 88  
             {
 89  0
                 count++;
 90  
                 try
 91  
                 {
 92  0
                     AudioFileIO.read(audioFile);
 93  
                 }
 94  0
                 catch (Throwable t)
 95  
                 {
 96  0
                     System.err.println("Unable to read record:" + count + ":" + audioFile.getPath());
 97  0
                     failed++;
 98  0
                     t.printStackTrace();
 99  0
                 }
 100  
             }
 101  
         }
 102  
 
 103  0
         final File[] audioFileDirs = dir.listFiles(new DirFilter());
 104  0
         if (audioFileDirs.length > 0)
 105  
         {
 106  0
             for (File audioFileDir : audioFileDirs)
 107  
             {
 108  0
                 scanSingleDir(audioFileDir);
 109  
             }
 110  
         }
 111  0
     }
 112  
 
 113  
 
 114  0
     public final class DirFilter implements java.io.FileFilter
 115  
     {
 116  
         public DirFilter()
 117  0
         {
 118  
 
 119  0
         }
 120  
 
 121  
 
 122  
         /**
 123  
          * Determines whether or not the file is an mp3 file.  If the file is
 124  
          * a directory, whether or not is accepted depends upon the
 125  
          * allowDirectories flag passed to the constructor.
 126  
          *
 127  
          * @param file the file to test
 128  
          * @return true if this file or directory should be accepted
 129  
          */
 130  
         public final boolean accept(final java.io.File file)
 131  
         {
 132  0
             return file.isDirectory();
 133  
         }
 134  
 
 135  
         public static final String IDENT = "$Id: TestAudioTagger.java 832 2009-11-12 13:25:38Z paultaylor $";
 136  
     }
 137  
 }