Closes issue #540 : handle file paths with space

This commit is contained in:
Sean Owen 2016-02-08 14:08:03 +00:00
parent 1eaa66dbfa
commit 3b4fc7a244
2 changed files with 17 additions and 3 deletions

View file

@ -19,6 +19,7 @@ package com.google.zxing.client.j2se;
import com.beust.jcommander.JCommander; import com.beust.jcommander.JCommander;
import java.io.IOException; import java.io.IOException;
import java.net.URI; import java.net.URI;
import java.net.URISyntaxException;
import java.nio.file.DirectoryStream; import java.nio.file.DirectoryStream;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
@ -55,7 +56,21 @@ public final class CommandLineRunner {
return; return;
} }
List<URI> inputs = config.inputPaths; List<URI> inputs = new ArrayList<>(config.inputPaths.size());
for (String inputPath : config.inputPaths) {
URI uri;
try {
uri = new URI(inputPath);
} catch (URISyntaxException use) {
// Assume it must be a file
if (!Files.exists(Paths.get(inputPath))) {
throw use;
}
uri = new URI("file", inputPath, null);
}
inputs.add(uri);
}
do { do {
inputs = retainValid(expand(inputs), config.recursive); inputs = retainValid(expand(inputs), config.recursive);
} while (config.recursive && isExpandable(inputs)); } while (config.recursive && isExpandable(inputs));

View file

@ -21,7 +21,6 @@ import com.beust.jcommander.validators.PositiveInteger;
import com.google.zxing.BarcodeFormat; import com.google.zxing.BarcodeFormat;
import com.google.zxing.DecodeHintType; import com.google.zxing.DecodeHintType;
import java.net.URI;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
@ -80,7 +79,7 @@ final class DecoderConfig {
boolean help; boolean help;
@Parameter(description = "(URIs to decode)", required = true, variableArity = true) @Parameter(description = "(URIs to decode)", required = true, variableArity = true)
List<URI> inputPaths; List<String> inputPaths;
Map<DecodeHintType,?> buildHints() { Map<DecodeHintType,?> buildHints() {
List<BarcodeFormat> finalPossibleFormats = possibleFormats; List<BarcodeFormat> finalPossibleFormats = possibleFormats;