Debian Codegraph @

src/uk/me/parabola/tdbfmt/HeaderBlock.java

raw symbols SCIP
1 /*
2 * Copyright (C) 2007 Steve Ratcliffe
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 *
14 * Author: Steve Ratcliffe
15 * Create date: 23-Sep-2007
16 */
17 package uk.me.parabola.tdbfmt;
18
19 import java.io.IOException;
20
21 import uk.me.parabola.io.FileBlock;
22 import uk.me.parabola.io.StructuredInputStream;
23 import uk.me.parabola.io.StructuredOutputStream;
24
25 /**
26 * The header block. Identifies the particular map set.
27 *
28 * @author Steve Ratcliffe
29 */
30 class HeaderBlock extends FileBlock {
31 static final int BLOCK_ID = 0x50;
32
33 /** The map family. */
34 private short familyId;
35
36 /** A unique number associated with the map product */
37 private short productId;
38
39 /** The version of TDB */
40 private final int tdbVersion;
41
42 /** The series name is an overall name eg 'US Topo' */
43 private String seriesName;
44
45 /** The version number of the map product */
46 private short productVersion;
47
48 /**
49 * Identifies a map within the series
50 * @see #seriesName
51 */
52 private String familyName;
53
54 private byte enableProfile;
55
56 private int codePage;
57
58 HeaderBlock(int tdbVersion) {
59 super(BLOCK_ID);
60 this.tdbVersion = tdbVersion;
61 }
62
63 public HeaderBlock(StructuredInputStream ds) throws IOException {
64 super(BLOCK_ID);
65
66 productId = (short) ds.read2();
67 familyId = (short) ds.read2();
68
69 tdbVersion = ds.read2();
70 seriesName = ds.readString();
71 productVersion = (short) ds.read2();
72 familyName = ds.readString();
73 }
74
75 /**
76 * This is to overridden in a subclass.
77 */
78 protected void writeBody(StructuredOutputStream os) throws IOException {
79 os.write2(productId);
80 os.write2(familyId);
81 os.write2(tdbVersion);
82 os.writeString(seriesName);
83 os.write2(productVersion);
84 os.writeString(familyName);
85
86 if (tdbVersion >= TdbFile.TDB_V407) {
87 // Unknown purpose
88
89 os.write(0);
90 os.write(0x12); // lowest map level
91 os.write(1);
92 os.write(1);
93 os.write(1);
94 os.write4(0);
95 os.write(0);
96 os.write(0x18); // highest routable? 19 no, 21 ok
97 os.write4(0);
98 os.write4(0);
99 os.write4(0);
100 os.write4(0);
101 os.write3(0);
102 os.write4(codePage);
103 os.write4(10000);
104 os.write(1); // map is routable
105 if (enableProfile == 1)
106 os.write(1); // map has profile information
107 else
108 os.write(0);
109 os.write(0);
110 }
111 }
112
113 public String toString() {
114 return "TDB header: "
115 + productId
116 + " version="
117 + tdbVersion
118 + ", series:"
119 + seriesName
120 + ", family:"
121 + familyName
122 + ", ver="
123 + productVersion
124 ;
125 }
126
127 public void setProductId(short productId) {
128 this.productId = productId;
129 }
130
131 public void setSeriesName(String seriesName) {
132 this.seriesName = seriesName;
133 }
134
135 public void setFamilyName(String familyName) {
136 this.familyName = familyName;
137 }
138
139 public void setProductVersion(short productVersion) {
140 this.productVersion = productVersion;
141 }
142
143 public void setFamilyId(short familyId) {
144 this.familyId = familyId;
145 }
146
147 void setCodePage(int codePage) {
148 this.codePage = codePage;
149 }
150
151 public int getTdbVersion() {
152 return tdbVersion;
153 }
154
155 public void setEnableProfile(byte enableProfile) {
156 this.enableProfile = enableProfile;
157 }
158 }