/** * Convert the parameter to a URI and validate the correctness of its host * and port. * * @return true if the address and port are valid. */ public static boolean validateResource(String uriString) { if(uriString == null) { return false; } try { return validateResource(createUri(uriString)); } catch(DataSourceException e) { Log.d(TAG, "URI is not valid", e); return false; } }
/** * Determine if two URIs refer to the same resource. * * The function safely attempts to convert the otherResource parameter to a * URI object before comparing. * * @return true if the address and port match the current in-use values. */ public static boolean sameResource(URI uri, String otherResource) { try { return createUri(otherResource).equals(uri); } catch(DataSourceException e) { return false; } }
@Override public boolean setResource(String otherResource) throws DataSourceException { if(!UriBasedVehicleInterfaceMixin.sameResource(mUri, massageUri(otherResource))) { setUri(otherResource); try { if(mSocket != null) { mSocket.close(); } } catch(IOException e) { } return true; } return false; }
private void setUri(URI uri) throws DataSourceResourceException { if(uri == null || !UriBasedVehicleInterfaceMixin.validateResource(uri)) { throw new DataSourceResourceException("URI is not valid"); } mUri = uri; } }
public NetworkVehicleInterface(Context context, String uriString) throws DataSourceException { this(context, UriBasedVehicleInterfaceMixin.createUri( massageUri(uriString))); }
@Override public boolean setResource(String otherUri) throws DataSourceException { if(mDeviceUri == UsbDeviceUtilities.DEFAULT_USB_DEVICE_URI && otherUri != null && !UriBasedVehicleInterfaceMixin.sameResource(mDeviceUri, otherUri)) { mDeviceUri = createUri(otherUri); stop(); start(); return true; } return false; }
/** * Return true if the address and port are valid. * * @return true if the address and port are valid. */ public static boolean validateResource(String uriString) { try { URI uri = UriBasedVehicleInterfaceMixin.createUri(massageUri(uriString)); return UriBasedVehicleInterfaceMixin.validateResource(uri) && uri.getPort() < 65536; } catch(DataSourceException e) { return false; } }
public static URI createUri(String uriString) throws DataSourceException { URI uri; if(uriString == null) { uri = null; } else { uri = UriBasedVehicleInterfaceMixin.createUri(uriString); } return createUri(uri); }
private void setUri(String uri) throws DataSourceException { setUri(UriBasedVehicleInterfaceMixin.createUri(massageUri(uri))); }