cleanup: LwHttp
This commit is contained in:
parent
0b82df4c21
commit
cb5de5135f
@ -34,7 +34,7 @@ import org.slf4j.LoggerFactory;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Lightweight HTTP connection for tile loading. Does not do redirects,
|
* Lightweight HTTP connection for tile loading. Does not do redirects,
|
||||||
* https, full header parsing or stuff.
|
* https, full header parsing or other stuff.
|
||||||
*/
|
*/
|
||||||
public class LwHttp implements HttpEngine {
|
public class LwHttp implements HttpEngine {
|
||||||
static final Logger log = LoggerFactory.getLogger(LwHttp.class);
|
static final Logger log = LoggerFactory.getLogger(LwHttp.class);
|
||||||
@ -81,7 +81,7 @@ public class LwHttp implements HttpEngine {
|
|||||||
|
|
||||||
String host = url.getHost();
|
String host = url.getHost();
|
||||||
String path = url.getPath();
|
String path = url.getPath();
|
||||||
log.debug("open database: " + host + " " + port + " " + path);
|
//log.debug("open database: {} {} {}", host, port, path);
|
||||||
|
|
||||||
REQUEST_GET_START = ("GET " + path).getBytes();
|
REQUEST_GET_START = ("GET " + path).getBytes();
|
||||||
|
|
||||||
@ -104,10 +104,6 @@ public class LwHttp implements HttpEngine {
|
|||||||
mRequestBuffer, 0, REQUEST_GET_START.length);
|
mRequestBuffer, 0, REQUEST_GET_START.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO:
|
|
||||||
// to avoid a copy in PbfDecoder one could manage the buffer
|
|
||||||
// array directly and provide access to it.
|
|
||||||
static class Buffer extends BufferedInputStream {
|
|
||||||
static final class Buffer extends BufferedInputStream {
|
static final class Buffer extends BufferedInputStream {
|
||||||
OutputStream cache;
|
OutputStream cache;
|
||||||
int bytesRead = 0;
|
int bytesRead = 0;
|
||||||
@ -203,9 +199,6 @@ public class LwHttp implements HttpEngine {
|
|||||||
if (data >= 0)
|
if (data >= 0)
|
||||||
bytesRead += 1;
|
bytesRead += 1;
|
||||||
|
|
||||||
//if (dbg)
|
|
||||||
// log.debug("read {} {}", bytesRead, contentLength);
|
|
||||||
|
|
||||||
if (cache != null && bytesRead > bytesWrote) {
|
if (cache != null && bytesRead > bytesWrote) {
|
||||||
bytesWrote = bytesRead;
|
bytesWrote = bytesRead;
|
||||||
cache.write(data);
|
cache.write(data);
|
||||||
@ -280,9 +273,8 @@ public class LwHttp implements HttpEngine {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!ok) {
|
if (ok) {
|
||||||
/* ignore until end of header */
|
if (first) {
|
||||||
} else if (first) {
|
|
||||||
first = false;
|
first = false;
|
||||||
/* check only for OK ("HTTP/1.? ".length == 9) */
|
/* check only for OK ("HTTP/1.? ".length == 9) */
|
||||||
if (!check(HEADER_HTTP_OK, buf, pos + 9, end))
|
if (!check(HEADER_HTTP_OK, buf, pos + 9, end))
|
||||||
@ -295,12 +287,7 @@ public class LwHttp implements HttpEngine {
|
|||||||
} else if (check(HEADER_CONNECTION_CLOSE, buf, pos, end)) {
|
} else if (check(HEADER_CONNECTION_CLOSE, buf, pos, end)) {
|
||||||
mMustClose = true;
|
mMustClose = true;
|
||||||
}
|
}
|
||||||
//} else if (check(HEADER_CONTENT_TYPE, buf, pos, end)) {
|
}
|
||||||
// check that response contains the expected
|
|
||||||
// Content-Type
|
|
||||||
//if (!check(mContentType, buf, pos +
|
|
||||||
// HEADER_CONTENT_TYPE.length + 2, end))
|
|
||||||
// ok = false;
|
|
||||||
|
|
||||||
if (!ok || dbg) {
|
if (!ok || dbg) {
|
||||||
String line = new String(buf, pos, end - pos - 1);
|
String line = new String(buf, pos, end - pos - 1);
|
||||||
@ -423,15 +410,6 @@ public class LwHttp implements HttpEngine {
|
|||||||
mResponseStream.setCache(null);
|
mResponseStream.setCache(null);
|
||||||
|
|
||||||
if (!mResponseStream.finishedReading()) {
|
if (!mResponseStream.finishedReading()) {
|
||||||
// StringBuffer sb = new StringBuffer();
|
|
||||||
// try {
|
|
||||||
// int val;
|
|
||||||
// while ((val = mResponseStream.read()) >= 0)
|
|
||||||
// sb.append((char) val);
|
|
||||||
// } catch (IOException e) {
|
|
||||||
//
|
|
||||||
// }
|
|
||||||
//log.debug("invalid buffer position {}", sb.toString());
|
|
||||||
log.debug("invalid buffer position");
|
log.debug("invalid buffer position");
|
||||||
close();
|
close();
|
||||||
return true;
|
return true;
|
||||||
@ -491,8 +469,6 @@ public class LwHttp implements HttpEngine {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Write tile url - the low level, no-allocations method,
|
|
||||||
*
|
|
||||||
* @param tile the Tile
|
* @param tile the Tile
|
||||||
* @param buf to write url string
|
* @param buf to write url string
|
||||||
* @param pos current position
|
* @param pos current position
|
||||||
|
Loading…
x
Reference in New Issue
Block a user