use of alma.alarmsystem.statistics.generated.Statistics in project ACS by ACS-Community.
the class StatHashMap method openOutputFile.
/**
* Open and create the output stream for writing statistics on file.
* <P>
* The file is opened for each writing and closed immediately.
* A new file is created, whenever the size of the actual file is
* greater then {@link #maxFileSize}.
*
* @return The stream for writing into the file
* @throws IOException If can't open/create the file for writing
* @throws ValidationException In case of error validating the Statistics element (should never happen)
* @throws MarshalException Error writing Statistics header in the file
*/
private BufferedWriter openOutputFile() throws IOException, MarshalException, ValidationException {
String actualFileName = fileNamePrefix + fileNumber + ".xml";
String folderName = folder.getAbsolutePath();
if (!folderName.endsWith("" + File.separator)) {
folderName = folderName + File.separator;
}
// Check the size of the file if it exists
File f = new File(folderName + actualFileName);
if (f.exists() && f.length() > maxFileSize) {
fileNumber++;
return openOutputFile();
}
if (f.length() == 0) {
// New file: write the header
Statistics statistics = new Statistics();
BufferedWriter outF = new BufferedWriter(new FileWriter(f, true));
Marshaller marshaller = getMarshaller(outF);
marshaller.setSupressXMLDeclaration(false);
marshaller.marshal(statistics);
outF.flush();
outF.close();
RandomAccessFile raf = new RandomAccessFile(f, "rw");
raf.setLength(raf.length() - 3);
raf.seek(raf.length());
raf.writeBytes(">\n");
raf.close();
} else {
// Remove the closing tag (closeXMLTag) before adding a new record
RandomAccessFile raf = new RandomAccessFile(f, "rw");
raf.setLength(raf.length() - closeXMLTag.length() - 1);
raf.seek(raf.length());
raf.writeBytes("\n");
raf.close();
}
return new BufferedWriter(new FileWriter(f, true));
}
use of alma.alarmsystem.statistics.generated.Statistics in project ACS by ACS-Community.
the class StatsHashMapTest method dump.
/**
* Dump the content of the file of statistics on stdout
*/
private void dump() throws Exception {
BufferedReader reader = new BufferedReader(new FileReader(buildFileName()));
String line = null;
while ((line = reader.readLine()) != null) {
System.out.println(line);
}
reader.close();
// Unmarshal the file to check if it is valid
Statistics stats = Statistics.unmarshalStatistics(new FileReader(buildFileName()));
}
Aggregations