use of java.text.FieldPosition in project ACS by ACS-Community.
the class LogFileSplitter method getOutputFile.
/**
* Create a new file for output.
*
* @param dest The name of the destination file
* @param index The index to append to the name
* @param startingDate The date of the first log to append to the
* name of the file
* It can be null.
*
* @return The writer for output
*/
private BufferedWriter getOutputFile(String dest, int idx, Date startingDate) throws IOException {
// Build the name of the file
StringBuilder name = new StringBuilder(dest);
name.append('-');
name.append(idx);
if (startingDate != null) {
name.append('-');
StringBuffer buffer = new StringBuffer();
synchronized (dateFormat) {
dateFormat.format(startingDate, buffer, new FieldPosition(0));
}
name.append(buffer.toString());
}
// Add the extension
if (converter instanceof XMLConverter) {
name.append(".xml");
} else {
name.append(".txt");
}
// Create and return the file
FileWriter outFile = null;
outFile = new FileWriter(name.toString(), false);
System.out.println("Writing logs on " + name);
return new BufferedWriter(outFile, OUTPUT_BUFFER_SIZE);
}
use of java.text.FieldPosition in project ACS by ACS-Community.
the class CacheTest method fillCache.
/**
* Fill the cache with dynamically generated logs
* The number of logs inserted in the list is greater than the
* memory cache size to stress the disk cache also.
*
* @return The number of logs inserted in the cache
*
* @throws Exception
*/
private long fillCache() throws Exception {
ACSLogParser parser = ACSLogParserFactory.getParser();
String logMsg = "Test log nr. ";
// Yesterday
long now = Calendar.getInstance().getTimeInMillis() - 1000 * 60 * 60 * 24;
SimpleDateFormat df = new IsoDateFormat();
cache.clear();
long logToInsert = 2 * cache.getCacheSize();
for (int t = 0; t < logToInsert; t++) {
Date dt = new Date(now + t * 1000);
StringBuffer dateSB = new StringBuffer();
FieldPosition pos = new FieldPosition(0);
df.format(dt, dateSB, pos);
String newLogMsg = logMsg + "t";
StringBuilder logStr = new StringBuilder("<Info TimeStamp=\"");
logStr.append(dateSB.toString());
logStr.append("\" Routine=\"CacheTest::testGet\" Host=\"this\" Process=\"test\" Thread=\"main\" Context=\"\"><![CDATA[");
logStr.append(newLogMsg);
logStr.append("]]></Info>");
ILogEntry newLog = parser.parse(logStr.toString());
cache.add(newLog);
}
return logToInsert;
}
use of java.text.FieldPosition in project ACS by ACS-Community.
the class SearchEngine method find.
/**
* The method executes the search for both the public overloaded
* find methods.
*
* @param regExp The regular expression to look for in the logs
* null if the method search for a string
* @param searchString The string to look for in the logs
* null if the method search for a reg exp
* @param caseSensitive If true performs a CaseSensitive search
* Ignored for reg exp searchs (it is coded
* in the Pattern)
* @param wholeWord If true look for the whole word int the column
* Ignored for reg exp searchs
* @param forwardSearch If true search forward otherwise backward
* @param cols The columns of each log tool for the string
* @return -1 if no log is found otherwise the row containing the string/reg exp
*/
private int find(Pattern regExp, String searchString, boolean caseSensitive, boolean wholeWord, boolean forwardSearch, boolean[] cols) {
// I want only one loop for both forward and backward searches
// For that I calculate the interval of valid rows to scan
// [a,b] where a<=b i.e. this interval is independedent from the
// direction of the search
// Then I use a cursor to navigate the rows, decreasing or
// increasing its value depending of the direction of the search
// Get the starting and the ending row for the search
int startingRow = getStartingRow(forwardSearch);
int endRow = (forwardSearch) ? logEntryTable.getRowCount() - 1 : 0;
// The position where the SimpleDate must be written
FieldPosition pos = new java.text.FieldPosition(0);
// A temporary buffer
StringBuffer tempSB = new StringBuffer();
// The variable used to browse the rows
int cursor = startingRow;
// Order end and start rown in growing order
if (endRow < startingRow) {
int temp = startingRow;
startingRow = endRow;
endRow = temp;
}
int foundRow = -1;
while (cursor >= startingRow && cursor <= endRow && foundRow == -1) {
// cols contains one entry for each field of a log entry
// plus one entry for the additional data
ILogEntry log = logTableDataModel.getVisibleLogEntry(logEntryTable.convertRowIndexToModel(cursor));
// The value of the field
String string = null;
for (int t = 0; t < cols.length - 1; t++) {
Object obj = log.getField(LogField.values()[t]);
if (obj == null) {
continue;
}
if (cols[t]) {
switch(LogField.values()[t]) {
case TIMESTAMP:
{
SimpleDateFormat df = new IsoDateFormat();
Date dt = new Date((Long) obj);
tempSB.delete(0, tempSB.length());
df.format(dt, tempSB, pos);
string = tempSB.toString();
break;
}
case ENTRYTYPE:
case LINE:
case PRIORITY:
case STACKLEVEL:
{
string = obj.toString();
break;
}
default:
{
string = obj.toString();
break;
}
}
if (matches(string, regExp, searchString, caseSensitive, wholeWord)) {
if ((forwardSearch && cursor != startingRow) || (!forwardSearch && cursor != endRow)) {
foundRow = cursor;
if (forwardSearch) {
cursor++;
} else {
cursor--;
}
return foundRow;
}
}
}
}
// searching for regular espressions
if (cols[cols.length - 1] && log.hasDatas()) {
Vector<ILogEntry.AdditionalData> addData = log.getAdditionalData();
for (int t = 0; t < addData.size(); t++) {
ILogEntry.AdditionalData data = addData.elementAt(t);
string = data.name;
if (matches(string, regExp, searchString, caseSensitive, wholeWord)) {
if ((forwardSearch && cursor != startingRow) || (!forwardSearch && cursor != endRow)) {
foundRow = cursor;
if (forwardSearch) {
cursor++;
} else {
cursor--;
}
return foundRow;
}
}
string = data.value;
if (matches(string, regExp, searchString, caseSensitive, wholeWord)) {
if ((forwardSearch && cursor != startingRow) || (!forwardSearch && cursor != endRow)) {
foundRow = cursor;
if (forwardSearch) {
cursor++;
} else {
cursor--;
}
return foundRow;
}
}
}
}
if (forwardSearch) {
cursor++;
} else {
cursor--;
}
}
return foundRow;
}
use of java.text.FieldPosition in project ACS by ACS-Community.
the class AntennaSourceReductionTest method createLog.
/**
* Create a log entry with the passed message and source
*
* @param logMsg The message
* @param logSrc The source
* @return The log entry
* @throws Exception
*/
private ILogEntry createLog(String logMsg, String logSrc) throws Exception {
ACSLogParser parser = ACSLogParserFactory.getParser();
long now = Calendar.getInstance().getTimeInMillis();
SimpleDateFormat df = new IsoDateFormat();
Date dt = new Date(now);
StringBuffer dateSB = new StringBuffer();
FieldPosition pos = new FieldPosition(0);
df.format(dt, dateSB, pos);
StringBuilder logStr = new StringBuilder("<Info TimeStamp=\"");
logStr.append(dateSB.toString());
logStr.append("\" Routine=\"CacheTest::testGet\" SourceObject=\"");
logStr.append(logSrc);
logStr.append("\" Host=\"this\" Process=\"test\" Thread=\"main\" Context=\"\"><![CDATA[");
logStr.append(logMsg);
logStr.append("]]></Info>");
ILogEntry newLog = parser.parse(logStr.toString());
return newLog;
}
use of java.text.FieldPosition in project ACS by ACS-Community.
the class AntennaReductionTest method createLog.
private ILogEntry createLog(String logMsg) throws Exception {
ACSLogParser parser = ACSLogParserFactory.getParser();
long now = Calendar.getInstance().getTimeInMillis();
SimpleDateFormat df = new IsoDateFormat();
Date dt = new Date(now);
StringBuffer dateSB = new StringBuffer();
FieldPosition pos = new FieldPosition(0);
df.format(dt, dateSB, pos);
StringBuilder logStr = new StringBuilder("<Info TimeStamp=\"");
logStr.append(dateSB.toString());
logStr.append("\" Routine=\"CacheTest::testGet\" Host=\"this\" Process=\"test\" Thread=\"main\" Context=\"\"><![CDATA[");
logStr.append(logMsg);
logStr.append("]]></Info>");
ILogEntry newLog = parser.parse(logStr.toString());
return newLog;
}
Aggregations