Changeset 34842 in osm for applications/editors/josm/plugins/o5m/src
- Timestamp:
- 2019-01-20T06:34:14+01:00 (6 years ago)
- Location:
- applications/editors/josm/plugins/o5m/src/org/openstreetmap/josm/plugins/o5m
- Files:
-
- 1 deleted
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/o5m/src/org/openstreetmap/josm/plugins/o5m/io/O5mImporter.java
r34820 r34842 1 1 // License: GPL. For details, see LICENSE file. 2 2 package org.openstreetmap.josm.plugins.o5m.io; 3 4 import static org.openstreetmap.josm.tools.I18n.tr; 3 5 4 6 import java.io.IOException; 5 7 import java.io.InputStream; 6 8 9 import org.openstreetmap.josm.actions.ExtensionFileFilter; 7 10 import org.openstreetmap.josm.data.osm.DataSet; 8 11 import org.openstreetmap.josm.gui.io.importexport.OsmImporter; … … 11 14 import org.openstreetmap.josm.io.IllegalDataException; 12 15 import org.openstreetmap.josm.io.CachedFile; 13 import org.openstreetmap.josm.plugins.o5m.O5mConstants;14 16 15 17 /** … … 19 21 */ 20 22 public class O5mImporter extends OsmImporter { 21 23 /** 24 * File extension. 25 */ 26 private static final String EXTENSION = "o5m"; 27 22 28 public O5mImporter() { 23 super(O5mConstants.FILE_FILTER); 29 super(new ExtensionFileFilter(EXTENSION, EXTENSION, 30 tr("OSM Server Files o5m compressed") + " (*."+EXTENSION+")")); 24 31 } 25 32 -
applications/editors/josm/plugins/o5m/src/org/openstreetmap/josm/plugins/o5m/io/O5mReader.java
r34835 r34842 21 21 import org.openstreetmap.josm.data.osm.NodeData; 22 22 import org.openstreetmap.josm.data.osm.OsmPrimitiveType; 23 import org.openstreetmap.josm.data.osm.PrimitiveData; 23 24 import org.openstreetmap.josm.data.osm.RelationData; 24 25 import org.openstreetmap.josm.data.osm.RelationMemberData; … … 40 41 */ 41 42 public class O5mReader extends AbstractReader { 42 private IllegalDataException exception = null;43 private IllegalDataException exception; 43 44 private boolean discourageUpload; 44 45 … … 77 78 private static final int MAX_STRING_PAIR_SIZE = 250 + 2; 78 79 private static final String[] REL_REF_TYPES = {"node", "way", "relation", "?"}; 79 private static final double FACTOR = 1d/1 000000000; // used with 100*<Val>*FACTOR80 private static final double FACTOR = 1d/1_000_000_000; // used with 100*<Val>*FACTOR 80 81 81 82 private BufferedInputStream fis; … … 86 87 87 88 private byte[] ioBuf; 88 private int io Pos;89 private int ioBufPos; 89 90 // the o5m string table 90 91 private String[][] stringTable; … … 114 115 this.cnvBuffer = new byte[4000]; // OSM data should not contain string pairs with length > 512 115 116 this.ioBuf = new byte[8192]; 116 this.io Pos = 0;117 this.ioBufPos = 0; 117 118 this.stringPair = new String[2]; 118 119 this.lastRef = new long[3]; … … 166 167 case TIMESTAMP_DATASET: 167 168 case HEADER_DATASET: 168 if (bytesToRead > ioBuf.length) { 169 ioBuf = new byte[bytesToRead+100]; 170 } 171 int bytesRead = 0; 172 int neededBytes = bytesToRead; 173 while (neededBytes > 0) { 174 bytesRead += is.read(ioBuf, bytesRead, neededBytes); 175 neededBytes -= bytesRead; 176 } 177 ioPos = 0; 178 is = new ByteArrayInputStream(ioBuf, 0, bytesToRead); 169 is = fillByteArray(); 179 170 break; 180 171 default: break; … … 196 187 } 197 188 189 private InputStream fillByteArray() throws IOException { 190 if (bytesToRead > ioBuf.length) { 191 ioBuf = new byte[bytesToRead + 100]; 192 } 193 int bytesRead = 0; 194 int neededBytes = bytesToRead; 195 while (neededBytes > 0) { 196 bytesRead += is.read(ioBuf, bytesRead, neededBytes); 197 neededBytes -= bytesRead; 198 } 199 ioBufPos = 0; 200 return new ByteArrayInputStream(ioBuf, 0, bytesToRead); 201 } 202 198 203 /** 199 204 * read (and ignore) the file timestamp data set … … 230 235 } else { 231 236 Logging.error("Invalid Bounds: " + b); 237 } 238 } 239 240 private void setMeta(PrimitiveData pd) throws IllegalDataException { 241 pd.setVersion(version == 0 ? 1 : version); 242 checkChangesetId(lastChangeSet); 243 pd.setChangesetId((int) lastChangeSet); 244 // User id 245 if (lastTs != 0) { 246 checkTimestamp(lastTs); 247 pd.setTimestamp(new Date(lastTs * 1000)); 248 if (osmUser != null) 249 pd.setUser(osmUser); 232 250 } 233 251 } … … 257 275 discourageUpload = true; 258 276 NodeData nd = new NodeData(lastNodeId); 259 nd.setVersion(version == 0 ? 1 : version);260 277 nd.setCoor(new LatLon(flat, flon).getRoundedToOsmPrecision()); 261 262 278 checkCoordinates(nd.getCoor()); 263 checkChangesetId(lastChangeSet); 264 nd.setChangesetId((int) lastChangeSet); 265 // User id 266 if (lastTs != 0) { 267 checkTimestamp(lastTs); 268 nd.setTimestamp(new Date(lastTs * 1000)); 269 if (osmUser != null) 270 nd.setUser(osmUser); 271 } 279 setMeta(nd); 280 272 281 if (bytesToRead > 0) { 273 282 Map<String, String> keys = readTags(); … … 279 288 exception = e; 280 289 } 281 282 290 } 283 291 … … 299 307 discourageUpload = true; 300 308 final WayData wd = new WayData(lastWayId); 301 wd.setVersion(version == 0 ? 1 : version); 302 checkChangesetId(lastChangeSet); 303 wd.setChangesetId((int) lastChangeSet); 304 // User id 305 if (lastTs != 0) { 306 checkTimestamp(lastTs); 307 wd.setTimestamp(new Date(lastTs * 1000)); 308 if (osmUser != null) 309 wd.setUser(osmUser); 310 } 309 setMeta(wd); 311 310 312 311 long refSize = readUnsignedNum32(); … … 345 344 discourageUpload = true; 346 345 final RelationData rel = new RelationData(lastRelId); 347 rel.setVersion(version == 0 ? 1 : version); 348 checkChangesetId(lastChangeSet); 349 rel.setChangesetId((int) lastChangeSet); 350 if (lastTs != 0) { 351 checkTimestamp(lastTs); 352 rel.setTimestamp(new Date(lastTs * 1000)); 353 if (osmUser != null) 354 rel.setUser(osmUser); 355 } 346 setMeta(rel); 356 347 357 348 long refSize = readUnsignedNum32(); … … 447 438 stringPair[0] = ""; 448 439 else { 449 stringPair[0] = Long.to String(uidNum);450 io Pos++; // skip terminating zero from uid440 stringPair[0] = Long.toUnsignedString(uidNum); 441 ioBufPos++; // skip terminating zero from uid 451 442 --bytesToRead; 452 443 } … … 455 446 stringPair[1] = null; 456 447 while (stringPair[1] == null) { 457 final int b = ioBuf[io Pos++];448 final int b = ioBuf[ioBufPos++]; 458 449 --bytesToRead; 459 450 cnvBuffer[buffPos++] = (byte) b; … … 483 474 int stringRef = readUnsignedNum32(); 484 475 if (stringRef == 0) { 485 refType = ioBuf[io Pos++] - 0x30;476 refType = ioBuf[ioBufPos++] - 0x30; 486 477 --bytesToRead; 487 478 … … 494 485 stringPair[1] = null; 495 486 while (stringPair[1] == null) { 496 final int b = ioBuf[io Pos++];487 final int b = ioBuf[ioBufPos++]; 497 488 --bytesToRead; 498 489 cnvBuffer[buffPos++] = (byte) b; … … 528 519 int start = 0; 529 520 while (cnt < 2) { 530 final int b = ioBuf[io Pos++];521 final int b = ioBuf[ioBufPos++]; 531 522 --bytesToRead; 532 523 cnvBuffer[buffPos++] = (byte) b; … … 571 562 */ 572 563 private int readSignedNum32() { 573 int result; 574 int b = ioBuf[ioPos++]; 575 --bytesToRead; 576 result = b; 577 if ((b & 0x80) == 0) { // just one byte 578 if ((b & 0x01) == 1) 579 return -1-(result >> 1); 580 return result >> 1; 581 } 582 int sign = b & 0x01; 583 result = (result & 0x7e) >> 1; 584 int shift = 6; 585 while (((b = ioBuf[ioPos++]) & 0x80) != 0) { // more bytes will follow 586 --bytesToRead; 587 result += (b & 0x7f) << shift; 588 shift += 7; 589 } 590 --bytesToRead; 591 result += b << shift; 592 if (sign == 1) // negative 593 return -1 - result; 594 return result; 595 564 return (int) readSignedNum64(); 596 565 } 597 566 … … 602 571 private long readSignedNum64() { 603 572 long result; 604 int b = ioBuf[io Pos++];573 int b = ioBuf[ioBufPos++]; 605 574 --bytesToRead; 606 575 result = b; … … 613 582 result = (result & 0x7e) >> 1; 614 583 int shift = 6; 615 while (((b = ioBuf[io Pos++]) & 0x80) != 0) { // more bytes will follow584 while (((b = ioBuf[ioBufPos++]) & 0x80) != 0) { // more bytes will follow 616 585 --bytesToRead; 617 586 result += ((long) (b & 0x7f)) << shift; … … 655 624 */ 656 625 private long readUnsignedNum64() { 657 int b = ioBuf[io Pos++];626 int b = ioBuf[ioBufPos++]; 658 627 --bytesToRead; 659 628 long result = b; … … 663 632 result &= 0x7f; 664 633 int shift = 7; 665 while (((b = ioBuf[io Pos++]) & 0x80) != 0) { // more bytes will follow634 while (((b = ioBuf[ioBufPos++]) & 0x80) != 0) { // more bytes will follow 666 635 --bytesToRead; 667 636 result += ((long) (b & 0x7f)) << shift; … … 675 644 /** 676 645 * read a varying length unsigned number (see o5m definition) 677 * is similar to the 64 bit version.678 646 * @return the number as int 679 647 */ 680 648 private int readUnsignedNum32() { 681 int b = ioBuf[ioPos++]; 682 --bytesToRead; 683 int result = b; 684 if ((b & 0x80) == 0) { // just one byte 685 return result; 686 } 687 result &= 0x7f; 688 int shift = 7; 689 while (((b = ioBuf[ioPos++]) & 0x80) != 0) { // more bytes will follow 690 --bytesToRead; 691 result += (b & 0x7f) << shift; 692 shift += 7; 693 } 694 --bytesToRead; 695 result += b << shift; 696 return result; 649 return (int) readUnsignedNum64(); 697 650 } 698 651 … … 700 653 * Exception thrown after user cancellation. 701 654 */ 702 @SuppressWarnings("serial")703 655 private static final class O5mParsingCancelException extends Exception implements ImportCancelException { 656 private static final long serialVersionUID = 1L; 657 704 658 O5mParsingCancelException(String msg) { 705 659 super(msg);
Note:
See TracChangeset
for help on using the changeset viewer.