Add parser for FLAC metadata.
[sonitus.git] / src / main / java / net / pterodactylus / sonitus / io / flac / BlockType.java
1 /*
2  * Sonitus - BlockType.java - Copyright © 2013 David Roden
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16  */
17
18 package net.pterodactylus.sonitus.io.flac;
19
20 /**
21  * The type of a metadata block.
22  *
23  * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
24  */
25 public enum BlockType {
26
27         /** A STREAMINFO block. */
28         STREAMINFO {
29                 @Override
30                 public Data createData(byte[] content) {
31                         return new StreamInfo(content);
32                 }
33         },
34
35         /** A PADDING block. */
36         PADDING,
37
38         /** An APPLICATION block. */
39         APPLICATION,
40
41         /** A SEEKTABLE block. */
42         SEEKTABLE,
43
44         /** A VORBIS_COMMENT block. */
45         VORBIS_COMMENT,
46
47         /** A CUESHEET block. */
48         CUESHEET,
49
50         /** A PICTURE block. */
51         PICTURE,
52
53         /** A RESERVED block. */
54         RESERVED,
55
56         /** An INVALID block. */
57         INVALID;
58
59         //
60         // ACTIONS
61         //
62
63         /**
64          * Creates a {@link Data} object from the given byte array. Block type
65          * enumeration values can override this to return specialized parser objects.
66          *
67          * @param content
68          *              The content of the metadata block
69          * @return The metadata block as a data object
70          */
71         public Data createData(byte[] content) {
72                 return new Data(content);
73         }
74
75         //
76         // STATIC METHODS
77         //
78
79         /**
80          * Creates a block type from the given block type number.
81          *
82          * @param blockType
83          *              The block type number
84          * @return The parsed block type
85          */
86         public static BlockType valueOf(int blockType) {
87                 if ((blockType >= 0) && (blockType <= 6)) {
88                         return values()[blockType];
89                 }
90                 if ((blockType > 6) && (blockType < 127)) {
91                         return RESERVED;
92                 }
93                 return INVALID;
94         }
95
96 }