KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jrobin > core > jrrd > Header


1 /*
2  * Copyright (C) 2001 Ciaran Treanor <ciaran@codeloop.com>
3  *
4  * Distributable under GPL license.
5  * See terms of license at gnu.org.
6  *
7  * $Id: Header.java,v 1.1 2004/07/22 09:34:10 saxon64 Exp $
8  */

9 package org.jrobin.core.jrrd;
10
11 import java.io.*;
12
13 /**
14  * Instances of this class model the header section of an RRD file.
15  *
16  * @author <a HREF="mailto:ciaran@codeloop.com">Ciaran Treanor</a>
17  * @version $Revision: 1.1 $
18  */

19 public class Header implements Constants {
20
21     static final long offset = 0;
22     long size;
23     String JavaDoc version;
24     int dsCount;
25     int rraCount;
26     int pdpStep;
27
28     Header(RRDFile file) throws IOException {
29
30         if (!file.readString(4).equals(COOKIE)) {
31             throw new IOException("Invalid COOKIE");
32         }
33
34         if (!(version = file.readString(5)).equals(VERSION)) {
35             throw new IOException("Unsupported RRD version (" + version + ")");
36         }
37
38         file.align();
39
40         // Consume the FLOAT_COOKIE
41
file.readDouble();
42
43         dsCount = file.readInt();
44         rraCount = file.readInt();
45         pdpStep = file.readInt();
46
47         // Skip rest of stat_head_t.par
48
file.align();
49         file.skipBytes(80);
50
51         size = file.getFilePointer() - offset;
52     }
53
54     /**
55      * Returns the version of the database.
56      *
57      * @return the version of the database.
58      */

59     public String JavaDoc getVersion() {
60         return version;
61     }
62
63     /**
64      * Returns the number of <code>DataSource</code>s in the database.
65      *
66      * @return the number of <code>DataSource</code>s in the database.
67      */

68     public int getDSCount() {
69         return dsCount;
70     }
71
72     /**
73      * Returns the number of <code>Archive</code>s in the database.
74      *
75      * @return the number of <code>Archive</code>s in the database.
76      */

77     public int getRRACount() {
78         return rraCount;
79     }
80
81     /**
82      * Returns the primary data point interval in seconds.
83      *
84      * @return the primary data point interval in seconds.
85      */

86     public int getPDPStep() {
87         return pdpStep;
88     }
89
90     /**
91      * Returns a summary the contents of this header.
92      *
93      * @return a summary of the information contained in this header.
94      */

95     public String JavaDoc toString() {
96
97         StringBuffer JavaDoc sb = new StringBuffer JavaDoc("[Header: OFFSET=0x00, SIZE=0x");
98
99         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 }
113
Popular Tags