idx int64 0 165k | question stringlengths 73 4.15k | target stringlengths 5 918 | len_question int64 21 890 | len_target int64 3 255 |
|---|---|---|---|---|
150,200 | public void refresh ( ) { this . getRefreshLock ( ) . writeLock ( ) . lock ( ) ; try { this . authenticate ( ) ; } catch ( BoxAPIException e ) { this . notifyError ( e ) ; this . getRefreshLock ( ) . writeLock ( ) . unlock ( ) ; throw e ; } this . notifyRefresh ( ) ; this . getRefreshLock ( ) . writeLock ( ) . unlock ( ) ; } | Refresh s this connection s access token using Box Developer Edition . | 99 | 13 |
150,201 | public BoxTask . Info addTask ( BoxTask . Action action , String message , Date dueAt ) { JsonObject itemJSON = new JsonObject ( ) ; itemJSON . add ( "type" , "file" ) ; itemJSON . add ( "id" , this . getID ( ) ) ; JsonObject requestJSON = new JsonObject ( ) ; requestJSON . add ( "item" , itemJSON ) ; requestJSON . add ( "action" , action . toJSONString ( ) ) ; if ( message != null && ! message . isEmpty ( ) ) { requestJSON . add ( "message" , message ) ; } if ( dueAt != null ) { requestJSON . add ( "due_at" , BoxDateFormat . format ( dueAt ) ) ; } URL url = ADD_TASK_URL_TEMPLATE . build ( this . getAPI ( ) . getBaseURL ( ) ) ; BoxJSONRequest request = new BoxJSONRequest ( this . getAPI ( ) , url , "POST" ) ; request . setBody ( requestJSON . toString ( ) ) ; BoxJSONResponse response = ( BoxJSONResponse ) request . send ( ) ; JsonObject responseJSON = JsonObject . readFrom ( response . getJSON ( ) ) ; BoxTask addedTask = new BoxTask ( this . getAPI ( ) , responseJSON . get ( "id" ) . asString ( ) ) ; return addedTask . new Info ( responseJSON ) ; } | Adds a new task to this file . The task can have an optional message to include and a due date . | 320 | 22 |
150,202 | public URL getDownloadURL ( ) { URL url = CONTENT_URL_TEMPLATE . build ( this . getAPI ( ) . getBaseURL ( ) , this . getID ( ) ) ; BoxAPIRequest request = new BoxAPIRequest ( this . getAPI ( ) , url , "GET" ) ; request . setFollowRedirects ( false ) ; BoxRedirectResponse response = ( BoxRedirectResponse ) request . send ( ) ; return response . getRedirectURL ( ) ; } | Gets an expiring URL for downloading a file directly from Box . This can be user for example for sending as a redirect to a browser to cause the browser to download the file directly from Box . | 108 | 40 |
150,203 | public void downloadRange ( OutputStream output , long rangeStart , long rangeEnd ) { this . downloadRange ( output , rangeStart , rangeEnd , null ) ; } | Downloads a part of this file s contents starting at rangeStart and stopping at rangeEnd . | 35 | 19 |
150,204 | public void downloadRange ( OutputStream output , long rangeStart , long rangeEnd , ProgressListener listener ) { URL url = CONTENT_URL_TEMPLATE . build ( this . getAPI ( ) . getBaseURL ( ) , this . getID ( ) ) ; BoxAPIRequest request = new BoxAPIRequest ( this . getAPI ( ) , url , "GET" ) ; if ( rangeEnd > 0 ) { request . addHeader ( "Range" , String . format ( "bytes=%s-%s" , Long . toString ( rangeStart ) , Long . toString ( rangeEnd ) ) ) ; } else { request . addHeader ( "Range" , String . format ( "bytes=%s-" , Long . toString ( rangeStart ) ) ) ; } BoxAPIResponse response = request . send ( ) ; InputStream input = response . getBody ( listener ) ; byte [ ] buffer = new byte [ BUFFER_SIZE ] ; try { int n = input . read ( buffer ) ; while ( n != - 1 ) { output . write ( buffer , 0 , n ) ; n = input . read ( buffer ) ; } } catch ( IOException e ) { throw new BoxAPIException ( "Couldn't connect to the Box API due to a network error." , e ) ; } finally { response . disconnect ( ) ; } } | Downloads a part of this file s contents starting at rangeStart and stopping at rangeEnd while reporting the progress to a ProgressListener . | 292 | 27 |
150,205 | public void rename ( String newName ) { URL url = FILE_URL_TEMPLATE . build ( this . getAPI ( ) . getBaseURL ( ) , this . getID ( ) ) ; BoxJSONRequest request = new BoxJSONRequest ( this . getAPI ( ) , url , "PUT" ) ; JsonObject updateInfo = new JsonObject ( ) ; updateInfo . add ( "name" , newName ) ; request . setBody ( updateInfo . toString ( ) ) ; BoxAPIResponse response = request . send ( ) ; response . disconnect ( ) ; } | Renames this file . | 128 | 5 |
150,206 | public void getRepresentationContent ( String representationHint , String assetPath , OutputStream output ) { List < Representation > reps = this . getInfoWithRepresentations ( representationHint ) . getRepresentations ( ) ; if ( reps . size ( ) < 1 ) { throw new BoxAPIException ( "No matching representations found" ) ; } Representation representation = reps . get ( 0 ) ; String repState = representation . getStatus ( ) . getState ( ) ; if ( repState . equals ( "viewable" ) || repState . equals ( "success" ) ) { this . makeRepresentationContentRequest ( representation . getContent ( ) . getUrlTemplate ( ) , assetPath , output ) ; return ; } else if ( repState . equals ( "pending" ) || repState . equals ( "none" ) ) { String repContentURLString = null ; while ( repContentURLString == null ) { repContentURLString = this . pollRepInfo ( representation . getInfo ( ) . getUrl ( ) ) ; } this . makeRepresentationContentRequest ( repContentURLString , assetPath , output ) ; return ; } else if ( repState . equals ( "error" ) ) { throw new BoxAPIException ( "Representation had error status" ) ; } else { throw new BoxAPIException ( "Representation had unknown status" ) ; } } | Fetches the contents of a file representation with asset path and writes them to the provided output stream . | 293 | 21 |
150,207 | public Collection < BoxFileVersion > getVersions ( ) { URL url = VERSIONS_URL_TEMPLATE . build ( this . getAPI ( ) . getBaseURL ( ) , this . getID ( ) ) ; BoxAPIRequest request = new BoxAPIRequest ( this . getAPI ( ) , url , "GET" ) ; BoxJSONResponse response = ( BoxJSONResponse ) request . send ( ) ; JsonObject jsonObject = JsonObject . readFrom ( response . getJSON ( ) ) ; JsonArray entries = jsonObject . get ( "entries" ) . asArray ( ) ; Collection < BoxFileVersion > versions = new ArrayList < BoxFileVersion > ( ) ; for ( JsonValue entry : entries ) { versions . add ( new BoxFileVersion ( this . getAPI ( ) , entry . asObject ( ) , this . getID ( ) ) ) ; } return versions ; } | Gets any previous versions of this file . Note that only users with premium accounts will be able to retrieve previous versions of their files . | 196 | 27 |
150,208 | public boolean canUploadVersion ( String name , long fileSize ) { URL url = CONTENT_URL_TEMPLATE . build ( this . getAPI ( ) . getBaseURL ( ) , this . getID ( ) ) ; BoxJSONRequest request = new BoxJSONRequest ( this . getAPI ( ) , url , "OPTIONS" ) ; JsonObject preflightInfo = new JsonObject ( ) ; if ( name != null ) { preflightInfo . add ( "name" , name ) ; } preflightInfo . add ( "size" , fileSize ) ; request . setBody ( preflightInfo . toString ( ) ) ; try { BoxAPIResponse response = request . send ( ) ; return response . getResponseCode ( ) == 200 ; } catch ( BoxAPIException ex ) { if ( ex . getResponseCode ( ) >= 400 && ex . getResponseCode ( ) < 500 ) { // This looks like an error response, menaing the upload would fail return false ; } else { // This looks like a network error or server error, rethrow exception throw ex ; } } } | Checks if a new version of the file can be uploaded with the specified name and size . | 239 | 19 |
150,209 | public byte [ ] getThumbnail ( ThumbnailFileType fileType , int minWidth , int minHeight , int maxWidth , int maxHeight ) { QueryStringBuilder builder = new QueryStringBuilder ( ) ; builder . appendParam ( "min_width" , minWidth ) ; builder . appendParam ( "min_height" , minHeight ) ; builder . appendParam ( "max_width" , maxWidth ) ; builder . appendParam ( "max_height" , maxHeight ) ; URLTemplate template ; if ( fileType == ThumbnailFileType . PNG ) { template = GET_THUMBNAIL_PNG_TEMPLATE ; } else if ( fileType == ThumbnailFileType . JPG ) { template = GET_THUMBNAIL_JPG_TEMPLATE ; } else { throw new BoxAPIException ( "Unsupported thumbnail file type" ) ; } URL url = template . buildWithQuery ( this . getAPI ( ) . getBaseURL ( ) , builder . toString ( ) , this . getID ( ) ) ; BoxAPIRequest request = new BoxAPIRequest ( this . getAPI ( ) , url , "GET" ) ; BoxAPIResponse response = request . send ( ) ; ByteArrayOutputStream thumbOut = new ByteArrayOutputStream ( ) ; InputStream body = response . getBody ( ) ; byte [ ] buffer = new byte [ BUFFER_SIZE ] ; try { int n = body . read ( buffer ) ; while ( n != - 1 ) { thumbOut . write ( buffer , 0 , n ) ; n = body . read ( buffer ) ; } } catch ( IOException e ) { throw new BoxAPIException ( "Error reading thumbnail bytes from response body" , e ) ; } finally { response . disconnect ( ) ; } return thumbOut . toByteArray ( ) ; } | Retrieves a thumbnail or smaller image representation of this file . Sizes of 32x32 64x64 128x128 and 256x256 can be returned in the . png format and sizes of 32x32 94x94 160x160 and 320x320 can be returned in the . jpg format . | 395 | 64 |
150,210 | public List < BoxComment . Info > getComments ( ) { URL url = GET_COMMENTS_URL_TEMPLATE . build ( this . getAPI ( ) . getBaseURL ( ) , this . getID ( ) ) ; BoxAPIRequest request = new BoxAPIRequest ( this . getAPI ( ) , url , "GET" ) ; BoxJSONResponse response = ( BoxJSONResponse ) request . send ( ) ; JsonObject responseJSON = JsonObject . readFrom ( response . getJSON ( ) ) ; int totalCount = responseJSON . get ( "total_count" ) . asInt ( ) ; List < BoxComment . Info > comments = new ArrayList < BoxComment . Info > ( totalCount ) ; JsonArray entries = responseJSON . get ( "entries" ) . asArray ( ) ; for ( JsonValue value : entries ) { JsonObject commentJSON = value . asObject ( ) ; BoxComment comment = new BoxComment ( this . getAPI ( ) , commentJSON . get ( "id" ) . asString ( ) ) ; BoxComment . Info info = comment . new Info ( commentJSON ) ; comments . add ( info ) ; } return comments ; } | Gets a list of any comments on this file . | 258 | 11 |
150,211 | public List < BoxTask . Info > getTasks ( String ... fields ) { QueryStringBuilder builder = new QueryStringBuilder ( ) ; if ( fields . length > 0 ) { builder . appendParam ( "fields" , fields ) . toString ( ) ; } URL url = GET_TASKS_URL_TEMPLATE . buildWithQuery ( this . getAPI ( ) . getBaseURL ( ) , builder . toString ( ) , this . getID ( ) ) ; BoxAPIRequest request = new BoxAPIRequest ( this . getAPI ( ) , url , "GET" ) ; BoxJSONResponse response = ( BoxJSONResponse ) request . send ( ) ; JsonObject responseJSON = JsonObject . readFrom ( response . getJSON ( ) ) ; int totalCount = responseJSON . get ( "total_count" ) . asInt ( ) ; List < BoxTask . Info > tasks = new ArrayList < BoxTask . Info > ( totalCount ) ; JsonArray entries = responseJSON . get ( "entries" ) . asArray ( ) ; for ( JsonValue value : entries ) { JsonObject taskJSON = value . asObject ( ) ; BoxTask task = new BoxTask ( this . getAPI ( ) , taskJSON . get ( "id" ) . asString ( ) ) ; BoxTask . Info info = task . new Info ( taskJSON ) ; tasks . add ( info ) ; } return tasks ; } | Gets a list of any tasks on this file with requested fields . | 311 | 14 |
150,212 | public Metadata createMetadata ( String typeName , Metadata metadata ) { String scope = Metadata . scopeBasedOnType ( typeName ) ; return this . createMetadata ( typeName , scope , metadata ) ; } | Creates metadata on this file in the specified template type . | 47 | 12 |
150,213 | public String updateClassification ( String classificationType ) { Metadata metadata = new Metadata ( "enterprise" , Metadata . CLASSIFICATION_TEMPLATE_KEY ) ; metadata . add ( "/Box__Security__Classification__Key" , classificationType ) ; Metadata classification = this . updateMetadata ( metadata ) ; return classification . getString ( Metadata . CLASSIFICATION_KEY ) ; } | Updates a metadata classification on the specified file . | 88 | 10 |
150,214 | public String setClassification ( String classificationType ) { Metadata metadata = new Metadata ( ) . add ( Metadata . CLASSIFICATION_KEY , classificationType ) ; Metadata classification = null ; try { classification = this . createMetadata ( Metadata . CLASSIFICATION_TEMPLATE_KEY , "enterprise" , metadata ) ; } catch ( BoxAPIException e ) { if ( e . getResponseCode ( ) == 409 ) { metadata = new Metadata ( "enterprise" , Metadata . CLASSIFICATION_TEMPLATE_KEY ) ; metadata . replace ( Metadata . CLASSIFICATION_KEY , classificationType ) ; classification = this . updateMetadata ( metadata ) ; } else { throw e ; } } return classification . getString ( Metadata . CLASSIFICATION_KEY ) ; } | Attempts to add classification to a file . If classification already exists then do update . | 175 | 16 |
150,215 | public BoxLock lock ( Date expiresAt , boolean isDownloadPrevented ) { String queryString = new QueryStringBuilder ( ) . appendParam ( "fields" , "lock" ) . toString ( ) ; URL url = FILE_URL_TEMPLATE . buildWithQuery ( this . getAPI ( ) . getBaseURL ( ) , queryString , this . getID ( ) ) ; BoxAPIRequest request = new BoxAPIRequest ( this . getAPI ( ) , url , "PUT" ) ; JsonObject lockConfig = new JsonObject ( ) ; lockConfig . add ( "type" , "lock" ) ; if ( expiresAt != null ) { lockConfig . add ( "expires_at" , BoxDateFormat . format ( expiresAt ) ) ; } lockConfig . add ( "is_download_prevented" , isDownloadPrevented ) ; JsonObject requestJSON = new JsonObject ( ) ; requestJSON . add ( "lock" , lockConfig ) ; request . setBody ( requestJSON . toString ( ) ) ; BoxJSONResponse response = ( BoxJSONResponse ) request . send ( ) ; JsonObject responseJSON = JsonObject . readFrom ( response . getJSON ( ) ) ; JsonValue lockValue = responseJSON . get ( "lock" ) ; JsonObject lockJSON = JsonObject . readFrom ( lockValue . toString ( ) ) ; return new BoxLock ( lockJSON , this . getAPI ( ) ) ; } | Locks a file . | 322 | 5 |
150,216 | public void unlock ( ) { String queryString = new QueryStringBuilder ( ) . appendParam ( "fields" , "lock" ) . toString ( ) ; URL url = FILE_URL_TEMPLATE . buildWithQuery ( this . getAPI ( ) . getBaseURL ( ) , queryString , this . getID ( ) ) ; BoxAPIRequest request = new BoxAPIRequest ( this . getAPI ( ) , url , "PUT" ) ; JsonObject lockObject = new JsonObject ( ) ; lockObject . add ( "lock" , JsonObject . NULL ) ; request . setBody ( lockObject . toString ( ) ) ; request . send ( ) ; } | Unlocks a file . | 148 | 5 |
150,217 | public Metadata updateMetadata ( Metadata metadata ) { String scope ; if ( metadata . getScope ( ) . equals ( Metadata . GLOBAL_METADATA_SCOPE ) ) { scope = Metadata . GLOBAL_METADATA_SCOPE ; } else { scope = Metadata . ENTERPRISE_METADATA_SCOPE ; } URL url = METADATA_URL_TEMPLATE . build ( this . getAPI ( ) . getBaseURL ( ) , this . getID ( ) , scope , metadata . getTemplateName ( ) ) ; BoxAPIRequest request = new BoxAPIRequest ( this . getAPI ( ) , url , "PUT" ) ; request . addHeader ( "Content-Type" , "application/json-patch+json" ) ; request . setBody ( metadata . getPatch ( ) ) ; BoxJSONResponse response = ( BoxJSONResponse ) request . send ( ) ; return new Metadata ( JsonObject . readFrom ( response . getJSON ( ) ) ) ; } | Updates the file metadata . | 222 | 6 |
150,218 | public BoxFileUploadSession . Info createUploadSession ( long fileSize ) { URL url = UPLOAD_SESSION_URL_TEMPLATE . build ( this . getAPI ( ) . getBaseUploadURL ( ) , this . getID ( ) ) ; BoxJSONRequest request = new BoxJSONRequest ( this . getAPI ( ) , url , "POST" ) ; request . addHeader ( "Content-Type" , "application/json" ) ; JsonObject body = new JsonObject ( ) ; body . add ( "file_size" , fileSize ) ; request . setBody ( body . toString ( ) ) ; BoxJSONResponse response = ( BoxJSONResponse ) request . send ( ) ; JsonObject jsonObject = JsonObject . readFrom ( response . getJSON ( ) ) ; String sessionId = jsonObject . get ( "id" ) . asString ( ) ; BoxFileUploadSession session = new BoxFileUploadSession ( this . getAPI ( ) , sessionId ) ; return session . new Info ( jsonObject ) ; } | Creates an upload session to create a new version of a file in chunks . This will first verify that the version can be created and then open a session for uploading pieces of the file . | 228 | 38 |
150,219 | public static EventLog getEnterpriseEvents ( BoxAPIConnection api , Date after , Date before , BoxEvent . Type ... types ) { return getEnterpriseEvents ( api , null , after , before , ENTERPRISE_LIMIT , types ) ; } | Gets all the enterprise events that occurred within a specified date range . | 57 | 14 |
150,220 | public BoxStoragePolicy . Info getInfo ( String ... fields ) { QueryStringBuilder builder = new QueryStringBuilder ( ) ; if ( fields . length > 0 ) { builder . appendParam ( "fields" , fields ) ; } URL url = STORAGE_POLICY_WITH_ID_URL_TEMPLATE . buildWithQuery ( this . getAPI ( ) . getBaseURL ( ) , builder . toString ( ) , this . getID ( ) ) ; BoxAPIRequest request = new BoxAPIRequest ( this . getAPI ( ) , url , "GET" ) ; BoxJSONResponse response = ( BoxJSONResponse ) request . send ( ) ; return new Info ( response . getJSON ( ) ) ; } | Gets information for a Box Storage Policy with optional fields . | 155 | 12 |
150,221 | public BoxFile . Info upload ( BoxAPIConnection boxApi , String folderId , InputStream stream , URL url , String fileName , long fileSize ) throws InterruptedException , IOException { //Create a upload session BoxFileUploadSession . Info session = this . createUploadSession ( boxApi , folderId , url , fileName , fileSize ) ; return this . uploadHelper ( session , stream , fileSize ) ; } | Uploads a new large file . | 94 | 7 |
150,222 | public String generateDigest ( InputStream stream ) { MessageDigest digest = null ; try { digest = MessageDigest . getInstance ( DIGEST_ALGORITHM_SHA1 ) ; } catch ( NoSuchAlgorithmException ae ) { throw new BoxAPIException ( "Digest algorithm not found" , ae ) ; } //Calcuate the digest using the stream. DigestInputStream dis = new DigestInputStream ( stream , digest ) ; try { int value = dis . read ( ) ; while ( value != - 1 ) { value = dis . read ( ) ; } } catch ( IOException ioe ) { throw new BoxAPIException ( "Reading the stream failed." , ioe ) ; } //Get the calculated digest for the stream byte [ ] digestBytes = digest . digest ( ) ; return Base64 . encode ( digestBytes ) ; } | Generates the Base64 encoded SHA - 1 hash for content available in the stream . It can be used to calculate the hash of a file . | 185 | 29 |
150,223 | public void setPermissions ( Permissions permissions ) { if ( this . permissions == permissions ) { return ; } this . removeChildObject ( "permissions" ) ; this . permissions = permissions ; this . addChildObject ( "permissions" , permissions ) ; } | Sets the permissions associated with this shared link . | 56 | 10 |
150,224 | public void deleteFolder ( String folderID ) { URL url = FOLDER_INFO_URL_TEMPLATE . build ( this . api . getBaseURL ( ) , folderID ) ; BoxAPIRequest request = new BoxAPIRequest ( this . api , url , "DELETE" ) ; BoxAPIResponse response = request . send ( ) ; response . disconnect ( ) ; } | Permanently deletes a trashed folder . | 85 | 10 |
150,225 | public BoxFolder . Info getFolderInfo ( String folderID ) { URL url = FOLDER_INFO_URL_TEMPLATE . build ( this . api . getBaseURL ( ) , folderID ) ; BoxAPIRequest request = new BoxAPIRequest ( this . api , url , "GET" ) ; BoxJSONResponse response = ( BoxJSONResponse ) request . send ( ) ; JsonObject jsonObject = JsonObject . readFrom ( response . getJSON ( ) ) ; BoxFolder folder = new BoxFolder ( this . api , jsonObject . get ( "id" ) . asString ( ) ) ; return folder . new Info ( response . getJSON ( ) ) ; } | Gets information about a trashed folder . | 147 | 9 |
150,226 | public BoxFolder . Info getFolderInfo ( String folderID , String ... fields ) { String queryString = new QueryStringBuilder ( ) . appendParam ( "fields" , fields ) . toString ( ) ; URL url = FOLDER_INFO_URL_TEMPLATE . buildWithQuery ( this . api . getBaseURL ( ) , queryString , folderID ) ; BoxAPIRequest request = new BoxAPIRequest ( this . api , url , "GET" ) ; BoxJSONResponse response = ( BoxJSONResponse ) request . send ( ) ; JsonObject jsonObject = JsonObject . readFrom ( response . getJSON ( ) ) ; BoxFolder folder = new BoxFolder ( this . api , jsonObject . get ( "id" ) . asString ( ) ) ; return folder . new Info ( response . getJSON ( ) ) ; } | Gets information about a trashed folder that s limited to a list of specified fields . | 182 | 18 |
150,227 | public BoxFolder . Info restoreFolder ( String folderID ) { URL url = RESTORE_FOLDER_URL_TEMPLATE . build ( this . api . getBaseURL ( ) , folderID ) ; BoxAPIRequest request = new BoxAPIRequest ( this . api , url , "POST" ) ; JsonObject requestJSON = new JsonObject ( ) . add ( "" , "" ) ; request . setBody ( requestJSON . toString ( ) ) ; BoxJSONResponse response = ( BoxJSONResponse ) request . send ( ) ; JsonObject responseJSON = JsonObject . readFrom ( response . getJSON ( ) ) ; BoxFolder restoredFolder = new BoxFolder ( this . api , responseJSON . get ( "id" ) . asString ( ) ) ; return restoredFolder . new Info ( responseJSON ) ; } | Restores a trashed folder back to its original location . | 179 | 12 |
150,228 | public BoxFolder . Info restoreFolder ( String folderID , String newName , String newParentID ) { JsonObject requestJSON = new JsonObject ( ) ; if ( newName != null ) { requestJSON . add ( "name" , newName ) ; } if ( newParentID != null ) { JsonObject parent = new JsonObject ( ) ; parent . add ( "id" , newParentID ) ; requestJSON . add ( "parent" , parent ) ; } URL url = RESTORE_FOLDER_URL_TEMPLATE . build ( this . api . getBaseURL ( ) , folderID ) ; BoxJSONRequest request = new BoxJSONRequest ( this . api , url , "POST" ) ; request . setBody ( requestJSON . toString ( ) ) ; BoxJSONResponse response = ( BoxJSONResponse ) request . send ( ) ; JsonObject responseJSON = JsonObject . readFrom ( response . getJSON ( ) ) ; BoxFolder restoredFolder = new BoxFolder ( this . api , responseJSON . get ( "id" ) . asString ( ) ) ; return restoredFolder . new Info ( responseJSON ) ; } | Restores a trashed folder to a new location with a new name . | 250 | 15 |
150,229 | public void deleteFile ( String fileID ) { URL url = FILE_INFO_URL_TEMPLATE . build ( this . api . getBaseURL ( ) , fileID ) ; BoxAPIRequest request = new BoxAPIRequest ( this . api , url , "DELETE" ) ; BoxAPIResponse response = request . send ( ) ; response . disconnect ( ) ; } | Permanently deletes a trashed file . | 83 | 10 |
150,230 | public BoxFile . Info getFileInfo ( String fileID ) { URL url = FILE_INFO_URL_TEMPLATE . build ( this . api . getBaseURL ( ) , fileID ) ; BoxAPIRequest request = new BoxAPIRequest ( this . api , url , "GET" ) ; BoxJSONResponse response = ( BoxJSONResponse ) request . send ( ) ; JsonObject jsonObject = JsonObject . readFrom ( response . getJSON ( ) ) ; BoxFile file = new BoxFile ( this . api , jsonObject . get ( "id" ) . asString ( ) ) ; return file . new Info ( response . getJSON ( ) ) ; } | Gets information about a trashed file . | 145 | 9 |
150,231 | public BoxFile . Info getFileInfo ( String fileID , String ... fields ) { String queryString = new QueryStringBuilder ( ) . appendParam ( "fields" , fields ) . toString ( ) ; URL url = FILE_INFO_URL_TEMPLATE . buildWithQuery ( this . api . getBaseURL ( ) , queryString , fileID ) ; BoxAPIRequest request = new BoxAPIRequest ( this . api , url , "GET" ) ; BoxJSONResponse response = ( BoxJSONResponse ) request . send ( ) ; JsonObject jsonObject = JsonObject . readFrom ( response . getJSON ( ) ) ; BoxFile file = new BoxFile ( this . api , jsonObject . get ( "id" ) . asString ( ) ) ; return file . new Info ( response . getJSON ( ) ) ; } | Gets information about a trashed file that s limited to a list of specified fields . | 180 | 18 |
150,232 | public BoxFile . Info restoreFile ( String fileID ) { URL url = RESTORE_FILE_URL_TEMPLATE . build ( this . api . getBaseURL ( ) , fileID ) ; BoxAPIRequest request = new BoxAPIRequest ( this . api , url , "POST" ) ; JsonObject requestJSON = new JsonObject ( ) . add ( "" , "" ) ; request . setBody ( requestJSON . toString ( ) ) ; BoxJSONResponse response = ( BoxJSONResponse ) request . send ( ) ; JsonObject responseJSON = JsonObject . readFrom ( response . getJSON ( ) ) ; BoxFile restoredFile = new BoxFile ( this . api , responseJSON . get ( "id" ) . asString ( ) ) ; return restoredFile . new Info ( responseJSON ) ; } | Restores a trashed file back to its original location . | 177 | 12 |
150,233 | public BoxFile . Info restoreFile ( String fileID , String newName , String newParentID ) { JsonObject requestJSON = new JsonObject ( ) ; if ( newName != null ) { requestJSON . add ( "name" , newName ) ; } if ( newParentID != null ) { JsonObject parent = new JsonObject ( ) ; parent . add ( "id" , newParentID ) ; requestJSON . add ( "parent" , parent ) ; } URL url = RESTORE_FILE_URL_TEMPLATE . build ( this . api . getBaseURL ( ) , fileID ) ; BoxJSONRequest request = new BoxJSONRequest ( this . api , url , "POST" ) ; request . setBody ( requestJSON . toString ( ) ) ; BoxJSONResponse response = ( BoxJSONResponse ) request . send ( ) ; JsonObject responseJSON = JsonObject . readFrom ( response . getJSON ( ) ) ; BoxFile restoredFile = new BoxFile ( this . api , responseJSON . get ( "id" ) . asString ( ) ) ; return restoredFile . new Info ( responseJSON ) ; } | Restores a trashed file to a new location with a new name . | 248 | 15 |
150,234 | public Iterator < BoxItem . Info > iterator ( ) { URL url = GET_ITEMS_URL . build ( this . api . getBaseURL ( ) ) ; return new BoxItemIterator ( this . api , url ) ; } | Returns an iterator over the items in the trash . | 50 | 10 |
150,235 | public static MetadataTemplate createMetadataTemplate ( BoxAPIConnection api , String scope , String templateKey , String displayName , boolean hidden , List < Field > fields ) { JsonObject jsonObject = new JsonObject ( ) ; jsonObject . add ( "scope" , scope ) ; jsonObject . add ( "displayName" , displayName ) ; jsonObject . add ( "hidden" , hidden ) ; if ( templateKey != null ) { jsonObject . add ( "templateKey" , templateKey ) ; } JsonArray fieldsArray = new JsonArray ( ) ; if ( fields != null && ! fields . isEmpty ( ) ) { for ( Field field : fields ) { JsonObject fieldObj = getFieldJsonObject ( field ) ; fieldsArray . add ( fieldObj ) ; } jsonObject . add ( "fields" , fieldsArray ) ; } URL url = METADATA_TEMPLATE_SCHEMA_URL_TEMPLATE . build ( api . getBaseURL ( ) ) ; BoxJSONRequest request = new BoxJSONRequest ( api , url , "POST" ) ; request . setBody ( jsonObject . toString ( ) ) ; BoxJSONResponse response = ( BoxJSONResponse ) request . send ( ) ; JsonObject responseJSON = JsonObject . readFrom ( response . getJSON ( ) ) ; return new MetadataTemplate ( responseJSON ) ; } | Creates new metadata template . | 303 | 6 |
150,236 | private static JsonObject getFieldJsonObject ( Field field ) { JsonObject fieldObj = new JsonObject ( ) ; fieldObj . add ( "type" , field . getType ( ) ) ; fieldObj . add ( "key" , field . getKey ( ) ) ; fieldObj . add ( "displayName" , field . getDisplayName ( ) ) ; String fieldDesc = field . getDescription ( ) ; if ( fieldDesc != null ) { fieldObj . add ( "description" , field . getDescription ( ) ) ; } Boolean fieldIsHidden = field . getIsHidden ( ) ; if ( fieldIsHidden != null ) { fieldObj . add ( "hidden" , field . getIsHidden ( ) ) ; } JsonArray array = new JsonArray ( ) ; List < String > options = field . getOptions ( ) ; if ( options != null && ! options . isEmpty ( ) ) { for ( String option : options ) { JsonObject optionObj = new JsonObject ( ) ; optionObj . add ( "key" , option ) ; array . add ( optionObj ) ; } fieldObj . add ( "options" , array ) ; } return fieldObj ; } | Gets the JsonObject representation of the given field object . | 259 | 13 |
150,237 | public static MetadataTemplate updateMetadataTemplate ( BoxAPIConnection api , String scope , String template , List < FieldOperation > fieldOperations ) { JsonArray array = new JsonArray ( ) ; for ( FieldOperation fieldOperation : fieldOperations ) { JsonObject jsonObject = getFieldOperationJsonObject ( fieldOperation ) ; array . add ( jsonObject ) ; } QueryStringBuilder builder = new QueryStringBuilder ( ) ; URL url = METADATA_TEMPLATE_URL_TEMPLATE . build ( api . getBaseURL ( ) , scope , template ) ; BoxJSONRequest request = new BoxJSONRequest ( api , url , "PUT" ) ; request . setBody ( array . toString ( ) ) ; BoxJSONResponse response = ( BoxJSONResponse ) request . send ( ) ; JsonObject responseJson = JsonObject . readFrom ( response . getJSON ( ) ) ; return new MetadataTemplate ( responseJson ) ; } | Updates the schema of an existing metadata template . | 212 | 10 |
150,238 | public static void deleteMetadataTemplate ( BoxAPIConnection api , String scope , String template ) { URL url = METADATA_TEMPLATE_URL_TEMPLATE . build ( api . getBaseURL ( ) , scope , template ) ; BoxJSONRequest request = new BoxJSONRequest ( api , url , "DELETE" ) ; request . send ( ) ; } | Deletes the schema of an existing metadata template . | 85 | 10 |
150,239 | private static JsonObject getFieldOperationJsonObject ( FieldOperation fieldOperation ) { JsonObject jsonObject = new JsonObject ( ) ; jsonObject . add ( "op" , fieldOperation . getOp ( ) . toString ( ) ) ; String fieldKey = fieldOperation . getFieldKey ( ) ; if ( fieldKey != null ) { jsonObject . add ( "fieldKey" , fieldKey ) ; } Field field = fieldOperation . getData ( ) ; if ( field != null ) { JsonObject fieldObj = new JsonObject ( ) ; String type = field . getType ( ) ; if ( type != null ) { fieldObj . add ( "type" , type ) ; } String key = field . getKey ( ) ; if ( key != null ) { fieldObj . add ( "key" , key ) ; } String displayName = field . getDisplayName ( ) ; if ( displayName != null ) { fieldObj . add ( "displayName" , displayName ) ; } String description = field . getDescription ( ) ; if ( description != null ) { fieldObj . add ( "description" , description ) ; } Boolean hidden = field . getIsHidden ( ) ; if ( hidden != null ) { fieldObj . add ( "hidden" , hidden ) ; } List < String > options = field . getOptions ( ) ; if ( options != null ) { JsonArray array = new JsonArray ( ) ; for ( String option : options ) { JsonObject optionObj = new JsonObject ( ) ; optionObj . add ( "key" , option ) ; array . add ( optionObj ) ; } fieldObj . add ( "options" , array ) ; } jsonObject . add ( "data" , fieldObj ) ; } List < String > fieldKeys = fieldOperation . getFieldKeys ( ) ; if ( fieldKeys != null ) { jsonObject . add ( "fieldKeys" , getJsonArray ( fieldKeys ) ) ; } List < String > enumOptionKeys = fieldOperation . getEnumOptionKeys ( ) ; if ( enumOptionKeys != null ) { jsonObject . add ( "enumOptionKeys" , getJsonArray ( enumOptionKeys ) ) ; } String enumOptionKey = fieldOperation . getEnumOptionKey ( ) ; if ( enumOptionKey != null ) { jsonObject . add ( "enumOptionKey" , enumOptionKey ) ; } String multiSelectOptionKey = fieldOperation . getMultiSelectOptionKey ( ) ; if ( multiSelectOptionKey != null ) { jsonObject . add ( "multiSelectOptionKey" , multiSelectOptionKey ) ; } List < String > multiSelectOptionKeys = fieldOperation . getMultiSelectOptionKeys ( ) ; if ( multiSelectOptionKeys != null ) { jsonObject . add ( "multiSelectOptionKeys" , getJsonArray ( multiSelectOptionKeys ) ) ; } return jsonObject ; } | Gets the JsonObject representation of the Field Operation . | 622 | 12 |
150,240 | private static JsonArray getJsonArray ( List < String > keys ) { JsonArray array = new JsonArray ( ) ; for ( String key : keys ) { array . add ( key ) ; } return array ; } | Gets the Json Array representation of the given list of strings . | 49 | 14 |
150,241 | public static MetadataTemplate getMetadataTemplateByID ( BoxAPIConnection api , String templateID ) { URL url = METADATA_TEMPLATE_BY_ID_URL_TEMPLATE . build ( api . getBaseURL ( ) , templateID ) ; BoxAPIRequest request = new BoxAPIRequest ( api , url , "GET" ) ; BoxJSONResponse response = ( BoxJSONResponse ) request . send ( ) ; return new MetadataTemplate ( response . getJSON ( ) ) ; } | Geta the specified metadata template by its ID . | 112 | 10 |
150,242 | public boolean clearParameters ( ) { this . query = null ; this . fields = null ; this . scope = null ; this . fileExtensions = null ; this . createdRange = null ; this . updatedRange = null ; this . sizeRange = null ; this . ownerUserIds = null ; this . ancestorFolderIds = null ; this . contentTypes = null ; this . type = null ; this . trashContent = null ; this . metadataFilter = null ; this . sort = null ; this . direction = null ; return true ; } | Clears the Parameters before performing a new search . | 115 | 10 |
150,243 | private boolean isNullOrEmpty ( Object paramValue ) { boolean isNullOrEmpty = false ; if ( paramValue == null ) { isNullOrEmpty = true ; } if ( paramValue instanceof String ) { if ( ( ( String ) paramValue ) . trim ( ) . equalsIgnoreCase ( "" ) ) { isNullOrEmpty = true ; } } else if ( paramValue instanceof List ) { return ( ( List ) paramValue ) . isEmpty ( ) ; } return isNullOrEmpty ; } | Checks String to see if the parameter is null . | 109 | 11 |
150,244 | private JsonArray formatBoxMetadataFilterRequest ( ) { JsonArray boxMetadataFilterRequestArray = new JsonArray ( ) ; JsonObject boxMetadataFilter = new JsonObject ( ) . add ( "templateKey" , this . metadataFilter . getTemplateKey ( ) ) . add ( "scope" , this . metadataFilter . getScope ( ) ) . add ( "filters" , this . metadataFilter . getFiltersList ( ) ) ; boxMetadataFilterRequestArray . add ( boxMetadataFilter ) ; return boxMetadataFilterRequestArray ; } | Add BoxMetaDataFilter to the JsonArray boxMetadataFilterRequestArray . | 125 | 17 |
150,245 | private String listToCSV ( List < String > list ) { String csvStr = "" ; for ( String item : list ) { csvStr += "," + item ; } return csvStr . length ( ) > 1 ? csvStr . substring ( 1 ) : csvStr ; } | Concat a List into a CSV String . | 65 | 9 |
150,246 | public QueryStringBuilder getQueryParameters ( ) { QueryStringBuilder builder = new QueryStringBuilder ( ) ; if ( this . isNullOrEmpty ( this . query ) && this . metadataFilter == null ) { throw new BoxAPIException ( "BoxSearchParameters requires either a search query or Metadata filter to be set." ) ; } //Set the query of the search if ( ! this . isNullOrEmpty ( this . query ) ) { builder . appendParam ( "query" , this . query ) ; } //Set the scope of the search if ( ! this . isNullOrEmpty ( this . scope ) ) { builder . appendParam ( "scope" , this . scope ) ; } //Acceptable Value: "jpg,png" if ( ! this . isNullOrEmpty ( this . fileExtensions ) ) { builder . appendParam ( "file_extensions" , this . listToCSV ( this . fileExtensions ) ) ; } //Created Date Range: From Date - To Date if ( ( this . createdRange != null ) ) { builder . appendParam ( "created_at_range" , this . createdRange . buildRangeString ( ) ) ; } //Updated Date Range: From Date - To Date if ( ( this . updatedRange != null ) ) { builder . appendParam ( "updated_at_range" , this . updatedRange . buildRangeString ( ) ) ; } //Filesize Range if ( ( this . sizeRange != null ) ) { builder . appendParam ( "size_range" , this . sizeRange . buildRangeString ( ) ) ; } //Owner Id's if ( ! this . isNullOrEmpty ( this . ownerUserIds ) ) { builder . appendParam ( "owner_user_ids" , this . listToCSV ( this . ownerUserIds ) ) ; } //Ancestor ID's if ( ! this . isNullOrEmpty ( this . ancestorFolderIds ) ) { builder . appendParam ( "ancestor_folder_ids" , this . listToCSV ( this . ancestorFolderIds ) ) ; } //Content Types: "name, description" if ( ! this . isNullOrEmpty ( this . contentTypes ) ) { builder . appendParam ( "content_types" , this . listToCSV ( this . contentTypes ) ) ; } //Type of File: "file,folder,web_link" if ( this . type != null ) { builder . appendParam ( "type" , this . type ) ; } //Trash Content if ( ! this . isNullOrEmpty ( this . trashContent ) ) { builder . appendParam ( "trash_content" , this . trashContent ) ; } //Metadata filters if ( this . metadataFilter != null ) { builder . appendParam ( "mdfilters" , this . formatBoxMetadataFilterRequest ( ) . toString ( ) ) ; } //Fields if ( ! this . isNullOrEmpty ( this . fields ) ) { builder . appendParam ( "fields" , this . listToCSV ( this . fields ) ) ; } //Sort if ( ! this . isNullOrEmpty ( this . sort ) ) { builder . appendParam ( "sort" , this . sort ) ; } //Direction if ( ! this . isNullOrEmpty ( this . direction ) ) { builder . appendParam ( "direction" , this . direction ) ; } return builder ; } | Get the Query Paramaters to be used for search request . | 735 | 12 |
150,247 | public JsonObject getJsonObject ( ) { JsonObject obj = new JsonObject ( ) ; obj . add ( "field" , this . field ) ; obj . add ( "value" , this . value ) ; return obj ; } | Get the JSON representation of the metadata field filter . | 53 | 10 |
150,248 | public static BoxAPIConnection restore ( String clientID , String clientSecret , String state ) { BoxAPIConnection api = new BoxAPIConnection ( clientID , clientSecret ) ; api . restore ( state ) ; return api ; } | Restores a BoxAPIConnection from a saved state . | 56 | 14 |
150,249 | public static URL getAuthorizationURL ( String clientID , URI redirectUri , String state , List < String > scopes ) { URLTemplate template = new URLTemplate ( AUTHORIZATION_URL ) ; QueryStringBuilder queryBuilder = new QueryStringBuilder ( ) . appendParam ( "client_id" , clientID ) . appendParam ( "response_type" , "code" ) . appendParam ( "redirect_uri" , redirectUri . toString ( ) ) . appendParam ( "state" , state ) ; if ( scopes != null && ! scopes . isEmpty ( ) ) { StringBuilder builder = new StringBuilder ( ) ; int size = scopes . size ( ) - 1 ; int i = 0 ; while ( i < size ) { builder . append ( scopes . get ( i ) ) ; builder . append ( " " ) ; i ++ ; } builder . append ( scopes . get ( i ) ) ; queryBuilder . appendParam ( "scope" , builder . toString ( ) ) ; } return template . buildWithQuery ( "" , queryBuilder . toString ( ) ) ; } | Return the authorization URL which is used to perform the authorization_code based OAuth2 flow . | 240 | 19 |
150,250 | public void authenticate ( String authCode ) { URL url = null ; try { url = new URL ( this . tokenURL ) ; } catch ( MalformedURLException e ) { assert false : "An invalid token URL indicates a bug in the SDK." ; throw new RuntimeException ( "An invalid token URL indicates a bug in the SDK." , e ) ; } String urlParameters = String . format ( "grant_type=authorization_code&code=%s&client_id=%s&client_secret=%s" , authCode , this . clientID , this . clientSecret ) ; BoxAPIRequest request = new BoxAPIRequest ( this , url , "POST" ) ; request . shouldAuthenticate ( false ) ; request . setBody ( urlParameters ) ; BoxJSONResponse response = ( BoxJSONResponse ) request . send ( ) ; String json = response . getJSON ( ) ; JsonObject jsonObject = JsonObject . readFrom ( json ) ; this . accessToken = jsonObject . get ( "access_token" ) . asString ( ) ; this . refreshToken = jsonObject . get ( "refresh_token" ) . asString ( ) ; this . lastRefresh = System . currentTimeMillis ( ) ; this . expires = jsonObject . get ( "expires_in" ) . asLong ( ) * 1000 ; } | Authenticates the API connection by obtaining access and refresh tokens using the auth code that was obtained from the first half of OAuth . | 295 | 26 |
150,251 | public boolean needsRefresh ( ) { boolean needsRefresh ; this . refreshLock . readLock ( ) . lock ( ) ; long now = System . currentTimeMillis ( ) ; long tokenDuration = ( now - this . lastRefresh ) ; needsRefresh = ( tokenDuration >= this . expires - REFRESH_EPSILON ) ; this . refreshLock . readLock ( ) . unlock ( ) ; return needsRefresh ; } | Determines if this connection s access token has expired and needs to be refreshed . | 95 | 17 |
150,252 | public void refresh ( ) { this . refreshLock . writeLock ( ) . lock ( ) ; if ( ! this . canRefresh ( ) ) { this . refreshLock . writeLock ( ) . unlock ( ) ; throw new IllegalStateException ( "The BoxAPIConnection cannot be refreshed because it doesn't have a " + "refresh token." ) ; } URL url = null ; try { url = new URL ( this . tokenURL ) ; } catch ( MalformedURLException e ) { this . refreshLock . writeLock ( ) . unlock ( ) ; assert false : "An invalid refresh URL indicates a bug in the SDK." ; throw new RuntimeException ( "An invalid refresh URL indicates a bug in the SDK." , e ) ; } String urlParameters = String . format ( "grant_type=refresh_token&refresh_token=%s&client_id=%s&client_secret=%s" , this . refreshToken , this . clientID , this . clientSecret ) ; BoxAPIRequest request = new BoxAPIRequest ( this , url , "POST" ) ; request . shouldAuthenticate ( false ) ; request . setBody ( urlParameters ) ; String json ; try { BoxJSONResponse response = ( BoxJSONResponse ) request . send ( ) ; json = response . getJSON ( ) ; } catch ( BoxAPIException e ) { this . notifyError ( e ) ; this . refreshLock . writeLock ( ) . unlock ( ) ; throw e ; } JsonObject jsonObject = JsonObject . readFrom ( json ) ; this . accessToken = jsonObject . get ( "access_token" ) . asString ( ) ; this . refreshToken = jsonObject . get ( "refresh_token" ) . asString ( ) ; this . lastRefresh = System . currentTimeMillis ( ) ; this . expires = jsonObject . get ( "expires_in" ) . asLong ( ) * 1000 ; this . notifyRefresh ( ) ; this . refreshLock . writeLock ( ) . unlock ( ) ; } | Refresh s this connection s access token using its refresh token . | 444 | 13 |
150,253 | public void restore ( String state ) { JsonObject json = JsonObject . readFrom ( state ) ; String accessToken = json . get ( "accessToken" ) . asString ( ) ; String refreshToken = json . get ( "refreshToken" ) . asString ( ) ; long lastRefresh = json . get ( "lastRefresh" ) . asLong ( ) ; long expires = json . get ( "expires" ) . asLong ( ) ; String userAgent = json . get ( "userAgent" ) . asString ( ) ; String tokenURL = json . get ( "tokenURL" ) . asString ( ) ; String baseURL = json . get ( "baseURL" ) . asString ( ) ; String baseUploadURL = json . get ( "baseUploadURL" ) . asString ( ) ; boolean autoRefresh = json . get ( "autoRefresh" ) . asBoolean ( ) ; int maxRequestAttempts = json . get ( "maxRequestAttempts" ) . asInt ( ) ; this . accessToken = accessToken ; this . refreshToken = refreshToken ; this . lastRefresh = lastRefresh ; this . expires = expires ; this . userAgent = userAgent ; this . tokenURL = tokenURL ; this . baseURL = baseURL ; this . baseUploadURL = baseUploadURL ; this . autoRefresh = autoRefresh ; this . maxRequestAttempts = maxRequestAttempts ; } | Restores a saved connection state into this BoxAPIConnection . | 309 | 15 |
150,254 | public ScopedToken getLowerScopedToken ( List < String > scopes , String resource ) { assert ( scopes != null ) ; assert ( scopes . size ( ) > 0 ) ; URL url = null ; try { url = new URL ( this . getTokenURL ( ) ) ; } catch ( MalformedURLException e ) { assert false : "An invalid refresh URL indicates a bug in the SDK." ; throw new RuntimeException ( "An invalid refresh URL indicates a bug in the SDK." , e ) ; } StringBuilder spaceSeparatedScopes = new StringBuilder ( ) ; for ( int i = 0 ; i < scopes . size ( ) ; i ++ ) { spaceSeparatedScopes . append ( scopes . get ( i ) ) ; if ( i < scopes . size ( ) - 1 ) { spaceSeparatedScopes . append ( " " ) ; } } String urlParameters = null ; if ( resource != null ) { //this.getAccessToken() ensures we have a valid access token urlParameters = String . format ( "grant_type=urn:ietf:params:oauth:grant-type:token-exchange" + "&subject_token_type=urn:ietf:params:oauth:token-type:access_token&subject_token=%s" + "&scope=%s&resource=%s" , this . getAccessToken ( ) , spaceSeparatedScopes , resource ) ; } else { //this.getAccessToken() ensures we have a valid access token urlParameters = String . format ( "grant_type=urn:ietf:params:oauth:grant-type:token-exchange" + "&subject_token_type=urn:ietf:params:oauth:token-type:access_token&subject_token=%s" + "&scope=%s" , this . getAccessToken ( ) , spaceSeparatedScopes ) ; } BoxAPIRequest request = new BoxAPIRequest ( this , url , "POST" ) ; request . shouldAuthenticate ( false ) ; request . setBody ( urlParameters ) ; String json ; try { BoxJSONResponse response = ( BoxJSONResponse ) request . send ( ) ; json = response . getJSON ( ) ; } catch ( BoxAPIException e ) { this . notifyError ( e ) ; throw e ; } JsonObject jsonObject = JsonObject . readFrom ( json ) ; ScopedToken token = new ScopedToken ( jsonObject ) ; token . setObtainedAt ( System . currentTimeMillis ( ) ) ; token . setExpiresIn ( jsonObject . get ( "expires_in" ) . asLong ( ) * 1000 ) ; return token ; } | Get a lower - scoped token restricted to a resource for the list of scopes that are passed . | 597 | 21 |
150,255 | public String save ( ) { JsonObject state = new JsonObject ( ) . add ( "accessToken" , this . accessToken ) . add ( "refreshToken" , this . refreshToken ) . add ( "lastRefresh" , this . lastRefresh ) . add ( "expires" , this . expires ) . add ( "userAgent" , this . userAgent ) . add ( "tokenURL" , this . tokenURL ) . add ( "baseURL" , this . baseURL ) . add ( "baseUploadURL" , this . baseUploadURL ) . add ( "autoRefresh" , this . autoRefresh ) . add ( "maxRequestAttempts" , this . maxRequestAttempts ) ; return state . toString ( ) ; } | Saves the state of this connection to a string so that it can be persisted and restored at a later time . | 165 | 23 |
150,256 | public Info getInfo ( String ... fields ) { QueryStringBuilder builder = new QueryStringBuilder ( ) ; if ( fields . length > 0 ) { builder . appendParam ( "fields" , fields ) ; } URL url = DEVICE_PIN_URL_TEMPLATE . buildWithQuery ( this . getAPI ( ) . getBaseURL ( ) , builder . toString ( ) , this . getID ( ) ) ; BoxAPIRequest request = new BoxAPIRequest ( this . getAPI ( ) , url , "GET" ) ; BoxJSONResponse response = ( BoxJSONResponse ) request . send ( ) ; JsonObject responseJSON = JsonObject . readFrom ( response . getJSON ( ) ) ; return new Info ( responseJSON ) ; } | Gets information about the device pin . | 161 | 8 |
150,257 | public void delete ( ) { URL url = DEVICE_PIN_URL_TEMPLATE . build ( this . getAPI ( ) . getBaseURL ( ) , this . getID ( ) ) ; BoxAPIRequest request = new BoxAPIRequest ( this . getAPI ( ) , url , "DELETE" ) ; BoxAPIResponse response = request . send ( ) ; response . disconnect ( ) ; } | Deletes the device pin . | 90 | 6 |
150,258 | public void forceApply ( String conflictResolution ) { URL url = FORCE_METADATA_CASCADE_POLICIES_URL_TEMPLATE . build ( this . getAPI ( ) . getBaseURL ( ) , this . getID ( ) ) ; BoxJSONRequest request = new BoxJSONRequest ( this . getAPI ( ) , url , "POST" ) ; JsonObject requestJSON = new JsonObject ( ) . add ( "conflict_resolution" , conflictResolution ) ; request . setBody ( requestJSON . toString ( ) ) ; request . send ( ) ; } | If a policy already exists on a folder this will apply that policy to all existing files and sub folders within the target folder . | 131 | 25 |
150,259 | public BoxTaskAssignment . Info addAssignment ( BoxUser assignTo ) { JsonObject taskJSON = new JsonObject ( ) ; taskJSON . add ( "type" , "task" ) ; taskJSON . add ( "id" , this . getID ( ) ) ; JsonObject assignToJSON = new JsonObject ( ) ; assignToJSON . add ( "id" , assignTo . getID ( ) ) ; JsonObject requestJSON = new JsonObject ( ) ; requestJSON . add ( "task" , taskJSON ) ; requestJSON . add ( "assign_to" , assignToJSON ) ; URL url = ADD_TASK_ASSIGNMENT_URL_TEMPLATE . build ( this . getAPI ( ) . getBaseURL ( ) ) ; BoxJSONRequest request = new BoxJSONRequest ( this . getAPI ( ) , url , "POST" ) ; request . setBody ( requestJSON . toString ( ) ) ; BoxJSONResponse response = ( BoxJSONResponse ) request . send ( ) ; JsonObject responseJSON = JsonObject . readFrom ( response . getJSON ( ) ) ; BoxTaskAssignment addedAssignment = new BoxTaskAssignment ( this . getAPI ( ) , responseJSON . get ( "id" ) . asString ( ) ) ; return addedAssignment . new Info ( responseJSON ) ; } | Adds a new assignment to this task . | 298 | 8 |
150,260 | public List < BoxTaskAssignment . Info > getAssignments ( ) { URL url = GET_ASSIGNMENTS_URL_TEMPLATE . build ( this . getAPI ( ) . getBaseURL ( ) , this . getID ( ) ) ; BoxAPIRequest request = new BoxAPIRequest ( this . getAPI ( ) , url , "GET" ) ; BoxJSONResponse response = ( BoxJSONResponse ) request . send ( ) ; JsonObject responseJSON = JsonObject . readFrom ( response . getJSON ( ) ) ; int totalCount = responseJSON . get ( "total_count" ) . asInt ( ) ; List < BoxTaskAssignment . Info > assignments = new ArrayList < BoxTaskAssignment . Info > ( totalCount ) ; JsonArray entries = responseJSON . get ( "entries" ) . asArray ( ) ; for ( JsonValue value : entries ) { JsonObject assignmentJSON = value . asObject ( ) ; BoxTaskAssignment assignment = new BoxTaskAssignment ( this . getAPI ( ) , assignmentJSON . get ( "id" ) . asString ( ) ) ; BoxTaskAssignment . Info info = assignment . new Info ( assignmentJSON ) ; assignments . add ( info ) ; } return assignments ; } | Gets any assignments for this task . | 273 | 8 |
150,261 | public Iterable < BoxTaskAssignment . Info > getAllAssignments ( String ... fields ) { final QueryStringBuilder builder = new QueryStringBuilder ( ) ; if ( fields . length > 0 ) { builder . appendParam ( "fields" , fields ) ; } return new Iterable < BoxTaskAssignment . Info > ( ) { public Iterator < BoxTaskAssignment . Info > iterator ( ) { URL url = GET_ASSIGNMENTS_URL_TEMPLATE . buildWithQuery ( BoxTask . this . getAPI ( ) . getBaseURL ( ) , builder . toString ( ) , BoxTask . this . getID ( ) ) ; return new BoxTaskAssignmentIterator ( BoxTask . this . getAPI ( ) , url ) ; } } ; } | Gets an iterable of all the assignments of this task . | 166 | 13 |
150,262 | public String getPendingChanges ( ) { JsonObject jsonObject = this . getPendingJSONObject ( ) ; if ( jsonObject == null ) { return null ; } return jsonObject . toString ( ) ; } | Gets a JSON string containing any pending changes to this object that can be sent back to the Box API . | 47 | 22 |
150,263 | void update ( JsonObject jsonObject ) { for ( JsonObject . Member member : jsonObject ) { if ( member . getValue ( ) . isNull ( ) ) { continue ; } this . parseJSONMember ( member ) ; } this . clearPendingChanges ( ) ; } | Updates this BoxJSONObject using the information in a JSON object . | 61 | 14 |
150,264 | private JsonObject getPendingJSONObject ( ) { for ( Map . Entry < String , BoxJSONObject > entry : this . children . entrySet ( ) ) { BoxJSONObject child = entry . getValue ( ) ; JsonObject jsonObject = child . getPendingJSONObject ( ) ; if ( jsonObject != null ) { if ( this . pendingChanges == null ) { this . pendingChanges = new JsonObject ( ) ; } this . pendingChanges . set ( entry . getKey ( ) , jsonObject ) ; } } return this . pendingChanges ; } | Gets a JsonObject containing any pending changes to this object that can be sent back to the Box API . | 122 | 23 |
150,265 | public void addHeader ( String key , String value ) { if ( key . equals ( "As-User" ) ) { for ( int i = 0 ; i < this . headers . size ( ) ; i ++ ) { if ( this . headers . get ( i ) . getKey ( ) . equals ( "As-User" ) ) { this . headers . remove ( i ) ; } } } if ( key . equals ( "X-Box-UA" ) ) { throw new IllegalArgumentException ( "Altering the X-Box-UA header is not permitted" ) ; } this . headers . add ( new RequestHeader ( key , value ) ) ; } | Adds an HTTP header to this request . | 142 | 8 |
150,266 | public void setBody ( String body ) { byte [ ] bytes = body . getBytes ( StandardCharsets . UTF_8 ) ; this . bodyLength = bytes . length ; this . body = new ByteArrayInputStream ( bytes ) ; } | Sets the request body to the contents of a String . | 52 | 12 |
150,267 | public BoxAPIResponse send ( ProgressListener listener ) { if ( this . api == null ) { this . backoffCounter . reset ( BoxGlobalSettings . getMaxRequestAttempts ( ) ) ; } else { this . backoffCounter . reset ( this . api . getMaxRequestAttempts ( ) ) ; } while ( this . backoffCounter . getAttemptsRemaining ( ) > 0 ) { try { return this . trySend ( listener ) ; } catch ( BoxAPIException apiException ) { if ( ! this . backoffCounter . decrement ( ) || ! isResponseRetryable ( apiException . getResponseCode ( ) ) ) { throw apiException ; } try { this . resetBody ( ) ; } catch ( IOException ioException ) { throw apiException ; } try { this . backoffCounter . waitBackoff ( ) ; } catch ( InterruptedException interruptedException ) { Thread . currentThread ( ) . interrupt ( ) ; throw apiException ; } } } throw new RuntimeException ( ) ; } | Sends this request while monitoring its progress and returns a BoxAPIResponse containing the server s response . | 215 | 22 |
150,268 | protected void writeBody ( HttpURLConnection connection , ProgressListener listener ) { if ( this . body == null ) { return ; } connection . setDoOutput ( true ) ; try { OutputStream output = connection . getOutputStream ( ) ; if ( listener != null ) { output = new ProgressOutputStream ( output , listener , this . bodyLength ) ; } int b = this . body . read ( ) ; while ( b != - 1 ) { output . write ( b ) ; b = this . body . read ( ) ; } output . close ( ) ; } catch ( IOException e ) { throw new BoxAPIException ( "Couldn't connect to the Box API due to a network error." , e ) ; } } | Writes the body of this request to an HttpURLConnection . | 154 | 14 |
150,269 | public static BoxLegalHoldPolicy . Info createOngoing ( BoxAPIConnection api , String name , String description ) { URL url = ALL_LEGAL_HOLD_URL_TEMPLATE . build ( api . getBaseURL ( ) ) ; BoxJSONRequest request = new BoxJSONRequest ( api , url , "POST" ) ; JsonObject requestJSON = new JsonObject ( ) . add ( "policy_name" , name ) . add ( "is_ongoing" , true ) ; if ( description != null ) { requestJSON . add ( "description" , description ) ; } request . setBody ( requestJSON . toString ( ) ) ; BoxJSONResponse response = ( BoxJSONResponse ) request . send ( ) ; JsonObject responseJSON = JsonObject . readFrom ( response . getJSON ( ) ) ; BoxLegalHoldPolicy createdPolicy = new BoxLegalHoldPolicy ( api , responseJSON . get ( "id" ) . asString ( ) ) ; return createdPolicy . new Info ( responseJSON ) ; } | Creates a new ongoing Legal Hold Policy . | 227 | 9 |
150,270 | public Iterable < BoxLegalHoldAssignment . Info > getAssignments ( String ... fields ) { return this . getAssignments ( null , null , DEFAULT_LIMIT , fields ) ; } | Returns iterable containing assignments for this single legal hold policy . | 45 | 12 |
150,271 | public Iterable < BoxLegalHoldAssignment . Info > getAssignments ( String type , String id , int limit , String ... fields ) { QueryStringBuilder builder = new QueryStringBuilder ( ) ; if ( type != null ) { builder . appendParam ( "assign_to_type" , type ) ; } if ( id != null ) { builder . appendParam ( "assign_to_id" , id ) ; } if ( fields . length > 0 ) { builder . appendParam ( "fields" , fields ) ; } return new BoxResourceIterable < BoxLegalHoldAssignment . Info > ( this . getAPI ( ) , LEGAL_HOLD_ASSIGNMENTS_URL_TEMPLATE . buildWithQuery ( this . getAPI ( ) . getBaseURL ( ) , builder . toString ( ) , this . getID ( ) ) , limit ) { @ Override protected BoxLegalHoldAssignment . Info factory ( JsonObject jsonObject ) { BoxLegalHoldAssignment assignment = new BoxLegalHoldAssignment ( BoxLegalHoldPolicy . this . getAPI ( ) , jsonObject . get ( "id" ) . asString ( ) ) ; return assignment . new Info ( jsonObject ) ; } } ; } | Returns iterable containing assignments for this single legal hold policy . Parameters can be used to filter retrieved assignments . | 266 | 21 |
150,272 | public Iterable < BoxFileVersionLegalHold . Info > getFileVersionHolds ( int limit , String ... fields ) { QueryStringBuilder queryString = new QueryStringBuilder ( ) . appendParam ( "policy_id" , this . getID ( ) ) ; if ( fields . length > 0 ) { queryString . appendParam ( "fields" , fields ) ; } URL url = LIST_OF_FILE_VERSION_HOLDS_URL_TEMPLATE . buildWithQuery ( getAPI ( ) . getBaseURL ( ) , queryString . toString ( ) ) ; return new BoxResourceIterable < BoxFileVersionLegalHold . Info > ( getAPI ( ) , url , limit ) { @ Override protected BoxFileVersionLegalHold . Info factory ( JsonObject jsonObject ) { BoxFileVersionLegalHold assignment = new BoxFileVersionLegalHold ( getAPI ( ) , jsonObject . get ( "id" ) . asString ( ) ) ; return assignment . new Info ( jsonObject ) ; } } ; } | Returns iterable with all non - deleted file version legal holds for this legal hold policy . | 220 | 18 |
150,273 | public static Iterable < BoxFileVersionRetention . Info > getAll ( BoxAPIConnection api , String ... fields ) { return getRetentions ( api , new QueryFilter ( ) , fields ) ; } | Retrieves all file version retentions . | 47 | 10 |
150,274 | public static Iterable < BoxFileVersionRetention . Info > getRetentions ( final BoxAPIConnection api , QueryFilter filter , String ... fields ) { filter . addFields ( fields ) ; return new BoxResourceIterable < BoxFileVersionRetention . Info > ( api , ALL_RETENTIONS_URL_TEMPLATE . buildWithQuery ( api . getBaseURL ( ) , filter . toString ( ) ) , DEFAULT_LIMIT ) { @ Override protected BoxFileVersionRetention . Info factory ( JsonObject jsonObject ) { BoxFileVersionRetention retention = new BoxFileVersionRetention ( api , jsonObject . get ( "id" ) . asString ( ) ) ; return retention . new Info ( jsonObject ) ; } } ; } | Retrieves all file version retentions matching given filters as an Iterable . | 170 | 17 |
150,275 | public boolean verify ( String signatureVersion , String signatureAlgorithm , String primarySignature , String secondarySignature , String webHookPayload , String deliveryTimestamp ) { // enforce versions supported by this implementation if ( ! SUPPORTED_VERSIONS . contains ( signatureVersion ) ) { return false ; } // enforce algorithms supported by this implementation BoxSignatureAlgorithm algorithm = BoxSignatureAlgorithm . byName ( signatureAlgorithm ) ; if ( ! SUPPORTED_ALGORITHMS . contains ( algorithm ) ) { return false ; } // check primary key signature if primary key exists if ( this . primarySignatureKey != null && this . verify ( this . primarySignatureKey , algorithm , primarySignature , webHookPayload , deliveryTimestamp ) ) { return true ; } // check secondary key signature if secondary key exists if ( this . secondarySignatureKey != null && this . verify ( this . secondarySignatureKey , algorithm , secondarySignature , webHookPayload , deliveryTimestamp ) ) { return true ; } // default strategy is false, to minimize security issues return false ; } | Verifies given web - hook information . | 233 | 8 |
150,276 | private boolean verify ( String key , BoxSignatureAlgorithm actualAlgorithm , String actualSignature , String webHookPayload , String deliveryTimestamp ) { if ( actualSignature == null ) { return false ; } byte [ ] actual = Base64 . decode ( actualSignature ) ; byte [ ] expected = this . signRaw ( actualAlgorithm , key , webHookPayload , deliveryTimestamp ) ; return Arrays . equals ( expected , actual ) ; } | Verifies a provided signature . | 101 | 6 |
150,277 | public PartialCollection < BoxItem . Info > searchRange ( long offset , long limit , final BoxSearchParameters bsp ) { QueryStringBuilder builder = bsp . getQueryParameters ( ) . appendParam ( "limit" , limit ) . appendParam ( "offset" , offset ) ; URL url = SEARCH_URL_TEMPLATE . buildWithQuery ( this . getAPI ( ) . getBaseURL ( ) , builder . toString ( ) ) ; BoxAPIRequest request = new BoxAPIRequest ( this . getAPI ( ) , url , "GET" ) ; BoxJSONResponse response = ( BoxJSONResponse ) request . send ( ) ; JsonObject responseJSON = JsonObject . readFrom ( response . getJSON ( ) ) ; String totalCountString = responseJSON . get ( "total_count" ) . toString ( ) ; long fullSize = Double . valueOf ( totalCountString ) . longValue ( ) ; PartialCollection < BoxItem . Info > results = new PartialCollection < BoxItem . Info > ( offset , limit , fullSize ) ; JsonArray jsonArray = responseJSON . get ( "entries" ) . asArray ( ) ; for ( JsonValue value : jsonArray ) { JsonObject jsonObject = value . asObject ( ) ; BoxItem . Info parsedItemInfo = ( BoxItem . Info ) BoxResource . parseInfo ( this . getAPI ( ) , jsonObject ) ; if ( parsedItemInfo != null ) { results . add ( parsedItemInfo ) ; } } return results ; } | Searches all descendant folders using a given query and query parameters . | 329 | 14 |
150,278 | public static BoxAPIConnection getTransactionConnection ( String accessToken , String scope ) { return BoxTransactionalAPIConnection . getTransactionConnection ( accessToken , scope , null ) ; } | Request a scoped transactional token . | 44 | 8 |
150,279 | public static BoxAPIConnection getTransactionConnection ( String accessToken , String scope , String resource ) { BoxAPIConnection apiConnection = new BoxAPIConnection ( accessToken ) ; URL url ; try { url = new URL ( apiConnection . getTokenURL ( ) ) ; } catch ( MalformedURLException e ) { assert false : "An invalid token URL indicates a bug in the SDK." ; throw new RuntimeException ( "An invalid token URL indicates a bug in the SDK." , e ) ; } String urlParameters ; try { urlParameters = String . format ( "grant_type=%s&subject_token=%s&subject_token_type=%s&scope=%s" , GRANT_TYPE , URLEncoder . encode ( accessToken , "UTF-8" ) , SUBJECT_TOKEN_TYPE , URLEncoder . encode ( scope , "UTF-8" ) ) ; if ( resource != null ) { urlParameters += "&resource=" + URLEncoder . encode ( resource , "UTF-8" ) ; } } catch ( UnsupportedEncodingException e ) { throw new BoxAPIException ( "An error occurred while attempting to encode url parameters for a transactional token request" ) ; } BoxAPIRequest request = new BoxAPIRequest ( apiConnection , url , "POST" ) ; request . shouldAuthenticate ( false ) ; request . setBody ( urlParameters ) ; BoxJSONResponse response = ( BoxJSONResponse ) request . send ( ) ; JsonObject responseJSON = JsonObject . readFrom ( response . getJSON ( ) ) ; final String fileToken = responseJSON . get ( "access_token" ) . asString ( ) ; BoxTransactionalAPIConnection transactionConnection = new BoxTransactionalAPIConnection ( fileToken ) ; transactionConnection . setExpires ( responseJSON . get ( "expires_in" ) . asLong ( ) * 1000 ) ; return transactionConnection ; } | Request a scoped transactional token for a particular resource . | 431 | 12 |
150,280 | public static BoxItem . Info getSharedItem ( BoxAPIConnection api , String sharedLink ) { return getSharedItem ( api , sharedLink , null ) ; } | Gets an item that was shared with a shared link . | 39 | 12 |
150,281 | public static BoxItem . Info getSharedItem ( BoxAPIConnection api , String sharedLink , String password ) { BoxAPIConnection newAPI = new SharedLinkAPIConnection ( api , sharedLink , password ) ; URL url = SHARED_ITEM_URL_TEMPLATE . build ( newAPI . getBaseURL ( ) ) ; BoxAPIRequest request = new BoxAPIRequest ( newAPI , url , "GET" ) ; BoxJSONResponse response = ( BoxJSONResponse ) request . send ( ) ; JsonObject json = JsonObject . readFrom ( response . getJSON ( ) ) ; return ( BoxItem . Info ) BoxResource . parseInfo ( newAPI , json ) ; } | Gets an item that was shared with a password - protected shared link . | 157 | 15 |
150,282 | protected BoxWatermark getWatermark ( URLTemplate itemUrl , String ... fields ) { URL watermarkUrl = itemUrl . build ( this . getAPI ( ) . getBaseURL ( ) , this . getID ( ) ) ; QueryStringBuilder builder = new QueryStringBuilder ( ) ; if ( fields . length > 0 ) { builder . appendParam ( "fields" , fields ) ; } URL url = WATERMARK_URL_TEMPLATE . buildWithQuery ( watermarkUrl . toString ( ) , builder . toString ( ) ) ; BoxAPIRequest request = new BoxAPIRequest ( this . getAPI ( ) , url , "GET" ) ; BoxJSONResponse response = ( BoxJSONResponse ) request . send ( ) ; return new BoxWatermark ( response . getJSON ( ) ) ; } | Used to retrieve the watermark for the item . If the item does not have a watermark applied to it a 404 Not Found will be returned by API . | 174 | 32 |
150,283 | protected BoxWatermark applyWatermark ( URLTemplate itemUrl , String imprint ) { URL watermarkUrl = itemUrl . build ( this . getAPI ( ) . getBaseURL ( ) , this . getID ( ) ) ; URL url = WATERMARK_URL_TEMPLATE . build ( watermarkUrl . toString ( ) ) ; BoxJSONRequest request = new BoxJSONRequest ( this . getAPI ( ) , url , "PUT" ) ; JsonObject body = new JsonObject ( ) . add ( BoxWatermark . WATERMARK_JSON_KEY , new JsonObject ( ) . add ( BoxWatermark . WATERMARK_IMPRINT_JSON_KEY , imprint ) ) ; request . setBody ( body . toString ( ) ) ; BoxJSONResponse response = ( BoxJSONResponse ) request . send ( ) ; return new BoxWatermark ( response . getJSON ( ) ) ; } | Used to apply or update the watermark for the item . | 200 | 12 |
150,284 | protected void removeWatermark ( URLTemplate itemUrl ) { URL watermarkUrl = itemUrl . build ( this . getAPI ( ) . getBaseURL ( ) , this . getID ( ) ) ; URL url = WATERMARK_URL_TEMPLATE . build ( watermarkUrl . toString ( ) ) ; BoxAPIRequest request = new BoxAPIRequest ( this . getAPI ( ) , url , "DELETE" ) ; BoxAPIResponse response = request . send ( ) ; response . disconnect ( ) ; } | Removes a watermark from the item . If the item did not have a watermark applied to it a 404 Not Found will be returned by API . | 116 | 31 |
150,285 | private void parseJSON ( JsonObject jsonObject ) { for ( JsonObject . Member member : jsonObject ) { JsonValue value = member . getValue ( ) ; if ( value . isNull ( ) ) { continue ; } try { String memberName = member . getName ( ) ; if ( memberName . equals ( "id" ) ) { this . versionID = value . asString ( ) ; } else if ( memberName . equals ( "sha1" ) ) { this . sha1 = value . asString ( ) ; } else if ( memberName . equals ( "name" ) ) { this . name = value . asString ( ) ; } else if ( memberName . equals ( "size" ) ) { this . size = Double . valueOf ( value . toString ( ) ) . longValue ( ) ; } else if ( memberName . equals ( "created_at" ) ) { this . createdAt = BoxDateFormat . parse ( value . asString ( ) ) ; } else if ( memberName . equals ( "modified_at" ) ) { this . modifiedAt = BoxDateFormat . parse ( value . asString ( ) ) ; } else if ( memberName . equals ( "trashed_at" ) ) { this . trashedAt = BoxDateFormat . parse ( value . asString ( ) ) ; } else if ( memberName . equals ( "modified_by" ) ) { JsonObject userJSON = value . asObject ( ) ; String userID = userJSON . get ( "id" ) . asString ( ) ; BoxUser user = new BoxUser ( getAPI ( ) , userID ) ; this . modifiedBy = user . new Info ( userJSON ) ; } } catch ( ParseException e ) { assert false : "A ParseException indicates a bug in the SDK." ; } } } | Method used to update fields with values received from API . | 399 | 11 |
150,286 | public void download ( OutputStream output , ProgressListener listener ) { URL url = CONTENT_URL_TEMPLATE . build ( this . getAPI ( ) . getBaseURL ( ) , this . fileID , this . getID ( ) ) ; BoxAPIRequest request = new BoxAPIRequest ( this . getAPI ( ) , url , "GET" ) ; BoxAPIResponse response = request . send ( ) ; InputStream input = response . getBody ( listener ) ; long totalRead = 0 ; byte [ ] buffer = new byte [ BUFFER_SIZE ] ; try { int n = input . read ( buffer ) ; totalRead += n ; while ( n != - 1 ) { output . write ( buffer , 0 , n ) ; n = input . read ( buffer ) ; totalRead += n ; } } catch ( IOException e ) { throw new BoxAPIException ( "Couldn't connect to the Box API due to a network error." , e ) ; } response . disconnect ( ) ; } | Downloads this version of the file to a given OutputStream while reporting the progress to a ProgressListener . | 215 | 21 |
150,287 | public void promote ( ) { URL url = VERSION_URL_TEMPLATE . build ( this . getAPI ( ) . getBaseURL ( ) , this . fileID , "current" ) ; JsonObject jsonObject = new JsonObject ( ) ; jsonObject . add ( "type" , "file_version" ) ; jsonObject . add ( "id" , this . getID ( ) ) ; BoxJSONRequest request = new BoxJSONRequest ( this . getAPI ( ) , url , "POST" ) ; request . setBody ( jsonObject . toString ( ) ) ; BoxJSONResponse response = ( BoxJSONResponse ) request . send ( ) ; this . parseJSON ( JsonObject . readFrom ( response . getJSON ( ) ) ) ; } | Promotes this version of the file to be the latest version . | 166 | 13 |
150,288 | public static BoxUser . Info createAppUser ( BoxAPIConnection api , String name ) { return createAppUser ( api , name , new CreateUserParams ( ) ) ; } | Provisions a new app user in an enterprise using Box Developer Edition . | 41 | 14 |
150,289 | public static BoxUser . Info createAppUser ( BoxAPIConnection api , String name , CreateUserParams params ) { params . setIsPlatformAccessOnly ( true ) ; return createEnterpriseUser ( api , null , name , params ) ; } | Provisions a new app user in an enterprise with additional user information using Box Developer Edition . | 55 | 18 |
150,290 | public static BoxUser . Info createEnterpriseUser ( BoxAPIConnection api , String login , String name ) { return createEnterpriseUser ( api , login , name , null ) ; } | Provisions a new user in an enterprise . | 42 | 9 |
150,291 | public static BoxUser . Info createEnterpriseUser ( BoxAPIConnection api , String login , String name , CreateUserParams params ) { JsonObject requestJSON = new JsonObject ( ) ; requestJSON . add ( "login" , login ) ; requestJSON . add ( "name" , name ) ; if ( params != null ) { if ( params . getRole ( ) != null ) { requestJSON . add ( "role" , params . getRole ( ) . toJSONValue ( ) ) ; } if ( params . getStatus ( ) != null ) { requestJSON . add ( "status" , params . getStatus ( ) . toJSONValue ( ) ) ; } requestJSON . add ( "language" , params . getLanguage ( ) ) ; requestJSON . add ( "is_sync_enabled" , params . getIsSyncEnabled ( ) ) ; requestJSON . add ( "job_title" , params . getJobTitle ( ) ) ; requestJSON . add ( "phone" , params . getPhone ( ) ) ; requestJSON . add ( "address" , params . getAddress ( ) ) ; requestJSON . add ( "space_amount" , params . getSpaceAmount ( ) ) ; requestJSON . add ( "can_see_managed_users" , params . getCanSeeManagedUsers ( ) ) ; requestJSON . add ( "timezone" , params . getTimezone ( ) ) ; requestJSON . add ( "is_exempt_from_device_limits" , params . getIsExemptFromDeviceLimits ( ) ) ; requestJSON . add ( "is_exempt_from_login_verification" , params . getIsExemptFromLoginVerification ( ) ) ; requestJSON . add ( "is_platform_access_only" , params . getIsPlatformAccessOnly ( ) ) ; requestJSON . add ( "external_app_user_id" , params . getExternalAppUserId ( ) ) ; } URL url = USERS_URL_TEMPLATE . build ( api . getBaseURL ( ) ) ; BoxJSONRequest request = new BoxJSONRequest ( api , url , "POST" ) ; request . setBody ( requestJSON . toString ( ) ) ; BoxJSONResponse response = ( BoxJSONResponse ) request . send ( ) ; JsonObject responseJSON = JsonObject . readFrom ( response . getJSON ( ) ) ; BoxUser createdUser = new BoxUser ( api , responseJSON . get ( "id" ) . asString ( ) ) ; return createdUser . new Info ( responseJSON ) ; } | Provisions a new user in an enterprise with additional user information . | 557 | 13 |
150,292 | public static BoxUser getCurrentUser ( BoxAPIConnection api ) { URL url = GET_ME_URL . build ( api . getBaseURL ( ) ) ; BoxAPIRequest request = new BoxAPIRequest ( api , url , "GET" ) ; BoxJSONResponse response = ( BoxJSONResponse ) request . send ( ) ; JsonObject jsonObject = JsonObject . readFrom ( response . getJSON ( ) ) ; return new BoxUser ( api , jsonObject . get ( "id" ) . asString ( ) ) ; } | Gets the current user . | 117 | 6 |
150,293 | public static Iterable < BoxUser . Info > getAllEnterpriseUsers ( final BoxAPIConnection api , final String filterTerm , final String ... fields ) { return getUsersInfoForType ( api , filterTerm , null , null , fields ) ; } | Returns an iterable containing all the enterprise users that matches the filter and specifies which child fields to retrieve from the API . | 56 | 24 |
150,294 | public static Iterable < BoxUser . Info > getAppUsersByExternalAppUserID ( final BoxAPIConnection api , final String externalAppUserId , final String ... fields ) { return getUsersInfoForType ( api , null , null , externalAppUserId , fields ) ; } | Gets any app users that has an exact match with the externalAppUserId term . | 63 | 18 |
150,295 | private static Iterable < BoxUser . Info > getUsersInfoForType ( final BoxAPIConnection api , final String filterTerm , final String userType , final String externalAppUserId , final String ... fields ) { return new Iterable < BoxUser . Info > ( ) { public Iterator < BoxUser . Info > iterator ( ) { QueryStringBuilder builder = new QueryStringBuilder ( ) ; if ( filterTerm != null ) { builder . appendParam ( "filter_term" , filterTerm ) ; } if ( userType != null ) { builder . appendParam ( "user_type" , userType ) ; } if ( externalAppUserId != null ) { builder . appendParam ( "external_app_user_id" , externalAppUserId ) ; } if ( fields . length > 0 ) { builder . appendParam ( "fields" , fields ) ; } URL url = USERS_URL_TEMPLATE . buildWithQuery ( api . getBaseURL ( ) , builder . toString ( ) ) ; return new BoxUserIterator ( api , url ) ; } } ; } | Helper method to abstract out the common logic from the various users methods . | 236 | 14 |
150,296 | public BoxUser . Info getInfo ( String ... fields ) { URL url ; if ( fields . length > 0 ) { String queryString = new QueryStringBuilder ( ) . appendParam ( "fields" , fields ) . toString ( ) ; url = USER_URL_TEMPLATE . buildWithQuery ( this . getAPI ( ) . getBaseURL ( ) , queryString , this . getID ( ) ) ; } else { url = USER_URL_TEMPLATE . build ( this . getAPI ( ) . getBaseURL ( ) , this . getID ( ) ) ; } BoxAPIRequest request = new BoxAPIRequest ( this . getAPI ( ) , url , "GET" ) ; BoxJSONResponse response = ( BoxJSONResponse ) request . send ( ) ; JsonObject jsonObject = JsonObject . readFrom ( response . getJSON ( ) ) ; return new Info ( jsonObject ) ; } | Gets information about this user . | 200 | 7 |
150,297 | public Collection < BoxGroupMembership . Info > getMemberships ( ) { BoxAPIConnection api = this . getAPI ( ) ; URL url = USER_MEMBERSHIPS_URL_TEMPLATE . build ( this . getAPI ( ) . getBaseURL ( ) , this . getID ( ) ) ; BoxAPIRequest request = new BoxAPIRequest ( api , url , "GET" ) ; BoxJSONResponse response = ( BoxJSONResponse ) request . send ( ) ; JsonObject responseJSON = JsonObject . readFrom ( response . getJSON ( ) ) ; int entriesCount = responseJSON . get ( "total_count" ) . asInt ( ) ; Collection < BoxGroupMembership . Info > memberships = new ArrayList < BoxGroupMembership . Info > ( entriesCount ) ; JsonArray entries = responseJSON . get ( "entries" ) . asArray ( ) ; for ( JsonValue entry : entries ) { JsonObject entryObject = entry . asObject ( ) ; BoxGroupMembership membership = new BoxGroupMembership ( api , entryObject . get ( "id" ) . asString ( ) ) ; BoxGroupMembership . Info info = membership . new Info ( entryObject ) ; memberships . add ( info ) ; } return memberships ; } | Gets information about all of the group memberships for this user . Does not support paging . | 284 | 20 |
150,298 | public Iterable < BoxGroupMembership . Info > getAllMemberships ( String ... fields ) { final QueryStringBuilder builder = new QueryStringBuilder ( ) ; if ( fields . length > 0 ) { builder . appendParam ( "fields" , fields ) ; } return new Iterable < BoxGroupMembership . Info > ( ) { public Iterator < BoxGroupMembership . Info > iterator ( ) { URL url = USER_MEMBERSHIPS_URL_TEMPLATE . buildWithQuery ( BoxUser . this . getAPI ( ) . getBaseURL ( ) , builder . toString ( ) , BoxUser . this . getID ( ) ) ; return new BoxGroupMembershipIterator ( BoxUser . this . getAPI ( ) , url ) ; } } ; } | Gets information about all of the group memberships for this user as iterable with paging support . | 169 | 21 |
150,299 | public EmailAlias addEmailAlias ( String email , boolean isConfirmed ) { URL url = EMAIL_ALIASES_URL_TEMPLATE . build ( this . getAPI ( ) . getBaseURL ( ) , this . getID ( ) ) ; BoxJSONRequest request = new BoxJSONRequest ( this . getAPI ( ) , url , "POST" ) ; JsonObject requestJSON = new JsonObject ( ) . add ( "email" , email ) ; if ( isConfirmed ) { requestJSON . add ( "is_confirmed" , isConfirmed ) ; } request . setBody ( requestJSON . toString ( ) ) ; BoxJSONResponse response = ( BoxJSONResponse ) request . send ( ) ; JsonObject responseJSON = JsonObject . readFrom ( response . getJSON ( ) ) ; return new EmailAlias ( responseJSON ) ; } | Adds a new email alias to this user s account and confirms it without user interaction . This functionality is only available for enterprise admins . | 188 | 26 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.