From 6fd4f617e5131bab9d289cf9ccb61b7383053279 Mon Sep 17 00:00:00 2001 From: Sylvia van Os Date: Sun, 11 Jul 2021 15:52:22 +0200 Subject: [PATCH] Fix .csv import fallback --- .../card_locker/importexport/CatimaImporter.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/protect/card_locker/importexport/CatimaImporter.java b/app/src/main/java/protect/card_locker/importexport/CatimaImporter.java index 4ba4a6275..f5df36e70 100644 --- a/app/src/main/java/protect/card_locker/importexport/CatimaImporter.java +++ b/app/src/main/java/protect/card_locker/importexport/CatimaImporter.java @@ -12,6 +12,7 @@ import org.apache.commons.csv.CSVFormat; import org.apache.commons.csv.CSVParser; import org.apache.commons.csv.CSVRecord; +import java.io.BufferedInputStream; import java.io.BufferedReader; import java.io.ByteArrayInputStream; import java.io.IOException; @@ -40,14 +41,17 @@ import protect.card_locker.ZipUtils; public class CatimaImporter implements Importer { public void importData(Context context, DBHelper db, InputStream input, char[] password) throws IOException, FormatException, InterruptedException { + InputStream bufferedInputStream = new BufferedInputStream(input); + bufferedInputStream.mark(100); + // First, check if this is a zip file - ZipInputStream zipInputStream = new ZipInputStream(input); + ZipInputStream zipInputStream = new ZipInputStream(bufferedInputStream); LocalFileHeader localFileHeader = zipInputStream.getNextEntry(); if (localFileHeader == null) { // This is not a zip file, try importing as bare CSV - input.reset(); - importCSV(context, db, input); + bufferedInputStream.reset(); + importCSV(context, db, bufferedInputStream); return; }