@Test(expected = URISyntaxException.class) public void testParse_withBadPort_shouldFail() throws URISyntaxException { SktUri.parse(String.format("OPGPSKT:%s/x%d/%s/SSID:%s", HOST, PORT, Hex.toHexString(PRESHARED_KEY), Hex.toHexString(SSID.getBytes()))); }
@NonNull public static SktUri parse(String input) throws URISyntaxException { if (!input.startsWith(Constants.SKT_SCHEME + ":")) { throw new URISyntaxException(input, "invalid scheme"); } String[] pieces = input.substring(input.indexOf(":") +1).split("/"); if (pieces.length < 3) { throw new URISyntaxException(input, "invalid syntax"); } String address = pieces[0]; int port; try { port = Integer.parseInt(pieces[1]); } catch (NumberFormatException e) { throw new URISyntaxException(input, "error parsing port"); } byte[] psk; try { psk = Hex.decode(pieces[2]); } catch (DecoderException e) { throw new URISyntaxException(input, "error parsing hex psk"); } String wifiSsid = null; for (int i = 3; i < pieces.length; i++) { String[] optarg = pieces[i].split(":", 2); if (optarg.length == 2 && "SSID".equals(optarg[0])) { try { wifiSsid = new String(Hex.decode(optarg[1])); } catch (DecoderException e) { Timber.d("error parsing ssid in skt uri, ignoring: " + input); } } } return new AutoValue_SktUri(address, port, psk, wifiSsid); }
SktUri { @NonNull public static SktUri parse(String input) throws URISyntaxException { if (!input.startsWith(Constants.SKT_SCHEME + ":")) { throw new URISyntaxException(input, "invalid scheme"); } String[] pieces = input.substring(input.indexOf(":") +1).split("/"); if (pieces.length < 3) { throw new URISyntaxException(input, "invalid syntax"); } String address = pieces[0]; int port; try { port = Integer.parseInt(pieces[1]); } catch (NumberFormatException e) { throw new URISyntaxException(input, "error parsing port"); } byte[] psk; try { psk = Hex.decode(pieces[2]); } catch (DecoderException e) { throw new URISyntaxException(input, "error parsing hex psk"); } String wifiSsid = null; for (int i = 3; i < pieces.length; i++) { String[] optarg = pieces[i].split(":", 2); if (optarg.length == 2 && "SSID".equals(optarg[0])) { try { wifiSsid = new String(Hex.decode(optarg[1])); } catch (DecoderException e) { Timber.d("error parsing ssid in skt uri, ignoring: " + input); } } } return new AutoValue_SktUri(address, port, psk, wifiSsid); } }
SktUri { @NonNull public static SktUri parse(String input) throws URISyntaxException { if (!input.startsWith(Constants.SKT_SCHEME + ":")) { throw new URISyntaxException(input, "invalid scheme"); } String[] pieces = input.substring(input.indexOf(":") +1).split("/"); if (pieces.length < 3) { throw new URISyntaxException(input, "invalid syntax"); } String address = pieces[0]; int port; try { port = Integer.parseInt(pieces[1]); } catch (NumberFormatException e) { throw new URISyntaxException(input, "error parsing port"); } byte[] psk; try { psk = Hex.decode(pieces[2]); } catch (DecoderException e) { throw new URISyntaxException(input, "error parsing hex psk"); } String wifiSsid = null; for (int i = 3; i < pieces.length; i++) { String[] optarg = pieces[i].split(":", 2); if (optarg.length == 2 && "SSID".equals(optarg[0])) { try { wifiSsid = new String(Hex.decode(optarg[1])); } catch (DecoderException e) { Timber.d("error parsing ssid in skt uri, ignoring: " + input); } } } return new AutoValue_SktUri(address, port, psk, wifiSsid); }  }
SktUri { @NonNull public static SktUri parse(String input) throws URISyntaxException { if (!input.startsWith(Constants.SKT_SCHEME + ":")) { throw new URISyntaxException(input, "invalid scheme"); } String[] pieces = input.substring(input.indexOf(":") +1).split("/"); if (pieces.length < 3) { throw new URISyntaxException(input, "invalid syntax"); } String address = pieces[0]; int port; try { port = Integer.parseInt(pieces[1]); } catch (NumberFormatException e) { throw new URISyntaxException(input, "error parsing port"); } byte[] psk; try { psk = Hex.decode(pieces[2]); } catch (DecoderException e) { throw new URISyntaxException(input, "error parsing hex psk"); } String wifiSsid = null; for (int i = 3; i < pieces.length; i++) { String[] optarg = pieces[i].split(":", 2); if (optarg.length == 2 && "SSID".equals(optarg[0])) { try { wifiSsid = new String(Hex.decode(optarg[1])); } catch (DecoderException e) { Timber.d("error parsing ssid in skt uri, ignoring: " + input); } } } return new AutoValue_SktUri(address, port, psk, wifiSsid); }  abstract String getHost(); abstract int getPort(); @SuppressWarnings("mutable") abstract byte[] getPresharedKey(); @Nullable abstract String getWifiSsid(); @NonNull static SktUri parse(String input); }
SktUri { @NonNull public static SktUri parse(String input) throws URISyntaxException { if (!input.startsWith(Constants.SKT_SCHEME + ":")) { throw new URISyntaxException(input, "invalid scheme"); } String[] pieces = input.substring(input.indexOf(":") +1).split("/"); if (pieces.length < 3) { throw new URISyntaxException(input, "invalid syntax"); } String address = pieces[0]; int port; try { port = Integer.parseInt(pieces[1]); } catch (NumberFormatException e) { throw new URISyntaxException(input, "error parsing port"); } byte[] psk; try { psk = Hex.decode(pieces[2]); } catch (DecoderException e) { throw new URISyntaxException(input, "error parsing hex psk"); } String wifiSsid = null; for (int i = 3; i < pieces.length; i++) { String[] optarg = pieces[i].split(":", 2); if (optarg.length == 2 && "SSID".equals(optarg[0])) { try { wifiSsid = new String(Hex.decode(optarg[1])); } catch (DecoderException e) { Timber.d("error parsing ssid in skt uri, ignoring: " + input); } } } return new AutoValue_SktUri(address, port, psk, wifiSsid); }  abstract String getHost(); abstract int getPort(); @SuppressWarnings("mutable") abstract byte[] getPresharedKey(); @Nullable abstract String getWifiSsid(); @NonNull static SktUri parse(String input);  }