public boolean tableIsExist() throws DbException { if (this.isCheckedDatabase()) { return true; } Cursor cursor = db.execQuery( "SELECT COUNT(*) AS c FROM sqlite_master WHERE type='table' AND name='" + tableName + "'"); if (cursor != null) { try { if (cursor.moveToNext()) { int count = cursor.getInt(0); if (count > 0) { this.setCheckedDatabase(true); return true; } } } catch (Throwable e) { throw new DbException(e); } finally { IOUtil.closeQuietly(cursor); } } return false; }
@Override protected void cancelWorks() { if (requestWorker != null && params.isCancelFast()) { requestWorker.interrupt(); } IOUtil.closeQuietly(request); }
@Override protected void onFinished() { if (tracker != null) { tracker.onFinished(request); } clearRawResult(); IOUtil.closeQuietly(request); callback.onFinished(); }
@Override public void close() throws IOException { if (inputStream != null) { IOUtil.closeQuietly(inputStream); } if (connection != null) { connection.disconnect(); } }
private void clearRawResult() { if (rawResult instanceof Closeable) { IOUtil.closeQuietly((Closeable) rawResult); } rawResult = null; }
/** * invoke via Loader * * @throws IOException */ @Override @TargetApi(Build.VERSION_CODES.KITKAT) public void sendRequest() throws IOException { isLoading = false; URL url = new URL(queryUrl); { // init connection Proxy proxy = params.getProxy(); if (proxy != null) { connection = (HttpURLConnection) url.openConnection(proxy); } else { connection = (HttpURLConnection) url.openConnection(); } connection.setInstanceFollowRedirects(true); connection.setReadTimeout(params.getConnectTimeout()); connection.setConnectTimeout(params.getConnectTimeout()); if (connection instanceof HttpsURLConnection) { ((HttpsURLConnection) connection).setSSLSocketFactory(params.getSslSocketFactory()); } } { // add headers try { Map<String, List<String>> singleMap = COOKIE_MANAGER.get(url.toURI(), new HashMap<String, List<String>>(0)); List<String> cookies = singleMap.get("Cookie"); if (cookies != null) { connection.setRequestProperty("Cookie", TextUtils.join(";", cookies)); } } catch (Throwable ex) { LogUtil.e(ex.getMessage(), ex); } HashMap<String, String> headers = params.getHeaders(); if (headers != null) { for (Map.Entry<String, String> entry : headers.entrySet()) { String name = entry.getKey(); String value = entry.getValue(); if (!TextUtils.isEmpty(name) && !TextUtils.isEmpty(value)) { connection.setRequestProperty(name, value); } } } } { // write body HttpMethod method = params.getMethod(); connection.setRequestMethod(method.toString()); if (HttpMethod.permitsRequestBody(method)) { RequestBody body = params.getRequestBody(); if (body != null) { if (body instanceof ProgressBody) { ((ProgressBody) body).setProgressHandler(progressHandler); } String contentType = body.getContentType(); if (!TextUtils.isEmpty(contentType)) { connection.setRequestProperty("Content-Type", contentType); } long contentLength = body.getContentLength(); if (contentLength < 0) { connection.setChunkedStreamingMode(256 * 1024); } else { if (contentLength < Integer.MAX_VALUE) { connection.setFixedLengthStreamingMode((int) contentLength); } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { connection.setFixedLengthStreamingMode(contentLength); } else { connection.setChunkedStreamingMode(256 * 1024); } } connection.setRequestProperty("Content-Length", String.valueOf(contentLength)); connection.setDoOutput(true); body.writeTo(connection.getOutputStream()); } } } LogUtil.d(queryUrl); int code = connection.getResponseCode(); if (code >= 300) { HttpException httpException = new HttpException(code, connection.getResponseMessage()); try { httpException.setResult(IOUtil.readStr(connection.getInputStream(), params.getCharset())); } catch (Throwable ignored) { } throw httpException; } { // save cookies try { Map<String, List<String>> headers = connection.getHeaderFields(); if (headers != null) { COOKIE_MANAGER.put(url.toURI(), headers); } } catch (Throwable ex) { LogUtil.e(ex.getMessage(), ex); } } isLoading = true; }