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: Header.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 header section of an RRD file.
015 *
016 * @author <a href="mailto:ciaran@codeloop.com">Ciaran Treanor</a>
017 * @version $Revision: 1.2 $
018 */
019 public class Header implements Constants {
020
021 static final long offset = 0;
022 long size;
023 String version;
024 int dsCount;
025 int rraCount;
026 int pdpStep;
027
028 Header(RRDFile file) throws IOException {
029
030 if (!file.readString(4).equals(COOKIE)) {
031 throw new IOException("Invalid COOKIE");
032 }
033
034 if (!(version = file.readString(5)).equals(VERSION)) {
035 throw new IOException("Unsupported RRD version (" + version + ")");
036 }
037
038 file.align();
039
040 // Consume the FLOAT_COOKIE
041 file.readDouble();
042
043 dsCount = file.readInt();
044 rraCount = file.readInt();
045 pdpStep = file.readInt();
046
047 // Skip rest of stat_head_t.par
048 file.align();
049 file.skipBytes(80);
050
051 size = file.getFilePointer() - offset;
052 }
053
054 /**
055 * Returns the version of the database.
056 *
057 * @return the version of the database.
058 */
059 public String getVersion() {
060 return version;
061 }
062
063 /**
064 * Returns the number of <code>DataSource</code>s in the database.
065 *
066 * @return the number of <code>DataSource</code>s in the database.
067 */
068 public int getDSCount() {
069 return dsCount;
070 }
071
072 /**
073 * Returns the number of <code>Archive</code>s in the database.
074 *
075 * @return the number of <code>Archive</code>s in the database.
076 */
077 public int getRRACount() {
078 return rraCount;
079 }
080
081 /**
082 * Returns the primary data point interval in seconds.
083 *
084 * @return the primary data point interval in seconds.
085 */
086 public int getPDPStep() {
087 return pdpStep;
088 }
089
090 /**
091 * Returns a summary the contents of this header.
092 *
093 * @return a summary of the information contained in this header.
094 */
095 public String toString() {
096
097 StringBuffer sb = new StringBuffer("[Header: OFFSET=0x00, SIZE=0x");
098
099 sb.append(Long.toHexString(size));
100 sb.append(", version=");
101 sb.append(version);
102 sb.append(", dsCount=");
103 sb.append(dsCount);
104 sb.append(", rraCount=");
105 sb.append(rraCount);
106 sb.append(", pdpStep=");
107 sb.append(pdpStep);
108 sb.append("]");
109
110 return sb.toString();
111 }
112 }