boolean authorize ( String resource ) throws IOException { if ( passwordProvider == null ) { throw new IOException ( "Authorization failed - no password provider present " + "(you must call setPasswordProvider)" ) ; } if ( passwordProvider . canAuthenticate ( resource ) ) { // RPC code FOR SANE_NET_AUTHORIZE outputStream . write ( SaneRpcCode . SANE_NET_AUTHORIZE ) ; outputStream . write ( resource ) ; outputStream . write ( passwordProvider . getUsername ( resource ) ) ; writePassword ( resource , passwordProvider . getPassword ( resource ) ) ; outputStream . flush ( ) ; // Read dummy reply and discard (according to the spec, it is unused). inputStream . readWord ( ) ; return true ; } return false ; }
Authorize the resource for access .