Method to import (copy) sqlite files via AIDL

This commit is contained in:
madwasp79 2019-02-06 13:13:23 +02:00
parent ea990b2b44
commit 6cefbfa82c

View file

@ -1966,38 +1966,46 @@ public class OsmandAidlApi {
gpxAsyncLoaderTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); gpxAsyncLoaderTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
} }
private static int counter = 0; private static int partsCounter = 0;
private static long startTime = 0;
boolean appendDataToFile(final String filename, final byte[] data) { boolean appendDataToFile(final String filename, final byte[] data) {
File file = app.getAppPath(IndexConstants.TILES_INDEX_DIR + filename); File file = app.getAppPath(IndexConstants.TILES_INDEX_DIR + filename);
if (partsCounter == 0) {
startTime = System.currentTimeMillis();
LOG.debug("Start time = " + startTime);
}
if (filename.isEmpty() || data == null) { if (filename.isEmpty() || data == null) {
return false; return false;
}else if (data.length == 0) { }else if (data.length == 0) {
if (file.exists() && filename.endsWith(IndexConstants.SQLITE_EXT)) { if (file.exists() && filename.endsWith(IndexConstants.SQLITE_EXT)) {
processSqliteFileImport(Uri.fromFile(file), filename); LOG.debug("Copied file: " + filename +" (size = " + file.length()
+ " bytes) in: " + ((System.currentTimeMillis() - startTime) + " ms"));
partsCounter = 0;
} }
} else { } else {
FileOutputStream fos; FileOutputStream fos;
file.getParentFile().mkdirs(); file.getParentFile().mkdirs();
try { try {
counter++; if (partsCounter == 0) {
LOG.debug("File chunk #" + counter + " of size: " + data.length); fos = new FileOutputStream(file);
file.createNewFile(); } else {
fos = new FileOutputStream(file); fos = new FileOutputStream(file, true);
}
fos.write(data); fos.write(data);
partsCounter++;
fos.close(); fos.close();
fos.flush();
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
return true; return true;
} }
private void processSqliteFileImport(Uri uri, String filename) {
LOG.debug("path:" + uri.getPath());
LOG.debug("file:" + filename);
}
private static class GpxAsyncLoaderTask extends AsyncTask<Void, Void, GPXFile> { private static class GpxAsyncLoaderTask extends AsyncTask<Void, Void, GPXFile> {