Coverage Report - org.jaudiotagger.fix.Fix202
 
Classes in this File Line Coverage Branch Coverage Complexity
Fix202
0%
0/40
0%
0/10
0
Fix202$OggFileFilter
0%
0/4
N/A
0
 
 1  
 package org.jaudiotagger.fix;
 2  
 
 3  
 import org.jaudiotagger.audio.ogg.OggFileReader;
 4  
 import org.jaudiotagger.audio.AudioFile;
 5  
 import org.jaudiotagger.fix.Fix;
 6  
 
 7  
 import java.io.File;
 8  
 
 9  
 /**
 10  
  * Simple class that will attempt to recusively read all files within a directory, flags
 11  
  * errors that occur.
 12  
  */
 13  0
 public class Fix202
 14  
 {
 15  
 
 16  
     public static void main(final String[] args)
 17  
     {
 18  0
         Fix202 test = new Fix202();
 19  
 
 20  0
         if (args.length != 1)
 21  
         {
 22  0
             System.err.println("usage Fix202 Folder");
 23  0
             System.err.println("      You must enter the folder containing the corrupted files");
 24  0
             System.exit(1);
 25  
         }
 26  
 
 27  0
         File dir = new File(args[0]);
 28  
 
 29  0
         if (!dir.exists())
 30  
         {
 31  0
             System.err.println("usage Fix202 Folder");
 32  0
             System.err.println("      File " + args[0] + " does not exist");
 33  0
             System.exit(1);
 34  
         }
 35  0
         if (!dir.isDirectory())
 36  
         {
 37  0
             System.err.println("usage Fix202 Folder");
 38  0
             System.err.println("      File " + args[0] + " is not a folder");
 39  0
             System.exit(1);
 40  
         }
 41  
 
 42  
         try
 43  
         {
 44  0
             final File[] audioFiles = dir.listFiles(new OggFileFilter());
 45  0
             if (audioFiles.length > 0)
 46  
             {
 47  0
                 for (File oggFile : audioFiles)
 48  
                 {
 49  0
                     System.out.print("Processing " + oggFile.getPath() +" ");
 50  
                     try
 51  
                     {
 52  
                           //Read as broken dir, and save to fix
 53  0
                           OggFileReader fileReader = new OggFileReader();
 54  0
                           AudioFile audioFile = fileReader.read(oggFile);
 55  
 
 56  
                           //Read normally so not broken
 57  0
                           System.out.println(":Not Broken");
 58  0
                           continue;
 59  
 
 60  
                     }
 61  0
                     catch (Throwable t)
 62  
                     {
 63  
                         //Nneds fix continue
 64  
                     }
 65  
 
 66  
                     try
 67  
                     {
 68  
                           //Read as broken dir, and save to fix
 69  0
                           OggFileReader fileReader = new OggFileReader(Fix.FIX_OGG_VORBIS_COMMENT_NOT_COUNTING_EMPTY_COLUMNS);
 70  0
                           AudioFile audioFile = fileReader.read(oggFile);
 71  0
                           audioFile.commit();
 72  
 
 73  
                           //Read again normally to check fix
 74  0
                           fileReader = new OggFileReader();
 75  0
                           audioFile = fileReader.read(oggFile);
 76  0
                           audioFile.commit();
 77  0
                           System.out.println(":********Fixed*************");
 78  
 
 79  
                     }
 80  0
                     catch (Throwable t)
 81  
                     {
 82  0
                         System.err.println("Unable to fix");
 83  0
                     }
 84  
                 }
 85  
             }
 86  
         }
 87  0
         catch (Exception e)
 88  
         {
 89  0
             System.err.println("Unable to extract tag");
 90  0
             System.exit(1);
 91  0
         }
 92  0
     }
 93  
 
 94  0
     static class OggFileFilter
 95  
             extends javax.swing.filechooser.FileFilter
 96  
             implements java.io.FileFilter
 97  
     {
 98  
 
 99  
 
 100  
 
 101  
         /**
 102  
          * Create a default OggFileFilter.  The allowDirectories field will
 103  
          * default to false.
 104  
          */
 105  
         public OggFileFilter()
 106  0
         {
 107  0
         }
 108  
 
 109  
 
 110  
 
 111  
         /**
 112  
          * Determines whether or not the file is an mp3 file.  If the file is
 113  
          * a directory, whether or not is accepted depends upon the
 114  
          * allowDirectories flag passed to the constructor.
 115  
          *
 116  
          * @param file the file to test
 117  
          * @return true if this file or directory should be accepted
 118  
          */
 119  
         public final boolean accept(final File file)
 120  
         {
 121  0
             return (
 122  
                     (file.getName()).toLowerCase().endsWith(".ogg")
 123  
 
 124  
             );
 125  
         }
 126  
 
 127  
         /**
 128  
          * Returns the Name of the Filter for use in the Chooser Dialog
 129  
          *
 130  
          * @return The Description of the Filter
 131  
          */
 132  
         public final String getDescription()
 133  
         {
 134  0
             return new String(".ogg Files");
 135  
         }
 136  
     }
 137  
 
 138  
     public static final String IDENT = "$Id: Fix202.java,v 1.1 2008/02/21 14:26:33 paultaylor Exp $";
 139  
 
 140  
 }