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 830 2009-11-12 12:23:47Z paultaylor $
 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 java.io.IOException;
 28  
 import java.io.RandomAccessFile;
 29  
 import java.nio.ByteBuffer;
 30  
 import java.nio.channels.FileChannel;
 31  
 import java.util.logging.Logger;
 32  
 import java.util.regex.Pattern;
 33  
 
 34  
 /**
 35  
  * This is the abstract base class for all ID3v1 tags.
 36  
  *
 37  
  * @author : Eric Farng
 38  
  * @author : Paul Taylor
 39  
  */
 40  
 abstract public class AbstractID3v1Tag extends AbstractID3Tag
 41  
 {
 42  
 
 43  
     //Logger
 44  4
     public static Logger logger = Logger.getLogger("org.jaudiotagger.tag.id3");
 45  
 
 46  
 
 47  
     public AbstractID3v1Tag()
 48  5112
     {
 49  5112
     }
 50  
 
 51  
     public AbstractID3v1Tag(AbstractID3v1Tag copyObject)
 52  
     {
 53  0
         super(copyObject);
 54  0
     }
 55  
 
 56  
     //If field is less than maximum field length this is how it is terminated
 57  
     protected static final byte END_OF_FIELD = (byte) 0;
 58  
 
 59  
     //Used to detect end of field in String constructed from Data
 60  4
     protected static Pattern endofStringPattern = Pattern.compile("\\x00");
 61  
 
 62  
     //Tag ID as held in file
 63  4
     protected static final byte[] TAG_ID = {(byte) 'T', (byte) 'A', (byte) 'G'};
 64  
 
 65  
     //Fields Lengths common to v1 and v1.1 tags
 66  
     protected static final int TAG_LENGTH = 128;
 67  
     protected static final int TAG_DATA_LENGTH = 125;
 68  
     protected static final int FIELD_TAGID_LENGTH = 3;
 69  
     protected static final int FIELD_TITLE_LENGTH = 30;
 70  
     protected static final int FIELD_ARTIST_LENGTH = 30;
 71  
     protected static final int FIELD_ALBUM_LENGTH = 30;
 72  
     protected static final int FIELD_YEAR_LENGTH = 4;
 73  
     protected static final int FIELD_GENRE_LENGTH = 1;
 74  
 
 75  
     //Field Positions, starting from zero so fits in with Java Terminology
 76  
     protected static final int FIELD_TAGID_POS = 0;
 77  
     protected static final int FIELD_TITLE_POS = 3;
 78  
     protected static final int FIELD_ARTIST_POS = 33;
 79  
     protected static final int FIELD_ALBUM_POS = 63;
 80  
     protected static final int FIELD_YEAR_POS = 93;
 81  
     protected static final int FIELD_GENRE_POS = 127;
 82  
 
 83  
     //For writing output
 84  
     protected static final String TYPE_TITLE = "title";
 85  
     protected static final String TYPE_ARTIST = "artist";
 86  
     protected static final String TYPE_ALBUM = "album";
 87  
     protected static final String TYPE_YEAR = "year";
 88  
     protected static final String TYPE_GENRE = "genre";
 89  
 
 90  
     /**
 91  
      * Return the size of this tag, the size is fixed for tags of this type
 92  
      *
 93  
      * @return size of this tag in bytes
 94  
      */
 95  
     public int getSize()
 96  
     {
 97  0
         return TAG_LENGTH;
 98  
     }
 99  
 
 100  
     /**
 101  
      * Delete tag from file
 102  
      * Looks for tag and if found lops it off the file.
 103  
      *
 104  
      * @param file to delete the tag from
 105  
      * @throws IOException if there was a problem accessing the file
 106  
      */
 107  
     public void delete(RandomAccessFile file) throws IOException
 108  
     {
 109  
         //Read into Byte Buffer
 110  1239
         logger.info("Deleting ID3v1 from file if exists");
 111  
 
 112  
         FileChannel fc;
 113  
         ByteBuffer byteBuffer;
 114  
 
 115  
 
 116  1239
         fc = file.getChannel();
 117  1239
         fc.position(file.length() - TAG_LENGTH);
 118  1239
         byteBuffer = ByteBuffer.allocate(TAG_LENGTH);
 119  1239
         fc.read(byteBuffer);
 120  1239
         byteBuffer.rewind();
 121  1239
         if (seek(byteBuffer))
 122  
         {
 123  241
             logger.info("Deleted ID3v1 tag ");
 124  241
             file.setLength(file.length() - TAG_LENGTH);
 125  
         }
 126  
         else
 127  
         {
 128  998
             logger.info("Unable to find ID3v1 tag to deleteField");
 129  
         }
 130  1239
     }
 131  
 
 132  
  
 133  
 }