Debian Codegraph @

src/uk/me/parabola/tdbfmt/DetailMapBlock.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 import java.util.ArrayList;
21 import java.util.List;
22
23 import uk.me.parabola.io.StructuredInputStream;
24 import uk.me.parabola.io.StructuredOutputStream;
25 import uk.me.parabola.mkgmap.combiners.SubFileInfo;
26
27 /**
28 * Details of a single .img file that is part of the map set. There will be
29 * one of these for each .img file.
30 *
31 * @author Steve Ratcliffe
32 */
33 public class DetailMapBlock extends OverviewMapBlock {
34 public static final int BLOCK_ID = 0x4c;
35
36 private int tdbVersion;
37
38 // Sizes of the regions.
39 private List<SubFileInfo> subFiles;
40
41 public DetailMapBlock(int tdbVersion) {
42 super(BLOCK_ID);
43
44 this.tdbVersion = tdbVersion;
45 }
46
47 /**
48 * Initialise this block from the raw block given.
49 *
50 * @throws IOException For io problems.
51 */
52 public DetailMapBlock(StructuredInputStream ds) throws IOException {
53 super(ds);
54
55 ds.read2(); // expected value : n + 1
56 int n = ds.read2();
57
58 // Sizes of the data
59 int[] sizes = new int[n];
60 for (int i = 0; i < n; i++) {
61 sizes[i] = ds.read4();
62 }
63
64 // some more ignored fields
65 ds.read();
66 ds.read();
67 ds.read();
68 ds.read4();
69
70 subFiles = new ArrayList<>();
71 for (int i = 0; i < n; i++) {
72 String name = ds.readString();
73 SubFileInfo si = new SubFileInfo(name, sizes[i]);
74 subFiles.add(si);
75 }
76 }
77
78 /**
79 * Write into the given block.
80 *
81 * @throws IOException Problems writing, probably can't really happen as
82 * we use an array backed stream.
83 */
84 public void writeBody(StructuredOutputStream os) throws IOException {
85 super.writeBody(os);
86
87 // We do not support writing a version less than v4.07
88 assert tdbVersion >= TdbFile.TDB_V407;
89
90 int n = subFiles.size();
91 os.write2(n+1);
92 os.write2(n);
93
94 for (SubFileInfo si : subFiles) {
95 os.write4((int) si.getSize());
96 }
97
98 //01 c3 00 ff
99 os.write4(0xff00c301);
100 os.write(0);
101 os.write(0);
102 os.write(0);
103
104 for (SubFileInfo si : subFiles) {
105 os.writeString(si.getName());
106 }
107 }
108
109 public void setSubFiles(List<SubFileInfo> subFiles) {
110 this.subFiles = subFiles;
111 }
112 }