当前位置: 首页>>代码示例>>Java>>正文


Java ReversedLinesFileReader.readLine方法代码示例

本文整理汇总了Java中org.apache.commons.io.input.ReversedLinesFileReader.readLine方法的典型用法代码示例。如果您正苦于以下问题:Java ReversedLinesFileReader.readLine方法的具体用法?Java ReversedLinesFileReader.readLine怎么用?Java ReversedLinesFileReader.readLine使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.commons.io.input.ReversedLinesFileReader的用法示例。


在下文中一共展示了ReversedLinesFileReader.readLine方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: serverVersion

import org.apache.commons.io.input.ReversedLinesFileReader; //导入方法依赖的package包/类
protected String serverVersion() {
    try {
        if (lsbRelease == null || lsbRelease.getPath().equals(""))
            throw new FileNotFoundException();

        String line = "";
        ReversedLinesFileReader rf = new ReversedLinesFileReader(lsbRelease);
        boolean isMatch = false;

        while ((line = rf.readLine()) != null) {
            if (Pattern.matches("^(#).*", line))
                continue;

            isMatch = Pattern.matches("^(DISTRIB_DESCRIPTION=).*", line);
            if (isMatch) {
                return "Version: " + line.substring(20);
            }
        }
        return "Could not detect Linux server version.";
    } catch (Exception e) {
        return "Could not read \"lsb-release\" file to detect Linux server version.";
    }
}
 
开发者ID:williamgrosset,项目名称:OSCAR-ConCert,代码行数:24,代码来源:Audit.java

示例2: verifySystemInfo

import org.apache.commons.io.input.ReversedLinesFileReader; //导入方法依赖的package包/类
public String verifySystemInfo() {
    try {
        if (lsbRelease == null || lsbRelease.getPath().equals(""))
            throw new FileNotFoundException();

        String line = "";
        ReversedLinesFileReader rf = new ReversedLinesFileReader(lsbRelease);
        Pattern patternComment = Pattern.compile("^(#).*");
        Pattern patternDIST_DESC = Pattern.compile("^(DISTRIB_DESCRIPTION\\s?=).*");

        while ((line = rf.readLine()) != null) {
            Matcher matcherComment = patternComment.matcher(line);
            if (matcherComment.matches()) continue;
            Matcher matcherDIST_DESC = patternDIST_DESC.matcher(line);

            if (matcherDIST_DESC.matches()) {
                this.systemVersion = line.substring(matcherDIST_DESC.group(1).length()).trim();
                return "Version: " + this.systemVersion;
            }
        }
        return "Could not detect Linux server version.";
    } catch (Exception e) {
        logger.error(e.getStackTrace());
        return "Could not read \"lsb-release\" file to detect Linux server version.";
    }
}
 
开发者ID:williamgrosset,项目名称:OSCAR-ConCert,代码行数:27,代码来源:Audit.java

示例3: getLatestLogEntries

import org.apache.commons.io.input.ReversedLinesFileReader; //导入方法依赖的package包/类
private static List<String> getLatestLogEntries(File logFile) {
    try {
        List<String> lines = new ArrayList<>(LOG_LINES_TO_SHOW);
        ReversedLinesFileReader reader = new ReversedLinesFileReader(logFile, Charset.defaultCharset());
        String current;
        while((current = reader.readLine()) != null && lines.size() < LOG_LINES_TO_SHOW) {
            lines.add(0, current);
        }
        return lines;
    } catch (Exception e) {
        logger.warn("Could not open log file " + logFile, e);
        return null;
    }
}
 
开发者ID:airsonic,项目名称:airsonic,代码行数:15,代码来源:HelpController.java

示例4: readLastEMStepSequences

import org.apache.commons.io.input.ReversedLinesFileReader; //导入方法依赖的package包/类
public static HashMap<Sequence, Double> readLastEMStepSequences(final File logFile) throws IOException {
	final HashMap<Sequence, Double> sequences = new HashMap<>();

	final ReversedLinesFileReader reader = new ReversedLinesFileReader(logFile);
	String line = reader.readLine();
	while (line != null) {

		if (line.contains("Parameter Optimal Sequences:")) {
			final Matcher m = Pattern
					.compile(
							"\\[((?:[0-9]|,| )+?)\\]=\\(((?:(?:[-+]?[0-9]*\\.?[0-9]+(?:[eE][-+]?[0-9]+)?)|,)+?)\\)")
					.matcher(line);
			while (m.find()) {
				final Sequence sequence = new Sequence();
				final String[] items = m.group(1).split(", ");
				for (final String item : items)
					sequence.add(Integer.parseInt(item));
				final double prob = 1 - Double.parseDouble(m.group(2).split(",")[0]);
				sequences.put(sequence, prob);
			}
			break;
		}
		line = reader.readLine();

	}
	reader.close();

	return sequences;
}
 
开发者ID:mast-group,项目名称:sequence-mining,代码行数:30,代码来源:PartialLogFixer.java

示例5: getLog

import org.apache.commons.io.input.ReversedLinesFileReader; //导入方法依赖的package包/类
protected LineRange getLog(HubContext ctx, String path, long startLine, long endLine, Appendable appendable) {
    try {
        ReversedLinesFileReader reader = new ReversedLinesFileReader(new File(path));

        long lineCount = endLine - startLine + 1;

        // read to the start line
        for (int i=0; i < startLine; i++) {
            reader.readLine();
        }

        // append the requested number of lines (aborting if start of file is hit)
        appendable.append("[\n");
        long count = 0;
        for (; count < lineCount; count++) {
            String s = reader.readLine();
            if (s == null) {
                break;
            } else if (count > 0) {
                appendable.append(",");
            }
            if (s.charAt(0) != '{') {
                s = "{\"message\":\"" + s + "\"}";
            }
            appendable.append("{\"item\":").append(s).append("}");
        }
        appendable.append("\n]");

        return new LineRange(startLine, count - 1);
    } catch (IOException e) {
        throw new HobsonRuntimeException("Unable to read log file", e);
    }
}
 
开发者ID:whizzosoftware,项目名称:hobson-hub-core,代码行数:34,代码来源:OSGIHubManager.java

示例6: readLastEMStepItemsets

import org.apache.commons.io.input.ReversedLinesFileReader; //导入方法依赖的package包/类
public static HashMap<Itemset, Double> readLastEMStepItemsets(
		final File logFile) throws IOException {
	final HashMap<Itemset, Double> itemsets = new HashMap<>();

	final ReversedLinesFileReader reader = new ReversedLinesFileReader(
			logFile);
	String line = reader.readLine();
	while (line != null) {

		if (line.contains("Parameter Optimal Itemsets:")) {
			final Matcher m = Pattern
					.compile(
							"\\{((?:[0-9]|,| )+?)\\}=([-+]?[0-9]*\\.?[0-9]+(?:[eE][-+]?[0-9]+)?)")
					.matcher(line);
			while (m.find()) {
				final Itemset itemset = new Itemset();
				final String[] items = m.group(1).split(", ");
				for (final String item : items)
					itemset.add(Integer.parseInt(item));
				final double prob = Double.parseDouble(m.group(2));
				itemsets.put(itemset, prob);
			}
			break;
		}
		line = reader.readLine();

	}
	reader.close();

	return itemsets;
}
 
开发者ID:mast-group,项目名称:itemset-mining,代码行数:32,代码来源:PartialLogFixer.java

示例7: getNewId

import org.apache.commons.io.input.ReversedLinesFileReader; //导入方法依赖的package包/类
/**
 * Generates a new ID by checking the last ID in the log, if the log contains non int ID's
 * the method will generate a new random ID.
 * @param lang The languageCode of the log
 * @return Last id in the log +1 OR a random int
 * @throws Exception if failed to get id
 */
public static String getNewId(String lang) throws Exception {
    File f = new File(SCRAPING_FOLDER+lang+LOG_FILE);
    String id = "";

    if(!f.exists()){
        FileUtils.writeStringToFile(f,"id: 1,url:www.test.com\n");
    }

    try {
        ReversedLinesFileReader fr = new ReversedLinesFileReader(f);

        String lastLine = fr.readLine();
        int commaLocation;
        try {
             commaLocation = lastLine.indexOf(",");
        }
        catch (Exception ex){
            lastLine = fr.readLine();
            commaLocation = lastLine.indexOf(",");
        }
        id = lastLine.substring(4, commaLocation);

        if (id == "0") {
            throw new Exception("Couldn't get ID");
        }

    } catch (IOException e) {
        log.error(e);
    }

    try{
        int numId = Integer.parseInt(id);
        id = String.valueOf(++numId);
        return id;
    }
    catch(Exception exx){
        Random rand = new Random();
        id = String.valueOf(rand.nextInt()%10000);
        return id;
    }

}
 
开发者ID:gidim,项目名称:Babler,代码行数:50,代码来源:LogDB.java

示例8: oscarBuild

import org.apache.commons.io.input.ReversedLinesFileReader; //导入方法依赖的package包/类
protected String oscarBuild(String fileName) {
    try {
        String output = "";
        String line = "";
        File oscar = new File(fileName);
        ReversedLinesFileReader rf = new ReversedLinesFileReader(oscar);
        boolean isMatch1 = false;
        boolean isMatch2 = false;
        boolean flag1 = false;
        boolean flag2 = false;

        while ((line = rf.readLine()) != null) {
            if (Pattern.matches("^(#).*", line)) continue;
            isMatch1 = Pattern.matches("^(buildtag=).*", line);
            isMatch2 = Pattern.matches("^(buildDateTime=).*", line);

            if (!flag1) {
                if (isMatch1) { // buildtag=
                    flag1 = true;
                    output += "Oscar build and version: " + line.substring(9) + "<br />";
                }
            }
            if (!flag2) {
                if (isMatch2) { // buildDateTime=
                    flag2 = true;
                    output += "Oscar build date and time: " + line.substring(14) + "<br />";
                }
            }
            if (flag1 && flag2)
                break;
        }

        if (!flag1)
            output += "Could not detect Oscar build tag." + "<br />";
        if (!flag2)
            output += "Could not detect Oscar build date and time." + "<br />";
        return output;
    } catch (Exception e) {
        return "Could not read properties file to detect Oscar build.<br />";
    }
}
 
开发者ID:williamgrosset,项目名称:OSCAR-ConCert,代码行数:42,代码来源:Audit.java

示例9: verifyOscarProperties

import org.apache.commons.io.input.ReversedLinesFileReader; //导入方法依赖的package包/类
protected String verifyOscarProperties(String fileName) {
    try {
        String output = "";
        String line = "";
        File oscar = new File(fileName);
        ReversedLinesFileReader rf = new ReversedLinesFileReader(oscar);
        boolean isMatch1 = false;
        boolean isMatch2 = false;
        boolean isMatch3 = false;
        boolean isMatch4 = false;
        boolean flag1 = false;
        boolean flag2 = false;
        boolean flag3 = false;
        boolean flag4 = false;

        while ((line = rf.readLine()) != null) {
            if (Pattern.matches("^(#).*", line)) continue;
            isMatch1 = Pattern.matches("^(HL7TEXT_LABS=).*", line);
            isMatch2 = Pattern.matches("^(SINGLE_PAGE_CHART=).*", line);
            isMatch3 = Pattern.matches("^(TMP_DIR(=|:)).*", line);
            isMatch4 = Pattern.matches("^(drugref_url=).*", line);

            if (!flag1) {
                if (isMatch1) { // HL7TEXT_LABS=
                    flag1 = true;
                    output += "\"HL7TEXT_LABS\" tag is configured as: " + line.substring(13) + "<br />";
                }
            }
            if (!flag2) {
                if (isMatch2) { // SINGLE_PAGE_CHART=
                    flag2 = true;
                    output += "\"SINGLE_PAGE_CHART\" tag is configured as: " + line.substring(18) + "<br />";
                }
            }
            if (!flag3) {
                if (isMatch3) { // TMP_DIR=
                    flag3 = true;
                    output += "\"TMP_DIR\" tag is configured as: " + line.substring(8) + "<br />";
                }
            }
            if (!flag4) {
                if (isMatch4) { // drugref_url=
                    flag4 = true;
                    output += "\"drugref_url\" tag is configured as: " + line.substring(12) + "<br />";
                    drugrefUrl = line.substring(12);
                }
            }
            if (flag1 && flag2 && flag3 && flag4)
                break;
        }
        
        if (!flag1)
            output += "Could not detect \"HL7TEXT_LABS\" tag." + "<br />";
        if (!flag2)
            output += "Could not detect \"SINGLE_PAGE_CHART\" tag." + "<br />";
        if (!flag3)
            output += "Could not detect \"TMP_DIR\" tag." + "<br />";
        if (!flag4)
            output += "Could not detect \"drugref_url\" tag." + "<br />";
        return output;
    } catch (Exception e) {
        return "Could not read properties file to verify Oscar tags.";
    }
}
 
开发者ID:williamgrosset,项目名称:OSCAR-ConCert,代码行数:65,代码来源:Audit.java

示例10: verifyDrugrefProperties

import org.apache.commons.io.input.ReversedLinesFileReader; //导入方法依赖的package包/类
protected String verifyDrugrefProperties(String fileName) {
    try {
        String output = "";
        String line = "";
        File drugref = new File(fileName);
        ReversedLinesFileReader rf = new ReversedLinesFileReader(drugref);
        boolean isMatch1 = false;
        boolean isMatch2 = false;
        boolean isMatch3 = false;
        boolean flag1 = false;
        boolean flag2 = false;
        boolean flag3 = false;

        while ((line = rf.readLine()) != null) {
            if (Pattern.matches("^(#).*", line)) continue;
            isMatch1 = Pattern.matches("^(db_user=).*", line);
            isMatch2 = Pattern.matches("^(db_url=).*", line);
            isMatch3 = Pattern.matches("^(db_driver=).*", line);

            if (!flag1) {
                if (isMatch1) { // db_user=
                    flag1 = true;
                    output += "\"db_user\" tag is configured as: " + line.substring(8) + "<br />";
                }
            }
            if (!flag2) {
                if (isMatch2) { // db_url=
                    flag2 = true;
                    output += "\"db_url\" tag is configured as: " + line.substring(7) + "<br />";
                }
            }
            if (!flag3) {
                if (isMatch3) { // db_driver=
                    flag3 = true;
                    output += "\"db_driver\" tag is configured as: " + line.substring(10) + "<br />";
                }
            }
            if (flag1 && flag2 && flag3)
                break;
        }

        if (!flag1)
            output += "Could not detect \"db_user\" tag." + "<br />";
        if (!flag2)
            output += "Could not detect \"db_url\" tag." + "<br />";
        if (!flag3)
            output += "Could not detect \"db_driver\" tag." + "<br />";
        return output;
    } catch (Exception e) {
        return "Could not read properties file to verify Drugref tags.";
    }
}
 
开发者ID:williamgrosset,项目名称:OSCAR-ConCert,代码行数:53,代码来源:Audit.java

示例11: tomcatReinforcement

import org.apache.commons.io.input.ReversedLinesFileReader; //导入方法依赖的package包/类
protected String tomcatReinforcement() {
    if (catalinaBase == null || catalinaBase.getPath().equals(""))
        return "Please verify that your \"catalina.base\" directory is setup correctly.";
    if (tomcatSettings == null || tomcatSettings.getPath().equals(""))
        return "Could not detect Tomcat settings file in /etc/default/ directory."; 

    try {
        String output = "";
        String line = "";
        String xmx = "";
        String xms = "";
        boolean isMatch1 = false;
        boolean isMatch2 = false;
        boolean flag1 = false;
        boolean flag2 = false;
        Pattern xmxPattern = Pattern.compile(".*(Xmx[0-9]+m).*");
        Pattern xmsPattern = Pattern.compile(".*(Xms[0-9]+m).*");
        ReversedLinesFileReader rf = new ReversedLinesFileReader(tomcatSettings);

        while ((line = rf.readLine()) != null) {
            if (Pattern.matches("^(#).*", line)) continue;
            Matcher xmxMatch = xmxPattern.matcher(line);
            isMatch1 = xmxMatch.matches();
            Matcher xmsMatch = xmsPattern.matcher(line);
            isMatch2 = xmsMatch.matches();

            if (!flag1) {
                if (isMatch1) { // e.g. Xmx1024m
                    xmx = xmxMatch.group(1);
                    String[] xmxString = xmx.toString().split("x");
                    flag1 = true;
                    output += "Xmx value: " + xmxString[1] + "<br />";
                }
            }
            if (!flag2) {
                if (isMatch2) { // e.g. Xms1024m
                    xms = xmsMatch.group(1);
                    String[] xmsString = xms.toString().split("s");
                    flag2 = true;
                    output += "Xms value: " + xmsString[1] + "<br />";
                }
            }
            if (flag1 && flag2)
                break;
        }

        if (!flag1) {
            output += "Could not detect Xmx value." + "<br />";
        }
        if (!flag2) {
            output += "Could not detect Xms value." + "<br />";
        }
        return output;
    } catch (Exception e) {
        return "Could not detect Tomcat memory allocation in Tomcat settings file.";
    }
}
 
开发者ID:williamgrosset,项目名称:OSCAR-ConCert,代码行数:58,代码来源:Audit.java

示例12: verifyTomcatReinforcement

import org.apache.commons.io.input.ReversedLinesFileReader; //导入方法依赖的package包/类
public String verifyTomcatReinforcement(String tomcatVersion) {
    if (tomcatVersion == null || tomcatVersion.equals(""))
        return "Could not detect Tomcat version.";
    if (catalinaBase == null || catalinaBase.getPath().equals(""))
        return "Please verify that your \"catalina.base\" directory is setup correctly.";

    this.tomcatVersion = tomcatVersion;

    try {
        // Determine which version of Tomcat settings file to check
        int version = extractTomcatVersionNumber(tomcatVersion);
        tomcatSettings = getTomcatSettings(version);
        if (tomcatSettings == null || tomcatSettings.getPath().equals(""))
            return "Could not detect Tomcat settings file."; 

        String line = "";
        StringBuilder output = new StringBuilder();
        ReversedLinesFileReader rf = new ReversedLinesFileReader(tomcatSettings);
        Pattern patternComment = Pattern.compile("^(#).*");
        Pattern patternXmx = Pattern.compile(".*(Xmx[0-9]+m).*");
        Pattern patternXms = Pattern.compile(".*(Xms[0-9]+m).*");
        boolean flag1 = false, flag2 = false;

        while ((line = rf.readLine()) != null) {
            Matcher matcherComment = patternComment.matcher(line);
            if (matcherComment.matches()) continue;
            Matcher matcherXmx = patternXmx.matcher(line);
            Matcher matcherXms = patternXms.matcher(line);

            if (!flag1 && matcherXmx.matches()) { // e.g. Xmx2056m
                flag1 = true;
                this.xmx = matcherXmx.group(1).substring(3);
                output.append("Xmx value: " + this.xmx + "\n");
            }
            if (!flag2 && matcherXms.matches()) { // e.g. Xms1024m
                flag2 = true;
                this.xms = matcherXms.group(1).substring(3);
                output.append("Xms value: " + this.xms + "\n");
            }
            if (flag1 && flag2)
                break;
        }

        if (!flag1)
            output.append("Could not detect Xmx value." + "\n");
        if (!flag2)
            output.append("Could not detect Xms value." + "\n");
        return output.toString();
    } catch (Exception e) {
        logger.error(e.getStackTrace());
        return "Could not detect Tomcat memory allocation in Tomcat settings file.";
    }
}
 
开发者ID:williamgrosset,项目名称:OSCAR-ConCert,代码行数:54,代码来源:Audit.java

示例13: verifyOscarProperties

import org.apache.commons.io.input.ReversedLinesFileReader; //导入方法依赖的package包/类
private String verifyOscarProperties(String filename) {
    try {
        if (filename == null || filename.equals(""))
            return "Could not detect filename for properties file.";

        String line = "";
        StringBuilder output = new StringBuilder();
        ReversedLinesFileReader rf = new ReversedLinesFileReader(new File(filename));
        Pattern patternComment = Pattern.compile("^(#).*");
        Pattern patternBuildtag = Pattern.compile("^(buildtag\\s?(=|:)).*");
        Pattern patternBuildDateTime = Pattern.compile("^(buildDateTime\\s?(=|:)).*");
        Pattern patternHL7TEXT_LABS = Pattern.compile("^(HL7TEXT_LABS\\s?(=|:)).*");
        Pattern patternSINGLE_PAGE_CHART = Pattern.compile("^(SINGLE_PAGE_CHART\\s?(=|:)).*");
        Pattern patternTMP_DIR = Pattern.compile("^(TMP_DIR\\s?(=|:)).*");
        Pattern patternDrugrefUrl = Pattern.compile("^(drugref_url\\s?(=|:)).*");
        boolean flag1 = false, flag2 = false, flag3 = false, flag4 = false, flag5 = false, flag6 = false;

        while ((line = rf.readLine()) != null) {
            Matcher matcherComment = patternComment.matcher(line);
            if (matcherComment.matches()) continue;
            Matcher matcherBuildtag = patternBuildtag.matcher(line);
            Matcher matcherBuildDateTime = patternBuildDateTime.matcher(line);
            Matcher matcherHL7TEXT_LABS = patternHL7TEXT_LABS.matcher(line);
            Matcher matcherSINGLE_PAGE_CHART = patternSINGLE_PAGE_CHART.matcher(line);
            Matcher matcherTMP_DIR = patternTMP_DIR.matcher(line);
            Matcher matcherDrugrefUrl = patternDrugrefUrl.matcher(line);

            if (!flag1 && matcherBuildtag.matches()) { // buildtag=
                flag1 = true;
                this.build = line.substring(matcherBuildtag.group(1).length()).trim();
                output.append("Oscar build and version: " + this.build + "\n");
            } else if (!flag2 && matcherBuildDateTime.matches()) { // buildDateTime=
                flag2 = true;
                this.buildDate = line.substring(matcherBuildDateTime.group(1).length()).trim();
                output.append("Oscar build date and time: " + this.buildDate + "\n");
            } else if (!flag3 && matcherHL7TEXT_LABS.matches()) { // HL7TEXT_LABS=
                flag3 = true;
                this.hl7TextLabs = line.substring(matcherHL7TEXT_LABS.group(1).length()).trim();
                output.append("\"HL7TEXT_LABS\" tag is configured as: " + this.hl7TextLabs + "\n");
            } else if (!flag4 && matcherSINGLE_PAGE_CHART.matches()) { // SINGLE_PAGE_CHART=
                flag4 = true;
                this.singlePageChart = line.substring(matcherSINGLE_PAGE_CHART.group(1).length()).trim();
                output.append("\"SINGLE_PAGE_CHART\" tag is configured as: " + this.singlePageChart + "\n");
            } else if (!flag5 && matcherTMP_DIR.matches()) { // TMP_DIR=
                flag5 = true;
                this.tmpDir = line.substring(matcherTMP_DIR.group(1).length()).trim();
                output.append("\"TMP_DIR\" tag is configured as: " + this.tmpDir + "\n");
            } else if (!flag6 && matcherDrugrefUrl.matches()) { // drugref_url=
                flag6 = true;
                this.drugrefUrl = line.substring(matcherDrugrefUrl.group(1).length()).trim();
                output.append("\"drugref_url\" tag is configured as: " + this.drugrefUrl + "\n");
            } else {
                if (flag1 && flag2 && flag3 && flag4 && flag5 && flag6)
                    break;
            }
        }

        if (!flag1)
            output.append("Could not detect Oscar build tag." + "\n");
        if (!flag2)
            output.append("Could not detect Oscar build date and time." + "\n");
        if (!flag3)
            output.append("Could not detect \"HL7TEXT_LABS\" tag." + "\n");
        if (!flag4)
            output.append("Could not detect \"SINGLE_PAGE_CHART\" tag." + "\n");
        if (!flag5)
            output.append("Could not detect \"TMP_DIR\" tag." + "\n");
        if (!flag6)
            output.append("Could not detect \"drugref_url\" tag." + "\n");
        return output.toString();
    } catch (Exception e) {
        logger.error(e.getStackTrace());
        return "Could not read properties file to verify Oscar tags.";
    }
}
 
开发者ID:williamgrosset,项目名称:OSCAR-ConCert,代码行数:76,代码来源:Audit.java

示例14: verifyDrugrefProperties

import org.apache.commons.io.input.ReversedLinesFileReader; //导入方法依赖的package包/类
private String verifyDrugrefProperties(String filename) {
    try {
        if (filename == null || filename.equals(""))
            return "Could not detect filename for properties file.";

        String line = "";
        StringBuilder output = new StringBuilder();
        ReversedLinesFileReader rf = new ReversedLinesFileReader(new File(filename));
        Pattern patternComment = Pattern.compile("^(#).*");
        Pattern patternDb_user = Pattern.compile("^(db_user\\s?(=|:)).*");
        Pattern patternDb_url = Pattern.compile("^(db_url\\s?(=|:)).*");
        Pattern patternDb_driver = Pattern.compile("^(db_driver\\s?(=|:)).*");
        boolean flag1 = false, flag2 = false, flag3 = false;

        while ((line = rf.readLine()) != null) {
            Matcher matcherComment = patternComment.matcher(line);
            if (Pattern.matches("^(#).*", line)) continue;
            Matcher matcherDb_user = patternDb_user.matcher(line);
            Matcher matcherDb_url = patternDb_url.matcher(line);
            Matcher matcherDb_driver = patternDb_driver.matcher(line);

            if (!flag1 && matcherDb_user.matches()) { // db_user=
                flag1 = true;
                this.dbUser = line.substring(matcherDb_user.group(1).length()).trim();
                output.append("\"db_user\" tag is configured as: " + this.dbUser + "\n");
            } else if (!flag2 && matcherDb_url.matches()) { // db_url=
                flag2 = true;
                this.dbUrl = line.substring(matcherDb_url.group(1).length()).trim();
                output.append("\"db_url\" tag is configured as: " + this.dbUrl + "\n");
            } else if (!flag3 && matcherDb_driver.matches()) { // db_driver=
                flag3 = true;
                this.dbDriver = line.substring(matcherDb_driver.group(1).length()).trim();
                output.append("\"db_driver\" tag is configured as: " + this.dbDriver + "\n");
            } else {
                if (flag1 && flag2 && flag3)
                    break;
            }
        }

        if (!flag1)
            output.append("Could not detect \"db_user\" tag." + "\n");
        if (!flag2)
            output.append("Could not detect \"db_url\" tag." + "\n");
        if (!flag3)
            output.append("Could not detect \"db_driver\" tag." + "\n");
        return output.toString();
    } catch (Exception e) {
        logger.error(e.getStackTrace());
        return "Could not read properties file to verify Drugref tags.";
    }
}
 
开发者ID:williamgrosset,项目名称:OSCAR-ConCert,代码行数:52,代码来源:Audit.java

示例15: getOperationResponseFromLogcat

import org.apache.commons.io.input.ReversedLinesFileReader; //导入方法依赖的package包/类
public static String getOperationResponseFromLogcat(Context context, String logcat) throws IOException {
    File logcatFile = new File(logcat);
    if (logcatFile.exists() && logcatFile.canRead()) {
        DeviceInfo deviceInfo = new DeviceInfo(context);
        EventPayload eventPayload = new EventPayload();
        eventPayload.setPayload(logcat);
        eventPayload.setType("LOGCAT");
        eventPayload.setDeviceIdentifier(deviceInfo.getDeviceId());

        StringBuilder emmBuilder = new StringBuilder();
        StringBuilder publisherBuilder = new StringBuilder();
        int index = 0;
        String line;
        ReversedLinesFileReader reversedLinesFileReader = new ReversedLinesFileReader(logcatFile, Charset.forName("US-ASCII"));
        while ((line = reversedLinesFileReader.readLine()) != null) {
            publisherBuilder.insert(0, "\n");
            publisherBuilder.insert(0, line);
            //OPERATION_RESPONSE filed in the DM_DEVICE_OPERATION_RESPONSE is declared as a blob and hence can only hold 64Kb.
            //So we don't want to throw exceptions in the server. Limiting the response in here to limit the server traffic also.
            if (emmBuilder.length() < Character.MAX_VALUE - 8192) { //Keeping 8kB for rest of the response payload.
                emmBuilder.insert(0, "\n");
                emmBuilder.insert(0, line);
            }
            if (++index >= Constants.LogPublisher.NUMBER_OF_LOG_LINES) {
                break;
            }
        }
        LogPublisherFactory publisher = new LogPublisherFactory(context);
        if (publisher.getLogPublisher() != null) {
            eventPayload.setPayload(publisherBuilder.toString());
            publisher.getLogPublisher().publish(eventPayload);
            if (Constants.DEBUG_MODE_ENABLED) {
                Log.d(TAG, "Logcat published size: " + eventPayload.getPayload().length());
            }
        }
        eventPayload.setPayload(emmBuilder.toString());
        Gson logcatResponse = new Gson();
        logcatFile.delete();
        if (Constants.DEBUG_MODE_ENABLED) {
            Log.d(TAG, "Logcat payload size: " + eventPayload.getPayload().length());
        }
        return logcatResponse.toJson(eventPayload);
    } else {
        throw new IOException("Unable to find or read log file.");
    }
}
 
开发者ID:wso2-attic,项目名称:product-emm,代码行数:47,代码来源:OperationManager.java


注:本文中的org.apache.commons.io.input.ReversedLinesFileReader.readLine方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。