2 * Sonitus - FileSink.java - Copyright © 2013 David Roden
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.
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.
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/>.
18 package net.pterodactylus.sonitus.data.sink;
20 import java.io.FileOutputStream;
21 import java.io.IOException;
22 import java.util.logging.Logger;
24 import net.pterodactylus.sonitus.data.Metadata;
25 import net.pterodactylus.sonitus.data.Sink;
28 * {@link net.pterodactylus.sonitus.data.Sink} that writes all received data
31 * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
33 public class FileSink implements Sink {
36 private static final Logger logger = Logger.getLogger(FileSink.class.getName());
38 /** The path of the file to write to. */
39 private final String path;
41 private FileOutputStream fileOutputStream;
44 * Creates a new file sink that will write to the given path.
47 * The path of the file to write to
49 public FileSink(String path) {
54 public void open(Metadata metadata) throws IOException {
55 fileOutputStream = new FileOutputStream(path);
61 fileOutputStream.close();
62 } catch (IOException e) {
68 public void metadataUpdated(Metadata metadata) {
73 public void process(byte[] buffer) throws IOException {
74 fileOutputStream.write(buffer);
75 logger.finest(String.format("FileSink: Wrote %d Bytes.", buffer.length));