/** * Opens a new HTTP stream for reading, i.e. a GET request. * * @param path the URL for the stream * @return the opened stream */ static HttpStreamWrapper openRead(HttpPath path) throws IOException { HttpStream stream = createStream(path); stream._isPost = false; HttpStreamWrapper wrapper = new HttpStreamWrapper(stream); String status = (String) wrapper.getAttribute("status"); // ioc/23p0 if ("404".equals(status)) { throw new FileNotFoundException(L.l("'{0}' returns a HTTP 404.", path.getURL())); } return wrapper; }
protected CacheEntry getCache() { if (_cacheEntry == null) { synchronized (_cache) { _cacheEntry = _cache.get(getPath()); if (_cacheEntry == null) { _cacheEntry = new CacheEntry(); _cache.put(getPath(), _cacheEntry); } } } long now; now = Alarm.getCurrentTime(); synchronized (_cacheEntry) { try { if (_cacheEntry.expires > now) return _cacheEntry; HttpStreamWrapper stream = (HttpStreamWrapper) openReadImpl(); stream.setHead(true); stream.setSocketTimeout(120000); String status = (String) stream.getAttribute("status"); if (status.equals("200")) { String lastModified = (String) stream.getAttribute("last-modified"); _cacheEntry.lastModified = 0; if (lastModified != null) { QDate date = QDate.getGlobalDate(); synchronized (date) { _cacheEntry.lastModified = date.parseDate(lastModified); } } String length = (String) stream.getAttribute("content-length"); _cacheEntry.length = 0; if (length != null) { _cacheEntry.length = Integer.parseInt(length); } } else _cacheEntry.lastModified = -1; _cacheEntry.expires = now + 5000; stream.close(); return _cacheEntry; } catch (Exception e) { _cacheEntry.lastModified = -1; _cacheEntry.expires = now + 5000; return _cacheEntry; } } }