View Javadoc

1   /*
2    * Entagged Audio Tag library
3    * Copyright (c) 2003-2005 Raphaël Slinckx <raphael@slinckx.net>
4    * 
5    * This library is free software; you can redistribute it and/or
6    * modify it under the terms of the GNU Lesser General Public
7    * License as published by the Free Software Foundation; either
8    * version 2.1 of the License, or (at your option) any later version.
9    *  
10   * This library is distributed in the hope that it will be useful,
11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13   * Lesser General Public License for more details.
14   * 
15   * You should have received a copy of the GNU Lesser General Public
16   * License along with this library; if not, write to the Free Software
17   * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18   */
19  package entagged.audioformats.ape.util;
20  
21  import java.io.UnsupportedEncodingException;
22  
23  import entagged.audioformats.generic.TagField;
24  
25  public abstract class ApeTagField implements TagField {
26      
27      private String id;
28      private boolean binary;
29      
30      public ApeTagField(String id, boolean binary) {
31          this.id = id;
32          this.binary = binary;
33      }
34      
35      public String getId() {
36          return this.id;
37      }
38  
39      public boolean isBinary() {
40          return binary;
41      }
42  
43      public void isBinary(boolean b) {
44          this.binary = b;
45      }
46  
47      public boolean isCommon() {
48          return id.equals("Title") ||
49  		  id.equals("Album") ||
50  		  id.equals("Artist") ||
51  		  id.equals("Genre") ||
52  		  id.equals("Track") ||
53  		  id.equals("Year") ||
54  		  id.equals("Comment");
55      }
56  
57      protected void copy(byte[] src, byte[] dst, int dstOffset) {
58  		for(int i = 0; i<src.length; i++)
59  			dst[i+dstOffset] = src[i];
60  	}
61  	
62  	protected byte[] getSize(int size) {
63  		byte[] b = new byte[4];
64  		b[3] = (byte) ( ( size & 0xFF000000 ) >> 24 );
65  		b[2] = (byte) ( ( size & 0x00FF0000 ) >> 16 );
66  		b[1] = (byte) ( ( size & 0x0000FF00 ) >> 8 );
67  		b[0] = (byte) (   size & 0x000000FF );
68  		return b;
69  	}
70  	
71  	protected byte[] getBytes(String s, String encoding) throws UnsupportedEncodingException{
72  		return s.getBytes(encoding);
73  	}
74  	
75      public abstract boolean isEmpty();
76      public abstract String toString();
77      public abstract void copyContent(TagField field);
78      public abstract byte[] getRawContent() throws UnsupportedEncodingException;
79  }