@Test public void testReadKeyFromFile_LicenseFileHasMultipleKeysWithWhitespace() throws Exception { File tmpLicenseFile = File.createTempFile("license", "lic"); PrintWriter out = new PrintWriter(tmpLicenseFile); out.println("4 = this-is-a-license"); out.println("5 = this-is-another-license"); out.close(); assertEquals("this-is-a-license", licenseChecker.readKeyFromFile( tmpLicenseFile.toURI().toURL(), 4)); assertEquals("this-is-another-license", licenseChecker.readKeyFromFile( tmpLicenseFile.toURI().toURL(), 5)); tmpLicenseFile.delete(); }
String readKeyFromFile(URL url, int majorVersion) throws IOException { String majorVersionStr = String.valueOf(majorVersion); List<String> lines = IOUtils.readLines(url.openStream()); String defaultKey = null; for (String line : lines) { String[] parts = line.split("\\s*=\\s*"); if (parts.length < 2) { defaultKey = parts[0].trim(); } if (parts[0].equals(majorVersionStr)) { return parts[1].trim(); } } return defaultKey; }
CvalChecker { String readKeyFromFile(URL url, int majorVersion) throws IOException { String majorVersionStr = String.valueOf(majorVersion); List<String> lines = IOUtils.readLines(url.openStream()); String defaultKey = null; for (String line : lines) { String[] parts = line.split("\\s*=\\s*"); if (parts.length < 2) { defaultKey = parts[0].trim(); } if (parts[0].equals(majorVersionStr)) { return parts[1].trim(); } } return defaultKey; } }
CvalChecker { String readKeyFromFile(URL url, int majorVersion) throws IOException { String majorVersionStr = String.valueOf(majorVersion); List<String> lines = IOUtils.readLines(url.openStream()); String defaultKey = null; for (String line : lines) { String[] parts = line.split("\\s*=\\s*"); if (parts.length < 2) { defaultKey = parts[0].trim(); } if (parts[0].equals(majorVersionStr)) { return parts[1].trim(); } } return defaultKey; } CvalChecker(); }
CvalChecker { String readKeyFromFile(URL url, int majorVersion) throws IOException { String majorVersionStr = String.valueOf(majorVersion); List<String> lines = IOUtils.readLines(url.openStream()); String defaultKey = null; for (String line : lines) { String[] parts = line.split("\\s*=\\s*"); if (parts.length < 2) { defaultKey = parts[0].trim(); } if (parts[0].equals(majorVersionStr)) { return parts[1].trim(); } } return defaultKey; } CvalChecker(); CvalInfo validateProduct(String productName, String productVersion,
            String productTitle); }
CvalChecker { String readKeyFromFile(URL url, int majorVersion) throws IOException { String majorVersionStr = String.valueOf(majorVersion); List<String> lines = IOUtils.readLines(url.openStream()); String defaultKey = null; for (String line : lines) { String[] parts = line.split("\\s*=\\s*"); if (parts.length < 2) { defaultKey = parts[0].trim(); } if (parts[0].equals(majorVersionStr)) { return parts[1].trim(); } } return defaultKey; } CvalChecker(); CvalInfo validateProduct(String productName, String productVersion,
            String productTitle); static final String LINE; }