@Test public void testPullLastLineReadNoFile() { logger.debug("testPullLastLineReadNoFile: enter"); final File file = new File("nonExistFile.txt"); try { assertEquals(null, ParseLog.pullLastLineRead(file, "pap-rest")); } catch (final IOException e) { fail(); } logger.debug("testPullLastLineReadNoFile: exit"); }
public static String pullLastLineRead(final File file, final String dataFileName) throws IOException { if (!file.exists()) { file.createNewFile(); return null; } try (RandomAccessFile randomAccessFile = new RandomAccessFile(file, "r");) { StringBuilder builder = new StringBuilder(); long length = file.length(); logger.debug("dataFileName: " + dataFileName); if (length == 0) { return null; } length--; randomAccessFile.seek(length); for (long seek = length; seek >= 0; --seek) { randomAccessFile.seek(seek); final char c = (char) randomAccessFile.read(); builder.append(c); if (c == '\n') { builder = builder.reverse(); logger.debug("builder.toString(): " + builder.toString()); if (builder.toString().contains(last + dataFileName + lineRead)) { final String[] parseString = builder.toString().split(last + dataFileName + lineRead); final String returnValue = parseString[1].replace("\r", ""); return returnValue.trim(); } builder = new StringBuilder(); } } } return null; }
ParseLog { public static String pullLastLineRead(final File file, final String dataFileName) throws IOException { if (!file.exists()) { file.createNewFile(); return null; } try (RandomAccessFile randomAccessFile = new RandomAccessFile(file, "r");) { StringBuilder builder = new StringBuilder(); long length = file.length(); logger.debug("dataFileName: " + dataFileName); if (length == 0) { return null; } length--; randomAccessFile.seek(length); for (long seek = length; seek >= 0; --seek) { randomAccessFile.seek(seek); final char c = (char) randomAccessFile.read(); builder.append(c); if (c == '\n') { builder = builder.reverse(); logger.debug("builder.toString(): " + builder.toString()); if (builder.toString().contains(last + dataFileName + lineRead)) { final String[] parseString = builder.toString().split(last + dataFileName + lineRead); final String returnValue = parseString[1].replace("\r", ""); return returnValue.trim(); } builder = new StringBuilder(); } } } return null; } }
ParseLog { public static String pullLastLineRead(final File file, final String dataFileName) throws IOException { if (!file.exists()) { file.createNewFile(); return null; } try (RandomAccessFile randomAccessFile = new RandomAccessFile(file, "r");) { StringBuilder builder = new StringBuilder(); long length = file.length(); logger.debug("dataFileName: " + dataFileName); if (length == 0) { return null; } length--; randomAccessFile.seek(length); for (long seek = length; seek >= 0; --seek) { randomAccessFile.seek(seek); final char c = (char) randomAccessFile.read(); builder.append(c); if (c == '\n') { builder = builder.reverse(); logger.debug("builder.toString(): " + builder.toString()); if (builder.toString().contains(last + dataFileName + lineRead)) { final String[] parseString = builder.toString().split(last + dataFileName + lineRead); final String returnValue = parseString[1].replace("\r", ""); return returnValue.trim(); } builder = new StringBuilder(); } } } return null; }  }
ParseLog { public static String pullLastLineRead(final File file, final String dataFileName) throws IOException { if (!file.exists()) { file.createNewFile(); return null; } try (RandomAccessFile randomAccessFile = new RandomAccessFile(file, "r");) { StringBuilder builder = new StringBuilder(); long length = file.length(); logger.debug("dataFileName: " + dataFileName); if (length == 0) { return null; } length--; randomAccessFile.seek(length); for (long seek = length; seek >= 0; --seek) { randomAccessFile.seek(seek); final char c = (char) randomAccessFile.read(); builder.append(c); if (c == '\n') { builder = builder.reverse(); logger.debug("builder.toString(): " + builder.toString()); if (builder.toString().contains(last + dataFileName + lineRead)) { final String[] parseString = builder.toString().split(last + dataFileName + lineRead); final String returnValue = parseString[1].replace("\r", ""); return returnValue.trim(); } builder = new StringBuilder(); } } } return null; }  static void main(final String[] args); static int countLines(final String filename); static String pullLastLineRead(final File file, final String dataFileName); static LogEntryObject pullOutLogValues(final String line, final String type); static void process(final String line, final String type, final LogType logFile); static Date parseDate(final String dateline, final String pattern, final boolean singleSplit); static String parseRemoteSystem(final String line); static String[] getPaths(final String logPath); static Properties getPropertiesValue(final String fileName); static Connection getDbConnection(); }
ParseLog { public static String pullLastLineRead(final File file, final String dataFileName) throws IOException { if (!file.exists()) { file.createNewFile(); return null; } try (RandomAccessFile randomAccessFile = new RandomAccessFile(file, "r");) { StringBuilder builder = new StringBuilder(); long length = file.length(); logger.debug("dataFileName: " + dataFileName); if (length == 0) { return null; } length--; randomAccessFile.seek(length); for (long seek = length; seek >= 0; --seek) { randomAccessFile.seek(seek); final char c = (char) randomAccessFile.read(); builder.append(c); if (c == '\n') { builder = builder.reverse(); logger.debug("builder.toString(): " + builder.toString()); if (builder.toString().contains(last + dataFileName + lineRead)) { final String[] parseString = builder.toString().split(last + dataFileName + lineRead); final String returnValue = parseString[1].replace("\r", ""); return returnValue.trim(); } builder = new StringBuilder(); } } } return null; }  static void main(final String[] args); static int countLines(final String filename); static String pullLastLineRead(final File file, final String dataFileName); static LogEntryObject pullOutLogValues(final String line, final String type); static void process(final String line, final String type, final LogType logFile); static Date parseDate(final String dateline, final String pattern, final boolean singleSplit); static String parseRemoteSystem(final String line); static String[] getPaths(final String logPath); static Properties getPropertiesValue(final String fileName); static Connection getDbConnection();  }