diff --git a/vtm/src/org/oscim/tiling/source/LwHttp.java b/vtm/src/org/oscim/tiling/source/LwHttp.java index 079e24fe..905a7f27 100644 --- a/vtm/src/org/oscim/tiling/source/LwHttp.java +++ b/vtm/src/org/oscim/tiling/source/LwHttp.java @@ -252,7 +252,6 @@ public class LwHttp implements HttpEngine { byte[] buf = buffer; boolean first = true; - boolean ok = true; boolean gzip = false; int read = 0; @@ -272,7 +271,7 @@ public class LwHttp implements HttpEngine { end++; if (end == BUFFER_SIZE) { - return null; + throw new IOException("Header too large!"); } if (buf[end] != '\n') @@ -284,25 +283,24 @@ public class LwHttp implements HttpEngine { break; } - if (ok) { - if (first) { - first = false; - /* check only for OK ("HTTP/1.? ".length == 9) */ - if (!check(HEADER_HTTP_OK, buf, pos + 9, end)) - ok = false; - - } else if (check(HEADER_CONTENT_LENGTH, buf, pos, end)) { - /* parse Content-Length */ - contentLength = parseInt(buf, pos + - HEADER_CONTENT_LENGTH.length + 2, end - 1); - } else if (check(HEADER_ENCODING_GZIP, buf, pos, end)) { - gzip = true; - } else if (check(HEADER_CONNECTION_CLOSE, buf, pos, end)) { - mMustCloseConnection = true; + if (first) { + first = false; + /* check only for OK ("HTTP/1.? ".length == 9) */ + if (!check(HEADER_HTTP_OK, buf, pos + 9, end)) { + throw new IOException("HTTP Error: " + + new String(buf, pos, end - pos - 1)); } + } else if (check(HEADER_CONTENT_LENGTH, buf, pos, end)) { + /* parse Content-Length */ + contentLength = parseInt(buf, pos + + HEADER_CONTENT_LENGTH.length + 2, end - 1); + } else if (check(HEADER_ENCODING_GZIP, buf, pos, end)) { + gzip = true; + } else if (check(HEADER_CONNECTION_CLOSE, buf, pos, end)) { + mMustCloseConnection = true; } - if (!ok || dbg) { + if (dbg) { String line = new String(buf, pos, end - pos - 1); log.debug("> {} <", line); } @@ -311,9 +309,6 @@ public class LwHttp implements HttpEngine { end = pos; } - if (!ok) - return null; - /* back to start of content */ is.reset(); is.mark(0); diff --git a/vtm/src/org/oscim/tiling/source/OkHttpEngine.java b/vtm/src/org/oscim/tiling/source/OkHttpEngine.java index 1393e65a..bdde7398 100644 --- a/vtm/src/org/oscim/tiling/source/OkHttpEngine.java +++ b/vtm/src/org/oscim/tiling/source/OkHttpEngine.java @@ -17,6 +17,7 @@ */ package org.oscim.tiling.source; +import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -69,7 +70,12 @@ public class OkHttpEngine implements HttpEngine { for (Entry opt : mTileSource.getRequestHeader().entrySet()) conn.addRequestProperty(opt.getKey(), opt.getValue()); - inputStream = conn.getInputStream(); + try { + inputStream = conn.getInputStream(); + } catch (FileNotFoundException e) { + throw new IOException("ERROR " + conn.getResponseCode() + + ": " + conn.getResponseMessage()); + } } @Override diff --git a/vtm/src/org/oscim/tiling/source/UrlTileDataSource.java b/vtm/src/org/oscim/tiling/source/UrlTileDataSource.java index 001d46ee..5289c71b 100644 --- a/vtm/src/org/oscim/tiling/source/UrlTileDataSource.java +++ b/vtm/src/org/oscim/tiling/source/UrlTileDataSource.java @@ -76,23 +76,19 @@ public class UrlTileDataSource implements ITileDataSource { try { mConn.sendRequest(tile); InputStream is = mConn.read(); - if (is == null) { - log.debug("{} Network Error", tile); - } else { - if (mUseCache) { - cacheWriter = cache.writeTile(tile); - mConn.setCache(cacheWriter.getOutputStream()); - } - success = mTileDecoder.decode(tile, sink, is); + if (mUseCache) { + cacheWriter = cache.writeTile(tile); + mConn.setCache(cacheWriter.getOutputStream()); } + success = mTileDecoder.decode(tile, sink, is); } catch (SocketException e) { - log.debug("{} Socket exception: {}", tile, e.getMessage()); + log.debug("{} Socket Error: {}", tile, e.getMessage()); } catch (SocketTimeoutException e) { log.debug("{} Socket Timeout", tile); } catch (UnknownHostException e) { log.debug("{} Unknown host: {}", tile, e.getMessage()); } catch (IOException e) { - e.printStackTrace(); + log.debug("{} Network Error: {}", tile, e.getMessage()); } finally { success = mConn.requestCompleted(success); if (cacheWriter != null)