001 /*
002 * Copyright (C) 2001 Ciaran Treanor <ciaran@codeloop.com>
003 *
004 * Distributable under GPL license.
005 * See terms of license at gnu.org.
006 *
007 * $Id: PDPStatusBlock.java,v 1.2 2006/12/21 18:02:42 tarus Exp $
008 */
009 package org.jrobin.core.jrrd;
010
011 import java.io.IOException;
012
013 /**
014 * Instances of this class model the primary data point status from an RRD file.
015 *
016 * @author <a href="mailto:ciaran@codeloop.com">Ciaran Treanor</a>
017 * @version $Revision: 1.2 $
018 */
019 public class PDPStatusBlock {
020
021 long offset;
022 long size;
023 String lastReading;
024 int unknownSeconds;
025 double value;
026
027 PDPStatusBlock(RRDFile file) throws IOException {
028
029 offset = file.getFilePointer();
030 lastReading = file.readString(Constants.LAST_DS_LEN);
031
032 file.align(4);
033
034 unknownSeconds = file.readInt();
035
036 file.skipBytes(4);
037
038 value = file.readDouble();
039
040 // Skip rest of pdp_prep_t.par[]
041 file.skipBytes(64);
042
043 size = file.getFilePointer() - offset;
044 }
045
046 /**
047 * Returns the last reading from the data source.
048 *
049 * @return the last reading from the data source.
050 */
051 public String getLastReading() {
052 return lastReading;
053 }
054
055 /**
056 * Returns the current value of the primary data point.
057 *
058 * @return the current value of the primary data point.
059 */
060 public double getValue() {
061 return value;
062 }
063
064 /**
065 * Returns the number of seconds of the current primary data point is
066 * unknown data.
067 *
068 * @return the number of seconds of the current primary data point is unknown data.
069 */
070 public int getUnknownSeconds() {
071 return unknownSeconds;
072 }
073
074 /**
075 * Returns a summary the contents of this PDP status block.
076 *
077 * @return a summary of the information contained in this PDP status block.
078 */
079 public String toString() {
080
081 StringBuffer sb = new StringBuffer("[PDPStatus: OFFSET=0x");
082
083 sb.append(Long.toHexString(offset));
084 sb.append(", SIZE=0x");
085 sb.append(Long.toHexString(size));
086 sb.append(", lastReading=");
087 sb.append(lastReading);
088 sb.append(", unknownSeconds=");
089 sb.append(unknownSeconds);
090 sb.append(", value=");
091 sb.append(value);
092 sb.append("]");
093
094 return sb.toString();
095 }
096 }