use of alma.acs.util.IsoDateFormat in project ACS by ACS-Community.
the class DetailedLogTable method setupContent.
/**
* Fill the table with the fields of the given log.
*
* @param log The log whose content is shown in the table
*/
public void setupContent(ILogEntry log) {
if (log == null) {
setEmptyContent();
return;
}
// The number of rows in the table is given by the number of fields
// of each LogEntry plus the number of the "data" elements for the selected log
Vector<ILogEntry.AdditionalData> additionalData = log.getAdditionalData();
rowsNum = LogField.values().length;
if (additionalData != null) {
rowsNum += additionalData.size();
}
if (rowsNum > 0) {
nameValue = new String[rowsNum][2];
for (int i = 0; i < LogField.values().length; i++) {
LogField field = LogField.values()[i];
nameValue[i][0] = "<HTML><B>" + field.getName() + "</B>";
Object obj = log.getField(field);
if (obj != null) {
if (field == LogField.ENTRYTYPE) {
nameValue[i][1] = obj.toString();
dataModel.logType = (LogTypeHelper) obj;
} else if (field == LogField.TIMESTAMP) {
SimpleDateFormat df = new IsoDateFormat();
Date dt = new Date((Long) obj);
StringBuffer dateSB = new StringBuffer();
java.text.FieldPosition pos = new java.text.FieldPosition(0);
df.format(dt, dateSB, pos);
nameValue[i][1] = dateSB.toString();
} else {
nameValue[i][1] = obj.toString();
}
} else {
nameValue[i][1] = "";
}
}
for (int i = LogField.values().length; i < rowsNum; i++) {
nameValue[i][0] = "<HTML><B>Additional</B> <I>" + additionalData.get(i - LogField.values().length).name + "</I>";
String temp = (String) additionalData.get(i - LogField.values().length).value;
nameValue[i][1] = temp;
}
dataModel.fireTableDataChanged();
}
}
use of alma.acs.util.IsoDateFormat in project ACS by ACS-Community.
the class ACSLogParserVTD method getLongFromTimestamp.
/**
* Gets a Long from VTD XML parser (using VTDNav navigation)
*
* @param vtdNav the navigator to use to navigate the parsed xml
* @param os output stream to use for conversion of bytes to useful formatted data.
* @param attrName the name of the field we are searching for
* @param bytesXML the bytes (containing XML) that are being referenced by the navigator.
* @return Long populated with the attribute's value
* @throws NavException if navigation encounters problems
* @throws LogParseException if parsing fails
*/
private Long getLongFromTimestamp(Object vtdNav, ByteArrayOutputStream os, String attrName, byte[] bytesXML) throws LogParseException, Exception {
Long retVal = null;
int tIndex = (Integer) VTDNav_getAttrVal.invoke(vtdNav, attrName);
int tOffset = (Integer) VTDNav_getTokenOffset.invoke(vtdNav, tIndex);
int tLen = (Integer) VTDNav_getTokenLength.invoke(vtdNav, tIndex);
os.reset();
//write the fragment out
os.write(bytesXML, tOffset, tLen);
try {
SimpleDateFormat dateFormat = new IsoDateFormat();
Date date = dateFormat.parse(os.toString());
retVal = Long.valueOf(date.getTime());
} catch (java.text.ParseException pEx) {
throw new LogParseException("Error parsing date", pEx);
}
return retVal;
}
use of alma.acs.util.IsoDateFormat in project ACS by ACS-Community.
the class FileHelper method dumpToFile.
/**
* Start the dumping process. This method should only be called if you know what you are doing.<br />
* Setting the prec lower will get leaks of data, and setting it higher, will get you duplicated data.
* @param frequency Frequency at which the data is to be separated in the printout file.
* @param prec How much of the Frequency will each entry take as a valid interval of time to look forward and backward for data.
*/
public void dumpToFile(long frequency, double prec) {
IsoDateFormat formater = new IsoDateFormat();
long timestamp = data.get(0).get(0).getTime();
boolean done = false;
frequency = 1000000L / frequency;
long w = (long) (frequency * prec);
int[] c = new int[data.size()];
openFile();
try {
writer.write(header + "\n");
} catch (IOException e1) {
e1.printStackTrace();
}
while (!done) {
String line = "" + formater.format(new Date(UTCUtility.utcOmgToJava(timestamp)));
boolean dataPresent = true;
for (int i = 0; i < data.size(); i++) {
dataPresent = false;
if (c[i] == data.get(i).size()) {
line += ";";
continue;
}
DataItem item = data.get(i).get(c[i]);
if ((item.getTime() >= (timestamp - w)) && (item.getTime() <= (timestamp + w))) {
line += ";" + item.getValue();
c[i]++;
dataPresent = true;
} else if ((item.getTime() >= (timestamp + w)) && (item.getTime() <= (timestamp + frequency - w))) {
line += ";";
c[i]++;
} else
line += ";";
}
try {
if (dataPresent) {
writer.write(line + "\n");
}
} catch (IOException e) {
e.printStackTrace();
}
/*Check if we passed over all dataItem recolected*/
int flag = 0;
for (int i = 0; i < c.length; i++) {
if (c[i] == data.get(i).size())
flag++;
}
if (flag == c.length)
done = true;
timestamp += frequency;
}
try {
writer.close();
} catch (IOException e) {
e.printStackTrace();
}
}
use of alma.acs.util.IsoDateFormat in project ACS by ACS-Community.
the class FilePrinter method openFile.
private boolean openFile() {
IsoDateFormat fo = new IsoDateFormat();
filename = component + "_" + property + "_" + getFrequency() + "_" + fo.format(new Date()) + ".csv";
try {
file = new FileWriter(filename);
} catch (IOException e) {
e.printStackTrace();
return false;
}
writer = new BufferedWriter(file);
return true;
}
use of alma.acs.util.IsoDateFormat in project ACS by ACS-Community.
the class PlotPrinter method openFile.
private boolean openFile() {
IsoDateFormat fo = new IsoDateFormat();
filename = component.replace('/', '-') + "_" + property.replace('/', '-') + "_" + getFrequency() + "_" + fo.format(new Date()) + ".csv";
try {
file = new FileWriter(filename);
} catch (IOException e) {
e.printStackTrace();
return false;
}
writer = new BufferedWriter(file);
return true;
}
Aggregations