extract compareBytes method

This commit is contained in:
Hannes Janetzek 2012-09-26 21:15:16 +02:00
parent 93d57c2577
commit 4fafce24b8

View File

@ -790,12 +790,12 @@ 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))
for (; i < 15 && pos + i < end; i++)
if (buf[pos + i] != RESPONSE_HTTP_OK[i])
return -1; return -1;
// for (int i = 0; i < 15 && pos + i < end; i++)
// if (buf[pos + i] != RESPONSE_HTTP_OK[i])
} else if (end - pos == 1) { } else if (end - pos == 1) {
// check empty line (header end) // check empty line (header end)
end += 1; end += 1;
@ -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();
} }