private /*@Nullable*/ Downloader startGetSomething ( final String apiPath , final /*@Nullable*/ String [ ] params ) throws DbxException { final String host = this . host . getContent ( ) ; // we don't use doGet() here because doGet() will close our input stream before we can // download the contents. return DbxRequestUtil . runAndRetry ( requestConfig . getMaxRetries ( ) , new DbxRequestUtil . RequestMaker < Downloader , DbxException > ( ) { @ Override public Downloader run ( ) throws DbxException { HttpRequestor . Response response = DbxRequestUtil . startGet ( requestConfig , accessToken , USER_AGENT_ID , host , apiPath , params , null ) ; boolean passedOwnershipOfStream = false ; try { if ( response . getStatusCode ( ) == 404 ) return null ; if ( response . getStatusCode ( ) != 200 ) throw DbxRequestUtil . unexpectedStatus ( response ) ; String metadataString = DbxRequestUtil . getFirstHeader ( response , "x-dropbox-metadata" ) ; DbxEntry . File metadata ; try { metadata = DbxEntry . File . Reader . readFully ( metadataString ) ; } catch ( JsonReadException ex ) { String requestId = DbxRequestUtil . getRequestId ( response ) ; throw new BadResponseException ( requestId , "Bad JSON in X-Dropbox-Metadata header: " + ex . getMessage ( ) , ex ) ; } // Package up the metadata with the response body's InputStream. Downloader result = new Downloader ( metadata , response . getBody ( ) ) ; passedOwnershipOfStream = true ; return result ; } finally { // If we haven't passed ownership the stream to the caller, then close it. if ( ! passedOwnershipOfStream ) { try { response . getBody ( ) . close ( ) ; } catch ( IOException ex ) { // Ignore, since we don't actually care about the data in this method. // We only care about IOExceptions when actually reading from the stream. } } } } } ) ; }
Generic function that downloads either files or thumbnails .