~ubuntu-branches/ubuntu/oneiric/mkgmap/oneiric

« back to all changes in this revision

Viewing changes to src/uk/me/parabola/imgfmt/app/lbl/LBLFile.java

  • Committer: Bazaar Package Importer
  • Author(s): Francesco Paolo Lovergine, Andreas Putzo, Francesco Paolo Lovergine
  • Date: 2009-07-16 11:10:16 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20090716111016-yycxqya1f26xmti7
Tags: 0.0.0+svn1067-1
[ Andreas Putzo ]
* New upstream snapshot.
* Added ${misc:Depends} among dependencies to fix a lintian warning.
* Bumped debhelper compatibility level to 7.
* Updated long description.
* Updated Homepage in debian/control, debian/copyright, debian/watch.
* Added numerous files from /doc to debian/docs.
* Mentioned Bernhard Heibler in debian/copyright and updated copyright
  year of software and packaging.
* Bumped policy to 3.8.2, without changes.
* Added DM-Upload-Allowed to debian/control.

[ Francesco Paolo Lovergine ]
* Added me as Uploader to avoid possible inappropriate NMU notices.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 */
17
17
package uk.me.parabola.imgfmt.app.lbl;
18
18
 
 
19
import java.util.HashMap;
 
20
import java.util.Map;
 
21
 
19
22
import uk.me.parabola.imgfmt.Utils;
20
 
import uk.me.parabola.imgfmt.app.BufferedReadStrategy;
21
 
import uk.me.parabola.imgfmt.app.BufferedWriteStrategy;
 
23
import uk.me.parabola.imgfmt.app.BufferedImgFileReader;
 
24
import uk.me.parabola.imgfmt.app.BufferedImgFileWriter;
22
25
import uk.me.parabola.imgfmt.app.ImgFile;
 
26
import uk.me.parabola.imgfmt.app.ImgFileReader;
23
27
import uk.me.parabola.imgfmt.app.Label;
24
 
import uk.me.parabola.imgfmt.app.ReadStrategy;
25
28
import uk.me.parabola.imgfmt.app.labelenc.BaseEncoder;
26
29
import uk.me.parabola.imgfmt.app.labelenc.CharacterDecoder;
27
30
import uk.me.parabola.imgfmt.app.labelenc.CharacterEncoder;
28
31
import uk.me.parabola.imgfmt.app.labelenc.CodeFunctions;
29
32
import uk.me.parabola.imgfmt.app.labelenc.EncodedText;
 
33
import uk.me.parabola.imgfmt.app.trergn.Subdivision;
30
34
import uk.me.parabola.imgfmt.fs.ImgChannel;
31
35
import uk.me.parabola.log.Logger;
32
 
 
33
 
import java.io.IOException;
34
 
import java.util.HashMap;
35
 
import java.util.Map;
 
36
import uk.me.parabola.imgfmt.app.Exit;
36
37
 
37
38
/**
38
39
 * The file that holds all the labels for the map.
64
65
                setHeader(lblHeader);
65
66
 
66
67
                if (write) {
67
 
                        setWriter(new BufferedWriteStrategy(chan));
 
68
                        setWriter(new BufferedImgFileWriter(chan));
68
69
 
69
70
                        position(LBLHeader.HEADER_LEN + LBLHeader.INFO_LEN);
70
71
 
71
72
                        // The zero offset is for no label.
72
73
                        getWriter().put((byte) 0);
73
74
                } else {
74
 
                        setReader(new BufferedReadStrategy(chan));
 
75
                        setReader(new BufferedImgFileReader(chan));
75
76
                        lblHeader.readHeader(getReader());
76
77
                        CodeFunctions funcs = CodeFunctions.createEncoderForLBL(
77
78
                                        lblHeader.getEncodingType());
82
83
                places.init(this, lblHeader.getPlaceHeader());
83
84
        }
84
85
 
85
 
        public void sync() throws IOException {
86
 
                log.debug("syncing lbl file");
87
 
 
 
86
        public void write() {
88
87
                writeBody();
 
88
        }
89
89
 
 
90
        public void writePost() {
90
91
                // Now that the body is written all the required offsets will be set up
91
92
                // inside the header, so we can go back and write it.
92
93
                getHeader().writeHeader(getWriter());
93
94
 
 
95
                // Text can be put between the header and the body of the file.
94
96
                getWriter().put(Utils.toBytes("mkgmap"));
95
 
                
96
 
                // Sync our writer.
97
 
                getWriter().sync();
98
97
        }
99
98
 
100
99
        private void writeBody() {
115
114
                        baseEncoder.setUpperCase(true);
116
115
                }
117
116
                textDecoder = cfuncs.getDecoder();
 
117
                if (lblHeader.getCodePage() == 0)
 
118
                        setCodePage(cfuncs.getCodepage());
118
119
        }
119
120
        
120
121
        /**
125
126
         * @return A reference to the created label.
126
127
         */
127
128
        public Label newLabel(String text) {
128
 
                Label l;
129
129
                EncodedText etext = textEncoder.encodeText(text);
130
 
                l = labelCache.get(text);
 
130
                Label l = labelCache.get(text);
131
131
                if (l == null) {
132
132
                        l = new Label(etext);
133
133
                        labelCache.put(text, l);
143
143
                return places.createPOI(name);
144
144
        }
145
145
 
 
146
        public POIRecord createExitPOI(String name, Exit exit) {
 
147
                return places.createExitPOI(name, exit);
 
148
        }
 
149
 
 
150
        public POIIndex createPOIIndex(String name, int poiIndex, Subdivision group, int type) {
 
151
                return places.createPOIIndex(name, poiIndex, group, type);
 
152
        }
 
153
        
 
154
        public Country createCountry(String name, String abbr) {
 
155
                return places.createCountry(name, abbr);
 
156
        }
 
157
        
 
158
        public Region createRegion(Country country, String region, String abbr) {
 
159
            return places.createRegion(country, region, abbr);
 
160
        }
 
161
        
 
162
        public City createCity(Region region, String city, boolean unique) {
 
163
                return places.createCity(region, city, unique);
 
164
        }
 
165
 
 
166
        public City createCity(Country country, String city, boolean unique) {
 
167
                return places.createCity(country, city, unique);
 
168
        }
 
169
 
 
170
        public Zip createZip(String code) {
 
171
                return places.createZip(code);
 
172
        }
 
173
 
 
174
        public Highway createHighway(Region region, String name) {
 
175
                return places.createHighway(region, name);
 
176
        }
 
177
 
 
178
        public ExitFacility createExitFacility(int type, char direction, int facilities, String description, boolean last) {
 
179
                return places.createExitFacility(type, direction, facilities, description, last);
 
180
        }
 
181
 
146
182
        public void allPOIsDone() {
147
183
                places.allPOIsDone();
148
184
        }
165
201
                if (offset == 0)
166
202
                        return "";  // or null ???
167
203
 
168
 
                ReadStrategy reader = getReader();
 
204
                ImgFileReader reader = getReader();
169
205
                reader.position(lblHeader.getLabelStart() + offset);
170
206
 
171
207
                byte b;
177
213
                return new String(text.getCtext(), 0, text.getLength());
178
214
        }
179
215
 
 
216
        public PlacesHeader getPlaceHeader() {
 
217
                return lblHeader.getPlaceHeader();
 
218
        }
 
219
 
 
220
        public int numCities() {
 
221
                return places.numCities();
 
222
        }
 
223
 
 
224
        public int numZips() {
 
225
                return places.numZips();
 
226
        }
 
227
 
 
228
        public int numHighways() {
 
229
                return places.numHighways();
 
230
        }
 
231
 
 
232
        public int numExitFacilities() {
 
233
                return places.numExitFacilities();
 
234
        }
180
235
}