1.Created new method multipleCardsExportImportPasswordProtected() in ImportExportTest.java \n 2.Added 5th Paramete

This commit is contained in:
Ankit Tiwari
2021-10-14 23:23:01 +05:30
parent d2b2a53109
commit fc9c616869
5 changed files with 54 additions and 12 deletions

View File

@@ -77,7 +77,7 @@ class ImportExportTask extends AsyncTask<Void, Void, ImportExportResult>
try
{
OutputStreamWriter writer = new OutputStreamWriter(stream, StandardCharsets.UTF_8);
result = MultiFormatExporter.exportData(context, db, stream, format);
result = MultiFormatExporter.exportData(context, db, stream, format,null);
writer.close();
}
catch (IOException e)

View File

@@ -6,6 +6,7 @@ import android.graphics.Bitmap;
import net.lingala.zip4j.io.outputstream.ZipOutputStream;
import net.lingala.zip4j.model.ZipParameters;
import net.lingala.zip4j.model.enums.EncryptionMethod;
import net.lingala.zip4j.util.InternalZipConstants;
import org.apache.commons.csv.CSVFormat;
@@ -30,14 +31,21 @@ import protect.card_locker.Utils;
*/
public class CatimaExporter implements Exporter
{
public void exportData(Context context, DBHelper db, OutputStream output) throws IOException, InterruptedException
public void exportData(Context context, DBHelper db, OutputStream output,char[] password) throws IOException, InterruptedException
{
// Necessary vars
int readLen;
byte[] readBuffer = new byte[InternalZipConstants.BUFF_SIZE];
// Create zip output stream
ZipOutputStream zipOutputStream = new ZipOutputStream(output);
ZipOutputStream zipOutputStream;
if(password!=null && password.length>0){
zipOutputStream = new ZipOutputStream(output,password);
}
else{
zipOutputStream = new ZipOutputStream(output);
}
// Generate CSV
ByteArrayOutputStream catimaOutputStream = new ByteArrayOutputStream();
@@ -47,6 +55,10 @@ public class CatimaExporter implements Exporter
// Add CSV to zip file
ZipParameters csvZipParameters = new ZipParameters();
csvZipParameters.setFileNameInZip("catima.csv");
if(password!=null && password.length>0){
csvZipParameters.setEncryptFiles(true);
csvZipParameters.setEncryptionMethod(EncryptionMethod.AES);
}
zipOutputStream.putNextEntry(csvZipParameters);
InputStream csvInputStream = new ByteArrayInputStream(catimaOutputStream.toByteArray());
while ((readLen = csvInputStream.read(readBuffer)) != -1) {

View File

@@ -17,5 +17,5 @@ public interface Exporter
* Export the database to the output stream in a given format.
* @throws IOException
*/
void exportData(Context context, DBHelper db, OutputStream output) throws IOException, InterruptedException;
void exportData(Context context, DBHelper db, OutputStream output,char[] password) throws IOException, InterruptedException;
}

View File

@@ -22,7 +22,7 @@ public class MultiFormatExporter
* another ImportExportResult otherwise. If not Success, partial data may have been
* written to the output stream, and it should be discarded.
*/
public static ImportExportResult exportData(Context context, DBHelper db, OutputStream output, DataFormat format)
public static ImportExportResult exportData(Context context, DBHelper db, OutputStream output, DataFormat format,char[] password)
{
Exporter exporter = null;
@@ -40,7 +40,7 @@ public class MultiFormatExporter
{
try
{
exporter.exportData(context, db, output);
exporter.exportData(context, db, output,password);
return ImportExportResult.Success;
}
catch(IOException e)