forked from codinguser/gnucash-android
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Always Zip files when exporting to QIF
When having transactions with multiple commodities, a QIF file for each commodity is created. With Android's Storage Access Framework we are limited to one file, so now we always pack QIFs into a single ZIP file. Fixes codinguser#696
- Loading branch information
Showing
2 changed files
with
48 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package org.gnucash.android.util; | ||
|
||
import java.io.File; | ||
import java.io.FileInputStream; | ||
import java.io.FileOutputStream; | ||
import java.io.IOException; | ||
import java.io.OutputStream; | ||
import java.util.List; | ||
import java.util.zip.ZipEntry; | ||
import java.util.zip.ZipOutputStream; | ||
|
||
/** | ||
* Misc methods for dealing with files. | ||
*/ | ||
public final class FileUtils { | ||
public static void zipFiles(List<String> files, String zipFileName) throws IOException { | ||
OutputStream outputStream = new FileOutputStream(zipFileName); | ||
ZipOutputStream zipOutputStream = new ZipOutputStream(outputStream); | ||
byte[] buffer = new byte[1024]; | ||
for (String fileName : files) { | ||
File file = new File(fileName); | ||
FileInputStream fileInputStream = new FileInputStream(file); | ||
zipOutputStream.putNextEntry(new ZipEntry(file.getName())); | ||
|
||
int length; | ||
while ((length = fileInputStream.read(buffer)) > 0) { | ||
zipOutputStream.write(buffer, 0, length); | ||
} | ||
zipOutputStream.closeEntry(); | ||
fileInputStream.close(); | ||
} | ||
zipOutputStream.close(); | ||
} | ||
} |