Debian Codegraph @

src/uk/me/parabola/imgfmt/mps/MpsFile.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: Dec 19, 2007
16 */
17 package uk.me.parabola.imgfmt.mps;
18
19 import java.io.IOException;
20 import java.util.ArrayList;
21 import java.util.HashSet;
22 import java.util.List;
23 import java.util.Set;
24
25 import uk.me.parabola.imgfmt.app.BufferedImgFileWriter;
26 import uk.me.parabola.imgfmt.app.ImgFileWriter;
27 import uk.me.parabola.imgfmt.fs.ImgChannel;
28 import uk.me.parabola.imgfmt.sys.FileNode;
29
30 /**
31 * This file is a description of the map set that is loaded into the
32 * gmapsupp.img file and an index of the maps that it contains.
33 *
34 * It is different than all the other files that fit inside the gmapsupp file
35 * in that it doesn't contain the common header. So it does not extend ImgFile.
36 *
37 * @author Steve Ratcliffe
38 */
39 public class MpsFile {
40 private String mapsetName = "OSM map set";
41
42 private final Set<ProductBlock> products = new HashSet<>();
43 private final List<MapBlock> maps = new ArrayList<>();
44
45 private final ImgFileWriter writer;
46
47 public MpsFile(ImgChannel chan) {
48 assert chan instanceof FileNode;
49 writer = new BufferedImgFileWriter(chan, "MPS");
50 }
51
52 public void sync() throws IOException {
53 for (MapBlock map : maps)
54 map.writeTo(writer, map.getCodePage());
55
56 for (ProductBlock block : products)
57 block.writeTo(writer, block.getCodePage());
58
59 MapsetBlock mapset = new MapsetBlock();
60 mapset.setName(mapsetName);
61 mapset.writeTo(writer, mapset.getCodePage());
62 }
63
64 public void addMap(MapBlock map) {
65 maps.add(map);
66 }
67
68 public void addProduct(ProductBlock pb) {
69 products.add(pb);
70 }
71
72 public void setMapsetName(String mapsetName) {
73 this.mapsetName = mapsetName;
74 }
75 }