public < T > T query ( String method , ArgMap argMap , Class < T > responseType ) throws VoteSmartException , VoteSmartErrorException { BufferedReader reader = null ; HttpURLConnection conn = null ; String charSet = "utf-8" ; try { if ( isCaching ( method , argMap ) ) { File file = getCacheFile ( method , argMap ) ; long fileLength = file . length ( ) ; logger . fine ( "Length of File in cache:" + fileLength + ": " + file . getName ( ) ) ; if ( fileLength == 0L ) { VoteSmart . cacheFileFromAPI ( method , argMap , file ) ; } reader = new BufferedReader ( new InputStreamReader ( new FileInputStream ( file ) , charSet ) ) ; } else { conn = VoteSmart . getConnectionFromAPI ( method , argMap ) ; charSet = getCharset ( conn ) ; reader = new BufferedReader ( new InputStreamReader ( conn . getInputStream ( ) , charSet ) ) ; } JAXBElement < T > e = unmarshaller . unmarshal ( new StreamSource ( reader ) , responseType ) ; if ( e . getName ( ) . getLocalPart ( ) . equals ( "error" ) ) { // ErrorBase error = unmarshaller.unmarshal( new StreamSource( reader = new StringReader(XMLStr) ), ErrorBase.class ).getValue(); throw new VoteSmartErrorException ( ( ( ErrorBase ) e . getValue ( ) ) , method , argMap ) ; } else { return e . getValue ( ) ; } /* Object o = unmarshaller.unmarshal( new StreamSource( reader ) ); if ( o instanceof ErrorBase ) { throw new VoteSmartErrorException((ErrorBase) o, method, argMap); } else { @SuppressWarnings("unchecked") T e = (T) o; return e; } */ } catch ( JAXBException e ) { throw new VoteSmartException ( e ) ; } catch ( URISyntaxException e ) { throw new VoteSmartException ( e ) ; } catch ( IOException e ) { throw new VoteSmartException ( e ) ; } finally { suspendCache = false ; if ( conn != null ) conn . disconnect ( ) ; if ( reader != null ) { try { reader . close ( ) ; } catch ( IOException e ) { throw new VoteSmartException ( e ) ; } } } }
Queries the API server for the information requested