Android Open Source - YourConsole Single Logcat Reader






From Project

Back to project page YourConsole.

License

The source code is released under:

MIT License

If you think the Android project YourConsole listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.akisute.yourconsole.app.reader;
//  w  w w. ja va2  s . com
import android.text.TextUtils;

import com.akisute.yourconsole.app.helper.LogcatHelper;
import com.akisute.yourconsole.app.helper.RuntimeHelper;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class SingleLogcatReader extends LogcatReader {

    private final Process mLogcatProcess;
    private final BufferedReader mBufferedReader;
    private final String mLogBufferName;
    private String mLastLine;

    public SingleLogcatReader(String logBufferName, String lastLine) throws IOException {
        super();
        mLogBufferName = logBufferName;
        mLastLine = lastLine;
        mLogcatProcess = LogcatHelper.getLogcatProcess(mLogBufferName);
        mBufferedReader = new BufferedReader(new InputStreamReader(mLogcatProcess.getInputStream()), 8192);
    }

    @Override
    public int read(char[] chars, int i, int i2) throws IOException {
        throw new UnsupportedOperationException("Must use readLine() instead");
    }

    @Override
    public void reset() throws IOException {
        // Do nothing, unsupported
    }

    @Override
    public boolean ready() throws IOException {
        return mBufferedReader.ready();
    }

    @Override
    public long skip(long charCount) throws IOException {
        throw new UnsupportedOperationException("Must use skipLine() instead");
    }

    @Override
    public void mark(int readLimit) throws IOException {
        // Do nothing, unsupported
    }

    @Override
    public boolean markSupported() {
        return false;
    }

    @Override
    public int read() throws IOException {
        throw new UnsupportedOperationException("Must use readLine() instead");
    }

    @Override
    public String readLine() throws IOException {
        String line = mBufferedReader.readLine();

        if (mLastLine != null) { // still skipping past the 'last line'
            if (mLastLine.equals(line) || isAfterLastTime(line)) {
                mLastLine = null; // indicates we've passed the last line
            }
        }

        return line;
    }

    @Override
    public void skipLine() throws IOException {
        // Just a sugar syntax of readLine()
        readLine();
    }

    @Override
    public boolean isReadyToReadNewLines() {
        return (mLastLine == null);
    }

    @Override
    public void close() throws IOException {
        if (mLogcatProcess != null) {
            RuntimeHelper.destroy(mLogcatProcess);
        }
        if (mBufferedReader != null) {
            mBufferedReader.close();
        }
    }

    private boolean isAfterLastTime(String line) {
        // doing a string comparison is sufficient to determine whether this line is chronologically
        // after the last line, because the format they use is exactly the same and
        // lists larger time period before smaller ones
        return isDatedLogLine(mLastLine) && isDatedLogLine(line) && line.compareTo(mLastLine) > 0;

    }

    private boolean isDatedLogLine(String line) {
        // 18 is the size of the logcat timestamp
        return (!TextUtils.isEmpty(line) && line.length() >= 18 && Character.isDigit(line.charAt(0)));
    }
}




Java Source Code List

com.akisute.yourconsole.app.AppModule.java
com.akisute.yourconsole.app.Application.java
com.akisute.yourconsole.app.ConsoleViewerFragment.java
com.akisute.yourconsole.app.LogcatRecordingService.java
com.akisute.yourconsole.app.MainActivity.java
com.akisute.yourconsole.app.SaveIntentService.java
com.akisute.yourconsole.app.dagger.DaggeredActivity.java
com.akisute.yourconsole.app.dagger.DaggeredApplicationModule.java
com.akisute.yourconsole.app.dagger.DaggeredApplication.java
com.akisute.yourconsole.app.dagger.DaggeredFragment.java
com.akisute.yourconsole.app.dagger.DaggeredIntentService.java
com.akisute.yourconsole.app.dagger.DaggeredService.java
com.akisute.yourconsole.app.dagger.ForApplication.java
com.akisute.yourconsole.app.dagger.ForInjecting.java
com.akisute.yourconsole.app.helper.LogcatHelper.java
com.akisute.yourconsole.app.helper.RuntimeHelper.java
com.akisute.yourconsole.app.intent.Intents.java
com.akisute.yourconsole.app.model.ConsoleListAdapter.java
com.akisute.yourconsole.app.model.LogcatLine.java
com.akisute.yourconsole.app.model.LogcatRecordingManager.java
com.akisute.yourconsole.app.model.MText.java
com.akisute.yourconsole.app.reader.LogcatReader.java
com.akisute.yourconsole.app.reader.SingleLogcatReader.java
com.akisute.yourconsole.app.util.GlobalEventBus.java
com.akisute.yourconsole.app.util.GlobalPreference.java