Coverage Report - org.jaudiotagger.test.ExtractID3TagFromFile
 
Classes in this File Line Coverage Branch Coverage Complexity
ExtractID3TagFromFile
0%
0/20
0%
0/4
1.6
ExtractID3TagFromFile$MP3FileFilter
0%
0/7
0%
0/6
1.6
 
 1  
 package org.jaudiotagger.test;
 2  
 
 3  
 import org.jaudiotagger.audio.mp3.MP3File;
 4  
 
 5  
 import java.io.File;
 6  
 
 7  
 /**
 8  
  * Simple class that will attempt to recusively read all files within a directory, flags
 9  
  * errors that occur.
 10  
  */
 11  0
 public class ExtractID3TagFromFile
 12  
 {
 13  
 
 14  
     public static void main(final String[] args)
 15  
     {
 16  0
         ExtractID3TagFromFile test = new ExtractID3TagFromFile();
 17  
 
 18  0
         if (args.length != 2)
 19  
         {
 20  0
             System.err.println("usage ExtractID3TagFromFile Filename FilenameOut");
 21  0
             System.err.println("      You must enter the file to extract the tag from and where to extract to");
 22  0
             System.exit(1);
 23  
         }
 24  
 
 25  0
         File file = new File(args[0]);
 26  0
         File outFile = new File(args[1]);
 27  0
         if (!file.isFile())
 28  
         {
 29  0
             System.err.println("usage ExtractID3TagFromFile Filename FilenameOut");
 30  0
             System.err.println("      File " + args[0] + " could not be found");
 31  0
             System.exit(1);
 32  
         }
 33  
 
 34  
         try
 35  
         {
 36  0
             final MP3File tmpMP3 = new MP3File(file);
 37  0
             tmpMP3.extractID3v2TagDataIntoFile(outFile);
 38  
         }
 39  0
         catch (Exception e)
 40  
         {
 41  0
             System.err.println("Unable to extract tag");
 42  0
             System.exit(1);
 43  0
         }
 44  0
     }
 45  
 
 46  0
     final class MP3FileFilter extends javax.swing.filechooser.FileFilter implements java.io.FileFilter
 47  
     {
 48  
 
 49  
         /**
 50  
          * allows Directories
 51  
          */
 52  
         private final boolean allowDirectories;
 53  
 
 54  
         /**
 55  
          * Create a default MP3FileFilter.  The allowDirectories field will
 56  
          * default to false.
 57  
          */
 58  
         public MP3FileFilter()
 59  
         {
 60  0
             this(false);
 61  0
         }
 62  
 
 63  
         /**
 64  
          * Create an MP3FileFilter.  If allowDirectories is true, then this filter
 65  
          * will accept directories as well as mp3 files.  If it is false then
 66  
          * only mp3 files will be accepted.
 67  
          *
 68  
          * @param allowDirectories whether or not to accept directories
 69  
          */
 70  
         private MP3FileFilter(final boolean allowDirectories)
 71  0
         {
 72  0
             this.allowDirectories = allowDirectories;
 73  0
         }
 74  
 
 75  
         /**
 76  
          * Determines whether or not the file is an mp3 file.  If the file is
 77  
          * a directory, whether or not is accepted depends upon the
 78  
          * allowDirectories flag passed to the constructor.
 79  
          *
 80  
          * @param file the file to test
 81  
          * @return true if this file or directory should be accepted
 82  
          */
 83  
         public final boolean accept(final File file)
 84  
         {
 85  0
             return (((file.getName()).toLowerCase().endsWith(".mp3")) || (file.isDirectory() && (this.allowDirectories == true)));
 86  
         }
 87  
 
 88  
         /**
 89  
          * Returns the Name of the Filter for use in the Chooser Dialog
 90  
          *
 91  
          * @return The Description of the Filter
 92  
          */
 93  
         public final String getDescription()
 94  
         {
 95  0
             return new String(".mp3 Files");
 96  
         }
 97  
     }
 98  
 
 99  
     public static final String IDENT = "$Id: ExtractID3TagFromFile.java,v 1.5 2008/07/21 10:46:30 paultaylor Exp $";
 100  
 
 101  
 }