Merge pull request #4153 from ByteHamster/fix-bom-opml

Fixed importing OPML files with BOM
This commit is contained in:
H. Lehmann 2020-05-16 22:31:17 +02:00 committed by GitHub
commit 5ff96fcc93
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 1 deletions

View File

@ -18,8 +18,12 @@ import de.danoeh.antennapod.asynctask.OpmlImportWorker;
import de.danoeh.antennapod.core.export.opml.OpmlElement;
import de.danoeh.antennapod.core.preferences.UserPreferences;
import de.danoeh.antennapod.core.util.LangUtils;
import org.apache.commons.io.ByteOrderMark;
import org.apache.commons.io.IOUtils;
import org.apache.commons.io.input.BOMInputStream;
import org.apache.commons.lang3.ArrayUtils;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.util.ArrayList;
@ -130,7 +134,12 @@ public class OpmlImportActivity extends AppCompatActivity {
/** Starts the import process. */
private void startImport() {
try {
Reader reader = new InputStreamReader(getContentResolver().openInputStream(uri), LangUtils.UTF_8);
InputStream opmlFileStream = getContentResolver().openInputStream(uri);
BOMInputStream bomInputStream = new BOMInputStream(opmlFileStream);
ByteOrderMark bom = bomInputStream.getBOM();
String charsetName = (bom == null) ? "UTF-8" : bom.getCharsetName();
Reader reader = new InputStreamReader(bomInputStream, charsetName);
OpmlImportWorker importWorker = new OpmlImportWorker(this, reader) {
@Override