/** * Reads all RRD bytes from the underlying storage. * * @return RRD bytes * @throws java.io.IOException Thrown in case of I/O error */ public final byte[] readAll() throws IOException { byte[] b = new byte[(int) getLength()]; read(0, b); return b; }
/** * Reads all RRD bytes from the underlying storage * * @return RRD bytes * @throws IOException Thrown in case of I/O error */ public final byte[] readAll() throws IOException { byte[] b = new byte[(int) getLength()]; read(0, b); return b; }
protected final void writeString(long offset, String value) throws IOException { if (nextBigStringOffset < 0) { nextBigStringOffset = getLength() - (Short.SIZE / 8); } value = value.trim(); // Over-sized string are appended at the end of the RRD // The real position is encoded in the "short" ds name, using the private use area from Unicode // This area span the range E000-F8FF, that' a 6400 char area, if (value.length() > RrdPrimitive.STRING_LENGTH) { String bigString = value; int byteStringLength = Math.min(MAXUNSIGNEDSHORT, bigString.length()); long bigStringOffset = nextBigStringOffset; nextBigStringOffset -= byteStringLength * 2 + (Short.SIZE / 8); writeShort(bigStringOffset, (short)byteStringLength); writeString(bigStringOffset - bigString.length() * 2, bigString, byteStringLength); // Now we generate the new string that encode the position long reminder = bigStringOffset; StringBuilder newValue = new StringBuilder(value.substring(0, RrdPrimitive.STRING_LENGTH)); int i = RrdPrimitive.STRING_LENGTH; // Read in inverse order, so write in inverse order while (reminder > 0) { // Only the first char is kept, as it will never byte a multi-char code point newValue.setCharAt(--i, Character.toChars((int)(reminder % PRIVATEAREASIZE + STARTPRIVATEAREACODEPOINT))[0]); reminder = (long) Math.floor( ((float)reminder) / (float)PRIVATEAREASIZE); } value = newValue.toString(); } writeString(offset, value, RrdPrimitive.STRING_LENGTH); }
void setFile(File newFile) { try { values = null; String path = newFile.getAbsolutePath(); RrdDb rrd = new RrdDb(path, true); try { Header header = rrd.getHeader(); String signature = header.getSignature(); String step = "" + header.getStep(); String lastTimestamp = header.getLastUpdateTime() + " [" + new Date(header.getLastUpdateTime() * 1000L) + "]"; String datasources = "" + header.getDsCount(); String archives = "" + header.getArcCount(); String size = rrd.getRrdBackend().getLength() + " bytes"; values = new Object[]{ path, signature, step, lastTimestamp, datasources, archives, size }; } finally { rrd.close(); } fireTableDataChanged(); } catch (Exception e) { Util.error(null, e); } } }