本文整理汇总了Java中org.apache.commons.io.input.ReversedLinesFileReader类的典型用法代码示例。如果您正苦于以下问题:Java ReversedLinesFileReader类的具体用法?Java ReversedLinesFileReader怎么用?Java ReversedLinesFileReader使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ReversedLinesFileReader类属于org.apache.commons.io.input包,在下文中一共展示了ReversedLinesFileReader类的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.";
}
}
示例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.";
}
}
示例3: getActivityLog
import org.apache.commons.io.input.ReversedLinesFileReader; //导入依赖的package包/类
@Override
public List<ActivityLogEntry> getActivityLog(long eventCount) {
List<ActivityLogEntry> events = new ArrayList<>();
try {
if (activityFile.exists()) {
try (ReversedLinesFileReader reader = new ReversedLinesFileReader(activityFile)) {
String line;
while ((line = reader.readLine()) != null && events.size() < eventCount) {
JSONObject json = new JSONObject(line);
events.add(new ActivityLogEntry(json.getLong("timestamp"), json.getString("name")));
}
}
}
} catch (IOException e) {
throw new HobsonRuntimeException("Unable to read activity events", e);
}
return events;
}
示例4: 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;
}
}
示例5: StreamReader
import org.apache.commons.io.input.ReversedLinesFileReader; //导入依赖的package包/类
/**
* Create an iterator that reads a file line-by-line in reverse
* @param rdf the RDF object
* @param file the file
* @param identifier the identifier
* @param time the time
*/
public StreamReader(final RDF rdf, final File file, final IRI identifier, final Instant time) {
this.rdf = rdf;
this.time = time;
this.identifier = identifier;
try {
this.reader = new ReversedLinesFileReader(file, UTF_8);
this.line = reader.readLine();
} catch (final IOException ex) {
throw new UncheckedIOException(ex);
}
bufferIter = readPatch();
}
示例6: verifyAnalytics
import org.apache.commons.io.input.ReversedLinesFileReader; //导入依赖的package包/类
@Override
public void verifyAnalytics(String analyticsParams){
String fileName = (System.getProperty("user.dir")).substring(0, System.getProperty("user.dir").lastIndexOf("/")) + "/appium.log";
logger.info("Analytics parameters from feature file : " + analyticsParams);
StringBuilder badParams = new StringBuilder("");
try (ReversedLinesFileReader rlr = new ReversedLinesFileReader(new File(fileName) ))
{
String analytics = getExpectedAnalytics(analyticsParams);
logger.info("Expected analytics values from xml file: " + analytics);
String [] analyticsValuePairs = analytics.split(";");
String sCurrentLine;
boolean isAnalyticsPresent = false;
while((sCurrentLine = rlr.readLine()) != null && !isAnalyticsPresent)
{
if (sCurrentLine.contains("<analytics_log>")) {
logger.info("Analytics log from appium log file : " + sCurrentLine.substring(sCurrentLine.indexOf("<analytics_log>"), sCurrentLine.indexOf("</analytics_log>")));
isAnalyticsPresent = sCurrentLine.contains(analytics);
for(String s : analyticsValuePairs) {
isAnalyticsPresent = sCurrentLine.contains(s);
if (!isAnalyticsPresent) {
badParams.append(s);
break;
}
if(!(badParams.toString().isEmpty()))
break;
}
if(!(badParams.toString().isEmpty()))
break;
}
if(!(badParams.toString().isEmpty()))
break;
}
assertThat(isAnalyticsPresent).as("Analytics "+ analyticsParams +" with paramaters "+ badParams +" isn't present or incorrect. Please check this situation").isTrue();
} catch (Exception e) {
e.printStackTrace();
}
}
示例7: sendLatestLogs
import org.apache.commons.io.input.ReversedLinesFileReader; //导入依赖的package包/类
public synchronized void sendLatestLogs() {
List<String> list = new ArrayList<>();
try {
ReversedLinesFileReader reader = new ReversedLinesFileReader(getLogsFile());
while (list.size() < configurationMediator.getLogsBufferSize()) {
list.add(reader.readLine());
}
reverse(list);
template.convertAndSend(LOGS_DESTINATION, list);
} catch (IOException e) {
LOG.warn("Failed to read logs {}", e);
reverse(list);
template.convertAndSend(LOGS_DESTINATION, list);
}
}
示例8: tailContent
import org.apache.commons.io.input.ReversedLinesFileReader; //导入依赖的package包/类
@Override
public void tailContent(Path folder, String filename, OutputStream stream, int lines) throws IOException {
try (ReversedLinesFileReader reader = new ReversedLinesFileReader(getFile(folder, filename))) {
int i = 0;
String line;
List<String> content = new ArrayList<>();
while ((line = reader.readLine()) != null && i++ < lines) {
content.add(line);
}
Collections.reverse(content);
IOUtils.writeLines(content, System.lineSeparator(), stream);
}
}
示例9: 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;
}
示例10: 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);
}
}
示例11: 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;
}
示例12: 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;
}
}
示例13: 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 />";
}
}
示例14: 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.";
}
}
示例15: 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.";
}
}