use of org.jrobin.core.RrdException in project i2p.i2p by i2p.
the class RrdGraphDefTemplate method resolveFont.
private Font resolveFont(Node parentNode) throws RrdException {
validateTagsOnlyOnce(parentNode, new String[] { "name", "style", "size" });
String name = null, style = null;
int size = 0;
Node[] childNodes = getChildNodes(parentNode);
for (Node childNode : childNodes) {
String nodeName = childNode.getNodeName();
if (nodeName.equals("name")) {
name = getValue(childNode);
} else if (nodeName.equals("style")) {
style = getValue(childNode).toLowerCase();
} else if (nodeName.equals("size")) {
size = getValueAsInt(childNode);
}
}
if (name != null && style != null && size > 0) {
boolean isItalic = style.contains("italic"), isBold = style.contains("bold");
int fstyle = Font.PLAIN;
if (isItalic && isBold) {
fstyle = Font.BOLD + Font.ITALIC;
} else if (isItalic) {
fstyle = Font.ITALIC;
} else if (isBold) {
fstyle = Font.BOLD;
}
return new Font(name, fstyle, size);
} else {
throw new RrdException("Incomplete font specification");
}
}
use of org.jrobin.core.RrdException in project i2p.i2p by i2p.
the class RRDFile method initDataLayout.
private void initDataLayout(File file) throws IOException, RrdException {
if (file.exists()) {
// Load the data formats from the file
int bytes = ras.read(buffer, 0, 24);
if (bytes < 24) {
throw new RrdException("Invalid RRD file");
}
int index;
if ((index = indexOf(FLOAT_COOKIE_BIG_ENDIAN, buffer)) != -1) {
bigEndian = true;
} else if ((index = indexOf(FLOAT_COOKIE_LITTLE_ENDIAN, buffer)) != -1) {
bigEndian = false;
} else {
throw new RrdException("Invalid RRD file");
}
switch(index) {
case 12:
alignment = 4;
break;
case 16:
alignment = 8;
break;
default:
throw new RuntimeException("Unsupported architecture - neither 32-bit nor 64-bit, or maybe the file is corrupt");
}
} else {
// Default to data formats for this hardware architecture
}
// Reset file pointer to start of file
ras.seek(0);
}
use of org.jrobin.core.RrdException in project i2p.i2p by i2p.
the class RRDatabase method getData.
/**
* Returns data from the database corresponding to the given consolidation
* function.
*
* @param type the consolidation function that should have been applied to
* the data.
* @param step the step size to use.
* @return the raw data.
* @throws RrdException if there was a problem locating a data archive with
* the requested consolidation function.
* @throws IOException if there was a problem reading data from the database.
*/
public DataChunk getData(ConsolidationFunctionType type, long step) throws RrdException, IOException {
ArrayList<Archive> possibleArchives = getArchiveList(type);
if (possibleArchives.size() == 0) {
throw new RrdException("Database does not contain an Archive of consolidation function type " + type);
}
Calendar endCal = Calendar.getInstance();
endCal.set(Calendar.MILLISECOND, 0);
Calendar startCal = (Calendar) endCal.clone();
startCal.add(Calendar.DATE, -1);
long end = endCal.getTime().getTime() / 1000;
long start = startCal.getTime().getTime() / 1000;
Archive archive = findBestArchive(start, end, step, possibleArchives);
// Tune the parameters
step = header.pdpStep * archive.pdpCount;
start -= start % step;
if (end % step != 0) {
end += step - end % step;
}
int rows = (int) ((end - start) / step + 1);
// cat.debug("start " + start + " end " + end + " step " + step + " rows "
// + rows);
// Find start and end offsets
// This is terrible - some of this should be encapsulated in Archive - CT.
long lastUpdateLong = lastUpdate.getTime() / 1000;
long archiveEndTime = lastUpdateLong - (lastUpdateLong % step);
long archiveStartTime = archiveEndTime - (step * (archive.rowCount - 1));
int startOffset = (int) ((start - archiveStartTime) / step);
int endOffset = (int) ((archiveEndTime - end) / step);
// cat.debug("start " + archiveStartTime + " end " + archiveEndTime
// + " startOffset " + startOffset + " endOffset "
// + (archive.rowCount - endOffset));
DataChunk chunk = new DataChunk(start, startOffset, endOffset, step, header.dsCount, rows);
archive.loadData(chunk);
return chunk;
}
use of org.jrobin.core.RrdException in project i2p.i2p by i2p.
the class Epoch method convert.
private void convert() {
String time = inputField.getText().trim();
if (time.length() > 0) {
// try simple timestamp
try {
long timestamp = Long.parseLong(time);
Date date = new Date(timestamp * 1000L);
formatDate(date);
} catch (NumberFormatException nfe) {
// failed, try as a date
try {
inputField.setText("" + parseDate(time));
} catch (RrdException e) {
inputField.setText("Could not convert, sorry");
}
}
}
}
use of org.jrobin.core.RrdException in project i2p.i2p by i2p.
the class TimeSpec method getTime.
GregorianCalendar getTime() throws RrdException {
GregorianCalendar gc;
// absoulte time, this is easy
if (type == TYPE_ABSOLUTE) {
gc = new GregorianCalendar(year + 1900, month, day, hour, min, sec);
} else // relative time, we need a context to evaluate it
if (context != null && context.type == TYPE_ABSOLUTE) {
gc = context.getTime();
} else // how would I guess what time it was?
{
throw new RrdException("Relative times like '" + dateString + "' require proper absolute context to be evaluated");
}
gc.add(Calendar.YEAR, dyear);
gc.add(Calendar.MONTH, dmonth);
gc.add(Calendar.DAY_OF_MONTH, dday);
gc.add(Calendar.HOUR_OF_DAY, dhour);
gc.add(Calendar.MINUTE, dmin);
gc.add(Calendar.SECOND, dsec);
return gc;
}
Aggregations