Tools { public static String[] tokenizeArgs(String args) { if (args == null || args.trim().length() == 0) { return null; } List<String> l = Arrays.asList(args.split(" ")); List<String> result = new ArrayList<String>(); for (int c = 0; c < l.size(); c++) { String s = l.get(c); if (s.startsWith("\"")) { c++; s += " " + l.get(c); while (!(s.endsWith("\"") && !s.endsWith("\\\"")) && c < l.size()) { c++; } s = c == l.size() ? s.substring(1) : s.substring(1, s.length() - 1); s = s.replace("\\\"", "\""); } result.add(s); } return result.toArray(new String[result.size()]); }  static String[] tokenizeArgs(String args); static String convertToHtml(String str); static String getFilename(String filePath); static String getDir(String filePath); static String ensureDir(String dir, String basedir); static String ensureFileDir(String file, String basedir); static String ensureDir(String outputDir); static String modifyUrl(final String url, Integer mods); static void openURL(String url); static ByteArrayOutputStream readAll(InputStream instream, long maxSize); static void readAndWrite(InputStream instream, long maxSize, OutputStream outstream); static int copyFile(File source, File target, boolean overwrite); static String joinRelativeUrl(String baseUrl, String url); static boolean isEmpty(String str); static long writeAll(OutputStream out, InputStream in); static String expandProperties(StringToStringMap values, String content, boolean leaveMissing); static String replaceHost(String endpoint, String host); static String getEndpointFromUrl(URL baseUrl); static String getContentTypeFromFilename(String fileName); static String getExtensionForContentType(String contentType); static String getFileContent(String path); static String getTitleProperty(String path); static String normalizeFileSeparators(String input); static void assertSimilar(String expected, String real, char wildcard); static boolean isSimilar(String expected, String real, char wildcard); static void main(String[] args); static File createTemporaryDirectory(); static void deleteDirectoryOnExit(final File directory); static boolean isPropertyExpansion(@Nullable String value); static String removePropertyExpansions(String definitionUrl, String definition); static final int COPY_BUFFER_SIZE; static final long READ_ALL; }
@Test public void tokenizesArgs() throws Exception { assertNull(Tools.tokenizeArgs("")); String[] args = Tools.tokenizeArgs("test ett"); assertEquals(args.length, 2); args = Tools.tokenizeArgs("\"test ett\""); assertEquals(args.length, 1); assertEquals(args[0], "test ett"); args = Tools.tokenizeArgs("\"test\\\" ett\" "); assertEquals(args.length, 1); assertEquals(args[0], "test\" ett"); }