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."; } }
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."; } }
@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; }
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; } }
/** * 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(); }
@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(); } }
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); } }
@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); } }
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; }
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); } }
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; }
/** * 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; } }
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 />"; } }
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."; } }
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."; } }
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."; } }
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."; } }
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."; } }
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."; } }
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."); } }
private void verifySavepoints(Integer numPartitions, String savepointDirectoryName, String objectType, ObjectMapper om, List<Map.Entry<Long, Long>> ranges) throws Exception { // Open up the savepoint directory File savepointDirectory = new File(savepointDirectoryName); assertTrue(savepointDirectory.exists()); assertTrue(savepointDirectory.isDirectory()); File[] fileArray = savepointDirectory.listFiles(); assertNotNull(fileArray); // Make sure we have all the savepoint files we expect Map<String, File> files = Maps.newHashMap(); for (File savepoint : fileArray) { files.put(savepoint.getName(), savepoint); } boolean foundAtLeastOneLine = false; UUID highestUuid = null; for (int i = 0; i < numPartitions; i++) { String filename = TableScanner.getSavepointFilename(i); assertTrue(files.containsKey(filename)); File file = files.get(filename); ReversedLinesFileReader reader = new ReversedLinesFileReader(file); String line = reader.readLine(); // A null line is actually ok, that just means there were no results in that partition's token range this time around if (line != null) { foundAtLeastOneLine = true; UUID savedUuid = UUID.fromString(line); assertNotNull(savedUuid); List<Map<String, Object>> values = om.scanTableWithStartId(objectType, savedUuid.toString(), TableScanner.maxToken, 1L); // This means there is no next id from this uuid so our normal check doesn't work. // This also means this is the highest uuid in the total range (might not be in the last partition if the last partition didn't end up with any objects) if (values.size() == 0) { // Make sure this only happens once assertNull(highestUuid); highestUuid = savedUuid; } else { // Otherwise there is a next uuid from the saved point, so compare that to the next uuid from the end of the partition's range and make sure they match UUID nextSavedUuid = (UUID) values.get(0).get("id"); UUID nextExpectedUuid = (UUID) om.scanTableWithStartToken(objectType, ranges.get(i).getValue(), TableScanner.maxToken, 1L).get(0).get("id"); assertEquals(nextExpectedUuid, nextSavedUuid); } } } assertTrue(foundAtLeastOneLine); }