com.atlassian.bamboo.build.logger
Class BuildLogFileAccessor

java.lang.Object
  extended by com.atlassian.bamboo.build.logger.BuildLogFileAccessor

@NotThreadSafe
public class BuildLogFileAccessor
extends java.lang.Object

This class provides a mechanism to perform operations on build log files. An accessor class must be instantiated for each build log file. Other notes: When using the file iterator, it is not thread safe. Be sure to open the file for iteration and close it once your done.


Method Summary
 void closeFileForIteration()
          close the file iterator
 java.util.List<LogEntry> getLastNLogs(int numLogs)
          Retrives a List of the last N logs.
 int getNumberOfLinesInFile()
          Counts the number of lines in the file.
 boolean hasNext()
          Requires file to be opened for iteration
 java.lang.String nextLine()
          Requires file to be opened for iteration
 LogEntry nextLogEntry()
          Requires file to be opened for iteration
 boolean openFileForIteration()
          Open the file contained within this accessor to perform iterations (must be called before the hasNext(), nextLogEntry() and nextLine()).
 LogEntry searchFileForEntry(java.lang.String textToSearchFor, boolean searchInErrorMessages)
          Looks incrementally through the file to see if the specified text exists
 LogEntry searchFileForEntry(java.lang.String textToSearchFor, int lastNLines, boolean searchInErrorMessages)
          Searchers for particular text within the last n lines of a file (eg search within the last 10 lines for a success message)
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

openFileForIteration

public boolean openFileForIteration()
Open the file contained within this accessor to perform iterations (must be called before the hasNext(), nextLogEntry() and nextLine()).

Returns:
true if the opening of the file was successful, otherwise false.

closeFileForIteration

public void closeFileForIteration()
close the file iterator


hasNext

public boolean hasNext()
Requires file to be opened for iteration

Returns:
true if there is another line in the file, otherwise false

nextLogEntry

public LogEntry nextLogEntry()
Requires file to be opened for iteration

Returns:
The next line in the file as a LogEntry

nextLine

public java.lang.String nextLine()
Requires file to be opened for iteration

Returns:
The next line in the file as a String, may return null;

searchFileForEntry

@Nullable
public LogEntry searchFileForEntry(@Nullable
                                            java.lang.String textToSearchFor,
                                            boolean searchInErrorMessages)
                            throws java.io.IOException
Looks incrementally through the file to see if the specified text exists

Parameters:
textToSearchFor - the specific text to search for
searchInErrorMessages - search also in error messages
Returns:
the LogEntry that the text was found in or null if the text was not found
Throws:
java.io.IOException - if there were errors accessing the file

searchFileForEntry

@Nullable
public LogEntry searchFileForEntry(@Nullable
                                            java.lang.String textToSearchFor,
                                            int lastNLines,
                                            boolean searchInErrorMessages)
                            throws java.io.IOException
Searchers for particular text within the last n lines of a file (eg search within the last 10 lines for a success message)

Parameters:
textToSearchFor - String text to find in file
lastNLines - number of lines from end to search from
searchInErrorMessages - search also in error messages
Returns:
the LogEntry the text was found in or null if the text was not found
Throws:
java.io.IOException - if error closing the log file

getLastNLogs

public java.util.List<LogEntry> getLastNLogs(int numLogs)
                                      throws java.io.IOException
Retrives a List of the last N logs. Avoid using this with large numbers as it has the potential to cause out of memory errors

Parameters:
numLogs - number of logs to retrive
Returns:
List of the last N LogEntry Objects in the file, may return an empty list
Throws:
java.io.IOException - if errors access the build log file

getNumberOfLinesInFile

public int getNumberOfLinesInFile()
                           throws java.io.IOException
Counts the number of lines in the file.

Returns:
number of lines in file
Throws:
java.io.IOException - if errors accessing the file


Copyright © 2011 Atlassian. All Rights Reserved.