Write the first bytes to the buffer correctly.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sun, 2 Jun 2013 00:08:41 +0000 (02:08 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Tue, 4 Jun 2013 04:21:44 +0000 (06:21 +0200)
buffer is used as a ring buffer so new bytes have to go in at the end.

src/main/java/net/pterodactylus/sonitus/io/mp3/Parser.java

index 8a7e771..55165d8 100644 (file)
@@ -53,16 +53,16 @@ public class Parser {
         */
        public Parser(InputStream inputStream) throws IOException {
                this.inputStream = inputStream;
-               readFully(inputStream, buffer, 0, 3);
-               if ((buffer[0] == 'I') && (buffer[1] == 'D') && (buffer[2] == '3')) {
-                       readFully(inputStream, buffer, 0, 3);
+               readFully(inputStream, buffer, 1, 3);
+               if ((buffer[1] == 'I') && (buffer[2] == 'D') && (buffer[3] == '3')) {
+                       readFully(inputStream, buffer, 1, 3);
                        byte[] lengthBuffer = new byte[4];
                        readFully(inputStream, lengthBuffer, 0, 4);
                        int headerLength = (lengthBuffer[0] << 21) | (lengthBuffer[1] << 14) | (lengthBuffer[2] << 7) | lengthBuffer[3];
                        id3Tag = new byte[headerLength + 10];
-                       System.arraycopy(new byte[] { 'I', 'D', '3', buffer[0], buffer[1], buffer[2], lengthBuffer[0], lengthBuffer[1], lengthBuffer[2], lengthBuffer[3] }, 0, id3Tag, 0, 10);
+                       System.arraycopy(new byte[] { 'I', 'D', '3', buffer[1], buffer[2], buffer[3], lengthBuffer[0], lengthBuffer[1], lengthBuffer[2], lengthBuffer[3] }, 0, id3Tag, 0, 10);
                        readFully(inputStream, id3Tag, 10, headerLength);
-                       readFully(inputStream, buffer, 0, 3);
+                       readFully(inputStream, buffer, 1, 3);
                } else {
                        id3Tag = null;
                }