private File getExistingCacheFile(final long id) { final File externalCacheDir = context.getExternalCacheDir(); if (externalCacheDir != null) { final File fExternal = new File(externalCacheDir, id + ext); if (fExternal.exists()) { return fExternal; } } final File fInternal = new File(context.getCacheDir(), id + ext); if (fInternal.exists()) { return fInternal; } return null; }
private boolean saveAndVerify(ZipInputStream data) throws IOException { try { ZipEntry ze; while ((ze = data.getNextEntry()) != null) { // Filename + reference to file. String filename = ze.getName(); File output = new File(local_path + filename); if (filename.endsWith("/")) { output.mkdirs(); } else { if (output.exists()) { // Delete the file if it already exists. if (!output.delete()) { return false; } } if (output.createNewFile()) { FileOutputStream out = new FileOutputStream(output); byte[] buffer = new byte[1024]; int count; while ((count = data.read(buffer)) != -1) { out.write(buffer, 0, count); } } else { return false; } } } } catch (Exception e) { e.printStackTrace(); return false; } finally { data.close(); } return true; }