Permalink
Browse files

#850 should fix resource leaks related to gemf files, offline archive…

…s and the demo app. adds some test files sources from US national aviation charts at zoom 4
  • Loading branch information...
spyhunter99 committed Jan 6, 2018
1 parent cb15128 commit b41a8d42ac470e60a2b505b9615698bd7a2ae9a9
View
@@ -104,6 +104,9 @@ before_script:
- adb shell chmod 777 /mnt/sdcard
- adb shell mkdir /sdcard/osmdroid/
- adb push world.map /sdcard/osmdroid/world.map
- adb push testzoom4.sqlite /sdcard/osmdroid/testzoom4.sqlite
- adb push testzoom4.zip /sdcard/osmdroid/testzoom4.zip
- adb push testzoom4.gemf /sdcard/osmdroid/testzoom4.gemf
#maybe one day it will be added to the repo- adb push ERDC_Whitehorse_GeoPackage.gpkg /sdcard/osmdroid/ERDC_Whitehorse_GeoPackage.gpkg
#- adb push resources/usgsbase.gemf /sdcard/osmdroid/usgsbase.gemf
#- adb push resources/usgstopo.sqlite /sdcard/osmdroid/usgstopo.sqlite
@@ -91,6 +91,13 @@ public void addOverlays() {
this.mMapView.setUseDataConnection(true);
}
@Override
public void onDestroy(){
super.onDestroy();
if (tileWriter!=null)
tileWriter.onDetach();
}
/**
* step 1, users selects files
*/
@@ -128,7 +135,7 @@ public void onSelectedFilePaths(String[] files) {
dialog.show();
}
IFilesystemCache tileWriter=null;
/**
* step two, configure our offline tile provider
* @param files
@@ -137,8 +144,9 @@ private void setProviderConfig(String[] files) {
if (files == null || files.length == 0)
return;
SimpleRegisterReceiver simpleRegisterReceiver = new SimpleRegisterReceiver(getContext());
if (tileWriter!=null)
tileWriter.onDetach();
IFilesystemCache tileWriter;
if (Build.VERSION.SDK_INT < 10) {
tileWriter = new TileWriter();
@@ -140,22 +140,25 @@ public void setTileSource(final ITileSource pTileSource) {
@Override
public void detach() {
clearArcives();
super.detach();
}
private void clearArcives(){
while(!mArchiveFiles.isEmpty()) {
IArchiveFile t = mArchiveFiles.get(0);
if (t!=null)
mArchiveFiles.get(0).close();
t.close();
mArchiveFiles.remove(0);
}
super.detach();
}
// ===========================================================
// Methods
// ===========================================================
private void findArchiveFiles() {
mArchiveFiles.clear();
clearArcives();
if (!isSdCardAvailable()) {
return;
@@ -200,6 +203,7 @@ private synchronized InputStream getInputStream(final MapTile pTile,
@Override
public Drawable loadTile(final MapTile pTile) {
Drawable returnValue=null;
ITileSource tileSource = mTileSource.get();
if (tileSource == null) {
return null;
@@ -225,7 +229,7 @@ public Drawable loadTile(final MapTile pTile) {
Log.d(IMapView.LOGTAG,"Use tile from archive: " + pTile);
}
final Drawable drawable = tileSource.getDrawable(inputStream);
return drawable;
returnValue = drawable;
}
} catch (final Throwable e) {
Log.e(IMapView.LOGTAG,"Error loading tile", e);
@@ -235,7 +239,7 @@ public Drawable loadTile(final MapTile pTile) {
}
}
return null;
return returnValue;
}
}
}
@@ -20,6 +20,9 @@
*
* Reference: https://sites.google.com/site/abudden/android-map-store
*
* Do not reference any android specific code in this class, it is reused in the JRE
* Tile Packager
*
* @author A. S. Budden
* @author Erik Burrows
*
@@ -575,7 +578,9 @@ public InputStream getInputStream(final int pX, final int pY, final int pZ) {
long dataOffset;
int dataLength;
InputStream returnValue=null;
GEMFInputStream stream=null;
ByteArrayOutputStream byteBuffer=null;
try {
// Determine offset to requested tile record in the header
@@ -612,11 +617,9 @@ public InputStream getInputStream(final int pX, final int pY, final int pZ) {
// Read data block into a byte array
pDataFile.seek(dataOffset);
GEMFInputStream stream= new GEMFInputStream(mFileNames.get(index), dataOffset, dataLength);
stream= new GEMFInputStream(mFileNames.get(index), dataOffset, dataLength);
// this dynamically extends to take the bytes you read
ByteArrayOutputStream byteBuffer = new ByteArrayOutputStream();
byteBuffer = new ByteArrayOutputStream();
// this is storage overwritten on each iteration with bytes
int bufferSize = 1024;
@@ -633,11 +636,26 @@ public InputStream getInputStream(final int pX, final int pY, final int pZ) {
// and then we can return your byte array.
byte[] bits = byteBuffer.toByteArray();
return new ByteArrayInputStream(bits);
returnValue= new ByteArrayInputStream(bits);
} catch (final java.io.IOException e) {
return null;
e.printStackTrace();
} finally {
if (byteBuffer!=null)
try {
byteBuffer.close();
} catch (IOException e) {
e.printStackTrace();
}
if (stream!=null)
try {
stream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return returnValue;
}
View
BIN +117 KB testzoom4.gemf
Binary file not shown.
View
BIN +235 KB testzoom4.sqlite
Binary file not shown.
View
BIN +231 KB testzoom4.zip
Binary file not shown.

0 comments on commit b41a8d4

Please sign in to comment.