EddystoneURL extends EddystoneBase { public static byte[] encode(String url) { if (null == url) { return null; } if (url.length() == 0) { return new byte[0]; } ByteArrayOutputStream baos = new ByteArrayOutputStream(18); int pos = 0; for (int schemeCode = 0; schemeCode < SCHEMES.length; ++schemeCode) { String scheme = SCHEMES[schemeCode]; if (url.startsWith(scheme)) { baos.write(schemeCode); pos = scheme.length(); break; } } if (pos <= 0) return null; while (pos < url.length()) { boolean foundExpansion = false; for (int expansionCode = 0; expansionCode < EXPANSIONS.length; ++expansionCode) { String expansion = EXPANSIONS[expansionCode]; if (url.startsWith(expansion, pos)) { baos.write(expansionCode); pos += expansion.length(); foundExpansion = true; break; } } if (!foundExpansion) { char charAt = url.charAt(pos++); if (charAt <= 32 || charAt >= 127) { return null; } baos.write(charAt); } } return baos.toByteArray(); } EddystoneURL(String url, byte[] lockKey, @Advertiser.Mode int mode,
                        @Advertiser.Power int txPowerLevel, String name);  EddystoneURL(String url, @Advertiser.Mode int mode,
                        @Advertiser.Power int txPowerLevel, String name);  EddystoneURL(String url, @Advertiser.Mode int mode,
                        @Advertiser.Power int txPowerLevel);  EddystoneURL(String url, byte[] lockKey, String name);  EddystoneURL(String url, String name);  EddystoneURL(String url, byte[] lockKey);  EddystoneURL(String url); static String decode(byte[] data); static String decode(byte[] data, int offset, int length); static byte[] encode(String url); @Override int getKind(); @Override EddystoneBase cloneBeacon(); @Override Advertiser createAdvertiser(BleService service); @Override CharSequence getNotificationSubject(); @Override EddystoneURLEditor edit(); String getURL();  }
@Test public void encode() throws Exception { for (Map.Entry<String, byte[]> entry : valid.entrySet()) { assertArrayEquals(entry.getKey(), EddystoneURL.encode(entry.getKey()), entry.getValue()); } for (Map.Entry<String, byte[]> entry : unexpanded.entrySet()) { assertNotEquals(entry.getKey(), EddystoneURL.encode(entry.getKey())); } for (String value : unencodable) { assertNull(value, EddystoneURL.encode(value)); } }