Coverage Report - org.jaudiotagger.tag.id3.AbstractID3v1Tag
 
Classes in this File Line Coverage Branch Coverage Complexity
AbstractID3v1Tag
84%
16/19
100%
2/2
1.25
 
 1  
 /**
 2  
  *  @author : Paul Taylor
 3  
  *  @author : Eric Farng
 4  
  *
 5  
  *  Version @version:$Id: AbstractID3v1Tag.java,v 1.16 2008/07/24 13:47:06 paultaylor Exp $
 6  
  *
 7  
  *  MusicTag Copyright (C)2003,2004
 8  
  *
 9  
  *  This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser
 10  
  *  General Public  License as published by the Free Software Foundation; either version 2.1 of the License,
 11  
  *  or (at your option) any later version.
 12  
  *
 13  
  *  This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
 14  
  *  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 15  
  *  See the GNU Lesser General Public License for more details.
 16  
  *
 17  
  *  You should have received a copy of the GNU Lesser General Public License along with this library; if not,
 18  
  *  you can get a copy from http://www.opensource.org/licenses/lgpl-license.php or write to the Free Software
 19  
  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 20  
  *
 21  
  * Description:
 22  
  * Abstract superclass of all URL Frames
 23  
  *
 24  
  */
 25  
 package org.jaudiotagger.tag.id3;
 26  
 
 27  
 import org.jaudiotagger.tag.datatype.Artwork;
 28  
 
 29  
 import java.io.IOException;
 30  
 import java.io.RandomAccessFile;
 31  
 import java.nio.ByteBuffer;
 32  
 import java.nio.channels.FileChannel;
 33  
 import java.util.logging.Logger;
 34  
 import java.util.regex.Pattern;
 35  
 import java.util.List;
 36  
 
 37  
 /**
 38  
  * This is the abstract base class for all ID3v1 tags.
 39  
  *
 40  
  * @author : Eric Farng
 41  
  * @author : Paul Taylor
 42  
  */
 43  
 abstract public class AbstractID3v1Tag extends AbstractID3Tag
 44  
 {
 45  
 
 46  
     //Logger
 47  49
     public static Logger logger = Logger.getLogger("org.jaudiotagger.tag.id3");
 48  
 
 49  
 
 50  
     public AbstractID3v1Tag()
 51  1083
     {
 52  1083
     }
 53  
 
 54  
     public AbstractID3v1Tag(AbstractID3v1Tag copyObject)
 55  
     {
 56  0
         super(copyObject);
 57  0
     }
 58  
 
 59  
     //If field is less than maximum field length this is how it is terminated
 60  
     protected static final byte END_OF_FIELD = (byte) 0;
 61  
 
 62  
     //Used to detect end of field in String constructed from Data
 63  1083
     protected Pattern endofStringPattern = Pattern.compile("\\x00");
 64  
 
 65  
     //Tag ID as held in file
 66  49
     protected static final byte[] TAG_ID = {(byte) 'T', (byte) 'A', (byte) 'G'};
 67  
 
 68  
     //Fields Lengths common to v1 and v1.1 tags
 69  
     protected static final int TAG_LENGTH = 128;
 70  
     protected static final int TAG_DATA_LENGTH = 125;
 71  
     protected static final int FIELD_TAGID_LENGTH = 3;
 72  
     protected static final int FIELD_TITLE_LENGTH = 30;
 73  
     protected static final int FIELD_ARTIST_LENGTH = 30;
 74  
     protected static final int FIELD_ALBUM_LENGTH = 30;
 75  
     protected static final int FIELD_YEAR_LENGTH = 4;
 76  
     protected static final int FIELD_GENRE_LENGTH = 1;
 77  
 
 78  
     //Field Positions, starting from zero so fits in with Java Terminology
 79  
     protected static final int FIELD_TAGID_POS = 0;
 80  
     protected static final int FIELD_TITLE_POS = 3;
 81  
     protected static final int FIELD_ARTIST_POS = 33;
 82  
     protected static final int FIELD_ALBUM_POS = 63;
 83  
     protected static final int FIELD_YEAR_POS = 93;
 84  
     protected static final int FIELD_GENRE_POS = 127;
 85  
 
 86  
     //For writing output
 87  
     protected static final String TYPE_TITLE = "title";
 88  
     protected static final String TYPE_ARTIST = "artist";
 89  
     protected static final String TYPE_ALBUM = "album";
 90  
     protected static final String TYPE_YEAR = "year";
 91  
     protected static final String TYPE_GENRE = "genre";
 92  
 
 93  
     /**
 94  
      * Return the size of this tag, the size is fixed for tags of this type
 95  
      *
 96  
      * @return size of this tag in bytes
 97  
      */
 98  
     public int getSize()
 99  
     {
 100  0
         return TAG_LENGTH;
 101  
     }
 102  
 
 103  
     /**
 104  
      * Delete tag from file
 105  
      * Looks for tag and if found lops it off the file.
 106  
      *
 107  
      * @param file to delete the tag from
 108  
      * @throws IOException if there was a problem accessing the file
 109  
      */
 110  
     public void delete(RandomAccessFile file) throws IOException
 111  
     {
 112  
         //Read into Byte Buffer
 113  261
         logger.info("Deleting ID3v1 from file if exists");
 114  
 
 115  
         FileChannel fc;
 116  
         ByteBuffer byteBuffer;
 117  
 
 118  
 
 119  261
         fc = file.getChannel();
 120  261
         fc.position(file.length() - TAG_LENGTH);
 121  261
         byteBuffer = ByteBuffer.allocate(TAG_LENGTH);
 122  261
         fc.read(byteBuffer);
 123  261
         byteBuffer.rewind();
 124  261
         if (seek(byteBuffer))
 125  
         {
 126  56
             logger.info("Deleted ID3v1 tag ");
 127  56
             file.setLength(file.length() - TAG_LENGTH);
 128  
         }
 129  
         else
 130  
         {
 131  205
             logger.info("Unable to find ID3v1 tag to delete");
 132  
         }
 133  261
     }
 134  
 
 135  
  
 136  
 }