1 | /*
|
---|
2 | * GeoTools - The Open Source Java GIS Toolkit
|
---|
3 | * http://geotools.org
|
---|
4 | *
|
---|
5 | * (C) 2004-2008, Open Source Geospatial Foundation (OSGeo)
|
---|
6 | *
|
---|
7 | * This library is free software; you can redistribute it and/or
|
---|
8 | * modify it under the terms of the GNU Lesser General Public
|
---|
9 | * License as published by the Free Software Foundation;
|
---|
10 | * version 2.1 of the License.
|
---|
11 | *
|
---|
12 | * This library is distributed in the hope that it will be useful,
|
---|
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
15 | * Lesser General Public License for more details.
|
---|
16 | */
|
---|
17 | package org.geotools.index.quadtree.fs;
|
---|
18 |
|
---|
19 | import java.io.IOException;
|
---|
20 | import java.nio.ByteBuffer;
|
---|
21 | import java.nio.channels.ReadableByteChannel;
|
---|
22 | import java.util.logging.Logger;
|
---|
23 |
|
---|
24 | import org.geotools.index.quadtree.StoreException;
|
---|
25 |
|
---|
26 | /**
|
---|
27 | * DOCUMENT ME!
|
---|
28 | *
|
---|
29 | * @author Tommaso Nolli
|
---|
30 | *
|
---|
31 | * @source $URL: http://svn.osgeo.org/geotools/branches/2.7.x/modules/plugin/shapefile/src/main/java/org/geotools/index/quadtree/fs/IndexHeader.java $
|
---|
32 | */
|
---|
33 | public class IndexHeader {
|
---|
34 | public static final byte LSB_ORDER = -1;
|
---|
35 | public static final byte MSB_ORDER = -2;
|
---|
36 | public static final byte NATIVE_ORDER = 0;
|
---|
37 | public static final byte NEW_LSB_ORDER = 1;
|
---|
38 | public static final byte NEW_MSB_ORDER = 2;
|
---|
39 | private static final String SIGNATURE = "SQT";
|
---|
40 | private static final Logger LOGGER = org.geotools.util.logging.Logging
|
---|
41 | .getLogger("org.geotools.index.quadtree");
|
---|
42 | private byte byteOrder;
|
---|
43 |
|
---|
44 | /**
|
---|
45 | * DOCUMENT ME!
|
---|
46 | *
|
---|
47 | * @param channel
|
---|
48 | *
|
---|
49 | * @throws IOException
|
---|
50 | * @throws StoreException
|
---|
51 | */
|
---|
52 | public IndexHeader(ReadableByteChannel channel) throws IOException,
|
---|
53 | StoreException {
|
---|
54 | ByteBuffer buf = ByteBuffer.allocate(8);
|
---|
55 |
|
---|
56 | channel.read(buf);
|
---|
57 | buf.flip();
|
---|
58 |
|
---|
59 | byte[] tmp = new byte[3];
|
---|
60 | buf.get(tmp);
|
---|
61 |
|
---|
62 | String s = new String(tmp, "US-ASCII");
|
---|
63 |
|
---|
64 | if (!s.equals(SIGNATURE)) {
|
---|
65 | // Old file format
|
---|
66 | LOGGER.warning("Old qix file format; this file format "
|
---|
67 | + "is deprecated; It is strongly recommended "
|
---|
68 | + "to regenerate it in new format.");
|
---|
69 |
|
---|
70 | buf.position(0);
|
---|
71 | tmp = buf.array();
|
---|
72 |
|
---|
73 | boolean lsb;
|
---|
74 |
|
---|
75 | if ((tmp[4] == 0) && (tmp[5] == 0) && (tmp[6] == 0)
|
---|
76 | && (tmp[7] == 0)) {
|
---|
77 | lsb = !((tmp[0] == 0) && (tmp[1] == 0));
|
---|
78 | } else {
|
---|
79 | lsb = !((tmp[4] == 0) && (tmp[5] == 0));
|
---|
80 | }
|
---|
81 |
|
---|
82 | this.byteOrder = lsb ? LSB_ORDER : MSB_ORDER;
|
---|
83 | } else {
|
---|
84 | this.byteOrder = buf.get();
|
---|
85 | }
|
---|
86 | }
|
---|
87 |
|
---|
88 | /**
|
---|
89 | * DOCUMENT ME!
|
---|
90 | *
|
---|
91 | * @return Returns the byteOrder.
|
---|
92 | */
|
---|
93 | public byte getByteOrder() {
|
---|
94 | return this.byteOrder;
|
---|
95 | }
|
---|
96 | }
|
---|