From d7c185979811626b5abf223b79e34d02e1326384 Mon Sep 17 00:00:00 2001 From: DXL <64101226@qq.com> Date: Thu, 27 Aug 2020 12:37:07 +0800 Subject: [PATCH] Delete LineParseUtils.java --- appmain/stream/LineParseUtils.java | 85 ------------------------------ 1 file changed, 85 deletions(-) delete mode 100644 appmain/stream/LineParseUtils.java diff --git a/appmain/stream/LineParseUtils.java b/appmain/stream/LineParseUtils.java deleted file mode 100644 index 8443f55..0000000 --- a/appmain/stream/LineParseUtils.java +++ /dev/null @@ -1,85 +0,0 @@ -package com.proxgrind.chameleon.utils.stream; - -import java.util.Queue; -import java.util.concurrent.LinkedBlockingQueue; - -public class LineParseUtils extends Thread { - - private String LOG_TAG = this.getClass().getSimpleName(); - - /* - * 回调接口,当有完整的一行出现时回调! - * */ - public interface OnNewLineLisenter { - void onNewLine(String str); - } - - //队列,生产消费! - private Queue mConsoleQueue = new LinkedBlockingQueue<>(); - //回调接口! - private OnNewLineLisenter mLisenter; - //标志,是否暂停! - private volatile boolean mPauseLabel = false; - //标志,是否结束! - private volatile boolean mCancelLabel = false; - - public LineParseUtils(OnNewLineLisenter lisenter) { - mLisenter = lisenter; - } - - @Override - public void run() { - //迭代队列 - StringBuilder sb = new StringBuilder(256); - while (!mCancelLabel) { - if (mPauseLabel) { - //Log.d(LOG_TAG, "DynamicLineParseThread is pause!"); - continue; - } - if (mConsoleQueue.size() == 0) continue; - if (mLisenter != null) { - Character c; - while ((c = mConsoleQueue.poll()) != null) { - //遇到的是换行符,则需要处理换行符! - if (c == '\n') { - //回调之前的结果! - String s = sb.toString(); - //Log.d("****", "DLPU新行: " + s); - //开始回调! - mLisenter.onNewLine(s); - //清除缓存,重新建立对象! - sb = new StringBuilder(256); - //尝试通知GC - System.gc(); - //直接跳过下一步的换行符添加! - break; - } - //否则一直追加进缓冲区 - sb.append((char) c); - //Log.d("****", "DLPU: " + sb.toString()); - } - } - } - } - - @Override - public synchronized void start() { - //处理启动相关的实现! - mPauseLabel = false; - if (!isAlive()) { - super.start(); - } - } - - public synchronized void appendText(Character txt) { - mConsoleQueue.add(txt); - } - - public synchronized void pause() { - mPauseLabel = true; - } - - public synchronized void cancel() { - mCancelLabel = true; - } -}