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.flac.util;
20  
21  public class MetadataBlockHeader {
22  	
23  	public final static int STREAMINFO=0,PADDING=1,APPLICATION=2,SEEKTABLE=3,VORBIS_COMMENT=4,CUESHEET=5,UNKNOWN=6;
24  	private boolean isLastBlock;
25  	private int blockType, dataLength;
26  	private byte[] bytes;
27  	
28  	public MetadataBlockHeader( byte[] b ) {
29  		isLastBlock = ( (b[0] & 0x80)>>>7 )==1;
30  		
31  		int type = b[0] & 0x7F;
32  		switch(type) {
33  			case 0: blockType = STREAMINFO;
34  					break;
35  			case 1: blockType = PADDING;
36  					break;
37  			case 2: blockType = APPLICATION;
38  					break;
39  			case 3: blockType = SEEKTABLE;
40  					break;
41  			case 4: blockType = VORBIS_COMMENT;
42  					break;
43  			case 5: blockType = CUESHEET;
44  					break;
45  			default: blockType = UNKNOWN;
46  		}
47  		
48  		dataLength = (u(b[1])<<16) + (u(b[2])<<8) + (u(b[3]));
49  		
50  		bytes = new byte[4];
51  		for(int i = 0; i< 4; i++)
52  			bytes[i] = b[i];
53  	}
54  	
55  	private int u(int i) {
56  		return i & 0xFF;
57  	}
58  	
59  	public int getDataLength() {
60  		return dataLength;
61  	}
62  	
63  	public int getBlockType() {
64  		return blockType;
65  	}
66  	
67  	public String getBlockTypeString() {
68  		switch(blockType) {
69  			case 0: return "STREAMINFO";
70  			case 1: return "PADDING";
71  			case 2: return "APPLICATION";
72  			case 3: return "SEEKTABLE";
73  			case 4: return "VORBIS_COMMENT";
74  			case 5: return "CUESHEET";
75  			default: return "UNKNOWN-RESERVED";
76  		}
77  	}
78  	
79  	public boolean isLastBlock() {
80  		return isLastBlock;
81  	}
82  	
83  	public byte[] getBytes() {
84  		bytes[0] = (byte)(bytes[0] & 0x7F);
85  		return bytes;
86  	}
87  }