summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorByteHamster <info@bytehamster.com>2022-10-19 20:29:29 +0200
committerByteHamster <info@bytehamster.com>2022-10-21 21:46:18 +0200
commit9624d8ce9e5e5dc4df6330197e3294a079e3eb94 (patch)
tree19221c9ff3cc32a37040d38df635e6de71465840
parent25dd4902ba47d60b854e329fc8344588b3a03977 (diff)
downloadAntennaPod-9624d8ce9e5e5dc4df6330197e3294a079e3eb94.zip
Speed up chapter parsing
-rw-r--r--core/src/main/java/de/danoeh/antennapod/core/feed/LocalFeedUpdater.java4
-rw-r--r--core/src/main/java/de/danoeh/antennapod/core/util/ChapterUtils.java9
-rw-r--r--parser/media/src/main/java/de/danoeh/antennapod/parser/media/id3/ID3Reader.java13
-rw-r--r--parser/media/src/main/java/de/danoeh/antennapod/parser/media/id3/model/FrameHeader.java11
4 files changed, 14 insertions, 23 deletions
diff --git a/core/src/main/java/de/danoeh/antennapod/core/feed/LocalFeedUpdater.java b/core/src/main/java/de/danoeh/antennapod/core/feed/LocalFeedUpdater.java
index e8bf3d495..742df3f14 100644
--- a/core/src/main/java/de/danoeh/antennapod/core/feed/LocalFeedUpdater.java
+++ b/core/src/main/java/de/danoeh/antennapod/core/feed/LocalFeedUpdater.java
@@ -9,6 +9,7 @@ import android.util.Log;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
+import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.text.ParseException;
@@ -218,7 +219,8 @@ public class LocalFeedUpdater {
mediaMetadataRetriever.close();
try (InputStream inputStream = context.getContentResolver().openInputStream(file.getUri())) {
- Id3MetadataReader reader = new Id3MetadataReader(new CountingInputStream(inputStream));
+ Id3MetadataReader reader = new Id3MetadataReader(
+ new CountingInputStream(new BufferedInputStream(inputStream)));
reader.readInputStream();
item.setDescriptionIfLonger(reader.getComment());
} catch (IOException | ID3ReaderException e) {
diff --git a/core/src/main/java/de/danoeh/antennapod/core/util/ChapterUtils.java b/core/src/main/java/de/danoeh/antennapod/core/util/ChapterUtils.java
index 723ea1d47..cc63bf2b0 100644
--- a/core/src/main/java/de/danoeh/antennapod/core/util/ChapterUtils.java
+++ b/core/src/main/java/de/danoeh/antennapod/core/util/ChapterUtils.java
@@ -23,6 +23,7 @@ import okhttp3.Request;
import okhttp3.Response;
import org.apache.commons.io.input.CountingInputStream;
+import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
@@ -120,17 +121,17 @@ public class ChapterUtils {
if (!source.exists()) {
throw new IOException("Local file does not exist");
}
- return new CountingInputStream(new FileInputStream(source));
+ return new CountingInputStream(new BufferedInputStream(new FileInputStream(source)));
} else if (playable.getStreamUrl().startsWith(ContentResolver.SCHEME_CONTENT)) {
Uri uri = Uri.parse(playable.getStreamUrl());
- return new CountingInputStream(context.getContentResolver().openInputStream(uri));
+ return new CountingInputStream(new BufferedInputStream(context.getContentResolver().openInputStream(uri)));
} else {
Request request = new Request.Builder().url(playable.getStreamUrl()).build();
Response response = AntennapodHttpClient.getHttpClient().newCall(request).execute();
if (response.body() == null) {
throw new IOException("Body is null");
}
- return new CountingInputStream(response.body().byteStream());
+ return new CountingInputStream(new BufferedInputStream(response.body().byteStream()));
}
}
@@ -171,7 +172,7 @@ public class ChapterUtils {
@NonNull
private static List<Chapter> readOggChaptersFromInputStream(InputStream input) throws VorbisCommentReaderException {
- VorbisCommentChapterReader reader = new VorbisCommentChapterReader(input);
+ VorbisCommentChapterReader reader = new VorbisCommentChapterReader(new BufferedInputStream(input));
reader.readInputStream();
List<Chapter> chapters = reader.getChapters();
if (chapters == null) {
diff --git a/parser/media/src/main/java/de/danoeh/antennapod/parser/media/id3/ID3Reader.java b/parser/media/src/main/java/de/danoeh/antennapod/parser/media/id3/ID3Reader.java
index baaff2752..a791baf66 100644
--- a/parser/media/src/main/java/de/danoeh/antennapod/parser/media/id3/ID3Reader.java
+++ b/parser/media/src/main/java/de/danoeh/antennapod/parser/media/id3/ID3Reader.java
@@ -46,7 +46,7 @@ public class ID3Reader {
}
protected void readFrame(@NonNull FrameHeader frameHeader) throws IOException, ID3ReaderException {
- Log.d(TAG, "Skipping frame: " + frameHeader.toString());
+ Log.d(TAG, "Skipping frame: " + frameHeader.getId() + ", size: " + frameHeader.getSize());
skipBytes(frameHeader.getSize());
}
@@ -106,7 +106,7 @@ public class ID3Reader {
@NonNull
FrameHeader readFrameHeader() throws IOException {
- String id = readIsoStringFixed(FRAME_ID_LENGTH);
+ String id = readPlainBytesToString(FRAME_ID_LENGTH);
int size = readInt();
if (tagHeader != null && tagHeader.getVersion() >= 0x0400) {
size = unsynchsafe(size);
@@ -136,15 +136,14 @@ public class ID3Reader {
return readEncodedString(encoding, max - 1);
}
- @SuppressWarnings("CharsetObjectCanBeUsed")
- protected String readIsoStringFixed(int length) throws IOException {
- ByteArrayOutputStream bytes = new ByteArrayOutputStream();
+ protected String readPlainBytesToString(int length) throws IOException {
+ StringBuilder stringBuilder = new StringBuilder();
int bytesRead = 0;
while (bytesRead < length) {
- bytes.write(readByte());
+ stringBuilder.append((char) readByte());
bytesRead++;
}
- return Charset.forName("ISO-8859-1").newDecoder().decode(ByteBuffer.wrap(bytes.toByteArray())).toString();
+ return stringBuilder.toString();
}
protected String readIsoStringNullTerminated(int max) throws IOException {
diff --git a/parser/media/src/main/java/de/danoeh/antennapod/parser/media/id3/model/FrameHeader.java b/parser/media/src/main/java/de/danoeh/antennapod/parser/media/id3/model/FrameHeader.java
index 1a298a0df..3dd19008c 100644
--- a/parser/media/src/main/java/de/danoeh/antennapod/parser/media/id3/model/FrameHeader.java
+++ b/parser/media/src/main/java/de/danoeh/antennapod/parser/media/id3/model/FrameHeader.java
@@ -1,18 +1,7 @@
package de.danoeh.antennapod.parser.media.id3.model;
-import androidx.annotation.NonNull;
-
public class FrameHeader extends Header {
- private final short flags;
-
public FrameHeader(String id, int size, short flags) {
super(id, size);
- this.flags = flags;
- }
-
- @Override
- @NonNull
- public String toString() {
- return String.format("FrameHeader [flags=%s, id=%s, size=%s]", Integer.toBinaryString(flags), id, size);
}
}