7bb10bdb93c50c4ac7fcd8782abf0cd1c8ec951c
[sonitus.git] / src / main / java / net / pterodactylus / sonitus / data / Source.java
1 /*
2  * Sonitus - Source.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.data;
19
20 import java.io.EOFException;
21 import java.io.IOException;
22
23 /**
24  * Defines an arbitrary media source. This can be almost anything; an MP3 file,
25  * a FastTracker module, or a decoded WAVE file.
26  *
27  * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
28  */
29 public interface Source {
30
31         /**
32          * Returns the metadata of this source.
33          *
34          * @return The metadata of this source
35          */
36         Metadata metadata();
37
38         /**
39          * Retrieves the given name of bytes from this source. The source should always
40          * try to read as much data as was requested but is free to return a byte array
41          * with less elements that requested. However, the byte array will always be
42          * the same size as the data that was actually read, i.e. there are no excess
43          * elements in the returned array.
44          *
45          * @param bufferSize
46          *              The size of the buffer
47          * @return A buffer that contains the read data
48          * @throws EOFException
49          *              if the end of the source was reached
50          * @throws IOException
51          *              if an I/O error occurs
52          */
53         byte[] get(int bufferSize) throws EOFException, IOException;
54
55 }