extract compareBytes method
This commit is contained in:
parent
93d57c2577
commit
4fafce24b8
@ -790,11 +790,11 @@ public class MapDatabase implements IMapDatabase {
|
|||||||
if (first) {
|
if (first) {
|
||||||
// check only for OK
|
// check only for OK
|
||||||
first = false;
|
first = false;
|
||||||
int i = 0;
|
if (!compareBytes(buf, pos, end, RESPONSE_HTTP_OK, 15))
|
||||||
|
return -1;
|
||||||
|
|
||||||
for (; i < 15 && pos + i < end; i++)
|
// for (int i = 0; i < 15 && pos + i < end; i++)
|
||||||
if (buf[pos + i] != RESPONSE_HTTP_OK[i])
|
// if (buf[pos + i] != RESPONSE_HTTP_OK[i])
|
||||||
return -1;
|
|
||||||
|
|
||||||
} else if (end - pos == 1) {
|
} else if (end - pos == 1) {
|
||||||
// check empty line (header end)
|
// check empty line (header end)
|
||||||
@ -935,8 +935,20 @@ public class MapDatabase implements IMapDatabase {
|
|||||||
return pos + i;
|
return pos + i;
|
||||||
}
|
}
|
||||||
|
|
||||||
// //////////////////////////// Tile cache
|
private static boolean compareBytes(byte[] buffer, int position, int available,
|
||||||
// ////////////////////////////////////
|
byte[] string, int length) {
|
||||||
|
|
||||||
|
if (available - position < length)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
for (int i = 0; i < length; i++)
|
||||||
|
if (buffer[position + i] != string[i])
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ///////////////////////// Tile cache /////////////////////////////////
|
||||||
|
|
||||||
private boolean cacheRead(Tile tile, File f) {
|
private boolean cacheRead(Tile tile, File f) {
|
||||||
if (f.exists() && f.length() > 0) {
|
if (f.exists() && f.length() > 0) {
|
||||||
@ -946,7 +958,7 @@ public class MapDatabase implements IMapDatabase {
|
|||||||
in = new FileInputStream(f);
|
in = new FileInputStream(f);
|
||||||
|
|
||||||
mContentLenth = f.length();
|
mContentLenth = f.length();
|
||||||
Log.d(TAG, tile + " using cache: " + mContentLenth);
|
Log.d(TAG, tile + " - using cache: " + mContentLenth);
|
||||||
mInputStream = in;
|
mInputStream = in;
|
||||||
|
|
||||||
decode();
|
decode();
|
||||||
@ -970,7 +982,7 @@ public class MapDatabase implements IMapDatabase {
|
|||||||
private boolean cacheBegin(Tile tile, File f) {
|
private boolean cacheBegin(Tile tile, File f) {
|
||||||
if (USE_CACHE) {
|
if (USE_CACHE) {
|
||||||
try {
|
try {
|
||||||
Log.d(TAG, "writing cache: " + tile);
|
Log.d(TAG, tile + " - writing cache");
|
||||||
mCacheFile = new FileOutputStream(f);
|
mCacheFile = new FileOutputStream(f);
|
||||||
|
|
||||||
if (mReadPos > 0) {
|
if (mReadPos > 0) {
|
||||||
@ -999,7 +1011,7 @@ public class MapDatabase implements IMapDatabase {
|
|||||||
try {
|
try {
|
||||||
mCacheFile.flush();
|
mCacheFile.flush();
|
||||||
mCacheFile.close();
|
mCacheFile.close();
|
||||||
Log.d(TAG, tile + " cache written " + file.length());
|
Log.d(TAG, tile + " - cache written " + file.length());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user