diff --git a/android/src/com/mapswithme/util/log/ZipLogsTask.java b/android/src/com/mapswithme/util/log/ZipLogsTask.java index c607eb3c46..b880d8d289 100644 --- a/android/src/com/mapswithme/util/log/ZipLogsTask.java +++ b/android/src/com/mapswithme/util/log/ZipLogsTask.java @@ -58,8 +58,6 @@ class ZipLogsTask implements Runnable try(FileOutputStream dest = new FileOutputStream(toLocation, false); ZipOutputStream out = new ZipOutputStream(new BufferedOutputStream(dest))) { - BufferedInputStream origin; - if (sourceFile.isDirectory()) { zipSubFolder(out, sourceFile, sourceFile.getParent().length()); @@ -67,14 +65,19 @@ class ZipLogsTask implements Runnable else { byte data[] = new byte[BUFFER_SIZE]; - FileInputStream fi = new FileInputStream(sourcePath); - origin = new BufferedInputStream(fi, BUFFER_SIZE); - ZipEntry entry = new ZipEntry(getLastPathComponent(sourcePath)); - out.putNextEntry(entry); - int count; - while ((count = origin.read(data, 0, BUFFER_SIZE)) != -1) + try(FileInputStream fi = new FileInputStream(sourcePath); + BufferedInputStream origin = new BufferedInputStream(fi, BUFFER_SIZE);) { + ZipEntry entry = new ZipEntry(getLastPathComponent(sourcePath)); + out.putNextEntry(entry); + int count; + while ((count = origin.read(data, 0, BUFFER_SIZE)) != -1) { + out.write(data, 0, count); + } + } catch (Exception e) { - out.write(data, 0, count); + Log.e(TAG, "Failed to read zip file entry '" + sourcePath +"' to location '" + + toLocation + "'", e); + return false; } } }