X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsonitus%2Fdata%2Fsource%2FFileSource.java;h=3d6e871903a063ba7babd937e1a216ed5733a634;hb=7188da95cfb6dc2bf140eb8ac7e4dc99a0761a97;hp=cc61ce0ae0bb45a15a113fc1ab1e9ec929ccdf40;hpb=b74bb6374b5b3f4d0f30fefe8771e9c48ceead13;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 cc61ce0..3d6e871 100644
--- a/src/main/java/net/pterodactylus/sonitus/data/source/FileSource.java
+++ b/src/main/java/net/pterodactylus/sonitus/data/source/FileSource.java
@@ -17,10 +17,10 @@
package net.pterodactylus.sonitus.data.source;
-import static com.google.common.base.Preconditions.*;
-import static net.pterodactylus.sonitus.data.Format.UNKNOWN_CHANNELS;
-import static net.pterodactylus.sonitus.data.Format.UNKNOWN_ENCODING;
-import static net.pterodactylus.sonitus.data.Format.UNKNOWN_FREQUENCY;
+import static com.google.common.base.Preconditions.checkNotNull;
+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 java.io.EOFException;
import java.io.FileInputStream;
@@ -28,15 +28,15 @@ import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
-import net.pterodactylus.sonitus.data.Format;
+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
*/
@@ -45,8 +45,8 @@ public class FileSource implements Source {
/** The path of the file. */
private final String path;
- /** The identified format of the file. */
- private final Format format;
+ /** The identified metadata of the file. */
+ private final Metadata metadata;
/** The input stream. */
private InputStream fileInputStream;
@@ -56,7 +56,7 @@ 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 {
@@ -66,10 +66,10 @@ public class FileSource implements Source {
/* identify file type. */
Optional identifyingInputStream = IdentifyingInputStream.create(new FileInputStream(path));
if (identifyingInputStream.isPresent()) {
- format = identifyingInputStream.get().format();
+ metadata = identifyingInputStream.get().metadata();
} else {
/* fallback. */
- format = new Format(UNKNOWN_CHANNELS, UNKNOWN_FREQUENCY, UNKNOWN_ENCODING);
+ metadata = new Metadata(UNKNOWN_CHANNELS, UNKNOWN_FREQUENCY, UNKNOWN_ENCODING).name(path);
}
}
@@ -78,27 +78,27 @@ public class FileSource implements Source {
//
@Override
- public Format format() {
- return format;
- }
-
- @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);
}
+ @Override
+ public Metadata metadata() {
+ return metadata;
+ }
+
//
// OBJECT METHODS
//
@Override
public String toString() {
- return String.format("%s (%s)", path, format);
+ return String.format("%s (%s)", path, metadata);
}
}