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: CDPStatusBlock.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    import java.io.PrintStream;
013    
014    /**
015     * Instances of this class model the consolidation data point status from an RRD file.
016     *
017     * @author <a href="mailto:ciaran@codeloop.com">Ciaran Treanor</a>
018     * @version $Revision: 1.2 $
019     */
020    public class CDPStatusBlock {
021    
022            long offset;
023            long size;
024            int unknownDatapoints;
025            double value;
026    
027            CDPStatusBlock(RRDFile file) throws IOException {
028    
029                    offset = file.getFilePointer();
030                    value = file.readDouble();
031                    unknownDatapoints = file.readInt();
032    
033                    // Skip rest of cdp_prep_t.scratch
034                    file.skipBytes(68);
035    
036                    size = file.getFilePointer() - offset;
037            }
038    
039            /**
040             * Returns the number of unknown primary data points that were integrated.
041             *
042             * @return the number of unknown primary data points that were integrated.
043             */
044            public int getUnknownDatapoints() {
045                    return unknownDatapoints;
046            }
047    
048            /**
049             * Returns the value of this consolidated data point.
050             *
051             * @return the value of this consolidated data point.
052             */
053            public double getValue() {
054                    return value;
055            }
056    
057            void toXml(PrintStream s) {
058    
059                    s.print("\t\t\t<ds><value> ");
060                    s.print(value);
061                    s.print(" </value>  <unknown_datapoints> ");
062                    s.print(unknownDatapoints);
063                    s.println(" </unknown_datapoints></ds>");
064            }
065    
066            /**
067             * Returns a summary the contents of this CDP status block.
068             *
069             * @return a summary of the information contained in the CDP status block.
070             */
071            public String toString() {
072    
073                    StringBuffer sb = new StringBuffer("[CDPStatusBlock: OFFSET=0x");
074    
075                    sb.append(Long.toHexString(offset));
076                    sb.append(", SIZE=0x");
077                    sb.append(Long.toHexString(size));
078                    sb.append(", unknownDatapoints=");
079                    sb.append(unknownDatapoints);
080                    sb.append(", value=");
081                    sb.append(value);
082                    sb.append("]");
083    
084                    return sb.toString();
085            }
086    }