Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/validation/ValidatorCLI.java
r19050 r19077 27 27 import java.util.stream.Collectors; 28 28 29 import org.apache.commons.io.FilenameUtils;30 29 import org.openstreetmap.josm.actions.ExtensionFileFilter; 31 30 import org.openstreetmap.josm.cli.CLIModule; … … 320 319 */ 321 320 private static String getDefaultOutputName(final String inputString) { 322 final String extension = FilenameUtils.getExtension(inputString); 321 final String[] parts = getFileParts(inputString); 322 final String extension = parts[1]; 323 323 if (!Arrays.asList("zip", "bz", "xz", "geojson").contains(extension)) { 324 return FilenameUtils.getBaseName(inputString)+ ".geojson";324 return parts[0] + ".geojson"; 325 325 } else if ("geojson".equals(extension)) { 326 326 // Account for geojson input files 327 return FilenameUtils.getBaseName(inputString) + ".validated.geojson"; 328 } 329 return FilenameUtils.getBaseName(FilenameUtils.getBaseName(inputString)) + ".geojson"; 327 return parts[0] + ".validated.geojson"; 328 } 329 return parts[0] + ".geojson"; 330 } 331 332 /** 333 * Split a string into a filename + extension. Example: 334 * "foo.bar.txt" -> ["foo.bar", "txt"] 335 * <p> 336 * Please note that future versions of Java may make this method redundant. It is not as of Java 21 (look for 337 * something like {@code Path#getExtension}, see <a href="https://bugs.openjdk.org/browse/JDK-8298318">JDK-8298318</a>. 338 * That may be in Java 22. 339 * @param inputString The string to get the filename and extension from 340 * @return The filename and the (optional) extension 341 */ 342 private static String[] getFileParts(String inputString) { 343 final int split = inputString.lastIndexOf('.'); 344 final int path = inputString.lastIndexOf(File.separatorChar); 345 if (split == -1 || path > split) { 346 return new String[] {inputString, ""}; 347 } else { 348 return new String[]{inputString.substring(0, split), inputString.substring(split + 1)}; 349 } 330 350 } 331 351 -
trunk/src/org/openstreetmap/josm/io/OsmPbfReader.java
r19050 r19077 7 7 import java.io.IOException; 8 8 import java.io.InputStream; 9 import java.io.OutputStream; 9 10 import java.util.ArrayList; 10 11 import java.util.Arrays; … … 16 17 import java.util.Set; 17 18 18 import org.apache.commons.io.input.BoundedInputStream;19 19 import org.openstreetmap.josm.data.Bounds; 20 20 import org.openstreetmap.josm.data.DataSource; … … 51 51 */ 52 52 public final class OsmPbfReader extends AbstractReader { 53 /** 54 * This could be replaced by {@link org.apache.commons.io.input.BoundedInputStream} from Apache Commons IO. 55 * However, Commons IO is not <i>currently</i> (2024-05-13) a required JOSM dependency, so we should avoid using it 56 * for now. Commons IO is a <i>transitive</i> dependency, currently pulled in by {@link org.apache.commons.compress} 57 * (see {@link org.apache.commons.compress.utils.BoundedInputStream}). 58 */ 59 private static final class BoundedInputStream extends InputStream { 60 private final InputStream source; 61 private long count; 62 private long mark; 63 64 BoundedInputStream(InputStream source) { 65 this.source = source; 66 } 67 68 @Override 69 public int read() throws IOException { 70 count++; 71 return this.source.read(); 72 } 73 74 @Override 75 public long skip(long n) throws IOException { 76 long skipped = super.skip(n); 77 this.count += skipped; 78 return skipped; 79 } 80 81 @Override 82 public int available() throws IOException { 83 return this.source.available(); 84 } 85 86 @Override 87 public void close() throws IOException { 88 this.source.close(); 89 } 90 91 @Override 92 public synchronized void mark(int readlimit) { 93 this.source.mark(readlimit); 94 this.mark = this.count; 95 } 96 97 @Override 98 public synchronized void reset() throws IOException { 99 this.source.reset(); 100 this.count = this.mark; 101 } 102 103 @Override 104 public boolean markSupported() { 105 return this.source.markSupported(); 106 } 107 108 @Override 109 public long transferTo(OutputStream out) throws IOException { 110 return super.transferTo(out); 111 } 112 113 long getCount() { 114 return this.count; 115 } 116 } 117 53 118 private static final long[] EMPTY_LONG = new long[0]; 54 119 /** -
trunk/test/unit/org/openstreetmap/josm/data/imagery/WMTSTileSourceTest.java
r19052 r19077 16 16 import java.nio.charset.StandardCharsets; 17 17 import java.nio.file.Files; 18 import java.nio.file.Path; 18 19 import java.nio.file.Paths; 19 20 import java.util.ArrayList; … … 22 23 import java.util.concurrent.TimeUnit; 23 24 24 import org.apache.commons.io.FileUtils;25 25 import org.junit.jupiter.api.Disabled; 26 26 import org.junit.jupiter.api.Test; … … 488 488 void testSupportedMimeTypesUrlEncode(String mimeType, @TempDir File temporaryDirectory) 489 489 throws IOException, WMTSGetCapabilitiesException, ReflectiveOperationException { 490 final String data = File Utils.readFileToString(new File(TestUtils.getTestDataRoot() +491 "wmts/bug13975-multiple-tile-matrices-for-one-layer-projection.xml"), StandardCharsets.UTF_8)490 final String data = Files.readString(Paths.get(TestUtils.getTestDataRoot() + 491 "wmts", "bug13975-multiple-tile-matrices-for-one-layer-projection.xml"), StandardCharsets.UTF_8) 492 492 .replace("image/jpgpng", mimeType); 493 File file = new File(temporaryDirectory,"testSupportedMimeTypes.xml");494 File Utils.writeStringToFile(file, data, StandardCharsets.UTF_8);495 WMTSCapabilities capabilities = WMTSTileSource.getCapabilities(file.toU RI().toURL().toExternalForm(), Collections.emptyMap());493 Path file = temporaryDirectory.toPath().resolve("testSupportedMimeTypes.xml"); 494 Files.writeString(file, data, StandardCharsets.UTF_8); 495 WMTSCapabilities capabilities = WMTSTileSource.getCapabilities(file.toUri().toURL().toExternalForm(), Collections.emptyMap()); 496 496 assertEquals(2, capabilities.getLayers().size()); 497 497 Field format = WMTSTileSource.Layer.class.getDeclaredField("format");
Note:
See TracChangeset
for help on using the changeset viewer.