Add parser for FLAC metadata.
[sonitus.git] / src / main / java / net / pterodactylus / sonitus / io / flac / MetadataBlock.java
1 /*
2  * Sonitus - MetadataBlock.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 import java.io.IOException;
21 import java.io.InputStream;
22
23 /**
24  * A metadata block.
25  *
26  * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
27  */
28 public class MetadataBlock {
29
30         /** The header of the metadata block. */
31         private final Header header;
32
33         /** The data of the metadata block. */
34         private final Data data;
35
36         /**
37          * Creates a new metadata block.
38          *
39          * @param header
40          *              The header of the metadata block
41          * @param data
42          *              The data of the metadata block
43          */
44         MetadataBlock(Header header, Data data) {
45                 this.header = header;
46                 this.data = data;
47         }
48
49         //
50         // ACCESSORS
51         //
52
53         /**
54          * Returns the header of this metadata block.
55          *
56          * @return The header of this metadata block
57          */
58         public Header header() {
59                 return header;
60         }
61
62         /**
63          * Returns the data of this metadata block.
64          *
65          * @return The data of this metadata block
66          */
67         public Data data() {
68                 return data;
69         }
70
71         //
72         // STATIC METHODS
73         //
74
75         /**
76          * Parses the metadata block from the current position of the given input
77          * stream.
78          *
79          * @param inputStream
80          *              The input stream to parse the metadata block from
81          * @return The parsed metadata block
82          * @throws IOException
83          *              if an I/O error occurs
84          */
85         public static MetadataBlock parse(InputStream inputStream) throws IOException {
86                 Header header = Header.parse(inputStream);
87                 Data data = Data.parse(inputStream, header.blockType(), header.length());
88                 return new MetadataBlock(header, data);
89         }
90
91 }