fix issue 200
git-svn-id: https://osmand.googlecode.com/svn/trunk@775 e29c36b1-1cfa-d876-8d93-3434fc2bb7b8
This commit is contained in:
parent
ab9aefe03c
commit
99e3111af0
1 changed files with 87 additions and 30 deletions
|
@ -109,6 +109,7 @@ public class BinaryInspector {
|
||||||
int c = 0;
|
int c = 0;
|
||||||
Set<String> addressNames = new LinkedHashSet<String>();
|
Set<String> addressNames = new LinkedHashSet<String>();
|
||||||
|
|
||||||
|
|
||||||
int version = -1;
|
int version = -1;
|
||||||
// Go through all files and validate conistency
|
// Go through all files and validate conistency
|
||||||
for(File f : partsToExtractFrom.keySet()){
|
for(File f : partsToExtractFrom.keySet()){
|
||||||
|
@ -131,6 +132,16 @@ public class BinaryInspector {
|
||||||
LinkedHashSet<Float> temp = new LinkedHashSet<Float>();
|
LinkedHashSet<Float> temp = new LinkedHashSet<Float>();
|
||||||
String pattern = partsToExtractFrom.get(f);
|
String pattern = partsToExtractFrom.get(f);
|
||||||
boolean minus = true;
|
boolean minus = true;
|
||||||
|
for (int i = 0; i < indexes[c].getIndexes().size(); i++) {
|
||||||
|
partsSet[c].add(i + 1f);
|
||||||
|
BinaryIndexPart part = indexes[c].getIndexes().get(i);
|
||||||
|
if(part instanceof MapIndex){
|
||||||
|
List<MapRoot> roots = ((MapIndex) part).getRoots();
|
||||||
|
for(int j=0; j<roots.size(); j++){
|
||||||
|
partsSet[c].add((i+1f)+(j+1)/10f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
if(pattern != null){
|
if(pattern != null){
|
||||||
minus = pattern.startsWith("-");
|
minus = pattern.startsWith("-");
|
||||||
String[] split = pattern.substring(1).split(",");
|
String[] split = pattern.substring(1).split(",");
|
||||||
|
@ -139,9 +150,7 @@ public class BinaryInspector {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < indexes[c].getIndexes().size(); i++) {
|
|
||||||
partsSet[c].add(i + 1f);
|
|
||||||
}
|
|
||||||
if(minus){
|
if(minus){
|
||||||
partsSet[c].removeAll(temp);
|
partsSet[c].removeAll(temp);
|
||||||
} else {
|
} else {
|
||||||
|
@ -172,38 +181,68 @@ public class BinaryInspector {
|
||||||
|
|
||||||
BinaryIndexPart part = index.getIndexes().get(i);
|
BinaryIndexPart part = index.getIndexes().get(i);
|
||||||
String map;
|
String map;
|
||||||
if (part instanceof AddressRegion) {
|
if (part instanceof MapIndex) {
|
||||||
ous.writeTag(OsmandOdb.OsmAndStructure.ADDRESSINDEX_FIELD_NUMBER, WireFormat.WIRETYPE_FIXED32_LENGTH_DELIMITED);
|
|
||||||
map = "Address";
|
|
||||||
if (addressNames.contains(part.getName())) {
|
|
||||||
System.err.println("Error : going to merge 2 addresses with same names. Skip " + part.getName());
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
addressNames.add(part.getName());
|
|
||||||
} else if (part instanceof TransportIndex) {
|
|
||||||
ous.writeTag(OsmandOdb.OsmAndStructure.TRANSPORTINDEX_FIELD_NUMBER, WireFormat.WIRETYPE_FIXED32_LENGTH_DELIMITED);
|
|
||||||
map = "Transport";
|
|
||||||
} else if (part instanceof MapIndex) {
|
|
||||||
ous.writeTag(OsmandOdb.OsmAndStructure.MAPINDEX_FIELD_NUMBER, WireFormat.WIRETYPE_FIXED32_LENGTH_DELIMITED);
|
ous.writeTag(OsmandOdb.OsmAndStructure.MAPINDEX_FIELD_NUMBER, WireFormat.WIRETYPE_FIXED32_LENGTH_DELIMITED);
|
||||||
map = "Map";
|
map = "Map";
|
||||||
|
List<MapRoot> roots = ((MapIndex) part).getRoots();
|
||||||
|
List<MapRoot> toSkip = new ArrayList<MapRoot>();
|
||||||
|
int newL = 0;
|
||||||
|
int tagAndFieldSize = CodedOutputStream.computeTagSize(OsmandOdb.OsmAndMapIndex.LEVELS_FIELD_NUMBER) + 4;
|
||||||
|
for(int j=0; j<roots.size(); j++){
|
||||||
|
if (!partSet.contains(i + 1f + (j+1)*0.1f)) {
|
||||||
|
newL -= (roots.get(j).getLength() + tagAndFieldSize);
|
||||||
|
toSkip.add(roots.get(j));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
writeInt(ous, part.getLength() + newL);
|
||||||
|
long seek = part.getFilePointer();
|
||||||
|
while(seek < (part.getFilePointer()+ part.getLength())){
|
||||||
|
MapRoot next = null;
|
||||||
|
for(MapRoot r : toSkip){
|
||||||
|
if(seek < r.getFilePointer()) {
|
||||||
|
if(next == null || next.getFilePointer() > r.getFilePointer()){
|
||||||
|
next = r;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
if(next == null){
|
||||||
|
copyBinaryPart(ous, BUFFER_TO_READ, raf, seek, (int) (part.getLength() - (seek - part.getFilePointer())));
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
int l = (int) (next.getFilePointer() - seek - tagAndFieldSize);
|
||||||
|
if(l > 0){
|
||||||
|
copyBinaryPart(ous, BUFFER_TO_READ, raf, seek, l);
|
||||||
|
}
|
||||||
|
seek += next.getLength() + tagAndFieldSize + l;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println(MessageFormat.format("{2} part {0} is extracted {1} bytes", part.getName(), part.getLength() + newL, map));
|
||||||
} else {
|
} else {
|
||||||
throw new UnsupportedOperationException();
|
if (part instanceof AddressRegion) {
|
||||||
}
|
ous.writeTag(OsmandOdb.OsmAndStructure.ADDRESSINDEX_FIELD_NUMBER, WireFormat.WIRETYPE_FIXED32_LENGTH_DELIMITED);
|
||||||
writeInt(ous, part.getLength());
|
map = "Address";
|
||||||
raf.seek(part.getFilePointer());
|
if (addressNames.contains(part.getName())) {
|
||||||
int toRead = part.getLength();
|
System.err.println("Error : going to merge 2 addresses with same names. Skip " + part.getName());
|
||||||
while (toRead > 0) {
|
continue;
|
||||||
int read = raf.read(BUFFER_TO_READ);
|
}
|
||||||
if (read == -1) {
|
addressNames.add(part.getName());
|
||||||
throw new IllegalArgumentException("Unexpected end of file");
|
} else if (part instanceof TransportIndex) {
|
||||||
|
ous.writeTag(OsmandOdb.OsmAndStructure.TRANSPORTINDEX_FIELD_NUMBER, WireFormat.WIRETYPE_FIXED32_LENGTH_DELIMITED);
|
||||||
|
map = "Transport";
|
||||||
|
} else {
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
if (toRead < read) {
|
writeInt(ous, part.getLength());
|
||||||
read = toRead;
|
copyBinaryPart(ous, BUFFER_TO_READ, raf, part.getFilePointer(), part.getLength());
|
||||||
}
|
System.out.println(MessageFormat.format("{2} part {0} is extracted {1} bytes", part.getName(), part.getLength(), map));
|
||||||
ous.writeRawBytes(BUFFER_TO_READ, 0, read);
|
|
||||||
toRead -= read;
|
|
||||||
}
|
}
|
||||||
System.out.println(MessageFormat.format("{2} part {0} is extracted {1} bytes", part.getName(), part.getLength(), map));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -214,6 +253,24 @@ public class BinaryInspector {
|
||||||
|
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private static void copyBinaryPart(CodedOutputStream ous, byte[] BUFFER, RandomAccessFile raf, long fp, int length)
|
||||||
|
throws IOException {
|
||||||
|
raf.seek(fp);
|
||||||
|
int toRead = length;
|
||||||
|
while (toRead > 0) {
|
||||||
|
int read = raf.read(BUFFER);
|
||||||
|
if (read == -1) {
|
||||||
|
throw new IllegalArgumentException("Unexpected end of file");
|
||||||
|
}
|
||||||
|
if (toRead < read) {
|
||||||
|
read = toRead;
|
||||||
|
}
|
||||||
|
ous.writeRawBytes(BUFFER, 0, read);
|
||||||
|
toRead -= read;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
protected static String formatBounds(int left, int right, int top, int bottom){
|
protected static String formatBounds(int left, int right, int top, int bottom){
|
||||||
|
|
Loading…
Reference in a new issue