Java Code Examples for org.kymjs.kjframe.utils.KJLoger#debug()

The following examples show how to use org.kymjs.kjframe.utils.KJLoger#debug() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: KJHttp.java    From KJFrameForAndroid with Apache License 2.0 6 votes vote down vote up
/**
 * 将一个请求标记为已完成
 */
public void finish(Request<?> request) {
    synchronized (mCurrentRequests) {
        mCurrentRequests.remove(request);
    }

    if (request.shouldCache()) {
        synchronized (mWaitingRequests) {
            String cacheKey = request.getCacheKey();
            Queue<Request<?>> waitingRequests = mWaitingRequests.remove(cacheKey);
            if (waitingRequests != null) {
                if (HttpConfig.DEBUG) {
                    KJLoger.debug("Releasing %d waiting requests for cacheKey=%s.",
                            waitingRequests.size(), cacheKey);
                }
                mCacheQueue.addAll(waitingRequests);
            }
        }
    }
}
 
Example 2
Source File: Parser.java    From KJFrameForAndroid with Apache License 2.0 6 votes vote down vote up
/**
 * 检测更新
 *
 * @param json
 */
public static String checkVersion(Context cxt, String json) {
    String url = "";
    try {
        JSONObject obj = new JSONObject(json);
        int serverVersion = obj.optInt("version", 0);
        int currentVersion = SystemTool.getAppVersionCode(cxt);
        KJLoger.debug("当前版本:" + currentVersion + "最新版本:" + serverVersion);
        if (serverVersion > currentVersion) {
            url = obj.optString("url");
        }
    } catch (JSONException e) {
        Log.e("kymjs", "getBlogList()解析异常");
    }
    return url;
}
 
Example 3
Source File: DiskCache.java    From KJFrameForAndroid with Apache License 2.0 6 votes vote down vote up
/**
 * Writes the contents of this CacheHeader to the specified
 * OutputStream.
 */
public boolean writeHeader(OutputStream os) {
    try {
        writeInt(os, CACHE_MAGIC);
        writeString(os, key);
        writeString(os, etag == null ? "" : etag);
        writeLong(os, serverDate);
        writeLong(os, ttl);
        writeLong(os, softTtl);
        writeStringStringMap(responseHeaders, os);
        os.flush();
        return true;
    } catch (IOException e) {
        KJLoger.debug("%s", e.toString());
        return false;
    }
}
 
Example 4
Source File: KJDB.java    From KJFrameForAndroid with Apache License 2.0 6 votes vote down vote up
/**
 * 删除所有数据表
 */
public void dropDb() {
    Cursor cursor = db.rawQuery(
            "SELECT name FROM sqlite_master WHERE type ='table'", null);
    if (cursor != null) {
        while (cursor.moveToNext()) {
            // 添加异常捕获.忽略删除所有表时出现的异常:
            // table sqlite_sequence may not be dropped
            try {
                db.execSQL("DROP TABLE " + cursor.getString(0));
            } catch (SQLException e) {
                KJLoger.debug(getClass().getName() + e.getMessage());
            }
        }
    }
    if (cursor != null) {
        cursor.close();
        cursor = null;
    }
}
 
Example 5
Source File: MainActivity.java    From Contacts with Apache License 2.0 6 votes vote down vote up
private void parser(String json) {
    try {
        JSONArray array = new JSONArray(json);
        for (int i = 0; i < array.length(); i++) {
            JSONObject object = array.optJSONObject(i);
            Contact data = new Contact();
            data.setName(object.optString("name"));
            data.setUrl(object.optString("portrait"));
            data.setId(object.optInt("id"));
            data.setPinyin(HanziToPinyin.getPinYin(data.getName()));
            datas.add(data);
        }
        mFooterView.setText(datas.size() + "位联系人");
        mAdapter = new ContactAdapter(mListView, datas);
        mListView.setAdapter(mAdapter);
    } catch (JSONException e) {
        KJLoger.debug("解析异常" + e.getMessage());
    }
}
 
Example 6
Source File: Network.java    From KJFrameForAndroid with Apache License 2.0 5 votes vote down vote up
/**
     * 把HttpEntry转换为byte[]
     *
     * @throws IOException
     * @throws KJHttpException
     */
    private byte[] entityToBytes(KJHttpResponse kjHttpResponse) throws IOException,
            KJHttpException {
        PoolingByteArrayOutputStream bytes = new PoolingByteArrayOutputStream(
                ByteArrayPool.get(), (int) kjHttpResponse.getContentLength());
        byte[] buffer = null;
        try {
            InputStream in = kjHttpResponse.getContentStream();
            if (in == null) {
                throw new KJHttpException("server error");
            }
            buffer = ByteArrayPool.get().getBuf(1024);
            int count;
            while ((count = in.read(buffer)) != -1) {
                bytes.write(buffer, 0, count);
            }
            return bytes.toByteArray();
        } finally {
            try {
//                entity.consumeContent();
                kjHttpResponse.getContentStream().close();
            } catch (IOException e) {
                KJLoger.debug("Error occured when calling consumingContent");
            }
            ByteArrayPool.get().returnBuf(buffer);
            bytes.close();
        }
    }
 
Example 7
Source File: FormRequest.java    From KJFrameForAndroid with Apache License 2.0 5 votes vote down vote up
@Override
public byte[] getBody() {
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    try {
        mParams.writeTo(bos);
    } catch (IOException e) {
        KJLoger.debug("FormRequest75--->IOException writing to ByteArrayOutputStream");
    }
    return bos.toByteArray();
}
 
Example 8
Source File: DiskCache.java    From KJFrameForAndroid with Apache License 2.0 5 votes vote down vote up
@Override
public synchronized void remove(String key) {
    boolean deleted = getFileForKey(key).delete();
    removeEntry(key);
    if (!deleted) {
        KJLoger.debug(
                "Could not delete cache entry for key=%s, filename=%s",
                key, getFilenameForKey(key));
    }
}
 
Example 9
Source File: DiskCache.java    From KJFrameForAndroid with Apache License 2.0 5 votes vote down vote up
/**
 * 获取一个cache
 *
 * @return 如果不存在返回null
 */
@Override
public synchronized Entry get(String key) {
    CacheHeader entry = mEntries.get(key);
    if (entry == null) {
        return null;
    }

    File file = getFileForKey(key);
    CountingInputStream cis = null;
    try {
        cis = new CountingInputStream(new FileInputStream(file));
        CacheHeader.readHeader(cis); // eat header
        byte[] data = streamToBytes(cis,
                (int) (file.length() - cis.bytesRead));
        return entry.toCacheEntry(data);
    } catch (IOException e) {
        KJLoger.debug("%s: %s", file.getAbsolutePath(), e.toString());
        remove(key);
        return null;
    } finally {
        if (cis != null) {
            try {
                cis.close();
            } catch (IOException ioe) {
                return null;
            }
        }
    }
}
 
Example 10
Source File: DiskCache.java    From KJFrameForAndroid with Apache License 2.0 5 votes vote down vote up
/**
 * 清空磁盘缓存
 */
@Override
public synchronized void clean() {
    File[] files = mRootDirectory.listFiles();
    if (files != null) {
        for (File file : files) {
            file.delete();
        }
    }
    mEntries.clear();
    mTotalSize = 0;
    KJLoger.debug("disk Cache cleared.");
}
 
Example 11
Source File: Request.java    From KJFrameForAndroid with Apache License 2.0 5 votes vote down vote up
/**
 * 通知请求队列,本次请求已经完成
 */
public void finish(final String tag) {
    if (mRequestQueue != null) {
        mRequestQueue.finish(this);
    }
    long requestTime = SystemClock.elapsedRealtime() - mRequestBirthTime;
    if (requestTime >= SLOW_REQUEST_THRESHOLD_MS) {
        KJLoger.debug("%d ms: %s", requestTime, this.toString());
    }
}
 
Example 12
Source File: JsonRequest.java    From KJFrameForAndroid with Apache License 2.0 5 votes vote down vote up
@Override
public byte[] getBody() {
    try {
        return mRequestBody == null ? null : mRequestBody
                .getBytes(PROTOCOL_CHARSET);
    } catch (UnsupportedEncodingException uee) {
        KJLoger.debug(
                "Unsupported Encoding while trying to get the bytes of %s using %s",
                mRequestBody, PROTOCOL_CHARSET);
        return null;
    }
}
 
Example 13
Source File: Property.java    From KJFrameForAndroid with Apache License 2.0 5 votes vote down vote up
private static Date stringToDateTime(String strDate) {
    if (strDate != null) {
        try {
            return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault()).parse
                    (strDate);
        } catch (ParseException e) {
            KJLoger.debug("时间解析异常");
        }
    }
    return null;
}
 
Example 14
Source File: ImageRequest.java    From KJFrameForAndroid with Apache License 2.0 5 votes vote down vote up
@Override
public Response<Bitmap> parseNetworkResponse(NetworkResponse response) {
    synchronized (sDecodeLock) {
        try {
            return doParse(response);
        } catch (OutOfMemoryError e) {
            KJLoger.debug("Caught OOM for %d byte image, url=%s",
                    response.data.length, getUrl());
            return Response.error(new KJHttpException(e));
        }
    }
}
 
Example 15
Source File: KJDB.java    From KJFrameForAndroid with Apache License 2.0 5 votes vote down vote up
private void exeSqlInfo(SqlInfo sqlInfo) {
    if (sqlInfo != null) {
        debugSql(sqlInfo.getSql());
        db.execSQL(sqlInfo.getSql(), sqlInfo.getBindArgsAsArray());
    } else {
        KJLoger.debug(getClass().getName() + "sava error:sqlInfo is null");
    }
}
 
Example 16
Source File: KJDB.java    From KJFrameForAndroid with Apache License 2.0 5 votes vote down vote up
/**
 * 把List<KeyValue>数据存储到ContentValues
 * 
 * @param list
 * @param cv
 */
private void insertContentValues(List<KeyValue> list, ContentValues cv) {
    if (list != null && cv != null) {
        for (KeyValue kv : list) {
            cv.put(kv.getKey(), kv.getValue().toString());
        }
    } else {
        KJLoger.debug(getClass().getName()
                + "insertContentValues: List<KeyValue> is empty or ContentValues is empty!");
    }

}
 
Example 17
Source File: GifRequest.java    From KJGallery with Apache License 2.0 5 votes vote down vote up
@Override
public Response<byte[]> parseNetworkResponse(NetworkResponse response) {
    synchronized (sDecodeLock) {
        try {
            return doParse(response);
        } catch (OutOfMemoryError e) {
            KJLoger.debug("Caught OOM for %d byte image, url=%s",
                    response.data.length, getUrl());
            return Response.error(new KJHttpException(e));
        }
    }
}
 
Example 18
Source File: DiskCache.java    From KJFrameForAndroid with Apache License 2.0 4 votes vote down vote up
/**
 * Prunes the cache to fit the amount of bytes specified.
 *
 * @param neededSpace The amount of bytes we are trying to fit into the cache.
 */
private void pruneIfNeeded(int neededSpace) {
    if ((mTotalSize + neededSpace) < mMaxCacheSizeInBytes) {
        return;
    }
    if (HttpConfig.DEBUG) {
        KJLoger.debug("Pruning old cache entries.");
    }

    long before = mTotalSize;
    int prunedFiles = 0;
    long startTime = SystemClock.elapsedRealtime();

    Iterator<Map.Entry<String, CacheHeader>> iterator = mEntries.entrySet()
            .iterator();
    while (iterator.hasNext()) {
        Map.Entry<String, CacheHeader> entry = iterator.next();
        CacheHeader e = entry.getValue();
        boolean deleted = getFileForKey(e.key).delete();
        if (deleted) {
            mTotalSize -= e.size;
        } else {
            KJLoger.debug(
                    "Could not delete cache entry for key=%s, filename=%s",
                    e.key, getFilenameForKey(e.key));
        }
        iterator.remove();
        prunedFiles++;

        if ((mTotalSize + neededSpace) < mMaxCacheSizeInBytes
                * HYSTERESIS_FACTOR) {
            break;
        }
    }

    if (HttpConfig.DEBUG) {
        KJLoger.debug("pruned %d files, %d bytes, %d ms", prunedFiles,
                (mTotalSize - before), SystemClock.elapsedRealtime()
                        - startTime);
    }
}
 
Example 19
Source File: HttpActivity.java    From KJFrameForAndroid with Apache License 2.0 4 votes vote down vote up
private void toast(String text) {
    Toast.makeText(this, text, Toast.LENGTH_LONG).show();
    KJLoger.debug(text);
}
 
Example 20
Source File: KJHttp.java    From KJFrameForAndroid with Apache License 2.0 4 votes vote down vote up
/**
 * 向请求队列加入一个请求
 * Note:此处工作模式是这样的:KJHttp可以看做是一个队列类,而本方法不断的向这个队列添加request;另一方面,
 * TaskThread不停的从这个队列中取request并执行。类似的设计可以参考Handle...Looper...MessageQueue的关系
 */
public <T> Request<T> add(Request<T> request) {
    if (request.getCallback() != null) {
        request.getCallback().onPreStart();
    }

    // 标记该请求属于该队列,并将它添加到该组当前的请求。
    request.setRequestQueue(this);
    synchronized (mCurrentRequests) {
        mCurrentRequests.add(request);
    }
    // 设置进程优先序列
    request.setSequence(mSequenceGenerator.incrementAndGet());

    // 如果请求不可缓存,跳过缓存队列,直接进入网络。
    if (!request.shouldCache()) {
        mNetworkQueue.add(request);
        return request;
    }

    // 如果已经在mWaitingRequests中有本请求,则替换
    synchronized (mWaitingRequests) {
        String cacheKey = request.getCacheKey();
        if (mWaitingRequests.containsKey(cacheKey)) {
            // There is already a request in flight. Queue up.
            Queue<Request<?>> stagedRequests = mWaitingRequests
                    .get(cacheKey);
            if (stagedRequests == null) {
                stagedRequests = new LinkedList<Request<?>>();
            }
            stagedRequests.add(request);
            mWaitingRequests.put(cacheKey, stagedRequests);
            if (HttpConfig.DEBUG) {
                KJLoger.debug("Request for cacheKey=%s is in flight, putting on hold.", 
                        cacheKey);
            }
        } else {
            mWaitingRequests.put(cacheKey, null);
            mCacheQueue.add(request);
        }
        return request;
    }
}