idx int64 0 165k | question stringlengths 73 4.15k | target stringlengths 5 918 | len_question int64 21 890 | len_target int64 3 255 |
|---|---|---|---|---|
152,100 | public BoxRequestsFile . UploadFile getUploadRequest ( File file , String destinationFolderId ) { BoxRequestsFile . UploadFile request = new BoxRequestsFile . UploadFile ( file , destinationFolderId , getFileUploadUrl ( ) , mSession ) ; return request ; } | Gets a request that uploads a file from an existing file | 60 | 13 |
152,101 | public BoxRequestsFile . UploadNewVersion getUploadNewVersionRequest ( InputStream fileInputStream , String destinationFileId ) { BoxRequestsFile . UploadNewVersion request = new BoxRequestsFile . UploadNewVersion ( fileInputStream , getFileUploadNewVersionUrl ( destinationFileId ) , mSession ) ; return request ; } | Gets a request that uploads a new file version from an input stream | 71 | 15 |
152,102 | public BoxRequestsFile . UploadNewVersion getUploadNewVersionRequest ( File file , String destinationFileId ) { try { BoxRequestsFile . UploadNewVersion request = getUploadNewVersionRequest ( new FileInputStream ( file ) , destinationFileId ) ; request . setUploadSize ( file . length ( ) ) ; request . setModifiedDate ( new Date ( file . lastModified ( ) ) ) ; return request ; } catch ( FileNotFoundException e ) { throw new IllegalArgumentException ( e ) ; } } | Gets a request that uploads a new file version from an existing file | 113 | 15 |
152,103 | public BoxRequestsFile . DownloadFile getDownloadRequest ( File target , String fileId ) throws IOException { if ( ! target . exists ( ) ) { throw new FileNotFoundException ( ) ; } BoxRequestsFile . DownloadFile request = new BoxRequestsFile . DownloadFile ( fileId , target , getFileDownloadUrl ( fileId ) , mSession ) ; return request ; } | Gets a request that downloads a given file to a target file | 83 | 13 |
152,104 | public BoxRequestsFile . DownloadFile getDownloadUrlRequest ( File target , String url ) throws IOException { if ( ! target . exists ( ) ) { throw new FileNotFoundException ( ) ; } BoxRequestsFile . DownloadFile request = new BoxRequestsFile . DownloadFile ( target , url , mSession ) ; return request ; } | Gets a request that downloads a given asset from the url to a target file This is used to download miscellaneous url assets for instance from the representations endpoint . | 73 | 32 |
152,105 | public BoxRequestsFile . DownloadFile getDownloadRequest ( OutputStream outputStream , String fileId ) { BoxRequestsFile . DownloadFile request = new BoxRequestsFile . DownloadFile ( fileId , outputStream , getFileDownloadUrl ( fileId ) , mSession ) ; return request ; } | Gets a request that downloads the given file to the provided outputStream . Developer is responsible for closing the outputStream provided . | 63 | 25 |
152,106 | public BoxRequestsFile . DownloadThumbnail getDownloadThumbnailRequest ( File target , String fileId ) throws IOException { if ( ! target . exists ( ) ) { throw new FileNotFoundException ( ) ; } if ( target . isDirectory ( ) ) { throw new RuntimeException ( "This endpoint only supports files and does not support directories" ) ; } BoxRequestsFile . DownloadThumbnail request = new BoxRequestsFile . DownloadThumbnail ( fileId , target , getThumbnailFileDownloadUrl ( fileId ) , mSession ) ; return request ; } | Gets a request that downloads a thumbnail to a target file | 115 | 12 |
152,107 | public BoxRequestsFile . DownloadThumbnail getDownloadThumbnailRequest ( OutputStream outputStream , String fileId ) { BoxRequestsFile . DownloadThumbnail request = new BoxRequestsFile . DownloadThumbnail ( fileId , outputStream , getThumbnailFileDownloadUrl ( fileId ) , mSession ) ; return request ; } | Gets a request that downloads the given file thumbnail to the provided outputStream . Developer is responsible for closing the outputStream provided . | 65 | 26 |
152,108 | public BoxRequestsFile . DownloadRepresentation getDownloadRepresentationRequest ( String id , File targetFile , BoxRepresentation representation ) { return new BoxRequestsFile . DownloadRepresentation ( id , targetFile , representation , mSession ) ; } | Gets a request to download a representation object for a given file representation | 51 | 14 |
152,109 | public BoxRequestsFile . GetTrashedFile getTrashedFileRequest ( String id ) { BoxRequestsFile . GetTrashedFile request = new BoxRequestsFile . GetTrashedFile ( id , getTrashedFileUrl ( id ) , mSession ) ; return request ; } | Gets a request that returns a file in the trash | 61 | 11 |
152,110 | public BoxRequestsFile . DeleteTrashedFile getDeleteTrashedFileRequest ( String id ) { BoxRequestsFile . DeleteTrashedFile request = new BoxRequestsFile . DeleteTrashedFile ( id , getTrashedFileUrl ( id ) , mSession ) ; return request ; } | Gets a request that permanently deletes a file from the trash | 62 | 13 |
152,111 | public BoxRequestsFile . RestoreTrashedFile getRestoreTrashedFileRequest ( String id ) { BoxRequestsFile . RestoreTrashedFile request = new BoxRequestsFile . RestoreTrashedFile ( id , getFileInfoUrl ( id ) , mSession ) ; return request ; } | Gets a request that restores a trashed file | 62 | 10 |
152,112 | public BoxRequestsFile . GetFileComments getCommentsRequest ( String id ) { BoxRequestsFile . GetFileComments request = new BoxRequestsFile . GetFileComments ( id , getFileCommentsUrl ( id ) , mSession ) ; return request ; } | Gets a request that retrieves the comments on a file | 55 | 12 |
152,113 | public BoxRequestsFile . GetCollaborations getCollaborationsRequest ( String id ) { BoxRequestsFile . GetCollaborations request = new BoxRequestsFile . GetCollaborations ( id , getFileCollaborationsUrl ( id ) , mSession ) ; return request ; } | Gets a request that gets the collaborations of a file | 62 | 11 |
152,114 | public BoxRequestsFile . GetFileVersions getVersionsRequest ( String id ) { BoxRequestsFile . GetFileVersions request = new BoxRequestsFile . GetFileVersions ( id , getFileVersionsUrl ( id ) , mSession ) ; return request ; } | Gets a request that retrieves the versions of a file | 55 | 12 |
152,115 | public BoxRequestsFile . DeleteFileVersion getDeleteVersionRequest ( String id , String versionId ) { BoxRequestsFile . DeleteFileVersion request = new BoxRequestsFile . DeleteFileVersion ( versionId , getDeleteFileVersionUrl ( id , versionId ) , mSession ) ; return request ; } | Gets a request that deletes a version of a file | 65 | 12 |
152,116 | public BoxRequestsFile . AddFileToCollection getAddToCollectionRequest ( String fileId , String collectionId ) { BoxRequestsFile . AddFileToCollection request = new BoxRequestsFile . AddFileToCollection ( fileId , collectionId , getFileInfoUrl ( fileId ) , mSession ) ; return request ; } | Gets a request that adds a file to a collection | 70 | 11 |
152,117 | public BoxRequestsFile . DeleteFileFromCollection getDeleteFromCollectionRequest ( String id ) { BoxRequestsFile . DeleteFileFromCollection request = new BoxRequestsFile . DeleteFileFromCollection ( id , getFileInfoUrl ( id ) , mSession ) ; return request ; } | Gets a request that removes a file from a collection | 60 | 11 |
152,118 | public BoxRequestsFile . FilePreviewed getFilePreviewedRequest ( String fileId ) { return new BoxRequestsFile . FilePreviewed ( fileId , getPreviewFileUrl ( ) , mSession ) ; } | Gets a request that inform the server that a file was previewed . This makes the file to be included on the recents list . | 46 | 28 |
152,119 | public BoxRequestsFile . GetUploadSession getUploadSession ( String uploadSessionId ) { return new BoxRequestsFile . GetUploadSession ( uploadSessionId , getUploadSessionInfoUrl ( uploadSessionId ) , mSession ) ; } | Gets a request to fetch the upload session using the upload session id . It contains the number of parts that are processed so far the total number of parts required for the commit and expiration date and time of the upload session . | 50 | 45 |
152,120 | public R setLimit ( final int limit ) { mQueryMap . put ( FIELD_LIMIT , Integer . toString ( limit ) ) ; return ( R ) this ; } | Sets the maximum number of events to return in the list of events . | 39 | 15 |
152,121 | public R setPreviousListEvents ( E listEvents ) { mListEvents = listEvents ; this . setStreamPosition ( ( ( IStreamPosition ) mListEvents ) . getNextStreamPosition ( ) . toString ( ) ) ; return ( R ) this ; } | Convenience method . When set the request will be set to the next stream position from the given event and will will aggregate the new results with the provided list . | 56 | 33 |
152,122 | private void writeObject ( java . io . ObjectOutputStream s ) throws java . io . IOException { // Write out capacity and any hidden stuff s . defaultWriteObject ( ) ; } | Serialize object . | 39 | 4 |
152,123 | public static BoxFolder createFromIdAndName ( String folderId , String name ) { JsonObject object = new JsonObject ( ) ; object . add ( BoxItem . FIELD_ID , folderId ) ; object . add ( BoxItem . FIELD_TYPE , BoxFolder . TYPE ) ; if ( ! TextUtils . isEmpty ( name ) ) { object . add ( BoxItem . FIELD_NAME , name ) ; } return new BoxFolder ( object ) ; } | A convenience method to create an empty folder with just the id and type fields set . This allows the ability to interact with the content sdk in a more descriptive and type safe manner | 103 | 36 |
152,124 | public static BoxBookmark createFromId ( String bookmarkId ) { JsonObject object = new JsonObject ( ) ; object . add ( FIELD_ID , bookmarkId ) ; object . add ( FIELD_TYPE , TYPE ) ; return new BoxBookmark ( object ) ; } | A convenience method to create an empty bookmark with just the id and type fields set . This allows the ability to interact with the content sdk in a more descriptive and type safe manner | 61 | 36 |
152,125 | public BoxHttpRequest addHeader ( String key , String value ) { mUrlConnection . addRequestProperty ( key , value ) ; return this ; } | Adds an HTTP header to the request . | 31 | 8 |
152,126 | public BoxHttpRequest setBody ( InputStream body ) throws IOException { mUrlConnection . setDoOutput ( true ) ; OutputStream output = mUrlConnection . getOutputStream ( ) ; int b = body . read ( ) ; while ( b != - 1 ) { output . write ( b ) ; b = body . read ( ) ; } output . close ( ) ; return this ; } | Sets the body for the HTTP request to the contents of an InputStream . | 83 | 16 |
152,127 | public BoxRequestsUser . GetUserInfo getCurrentUserInfoRequest ( ) { BoxRequestsUser . GetUserInfo request = new BoxRequestsUser . GetUserInfo ( getUserInformationUrl ( "me" ) , mSession ) ; return request ; } | Gets a request that gets information about the current user | 55 | 11 |
152,128 | public BoxRequestsUser . GetUserInfo getUserInfoRequest ( String id ) { BoxRequestsUser . GetUserInfo request = new BoxRequestsUser . GetUserInfo ( getUserInformationUrl ( id ) , mSession ) ; return request ; } | Gets a request that gets information about a user | 54 | 10 |
152,129 | public BoxRequestsUser . GetEnterpriseUsers getEnterpriseUsersRequest ( ) { BoxRequestsUser . GetEnterpriseUsers request = new BoxRequestsUser . GetEnterpriseUsers ( getUsersUrl ( ) , mSession ) ; return request ; } | Gets a request that gets all the users of an enterprise The session provided must be associated with an enterprise admin user | 54 | 23 |
152,130 | public BoxRequestsUser . CreateEnterpriseUser getCreateEnterpriseUserRequest ( String login , String name ) { BoxRequestsUser . CreateEnterpriseUser request = new BoxRequestsUser . CreateEnterpriseUser ( getUsersUrl ( ) , mSession , login , name ) ; return request ; } | Gets a request that creates an enterprise user The session provided must be associated with an enterprise admin user | 64 | 20 |
152,131 | public BoxRequestsUser . DeleteEnterpriseUser getDeleteEnterpriseUserRequest ( String userId ) { BoxRequestsUser . DeleteEnterpriseUser request = new BoxRequestsUser . DeleteEnterpriseUser ( getUserInformationUrl ( userId ) , mSession , userId ) ; return request ; } | Gets a request that deletes an enterprise user The session provided must be associated with an enterprise admin user | 64 | 21 |
152,132 | public BoxRequestsFile . DownloadAvatar getDownloadAvatarRequest ( File target , String userId ) throws IOException { if ( ! target . exists ( ) ) { throw new FileNotFoundException ( ) ; } BoxRequestsFile . DownloadAvatar request = new BoxRequestsFile . DownloadAvatar ( userId , target , getAvatarDownloadUrl ( userId ) , mSession ) . setAvatarType ( BoxRequestsFile . DownloadAvatar . LARGE ) ; return request ; } | Gets a request that downloads an avatar of the target user id . | 107 | 14 |
152,133 | public BoxRequestsFile . DownloadFile getDownloadAvatarRequest ( OutputStream outputStream , String userId ) { BoxRequestsFile . DownloadFile request = new BoxRequestsFile . DownloadFile ( userId , outputStream , getAvatarDownloadUrl ( userId ) , mSession ) ; return request ; } | Gets a request that downloads the given avatar to the provided outputStream . Developer is responsible for closing the outputStream provided . | 66 | 25 |
152,134 | public R setName ( String name ) { mBodyMap . put ( BoxUser . FIELD_NAME , name ) ; return ( R ) this ; } | Sets the new name for the user in the request . | 33 | 12 |
152,135 | public R setRole ( BoxUser . Role role ) { mBodyMap . put ( BoxUser . FIELD_ROLE , role ) ; return ( R ) this ; } | Sets the new role for the user . | 37 | 9 |
152,136 | public R setJobTitle ( String jobTitle ) { mBodyMap . put ( BoxUser . FIELD_JOB_TITLE , jobTitle ) ; return ( R ) this ; } | Sets the job title for the user in the request . | 40 | 12 |
152,137 | public R setPhone ( String phone ) { mBodyMap . put ( BoxUser . FIELD_PHONE , phone ) ; return ( R ) this ; } | Sets the phone number of the user in the request . | 34 | 12 |
152,138 | public R setAddress ( String address ) { mBodyMap . put ( BoxUser . FIELD_ADDRESS , address ) ; return ( R ) this ; } | Sets the address of the user in the request . | 35 | 11 |
152,139 | public R setStatus ( BoxUser . Status status ) { mBodyMap . put ( BoxUser . FIELD_STATUS , status ) ; return ( R ) this ; } | Sets the status for the user in the request . | 37 | 11 |
152,140 | public R setTimezone ( String timezone ) { mBodyMap . put ( BoxUser . FIELD_TIMEZONE , timezone ) ; return ( R ) this ; } | Sets the timezone for the user in the request . | 38 | 12 |
152,141 | public BoxRequestRecentItems . GetRecentItems getRecentItemsRequest ( ) { BoxRequestRecentItems . GetRecentItems request = new BoxRequestRecentItems . GetRecentItems ( getRecentItemsUrl ( ) , mSession ) ; return request ; } | Gets a request that gets users recent items | 51 | 9 |
152,142 | public boolean isEmbedLinkUrlExpired ( ) { Long urlCreationTime = getUrlCreationTime ( ) ; if ( urlCreationTime == null ) { return true ; } return ( System . currentTimeMillis ( ) - urlCreationTime ) < ( 60 * 1000 ) ; } | Convenience method to check if 60 seconds has passed since the time this link was created . | 64 | 19 |
152,143 | public boolean isPreviewSessionExpired ( ) { Long urlCreationTime = getUrlCreationTime ( ) ; if ( urlCreationTime == null ) { return true ; } return ( System . currentTimeMillis ( ) - urlCreationTime ) < ( 60 * 60 * 1000 ) ; } | Convenience method to check if 60 minutes has passed since the time this link was created . | 64 | 19 |
152,144 | public BoxRequestsBookmark . GetBookmarkInfo getInfoRequest ( final String id ) { BoxRequestsBookmark . GetBookmarkInfo request = new BoxRequestsBookmark . GetBookmarkInfo ( id , getBookmarkInfoUrl ( id ) , mSession ) ; return request ; } | Gets a request that retrieves information on a bookmark | 63 | 11 |
152,145 | public BoxRequestsBookmark . CreateBookmark getCreateRequest ( String parentId , String url ) { BoxRequestsBookmark . CreateBookmark request = new BoxRequestsBookmark . CreateBookmark ( parentId , url , getBookmarksUrl ( ) , mSession ) ; return request ; } | Gets a request that creates a bookmark in a parent bookmark | 64 | 12 |
152,146 | public BoxRequestsBookmark . UpdateBookmark getUpdateRequest ( String id ) { BoxRequestsBookmark . UpdateBookmark request = new BoxRequestsBookmark . UpdateBookmark ( id , getBookmarkInfoUrl ( id ) , mSession ) ; return request ; } | Gets a request that updates a bookmark s information | 59 | 10 |
152,147 | public BoxRequestsBookmark . CopyBookmark getCopyRequest ( String id , String parentId ) { BoxRequestsBookmark . CopyBookmark request = new BoxRequestsBookmark . CopyBookmark ( id , parentId , getBookmarkCopyUrl ( id ) , mSession ) ; return request ; } | Gets a request that copies a bookmark | 66 | 8 |
152,148 | public BoxRequestsBookmark . UpdateBookmark getRenameRequest ( String id , String newName ) { BoxRequestsBookmark . UpdateBookmark request = new BoxRequestsBookmark . UpdateBookmark ( id , getBookmarkInfoUrl ( id ) , mSession ) ; request . setName ( newName ) ; return request ; } | Gets a request that renames a bookmark | 73 | 9 |
152,149 | public BoxRequestsBookmark . UpdateBookmark getMoveRequest ( String id , String parentId ) { BoxRequestsBookmark . UpdateBookmark request = new BoxRequestsBookmark . UpdateBookmark ( id , getBookmarkInfoUrl ( id ) , mSession ) ; request . setParentId ( parentId ) ; return request ; } | Gets a request that moves a bookmark to another folder | 73 | 11 |
152,150 | public BoxRequestsBookmark . DeleteBookmark getDeleteRequest ( String id ) { BoxRequestsBookmark . DeleteBookmark request = new BoxRequestsBookmark . DeleteBookmark ( id , getBookmarkInfoUrl ( id ) , mSession ) ; return request ; } | Gets a request that deletes a bookmark | 59 | 9 |
152,151 | public BoxRequestsBookmark . UpdateSharedBookmark getCreateSharedLinkRequest ( String id ) { BoxRequestsBookmark . UpdateSharedBookmark request = new BoxRequestsBookmark . UpdateSharedBookmark ( id , getBookmarkInfoUrl ( id ) , mSession ) . setAccess ( null ) ; return request ; } | Gets a request that creates a shared link for a bookmark | 74 | 12 |
152,152 | public BoxRequestsBookmark . UpdateBookmark getDisableSharedLinkRequest ( String id ) { BoxRequestsBookmark . UpdateBookmark request = new BoxRequestsBookmark . UpdateBookmark ( id , getBookmarkInfoUrl ( id ) , mSession ) . setSharedLink ( null ) ; return request ; } | Gets a request that disables a shared link for a bookmark | 70 | 13 |
152,153 | public BoxRequestsBookmark . AddCommentToBookmark getAddCommentRequest ( String bookmarkId , String message ) { BoxRequestsBookmark . AddCommentToBookmark request = new BoxRequestsBookmark . AddCommentToBookmark ( bookmarkId , message , getCommentUrl ( ) , mSession ) ; return request ; } | Gets a request that adds a comment to a bookmark | 70 | 11 |
152,154 | public BoxRequestsBookmark . GetTrashedBookmark getTrashedBookmarkRequest ( String id ) { BoxRequestsBookmark . GetTrashedBookmark request = new BoxRequestsBookmark . GetTrashedBookmark ( id , getTrashedBookmarkUrl ( id ) , mSession ) ; return request ; } | Gets a request that returns a bookmark in the trash | 69 | 11 |
152,155 | public BoxRequestsBookmark . DeleteTrashedBookmark getDeleteTrashedBookmarkRequest ( String id ) { BoxRequestsBookmark . DeleteTrashedBookmark request = new BoxRequestsBookmark . DeleteTrashedBookmark ( id , getTrashedBookmarkUrl ( id ) , mSession ) ; return request ; } | Gets a request that permanently deletes a bookmark from the trash | 70 | 13 |
152,156 | public BoxRequestsBookmark . RestoreTrashedBookmark getRestoreTrashedBookmarkRequest ( String id ) { BoxRequestsBookmark . RestoreTrashedBookmark request = new BoxRequestsBookmark . RestoreTrashedBookmark ( id , getBookmarkInfoUrl ( id ) , mSession ) ; return request ; } | Gets a request that restores a trashed bookmark | 70 | 10 |
152,157 | public BoxRequestsBookmark . GetBookmarkComments getCommentsRequest ( String id ) { BoxRequestsBookmark . GetBookmarkComments request = new BoxRequestsBookmark . GetBookmarkComments ( id , getBookmarkCommentsUrl ( id ) , mSession ) ; return request ; } | Gets a request that retrieves the comments on a bookmark | 62 | 12 |
152,158 | public BoxRequestsBookmark . AddBookmarkToCollection getAddToCollectionRequest ( String bookmarkId , String collectionId ) { BoxRequestsBookmark . AddBookmarkToCollection request = new BoxRequestsBookmark . AddBookmarkToCollection ( bookmarkId , collectionId , getBookmarkInfoUrl ( bookmarkId ) , mSession ) ; return request ; } | Gets a request that adds a bookmark to a collection | 77 | 11 |
152,159 | public BoxRequestsBookmark . DeleteBookmarkFromCollection getDeleteFromCollectionRequest ( String id ) { BoxRequestsBookmark . DeleteBookmarkFromCollection request = new BoxRequestsBookmark . DeleteBookmarkFromCollection ( id , getBookmarkInfoUrl ( id ) , mSession ) ; return request ; } | Gets a request that removes a bookmark from a collection | 67 | 11 |
152,160 | public BoxSimpleMessage connect ( ) { mRetries = 0 ; try { BoxIteratorRealTimeServers servers = ( BoxIteratorRealTimeServers ) mRequest . send ( ) ; mBoxRealTimeServer = servers . get ( 0 ) ; } catch ( BoxException e ) { mChangeListener . onException ( e , this ) ; return null ; } BoxRequestsEvent . LongPollMessageRequest messageRequest = new BoxRequestsEvent . LongPollMessageRequest ( mBoxRealTimeServer . getUrl ( ) , mSession ) ; messageRequest . setTimeOut ( mBoxRealTimeServer . getFieldRetryTimeout ( ) . intValue ( ) * 1000 ) ; boolean shouldRetry = true ; do { BoxFutureTask < BoxSimpleMessage > task = null ; try { task = messageRequest . toTask ( ) . addOnCompletedListener ( this ) ; mExecutor . submit ( task ) ; BoxResponse < BoxSimpleMessage > response = task . get ( mBoxRealTimeServer . getFieldRetryTimeout ( ) . intValue ( ) , TimeUnit . SECONDS ) ; if ( response . isSuccess ( ) && ! response . getResult ( ) . getMessage ( ) . equals ( BoxSimpleMessage . MESSAGE_RECONNECT ) ) { return response . getResult ( ) ; } } catch ( TimeoutException e ) { if ( task != null ) { try { // if the timeout is coming from the task then cancel the task (as httpurlconnection timeout is unreliable). task . cancel ( true ) ; } catch ( CancellationException e1 ) { } } } catch ( InterruptedException e ) { mChangeListener . onException ( e , this ) ; } catch ( ExecutionException e ) { mChangeListener . onException ( e , this ) ; } mRetries ++ ; if ( mBoxRealTimeServer . getMaxRetries ( ) < mRetries ) { shouldRetry = false ; } } while ( shouldRetry ) ; mChangeListener . onException ( new BoxException . MaxAttemptsExceeded ( "Max retries exceeded, " , mRetries ) , this ) ; return null ; } | Returns a message once a change has been detected or error occurs . Otherwise this method will continue reconnecting . | 460 | 21 |
152,161 | public void putField ( String key , Date value ) { this . fields . put ( key , BoxDateFormat . format ( value ) ) ; } | Adds or updates a multipart field in this request . | 31 | 11 |
152,162 | public void setFile ( InputStream inputStream , String filename , long fileSize ) { this . setFile ( inputStream , filename ) ; this . fileSize = fileSize ; } | Sets the file contents of this request . | 38 | 9 |
152,163 | public static String getRepresentationHintString ( String repType , String repSize ) { StringBuffer sb = new StringBuffer ( repType ) ; if ( TYPE_JPG . equals ( repType ) || TYPE_PNG . equals ( repType ) ) { if ( TextUtils . isEmpty ( repSize ) ) { throw new InvalidParameterException ( "Size is not optional when creating representation hints for images" ) ; } sb . append ( "?" + BoxRepPropertiesMap . FIELD_PROPERTIES_DIMENSIONS + "=" + repSize ) ; } return sb . toString ( ) ; } | Helper method to generate representation hint string | 137 | 7 |
152,164 | public Long getNextStreamPosition ( ) { String longValue = getPropertyAsString ( FIELD_NEXT_STREAM_POSITION ) ; return Long . parseLong ( longValue . replace ( "\"" , "" ) ) ; } | Gets the next position in the event stream that you should request in order to get the next events . | 51 | 21 |
152,165 | public static BoxFile createFromIdAndName ( String fileId , String name ) { JsonObject object = new JsonObject ( ) ; object . add ( BoxItem . FIELD_ID , fileId ) ; object . add ( BoxItem . FIELD_TYPE , BoxFile . TYPE ) ; if ( ! TextUtils . isEmpty ( name ) ) { object . add ( BoxItem . FIELD_NAME , name ) ; } return new BoxFile ( object ) ; } | A convenience method to create an empty file with just the id and type fields set . This allows the ability to interact with the content sdk in a more descriptive and type safe manner | 103 | 36 |
152,166 | private void loadRootFolder ( ) { new Thread ( ) { @ Override public void run ( ) { try { //Api to fetch root folder final BoxIteratorItems folderItems = mFolderApi . getItemsRequest ( BoxConstants . ROOT_FOLDER_ID ) . send ( ) ; runOnUiThread ( new Runnable ( ) { @ Override public void run ( ) { mAdapter . clear ( ) ; for ( BoxItem boxItem : folderItems ) { mAdapter . add ( boxItem ) ; } } } ) ; } catch ( BoxException e ) { e . printStackTrace ( ) ; } } } . start ( ) ; } | Method to demonstrate fetching folder items from the root folder | 145 | 11 |
152,167 | private void uploadSampleFile ( ) { mDialog = ProgressDialog . show ( MainActivity . this , getText ( R . string . boxsdk_Please_wait ) , getText ( R . string . boxsdk_Please_wait ) ) ; new Thread ( ) { @ Override public void run ( ) { try { String uploadFileName = "box_logo.png" ; InputStream uploadStream = getResources ( ) . getAssets ( ) . open ( uploadFileName ) ; String destinationFolderId = "0" ; String uploadName = "BoxSDKUpload.png" ; BoxRequestsFile . UploadFile request = mFileApi . getUploadRequest ( uploadStream , uploadName , destinationFolderId ) ; final BoxFile uploadFileInfo = request . send ( ) ; showToast ( "Uploaded " + uploadFileInfo . getName ( ) ) ; loadRootFolder ( ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } catch ( BoxException e ) { e . printStackTrace ( ) ; BoxError error = e . getAsBoxError ( ) ; if ( error != null && error . getStatus ( ) == HttpURLConnection . HTTP_CONFLICT ) { ArrayList < BoxEntity > conflicts = error . getContextInfo ( ) . getConflicts ( ) ; if ( conflicts != null && conflicts . size ( ) == 1 && conflicts . get ( 0 ) instanceof BoxFile ) { uploadNewVersion ( ( BoxFile ) conflicts . get ( 0 ) ) ; return ; } } showToast ( "Upload failed" ) ; } finally { mDialog . dismiss ( ) ; } } } . start ( ) ; } | Method demonstrates a sample file being uploaded using the file api | 365 | 11 |
152,168 | private void uploadNewVersion ( final BoxFile file ) { new Thread ( ) { @ Override public void run ( ) { try { String uploadFileName = "box_logo.png" ; InputStream uploadStream = getResources ( ) . getAssets ( ) . open ( uploadFileName ) ; BoxRequestsFile . UploadNewVersion request = mFileApi . getUploadNewVersionRequest ( uploadStream , file . getId ( ) ) ; final BoxFile uploadFileVersionInfo = request . send ( ) ; showToast ( "Uploaded new version of " + uploadFileVersionInfo . getName ( ) ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } catch ( BoxException e ) { e . printStackTrace ( ) ; showToast ( "Upload failed" ) ; } finally { mDialog . dismiss ( ) ; } } } . start ( ) ; } | Method demonstrates a new version of a file being uploaded using the file api | 197 | 14 |
152,169 | public static void copyStream ( final InputStream inputStream , final OutputStream outputStream ) throws IOException , InterruptedException { copyStream ( inputStream , outputStream , null ) ; } | Utility method to write given inputStream to given outputStream . | 39 | 13 |
152,170 | public static String copyStreamAndComputeSha1 ( final InputStream inputStream , final OutputStream outputStream ) throws NoSuchAlgorithmException , IOException , InterruptedException { MessageDigest md = MessageDigest . getInstance ( "SHA-1" ) ; copyStream ( inputStream , outputStream , md ) ; return new String ( encodeHex ( md . digest ( ) ) ) ; } | Utility method to write given inputStream to given outputStream and compute the sha1 while transferring the bytes | 86 | 22 |
152,171 | private static void copyStream ( final InputStream inputStream , final OutputStream outputStream , MessageDigest messageDigest ) throws IOException , InterruptedException { // Read the rest of the stream and write to the destination OutputStream. final byte [ ] buffer = new byte [ BUFFER_SIZE ] ; int bufferLength = 0 ; Exception exception = null ; try { while ( ( bufferLength = inputStream . read ( buffer ) ) > 0 ) { if ( Thread . currentThread ( ) . isInterrupted ( ) ) { InterruptedException e = new InterruptedException ( ) ; throw e ; } outputStream . write ( buffer , 0 , bufferLength ) ; if ( messageDigest != null ) { messageDigest . update ( buffer , 0 , bufferLength ) ; } } } catch ( Exception e ) { exception = e ; if ( exception instanceof IOException ) { throw ( IOException ) e ; } if ( exception instanceof InterruptedException ) { throw ( InterruptedException ) e ; } } finally { // Try to flush the OutputStream if ( exception == null ) { outputStream . flush ( ) ; } } } | Utility method to write given inputStream to given outputStream and update the messageDigest while transferring the bytes | 238 | 22 |
152,172 | public static OutputStream createArrayOutputStream ( final OutputStream [ ] outputStreams ) { return new OutputStream ( ) { @ Override public void close ( ) throws IOException { for ( OutputStream o : outputStreams ) { o . close ( ) ; } super . close ( ) ; } @ Override public void flush ( ) throws IOException { for ( OutputStream o : outputStreams ) { o . flush ( ) ; } super . flush ( ) ; } @ Override public void write ( int oneByte ) throws IOException { for ( OutputStream o : outputStreams ) { o . write ( oneByte ) ; } } @ Override public void write ( byte [ ] buffer ) throws IOException { for ( OutputStream o : outputStreams ) { o . write ( buffer ) ; } } @ Override public void write ( byte [ ] buffer , int offset , int count ) throws IOException { for ( OutputStream o : outputStreams ) { o . write ( buffer , offset , count ) ; } } } ; } | Helper method that wraps given arrays inside of a single outputstream . | 221 | 13 |
152,173 | public static String sha1 ( final InputStream inputStream ) throws IOException , NoSuchAlgorithmException { MessageDigest md = MessageDigest . getInstance ( "SHA-1" ) ; byte [ ] bytes = new byte [ 8192 ] ; int byteCount ; while ( ( byteCount = inputStream . read ( bytes ) ) > 0 ) { md . update ( bytes , 0 , byteCount ) ; } inputStream . close ( ) ; return new String ( encodeHex ( md . digest ( ) ) ) ; } | Utilitiy method to calculate sha1 based on given inputStream . | 113 | 15 |
152,174 | public static long parseJsonValueToLong ( JsonValue value ) { try { return value . asLong ( ) ; } catch ( UnsupportedOperationException e ) { String s = value . asString ( ) . replace ( "\"" , "" ) ; return Long . parseLong ( s ) ; } } | Parse a given JsonValue to a long regardless of whether that value is a String or a long . | 66 | 22 |
152,175 | public static long parseJsonValueToInteger ( JsonValue value ) { try { return value . asInt ( ) ; } catch ( UnsupportedOperationException e ) { String s = value . asString ( ) . replace ( "\"" , "" ) ; return Integer . parseInt ( s ) ; } } | Parse a given JsonValue to an int regardless of whether that value is a String or an int . | 66 | 22 |
152,176 | public static String concatStringWithDelimiter ( String [ ] strings , String delimiter ) { StringBuilder sbr = new StringBuilder ( ) ; int size = strings . length ; for ( int i = 0 ; i < size - 1 ; i ++ ) { sbr . append ( strings [ i ] ) . append ( delimiter ) ; } sbr . append ( strings [ size - 1 ] ) ; return sbr . toString ( ) ; } | Utility method to create a large String with the given delimiter . | 97 | 14 |
152,177 | public static < T extends Object > T cloneSerializable ( T source ) { ByteArrayOutputStream baos = null ; ObjectOutputStream oos = null ; ByteArrayInputStream bais = null ; ObjectInputStream ois = null ; try { baos = new ByteArrayOutputStream ( ) ; oos = new ObjectOutputStream ( baos ) ; oos . writeObject ( source ) ; bais = new ByteArrayInputStream ( baos . toByteArray ( ) ) ; ois = new ObjectInputStream ( bais ) ; return ( T ) ois . readObject ( ) ; } catch ( IOException e ) { return null ; } catch ( ClassNotFoundException e ) { return null ; } finally { closeQuietly ( baos , oos , bais , ois ) ; } } | Helper method to clone a serializable object . | 174 | 9 |
152,178 | public static String convertSerializableToString ( Serializable obj ) { ByteArrayOutputStream baos = null ; ObjectOutputStream oos = null ; try { baos = new ByteArrayOutputStream ( ) ; oos = new ObjectOutputStream ( baos ) ; oos . writeObject ( obj ) ; return new String ( baos . toByteArray ( ) ) ; } catch ( IOException e ) { return null ; } finally { closeQuietly ( baos , oos ) ; closeQuietly ( oos ) ; } } | Helper method to write a serializable object into a String . | 116 | 12 |
152,179 | public static boolean deleteFolderRecursive ( final File f ) { if ( f . isDirectory ( ) ) { File [ ] files = f . listFiles ( ) ; if ( files == null ) { return false ; } for ( File c : files ) { deleteFolderRecursive ( c ) ; } } return f . delete ( ) ; } | Recursively delete a folder and all its subfolders and files . | 72 | 15 |
152,180 | public static boolean isInternetAvailable ( Context context ) { ConnectivityManager connectivityManager = ( ConnectivityManager ) context . getApplicationContext ( ) . getSystemService ( Context . CONNECTIVITY_SERVICE ) ; if ( Build . VERSION . SDK_INT >= Build . VERSION_CODES . LOLLIPOP ) { return isInternetAvailable ( connectivityManager ) ; } else { return isInternetAvailablePreLollipop ( connectivityManager ) ; } } | Check for an internet connection . | 98 | 6 |
152,181 | public static String getAssetFile ( final Context context , final String assetName ) { // if the file is not found create it and return that. // if we do not have a file we copy our asset out to create one. AssetManager assetManager = context . getAssets ( ) ; BufferedReader in = null ; try { StringBuilder buf = new StringBuilder ( ) ; InputStream is = assetManager . open ( assetName ) ; in = new BufferedReader ( new InputStreamReader ( is ) ) ; String str ; boolean isFirst = true ; while ( ( str = in . readLine ( ) ) != null ) { if ( isFirst ) isFirst = false ; else buf . append ( ' ' ) ; buf . append ( str ) ; } return buf . toString ( ) ; } catch ( IOException e ) { BoxLogUtils . e ( "getAssetFile" , assetName , e ) ; } finally { try { if ( in != null ) { in . close ( ) ; } } catch ( Exception e ) { BoxLogUtils . e ( "getAssetFile" , assetName , e ) ; } } // should never get here unless the asset file is inaccessible or cannot be copied out. return null ; } | Helper method for reading an asset file into a string . | 263 | 11 |
152,182 | public static void toastSafely ( final Context context , final int resId , final int duration ) { Long lastToastTime = LAST_TOAST_TIME . get ( resId ) ; if ( lastToastTime != null && ( lastToastTime + TOAST_MIN_REPEAT_DELAY ) < System . currentTimeMillis ( ) ) { return ; } Looper mainLooper = Looper . getMainLooper ( ) ; if ( Thread . currentThread ( ) . equals ( mainLooper . getThread ( ) ) ) { LAST_TOAST_TIME . put ( resId , System . currentTimeMillis ( ) ) ; Toast . makeText ( context , resId , duration ) . show ( ) ; } else { Handler handler = new Handler ( mainLooper ) ; handler . post ( new Runnable ( ) { @ Override public void run ( ) { LAST_TOAST_TIME . put ( resId , System . currentTimeMillis ( ) ) ; Toast . makeText ( context , resId , duration ) . show ( ) ; } } ) ; } } | Helper method for showing a toast message checking to see if user is on ui thread and not showing the same toast if it has already been shown within TOAST_MIN_REPEAT_DELAY time . | 238 | 44 |
152,183 | public static void setInitialsThumb ( Context context , TextView initialsView , String fullName ) { char initial1 = ' ' ; char initial2 = ' ' ; if ( fullName != null ) { String [ ] nameParts = fullName . split ( " " ) ; if ( nameParts [ 0 ] . length ( ) > 0 ) { initial1 = nameParts [ 0 ] . charAt ( 0 ) ; } if ( nameParts . length > 1 ) { initial2 = nameParts [ nameParts . length - 1 ] . charAt ( 0 ) ; } } setColorForInitialsThumb ( initialsView , initial1 + initial2 ) ; initialsView . setText ( initial1 + "" + initial2 ) ; initialsView . setTextColor ( Color . WHITE ) ; } | Helper method used to display initials into a given textview . | 167 | 12 |
152,184 | public static void setCollabNumberThumb ( Context context , TextView initialsView , int collabNumber ) { String collabNumberDisplay = ( collabNumber >= 100 ) ? "+99" : "+" + Integer . toString ( collabNumber ) ; setColorForCollabNumberThumb ( initialsView ) ; initialsView . setTextColor ( COLLAB_NUMBER_THUMB_COLOR ) ; initialsView . setText ( collabNumberDisplay ) ; } | Helper method to display number of collaborators . If there are more than 99 collaborators it would show 99 + due to the width constraint in the view . | 101 | 29 |
152,185 | public static void setColorsThumb ( TextView initialsView , int backgroundColor , int strokeColor ) { GradientDrawable drawable = ( GradientDrawable ) initialsView . getResources ( ) . getDrawable ( R . drawable . boxsdk_thumb_background ) ; drawable . setColorFilter ( backgroundColor , PorterDuff . Mode . MULTIPLY ) ; if ( Build . VERSION . SDK_INT > Build . VERSION_CODES . ICE_CREAM_SANDWICH_MR1 ) { drawable . setStroke ( 3 , strokeColor ) ; initialsView . setBackground ( drawable ) ; } else { drawable . setStroke ( 3 , strokeColor ) ; initialsView . setBackgroundDrawable ( drawable ) ; } } | Sets the the background thumb color for the account view to one of the material colors | 174 | 17 |
152,186 | public static void setColorForInitialsThumb ( TextView initialsView , int position ) { int backgroundColor = THUMB_COLORS [ ( position ) % THUMB_COLORS . length ] ; setColorsThumb ( initialsView , backgroundColor , Color . WHITE ) ; } | Sets the thumb color that displays users initials | 63 | 9 |
152,187 | public static String getLocalizedFileSize ( final Context context , double numSize ) { String localeLanguage = Locale . getDefault ( ) . getLanguage ( ) ; if ( ! SIZE_LANGUAGE . equals ( localeLanguage ) && context != null && context . getResources ( ) != null ) { Resources resources = context . getResources ( ) ; SIZE_BYTES = resources . getString ( R . string . boxsdk_bytes ) ; SIZE_KILOBYTES = resources . getString ( R . string . boxsdk_kilobytes ) ; SIZE_MEGABYTES = resources . getString ( R . string . boxsdk_megabytes ) ; SIZE_GIGABYTES = resources . getString ( R . string . boxsdk_gigabytes ) ; SIZE_TERABYTES = resources . getString ( R . string . boxsdk_terabytes ) ; SIZE_LANGUAGE = localeLanguage ; } String textSize = null ; double size ; if ( numSize < constKB ) { textSize = String . format ( Locale . getDefault ( ) , SIZE_BYTES , numSize ) ; } else if ( ( numSize >= constKB ) && ( numSize < constMB ) ) { size = numSize / floatKB ; textSize = String . format ( Locale . getDefault ( ) , SIZE_KILOBYTES , size ) ; } else if ( ( numSize >= constMB ) && ( numSize < constGB ) ) { size = numSize / floatMB ; textSize = String . format ( Locale . getDefault ( ) , SIZE_MEGABYTES , size ) ; } else if ( numSize >= constGB && ( numSize < constTB ) ) { size = numSize / floatGB ; textSize = String . format ( Locale . getDefault ( ) , SIZE_GIGABYTES , size ) ; } else if ( numSize >= constTB ) { size = numSize / floatTB ; textSize = String . format ( Locale . getDefault ( ) , SIZE_TERABYTES , size ) ; } return textSize ; } | Java version of routine to turn a long into a short user readable string . | 485 | 15 |
152,188 | protected R setCollectionId ( String id ) { JsonArray jsonArray = new JsonArray ( ) ; if ( ! TextUtils . isEmpty ( id ) ) { BoxCollection col = BoxCollection . createFromId ( id ) ; jsonArray . add ( col . toJsonObject ( ) ) ; } mBodyMap . put ( FIELD_COLLECTIONS , jsonArray ) ; return ( R ) this ; } | Sets the id of the collection to update . | 91 | 10 |
152,189 | public BoxRequestsFolder . GetFolderInfo getInfoRequest ( String id ) { BoxRequestsFolder . GetFolderInfo request = new BoxRequestsFolder . GetFolderInfo ( id , getFolderInfoUrl ( id ) , mSession ) ; return request ; } | Gets a request that retrieves information on a folder | 55 | 11 |
152,190 | public BoxRequestsFolder . GetFolderItems getItemsRequest ( String id ) { BoxRequestsFolder . GetFolderItems request = new BoxRequestsFolder . GetFolderItems ( id , getFolderItemsUrl ( id ) , mSession ) ; return request ; } | Gets a request that retrieves the items of a folder | 55 | 12 |
152,191 | public BoxRequestsFolder . CreateFolder getCreateRequest ( String parentId , String name ) { BoxRequestsFolder . CreateFolder request = new BoxRequestsFolder . CreateFolder ( parentId , name , getFoldersUrl ( ) , mSession ) ; return request ; } | Gets a request that creates a folder in a parent folder | 59 | 12 |
152,192 | public BoxRequestsFolder . UpdateFolder getUpdateRequest ( String id ) { BoxRequestsFolder . UpdateFolder request = new BoxRequestsFolder . UpdateFolder ( id , getFolderInfoUrl ( id ) , mSession ) ; return request ; } | Gets a request that updates a folders information | 52 | 9 |
152,193 | public BoxRequestsFolder . UpdateFolder getRenameRequest ( String id , String newName ) { BoxRequestsFolder . UpdateFolder request = new BoxRequestsFolder . UpdateFolder ( id , getFolderInfoUrl ( id ) , mSession ) . setName ( newName ) ; return request ; } | Gets a request that renames a folder | 64 | 9 |
152,194 | public BoxRequestsFolder . UpdateFolder getMoveRequest ( String id , String parentId ) { BoxRequestsFolder . UpdateFolder request = new BoxRequestsFolder . UpdateFolder ( id , getFolderInfoUrl ( id ) , mSession ) . setParentId ( parentId ) ; return request ; } | Gets a request that moves a folder to another folder | 64 | 11 |
152,195 | public BoxRequestsFolder . CopyFolder getCopyRequest ( String id , String parentId ) { BoxRequestsFolder . CopyFolder request = new BoxRequestsFolder . CopyFolder ( id , parentId , getFolderCopyUrl ( id ) , mSession ) ; return request ; } | Gets a request that copies a folder | 59 | 8 |
152,196 | public BoxRequestsFolder . GetCollaborations getCollaborationsRequest ( String id ) { BoxRequestsFolder . GetCollaborations request = new BoxRequestsFolder . GetCollaborations ( id , getFolderCollaborationsUrl ( id ) , mSession ) ; return request ; } | Gets a request that gets the collaborations of a folder | 62 | 11 |
152,197 | public BoxRequestsFolder . UpdateSharedFolder getCreateSharedLinkRequest ( String id ) { BoxRequestsFolder . UpdateSharedFolder request = new BoxRequestsFolder . UpdateSharedFolder ( id , getFolderInfoUrl ( id ) , mSession ) . setAccess ( null ) ; return request ; } | Gets a request that creates a shared link for a folder | 67 | 12 |
152,198 | public BoxRequestsFolder . AddFolderToCollection getAddToCollectionRequest ( String folderId , String collectionId ) { BoxRequestsFolder . AddFolderToCollection request = new BoxRequestsFolder . AddFolderToCollection ( folderId , collectionId , getFolderInfoUrl ( folderId ) , mSession ) ; return request ; } | Gets a request that adds a folder to a collection | 70 | 11 |
152,199 | public BoxRequestsFolder . DeleteFolderFromCollection getDeleteFromCollectionRequest ( String id ) { BoxRequestsFolder . DeleteFolderFromCollection request = new BoxRequestsFolder . DeleteFolderFromCollection ( id , getFolderInfoUrl ( id ) , mSession ) ; return request ; } | Gets a request that removes a folder from a collection | 60 | 11 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.