X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;ds=sidebyside;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsonitus%2Fdata%2Fsource%2FFileSource.java;h=9aff8d401289cb9ed4644c83265b7e626a8acbb2;hb=cbeadf6d9eea57ab98cacd60e2419dd3c18bef89;hp=010eeb9b773c85829804a307f124aad046d0a781;hpb=e856fa2e451dbc626a5269fc14d01bca935db39a;p=sonitus.git
diff --git a/src/main/java/net/pterodactylus/sonitus/data/source/FileSource.java b/src/main/java/net/pterodactylus/sonitus/data/source/FileSource.java
index 010eeb9..9aff8d4 100644
--- a/src/main/java/net/pterodactylus/sonitus/data/source/FileSource.java
+++ b/src/main/java/net/pterodactylus/sonitus/data/source/FileSource.java
@@ -17,37 +17,35 @@
package net.pterodactylus.sonitus.data.source;
-import static com.google.common.base.Preconditions.*;
-import static net.pterodactylus.sonitus.data.Metadata.UNKNOWN_CHANNELS;
-import static net.pterodactylus.sonitus.data.Metadata.UNKNOWN_ENCODING;
-import static net.pterodactylus.sonitus.data.Metadata.UNKNOWN_FREQUENCY;
+import static com.google.common.base.Preconditions.checkNotNull;
import java.io.EOFException;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import net.pterodactylus.sonitus.data.AbstractControlledComponent;
+import net.pterodactylus.sonitus.data.Controller;
import net.pterodactylus.sonitus.data.Metadata;
import net.pterodactylus.sonitus.data.Source;
import net.pterodactylus.sonitus.io.IdentifyingInputStream;
import com.google.common.base.Optional;
-import com.google.common.io.ByteStreams;
/**
- * A {@link Source} that is read from the local file system.
+ * A {@link net.pterodactylus.sonitus.data.Source} that is read from the local
+ * file system.
*
* @author David âBombeâ Roden
*/
-public class FileSource implements Source {
+public class FileSource extends AbstractControlledComponent implements Source {
/** The path of the file. */
private final String path;
- /** The identified metadata of the file. */
- private final Metadata metadata;
-
/** The input stream. */
private InputStream fileInputStream;
@@ -56,37 +54,42 @@ public class FileSource implements Source {
*
* @param path
* The path of the file
- * @throws IOException
+ * @throws java.io.IOException
* if the file can not be found, or an I/O error occurs
*/
public FileSource(String path) throws IOException {
+ super(path);
this.path = checkNotNull(path, "path must not be null");
fileInputStream = new FileInputStream(path);
/* identify file type. */
Optional identifyingInputStream = IdentifyingInputStream.create(new FileInputStream(path));
if (identifyingInputStream.isPresent()) {
- metadata = identifyingInputStream.get().metadata();
+ metadataUpdated(identifyingInputStream.get().metadata());
} else {
/* fallback. */
- metadata = new Metadata(UNKNOWN_CHANNELS, UNKNOWN_FREQUENCY, UNKNOWN_ENCODING).name(path);
+ metadataUpdated(new Metadata().name(path));
}
}
//
- // SOURCE METHODS
+ // CONTROLLED METHODS
//
@Override
- public Metadata metadata() {
- return metadata;
+ public List> controllers() {
+ return Collections.emptyList();
}
+ //
+ // SOURCE METHODS
+ //
+
@Override
public byte[] get(int bufferSize) throws IOException {
byte[] buffer = new byte[bufferSize];
- int read = ByteStreams.read(fileInputStream, buffer, 0, bufferSize);
- if (read == 0) {
+ int read = fileInputStream.read(buffer);
+ if (read == -1) {
throw new EOFException();
}
return Arrays.copyOf(buffer, read);
@@ -98,7 +101,7 @@ public class FileSource implements Source {
@Override
public String toString() {
- return String.format("%s (%s)", path, metadata);
+ return String.format("%s (%s)", path, metadata());
}
}