Search in sources :

Example 6 with TimeEntry

use of com.tencent.wstt.gt.ui.model.TimeEntry in project GT by Tencent.

the class LogUtils method writeTimeLog.

public static void writeTimeLog(List<GroupTimeEntry> list, String fileName) {
    if (!GTUtils.isSDCardExist()) {
        return;
    }
    int la = fileName.lastIndexOf(".");
    if (la < 0) {
        fileName = fileName + LogUtils.TLOG_POSFIX;
    } else {
        String temp = fileName.substring(la);
        if (temp.contains(FileUtil.separator) || temp.contains("\\")) {
            // "."是目录名的一部分而不是后缀名的情况
            fileName = fileName + LogUtils.TLOG_POSFIX;
        }
    // else fileName = fileName
    }
    File f = null;
    if (fileName.contains(FileUtil.separator) || fileName.contains("\\")) {
        f = new File(fileName);
    } else {
        Env.ROOT_TIME_FOLDER.mkdirs();
        f = new File(Env.ROOT_TIME_FOLDER, fileName);
    }
    if (f.exists()) {
        f.delete();
    }
    FileWriter fw = null;
    try {
        fw = new FileWriter(f, true);
    } catch (IOException e) {
        e.printStackTrace();
    }
    StringBuffer sb = null;
    for (GroupTimeEntry gte : list) {
        for (TagTimeEntry tte : gte.entrys()) {
            sb = new StringBuffer();
            sb.append("group,");
            sb.append(gte.getName());
            sb.append("\r\n");
            sb.append("tag,");
            sb.append(tte.getName());
            sb.append("\r\n");
            sb.append("isInThread,");
            sb.append(tte.getTid() == 0 ? "false" : "true");
            sb.append("\r\n");
            ArrayList<TimeEntry> tempRecordList = tte.getRecordList();
            for (TimeEntry time : tempRecordList) {
                if (sb.length() > 8192) {
                    writeNotClose(sb.toString(), f, fw);
                    sb = new StringBuffer();
                }
                sb.append(time);
                // sb.append(",");
                sb.append("\r\n");
            }
            if (!tempRecordList.isEmpty()) {
                sb.deleteCharAt(sb.length() - 1);
            }
            // 可以及时释放
            tempRecordList = null;
            sb.append("\r\n");
            writeNotClose(sb.toString(), f, fw);
        }
    }
    FileUtil.closeWriter(fw);
}
Also used : TagTimeEntry(com.tencent.wstt.gt.ui.model.TagTimeEntry) TagTimeEntry(com.tencent.wstt.gt.ui.model.TagTimeEntry) GroupTimeEntry(com.tencent.wstt.gt.ui.model.GroupTimeEntry) TimeEntry(com.tencent.wstt.gt.ui.model.TimeEntry) FileWriter(java.io.FileWriter) IOException(java.io.IOException) GroupTimeEntry(com.tencent.wstt.gt.ui.model.GroupTimeEntry) File(java.io.File)

Aggregations

TagTimeEntry (com.tencent.wstt.gt.ui.model.TagTimeEntry)6 TimeEntry (com.tencent.wstt.gt.ui.model.TimeEntry)6 GroupTimeEntry (com.tencent.wstt.gt.ui.model.GroupTimeEntry)4 File (java.io.File)4 FileWriter (java.io.FileWriter)4 IOException (java.io.IOException)4 Paint (android.graphics.Paint)1 Client (com.tencent.wstt.gt.manager.Client)1 MemInfo (com.tencent.wstt.gt.proInfo.floatView.MemInfo)1