
Public Member Functions | |
| LogStringBuffer () | |
| void | append (char ch, StringBuilder str) |
| String | toString () |
| void | dump () |
Private Member Functions | |
| void | clear () |
| char[] | doubleBuffer (char[] originalBuffer) |
| boolean | compare (char[] src, int srcPos, char[]dest) |
| boolean | compareFromLastChar (char src[], int lastCharPos, char[] dest) |
| LogTypeHelper | lookForStartTag (char[] str, int pos) |
Private Attributes | |
| char[] | buffer = new char[1024] |
| int | bufferPos = 0 |
| int | startTagPos |
| char[][] | xmlOpeningTags |
| final int | minStartXMLTagSize |
| char[][] | xmlClosingTags |
| char[] | cdataStart = (new String("<![CDATA[")).toCharArray() |
| char[] | cdataEnd = (new String("]]>")).toCharArray() |
| int | cdataStartPos |
| int | cdataEndPos |
| LogTypeHelper | startTag |
LogStringBuffer is a buffer of chars supporting the loading of logs from a file.
The buffer contains the chars read from the file and passed through the append(). For each new chars, append() checks if a closing or an ending XML tag of a log is in the buffer.
When a whole XML representing a log is in the buffer, it is returned to the caller and the buffer cleared to be ready to look for the next XML.
The size of the buffer is initially set to a default value and it is doubled whenever the algorithm needs more room in the array of char.
This functionality was initially implemented encapsulating a StringBuilder property but it was too slow compared to basic chars manipulation.
| alma::acs::logging::engine::io::LogStringBuffer::LogStringBuffer | ( | ) | [inline] |
The constructor
| size | The size of the rotating buffer |
References clear(), minStartXMLTagSize, xmlClosingTags, and xmlOpeningTags.
| void alma::acs::logging::engine::io::LogStringBuffer::append | ( | char | ch, | |
| StringBuilder | str | |||
| ) | [inline] |
Append a char to the end of the buffer.
This method checks if the buffer contains the XML representing a log entry. The str parameter is used to return the string with a log and must be empty. The method does not perform any check about the content of the passed StringBuilder so it is the caller that must ensure the correctness.
Note: the content of the StringBuilder is changed only and only if there is a whole log in the buffer.
| ch | The char to append | |
| str | A string representing the new log; the content of this parameter is changed if and only if there is a log in the buffer |
References buffer, bufferPos, cdataEnd, cdataEndPos, cdataStart, cdataStartPos, clear(), compareFromLastChar(), doubleBuffer(), lookForStartTag(), minStartXMLTagSize, startTag, startTagPos, and xmlClosingTags.
Referenced by alma::acs::logging::engine::io::IOHelper::loadLogs().
| void alma::acs::logging::engine::io::LogStringBuffer::clear | ( | ) | [inline, private] |
Clear the buffer
References bufferPos, cdataEndPos, cdataStartPos, startTag, and startTagPos.
Referenced by append(), and LogStringBuffer().
| boolean alma::acs::logging::engine::io::LogStringBuffer::compare | ( | char[] | src, | |
| int | srcPos, | |||
| char[] | dest | |||
| ) | [inline, private] |
Compare the src array starting at position srcPos with the dest array.
The method checks if all the chars starting at srcPos position of the first array are equal to the chars of the second array.
The comparison lasts for all the chars of the dest array i.e. this method compares the chars in src[newPos, newPos+dest.length] with those in dest[0,dest.length].
| src | The first array to compare | |
| srcPos | The position inside src to start the comparison at | |
| dest | The array to compare |
true If the chars of the src starting at srcPos are equal to the chars of dest. References bufferPos.
Referenced by compareFromLastChar(), and lookForStartTag().
| boolean alma::acs::logging::engine::io::LogStringBuffer::compareFromLastChar | ( | char | src[], | |
| int | lastCharPos, | |||
| char[] | dest | |||
| ) | [inline, private] |
Compare the content of 2 array of chars starting from the position of the last char of the first array.
The method checks is src and dest are equal. The check is done in reverse order, starting from the position of the last char of the first array, src.
The comparison lasts for all the chars of the dest array i.e. this method compares the chars in src[lastCharPos-dest.length,lastCharPos] with those in dest[0,dest.length].
| src | The first array to compare | |
| lastCharPos | The position of the last char of src to compare | |
| dest | The array to compare |
true If the chars of the src starting at lastCharPos-dest.length are equal to the chars of dest. References compare().
Referenced by append().
| char [] alma::acs::logging::engine::io::LogStringBuffer::doubleBuffer | ( | char[] | originalBuffer | ) | [inline, private] |
Doubles the array.
It creates a new array having the size double as the size of the passed array.
The content of the first array is copied in the newly created one.
| originalBuffer | The buffer to copy in the new array of a double size |
Referenced by append().
| void alma::acs::logging::engine::io::LogStringBuffer::dump | ( | ) | [inline] |
References buffer, bufferPos, cdataEndPos, cdataStartPos, startTag, and startTagPos.
| LogTypeHelper alma::acs::logging::engine::io::LogStringBuffer::lookForStartTag | ( | char[] | str, | |
| int | pos | |||
| ) | [inline, private] |
Look for an XML tag in the passed string, starting at the given position.
| str | The string to check | |
| pos | The position in the str to look for the tag |
LogTypehelper corresponding to the XML tag null if not XML tag is found at the given position References compare(), and xmlOpeningTags.
Referenced by append().
| String alma::acs::logging::engine::io::LogStringBuffer::toString | ( | ) | [inline] |
char [] alma::acs::logging::engine::io::LogStringBuffer::buffer = new char[1024] [private] |
The array of chars where the chars read from the input file are written.
The size passed in the construct is doubled when the length is not enough by calling doubleBuffer().
While reading logs from a file, each log is temporarily written in this array do it begins with an XML opening tag and terminates with the closing tag. Any extra char read at the beginning of an opening tag is skipped.
Referenced by append(), dump(), and toString().
int alma::acs::logging::engine::io::LogStringBuffer::bufferPos = 0 [private] |
The position where a new char must be written in the array buffer.
It represents also the length of the string in the buffer.
Referenced by append(), clear(), compare(), dump(), and toString().
char [] alma::acs::logging::engine::io::LogStringBuffer::cdataEnd = (new String("]]>")).toCharArray() [private] |
The end of a CDATA section
Referenced by append().
char [] alma::acs::logging::engine::io::LogStringBuffer::cdataStart = (new String("<![CDATA[")).toCharArray() [private] |
The starting of a CDATA section
Referenced by append().
final int alma::acs::logging::engine::io::LogStringBuffer::minStartXMLTagSize [private] |
This property, initialized in the constructor, contains the size of the shortest start tag and is used to reduce the number of checks while looking for the starting tag
Referenced by append(), and LogStringBuffer().
LogTypeHelper alma::acs::logging::engine::io::LogStringBuffer::startTag [private] |
char [][] alma::acs::logging::engine::io::LogStringBuffer::xmlClosingTags [private] |
The closing XML tags of the log types for example </Trace> and </Info>
The first dimension is the position of the tag in the array of LogTypeHelper, the second dimension is the length of the tag
Referenced by append(), and LogStringBuffer().
char [][] alma::acs::logging::engine::io::LogStringBuffer::xmlOpeningTags [private] |
The XML tags of the log types (including the leading '<') for example <Trace and <Info
The first dimension is the position of the tag in the array of LogTypeHelper, the second dimension is the length of the tag
Referenced by LogStringBuffer(), and lookForStartTag().
1.6.2