idx
int64
0
165k
question
stringlengths
73
4.15k
target
stringlengths
5
918
len_question
int64
21
890
len_target
int64
3
255
152,200
public BoxRequestsFolder . GetTrashedItems getTrashedItemsRequest ( ) { BoxRequestsFolder . GetTrashedItems request = new BoxRequestsFolder . GetTrashedItems ( getTrashedItemsUrl ( ) , mSession ) ; return request ; }
Gets a request that returns the items in the trash
56
11
152,201
public BoxRequestsFolder . GetTrashedFolder getTrashedFolderRequest ( String id ) { BoxRequestsFolder . GetTrashedFolder request = new BoxRequestsFolder . GetTrashedFolder ( id , getTrashedFolderUrl ( id ) , mSession ) ; return request ; }
Gets a request that returns a folder in the trash
61
11
152,202
public BoxRequestsFolder . DeleteTrashedFolder getDeleteTrashedFolderRequest ( String id ) { BoxRequestsFolder . DeleteTrashedFolder request = new BoxRequestsFolder . DeleteTrashedFolder ( id , getTrashedFolderUrl ( id ) , mSession ) ; return request ; }
Gets a request that permanently deletes a folder from the trash
62
13
152,203
public BoxRequestsFolder . RestoreTrashedFolder getRestoreTrashedFolderRequest ( String id ) { BoxRequestsFolder . RestoreTrashedFolder request = new BoxRequestsFolder . RestoreTrashedFolder ( id , getFolderInfoUrl ( id ) , mSession ) ; return request ; }
Gets a request that restores a trashed folder
62
10
152,204
public BoxRequestsShare . GetCollaborationInfo getInfoRequest ( String collaborationId ) { BoxRequestsShare . GetCollaborationInfo collab = new BoxRequestsShare . GetCollaborationInfo ( collaborationId , getCollaborationInfoUrl ( collaborationId ) , mSession ) ; return collab ; }
A request to retrieve a collaboration of a given id .
68
11
152,205
public BoxRequestsShare . AddCollaboration getAddRequest ( BoxCollaborationItem collaborationItem , BoxCollaboration . Role role , String login ) { BoxRequestsShare . AddCollaboration collab = new BoxRequestsShare . AddCollaboration ( getCollaborationsUrl ( ) , createStubItem ( collaborationItem ) , role , login , mSession ) ; return collab ; }
A request that adds a user as a collaborator to an item by using their login .
87
17
152,206
public BoxRequestsShare . GetPendingCollaborations getPendingCollaborationsRequest ( ) { BoxRequestsShare . GetPendingCollaborations request = new BoxRequestsShare . GetPendingCollaborations ( getCollaborationsUrl ( ) , mSession ) ; return request ; }
A request to retrieve a list of pending collaborations for the user .
64
13
152,207
public BoxRequestsShare . DeleteCollaboration getDeleteRequest ( String collaborationId ) { BoxRequestsShare . DeleteCollaboration collab = new BoxRequestsShare . DeleteCollaboration ( collaborationId , getCollaborationInfoUrl ( collaborationId ) , mSession ) ; return collab ; }
A request to delete a collaboration with given collaboration id .
65
11
152,208
public BoxRequestsShare . UpdateOwner getUpdateOwnerRequest ( String collaborationId ) { BoxRequestsShare . UpdateOwner collab = new BoxRequestsShare . UpdateOwner ( collaborationId , getCollaborationInfoUrl ( collaborationId ) , mSession ) ; return collab ; }
A request to change role to owner given a collaboration id .
60
12
152,209
public static String format ( Date date ) { String format = LOCAL_DATE_FORMAT . format ( date ) ; // Java 6 does not have a convenient way of having the colon in the timezone offset return format . substring ( 0 , 22 ) + ":" + format . substring ( 22 ) ; }
Formats a date as a string that can be sent to the Box API .
67
16
152,210
public static String getTimeRangeString ( Date fromDate , Date toDate ) { if ( fromDate == null && toDate == null ) { return null ; } StringBuilder sbr = new StringBuilder ( ) ; if ( fromDate != null ) { sbr . append ( format ( fromDate ) ) ; } sbr . append ( "," ) ; if ( toDate != null ) { sbr . append ( format ( toDate ) ) ; } return sbr . toString ( ) ; }
Get a String to represent a time range .
106
9
152,211
public BoxError getAsBoxError ( ) { try { BoxError error = new BoxError ( ) ; error . createFromJson ( getResponse ( ) ) ; return error ; } catch ( Exception e ) { return null ; } }
Gets the server response as a BoxError .
50
10
152,212
public String getDescription ( ) { return mBodyMap . containsKey ( BoxItem . FIELD_DESCRIPTION ) ? ( String ) mBodyMap . get ( BoxItem . FIELD_DESCRIPTION ) : null ; }
Returns the new description currently set for the item .
47
10
152,213
public R setDescription ( String description ) { mBodyMap . put ( BoxItem . FIELD_DESCRIPTION , description ) ; return ( R ) this ; }
Sets the new description for the item .
34
9
152,214
public BoxSharedLink getSharedLink ( ) { return mBodyMap . containsKey ( BoxItem . FIELD_SHARED_LINK ) ? ( ( BoxSharedLink ) mBodyMap . get ( BoxItem . FIELD_SHARED_LINK ) ) : null ; }
Returns the shared link currently set for the item .
65
10
152,215
public R setSharedLink ( BoxSharedLink sharedLink ) { mBodyMap . put ( BoxItem . FIELD_SHARED_LINK , sharedLink ) ; return ( R ) this ; }
Sets the new shared link for the item .
45
10
152,216
public List < String > getTags ( ) { return mBodyMap . containsKey ( BoxItem . FIELD_TAGS ) ? ( List < String > ) mBodyMap . get ( BoxItem . FIELD_TAGS ) : null ; }
Returns the tags currently set for the item .
53
9
152,217
public R setTags ( List < String > tags ) { JsonArray jsonArray = new JsonArray ( ) ; for ( String s : tags ) { jsonArray . add ( s ) ; } mBodyMap . put ( BoxItem . FIELD_TAGS , jsonArray ) ; return ( R ) this ; }
Sets the new tags for the item .
68
9
152,218
public BoxRequestsComment . GetCommentInfo getInfoRequest ( String id ) { BoxRequestsComment . GetCommentInfo request = new BoxRequestsComment . GetCommentInfo ( id , getCommentInfoUrl ( id ) , mSession ) ; return request ; }
Gets a request that retrieves information on a comment
55
11
152,219
public BoxRequestsComment . AddReplyComment getAddCommentReplyRequest ( String commentId , String message ) { BoxRequestsComment . AddReplyComment request = new BoxRequestsComment . AddReplyComment ( commentId , message , getCommentsUrl ( ) , mSession ) ; return request ; }
Gets a request that adds a reply comment to a comment
62
12
152,220
public BoxRequestsComment . UpdateComment getUpdateRequest ( String id , String newMessage ) { BoxRequestsComment . UpdateComment request = new BoxRequestsComment . UpdateComment ( id , newMessage , getCommentInfoUrl ( id ) , mSession ) ; return request ; }
Gets a request that updates a comment s information
59
10
152,221
public BoxRequestsComment . DeleteComment getDeleteRequest ( String id ) { BoxRequestsComment . DeleteComment request = new BoxRequestsComment . DeleteComment ( id , getCommentInfoUrl ( id ) , mSession ) ; return request ; }
Gets a request that deletes a comment
52
9
152,222
public String getType ( ) { String type = getPropertyAsString ( FIELD_TYPE ) ; if ( type == null ) { return getPropertyAsString ( FIELD_ITEM_TYPE ) ; } return type ; }
Gets the type of the entity .
48
8
152,223
public static ChooseAuthenticationFragment createChooseAuthenticationFragment ( final Context context , final ArrayList < BoxAuthentication . BoxAuthenticationInfo > listOfAuthInfo ) { ChooseAuthenticationFragment fragment = createAuthenticationActivity ( context ) ; Bundle b = fragment . getArguments ( ) ; if ( b == null ) { b = new Bundle ( ) ; } ArrayList < CharSequence > jsonSerialized = new ArrayList < CharSequence > ( listOfAuthInfo . size ( ) ) ; for ( BoxAuthentication . BoxAuthenticationInfo info : listOfAuthInfo ) { jsonSerialized . add ( info . toJson ( ) ) ; } b . putCharSequenceArrayList ( EXTRA_BOX_AUTHENTICATION_INFOS , jsonSerialized ) ; fragment . setArguments ( b ) ; return fragment ; }
Create an instance of this fragment to display the given list of BoxAuthenticationInfos .
184
18
152,224
BoxRefreshAuthRequest refreshOAuth ( String refreshToken , String clientId , String clientSecret ) { BoxRefreshAuthRequest request = new BoxRefreshAuthRequest ( mSession , getTokenUrl ( ) , refreshToken , clientId , clientSecret ) ; return request ; }
Refresh OAuth to be called when OAuth expires .
59
12
152,225
BoxCreateAuthRequest createOAuth ( String code , String clientId , String clientSecret ) { BoxCreateAuthRequest request = new BoxCreateAuthRequest ( mSession , getTokenUrl ( ) , code , clientId , clientSecret ) ; return request ; }
Create OAuth to be called the first time session tries to authenticate .
54
15
152,226
public BoxRequestsShare . GetSharedLink getSharedLinkRequest ( String sharedLink , String password ) { BoxSharedLinkSession session = null ; if ( mSession instanceof BoxSharedLinkSession ) { session = ( BoxSharedLinkSession ) mSession ; } else { session = new BoxSharedLinkSession ( mSession ) ; } session . setSharedLink ( sharedLink ) ; session . setPassword ( password ) ; BoxRequestsShare . GetSharedLink request = new BoxRequestsShare . GetSharedLink ( getSharedItemsUrl ( ) , session ) ; return request ; }
Returns a request to get a BoxItem from a shared link .
131
13
152,227
protected void cleanOutOldAvatars ( File directory , int maxLifeInDays ) { if ( directory != null ) { if ( mCleanedDirectories . contains ( directory . getAbsolutePath ( ) ) ) { return ; } long oldestTimeAllowed = System . currentTimeMillis ( ) - maxLifeInDays * TimeUnit . DAYS . toMillis ( maxLifeInDays ) ; File [ ] files = directory . listFiles ( ) ; if ( files != null ) { for ( File file : files ) { if ( file . getName ( ) . startsWith ( DEFAULT_AVATAR_FILE_PREFIX ) && file . lastModified ( ) < oldestTimeAllowed ) { file . delete ( ) ; } } } } }
Delete all files for user that is older than maxLifeInDays
163
13
152,228
public BoxSharedLink . Access getAccess ( ) { return mBodyMap . containsKey ( BoxItem . FIELD_SHARED_LINK ) ? ( ( BoxSharedLink ) mBodyMap . get ( BoxItem . FIELD_SHARED_LINK ) ) . getAccess ( ) : null ; }
Gets the shared link access currently set for the item in the request .
70
15
152,229
public R setAccess ( BoxSharedLink . Access access ) { JsonObject jsonObject = getSharedLinkJsonObject ( ) ; jsonObject . add ( BoxSharedLink . FIELD_ACCESS , SdkUtils . getAsStringSafely ( access ) ) ; BoxSharedLink sharedLink = new BoxSharedLink ( jsonObject ) ; mBodyMap . put ( BoxItem . FIELD_SHARED_LINK , sharedLink ) ; return ( R ) this ; }
Sets the shared link access for the item in the request .
108
13
152,230
public Date getUnsharedAt ( ) { if ( mBodyMap . containsKey ( BoxItem . FIELD_SHARED_LINK ) ) { return ( ( BoxSharedLink ) mBodyMap . get ( BoxItem . FIELD_SHARED_LINK ) ) . getUnsharedDate ( ) ; } return null ; }
Returns the date the link will be disabled at currently set in the request .
74
15
152,231
public String getPassword ( ) { return mBodyMap . containsKey ( BoxItem . FIELD_SHARED_LINK ) ? ( ( BoxSharedLink ) mBodyMap . get ( BoxItem . FIELD_SHARED_LINK ) ) . getPassword ( ) : null ; }
Returns the shared link password currently set in the request .
65
11
152,232
public R setPassword ( final String password ) { JsonObject jsonObject = getSharedLinkJsonObject ( ) ; jsonObject . add ( BoxSharedLink . FIELD_PASSWORD , password ) ; BoxSharedLink sharedLink = new BoxSharedLink ( jsonObject ) ; mBodyMap . put ( BoxItem . FIELD_SHARED_LINK , sharedLink ) ; return ( R ) this ; }
Sets the shared link password in the request .
93
10
152,233
protected Boolean getCanDownload ( ) { return mBodyMap . containsKey ( BoxItem . FIELD_SHARED_LINK ) ? ( ( BoxSharedLink ) mBodyMap . get ( BoxItem . FIELD_SHARED_LINK ) ) . getPermissions ( ) . getCanDownload ( ) : null ; }
Returns the value for whether the shared link allows downloads currently set in the request .
73
16
152,234
protected R setCanDownload ( boolean canDownload ) { JsonObject jsonPermissionsObject = getPermissionsJsonObject ( ) ; jsonPermissionsObject . add ( BoxSharedLink . Permissions . FIELD_CAN_DOWNLOAD , canDownload ) ; BoxSharedLink . Permissions permissions = new BoxSharedLink . Permissions ( jsonPermissionsObject ) ; JsonObject sharedLinkJsonObject = getSharedLinkJsonObject ( ) ; sharedLinkJsonObject . add ( BoxSharedLink . FIELD_PERMISSIONS , permissions . toJsonObject ( ) ) ; BoxSharedLink sharedLink = new BoxSharedLink ( sharedLinkJsonObject ) ; mBodyMap . put ( BoxItem . FIELD_SHARED_LINK , sharedLink ) ; return ( R ) this ; }
Sets whether the shared link allows downloads in the request .
179
12
152,235
public R setFields ( String ... fields ) { if ( fields . length == 1 && fields [ 0 ] == null ) { mQueryMap . remove ( QUERY_FIELDS ) ; return ( R ) this ; } if ( fields . length > 0 ) { StringBuilder sb = new StringBuilder ( ) ; sb . append ( fields [ 0 ] ) ; for ( int i = 1 ; i < fields . length ; ++ i ) { sb . append ( String . format ( Locale . ENGLISH , ",%s" , fields [ i ] ) ) ; } mQueryMap . put ( QUERY_FIELDS , sb . toString ( ) ) ; } return ( R ) this ; }
Sets the fields to return in the response .
155
10
152,236
public R addRepresentationHintGroup ( String ... hints ) { if ( hints != null ) { mHintHeader . append ( "[" ) ; mHintHeader . append ( TextUtils . join ( "," , hints ) ) ; mHintHeader . append ( "]" ) ; } return ( R ) this ; }
Include a representation hint group into this request . Please refer to representation documentation for more details
71
18
152,237
public void onReceivedAuthCode ( String code , String baseDomain ) { if ( authType == AUTH_TYPE_WEBVIEW ) { oauthView . setVisibility ( View . INVISIBLE ) ; } startMakingOAuthAPICall ( code , baseDomain ) ; }
Callback method to be called when authentication code is received along with a base domain . The code will then be used to make an API call to create OAuth tokens .
61
33
152,238
public boolean onAuthFailure ( AuthFailure failure ) { if ( failure . type == OAuthWebView . AuthFailure . TYPE_WEB_ERROR ) { if ( failure . mWebException . getErrorCode ( ) == WebViewClient . ERROR_CONNECT || failure . mWebException . getErrorCode ( ) == WebViewClient . ERROR_HOST_LOOKUP || failure . mWebException . getErrorCode ( ) == WebViewClient . ERROR_TIMEOUT ) { return false ; } Resources resources = this . getResources ( ) ; Toast . makeText ( this , String . format ( "%s\n%s: %s" , resources . getString ( com . box . sdk . android . R . string . boxsdk_Authentication_fail ) , resources . getString ( com . box . sdk . android . R . string . boxsdk_details ) , failure . mWebException . getErrorCode ( ) + " " + failure . mWebException . getDescription ( ) ) , Toast . LENGTH_LONG ) . show ( ) ; } else if ( SdkUtils . isEmptyString ( failure . message ) ) { Toast . makeText ( this , R . string . boxsdk_Authentication_fail , Toast . LENGTH_LONG ) . show ( ) ; } else { switch ( failure . type ) { case OAuthWebView . AuthFailure . TYPE_URL_MISMATCH : Resources resources = this . getResources ( ) ; Toast . makeText ( this , String . format ( "%s\n%s: %s" , resources . getString ( com . box . sdk . android . R . string . boxsdk_Authentication_fail ) , resources . getString ( com . box . sdk . android . R . string . boxsdk_details ) , resources . getString ( com . box . sdk . android . R . string . boxsdk_Authentication_fail_url_mismatch ) ) , Toast . LENGTH_LONG ) . show ( ) ; break ; case OAuthWebView . AuthFailure . TYPE_AUTHENTICATION_UNAUTHORIZED : AlertDialog loginAlert = new AlertDialog . Builder ( this ) . setTitle ( com . box . sdk . android . R . string . boxsdk_Authentication_fail ) . setMessage ( com . box . sdk . android . R . string . boxsdk_Authentication_fail_forbidden ) . setPositiveButton ( com . box . sdk . android . R . string . boxsdk_button_ok , new DialogInterface . OnClickListener ( ) { @ Override public void onClick ( final DialogInterface dialog , final int whichButton ) { dialog . dismiss ( ) ; finish ( ) ; } } ) . create ( ) ; loginAlert . show ( ) ; return true ; default : Toast . makeText ( this , com . box . sdk . android . R . string . boxsdk_Authentication_fail , Toast . LENGTH_LONG ) . show ( ) ; } } finish ( ) ; return true ; }
Callback method to be called when authentication failed .
678
9
152,239
protected void startMakingOAuthAPICall ( final String code , final String baseDomain ) { if ( apiCallStarted . getAndSet ( true ) ) { return ; } showSpinner ( ) ; if ( baseDomain != null ) { mSession . getAuthInfo ( ) . setBaseDomain ( baseDomain ) ; BoxLogUtils . nonFatalE ( "setting Base Domain" , baseDomain , new RuntimeException ( "base domain being used" ) ) ; } new Thread ( ) { public void run ( ) { try { BoxAuthenticationInfo sessionAuth = BoxAuthentication . getInstance ( ) . create ( mSession , code ) . get ( ) ; String restrictedUserId = getIntent ( ) . getStringExtra ( EXTRA_USER_ID_RESTRICTION ) ; if ( ! SdkUtils . isEmptyString ( restrictedUserId ) && ! sessionAuth . getUser ( ) . getId ( ) . equals ( restrictedUserId ) ) { // the user logged in as does not match the user id this activity was restricted to, treat this as a failure. throw new RuntimeException ( "Unexpected user logged in. Expected " + restrictedUserId + " received " + sessionAuth . getUser ( ) . getId ( ) ) ; } dismissSpinnerAndFinishAuthenticate ( sessionAuth ) ; } catch ( Exception e ) { e . printStackTrace ( ) ; dismissSpinnerAndFailAuthenticate ( e ) ; } } } . start ( ) ; }
Start to create OAuth after getting the code .
321
10
152,240
protected Dialog showDialogWhileWaitingForAuthenticationAPICall ( ) { return ProgressDialog . show ( this , getText ( R . string . boxsdk_Authenticating ) , getText ( R . string . boxsdk_Please_wait ) ) ; }
If you don t need the dialog just return null .
58
11
152,241
public static Intent createOAuthActivityIntent ( final Context context , BoxSession session , boolean loginViaBoxApp ) { Intent intent = createOAuthActivityIntent ( context , session . getClientId ( ) , session . getClientSecret ( ) , session . getRedirectUrl ( ) , loginViaBoxApp ) ; intent . putExtra ( EXTRA_SESSION , session ) ; if ( ! SdkUtils . isEmptyString ( session . getUserId ( ) ) ) { intent . putExtra ( EXTRA_USER_ID_RESTRICTION , session . getUserId ( ) ) ; } return intent ; }
Create intent to launch OAuthActivity using information from the given session .
135
14
152,242
private OAuthWebView . AuthFailure getAuthFailure ( Exception e ) { String error = getString ( R . string . boxsdk_Authentication_fail ) ; if ( e != null ) { // Get the proper exception Throwable ex = e instanceof ExecutionException ? ( ( ExecutionException ) e ) . getCause ( ) : e ; if ( ex instanceof BoxException ) { BoxError boxError = ( ( BoxException ) ex ) . getAsBoxError ( ) ; if ( boxError != null ) { if ( ( ( BoxException ) ex ) . getResponseCode ( ) == HttpURLConnection . HTTP_FORBIDDEN || ( ( BoxException ) ex ) . getResponseCode ( ) == HttpURLConnection . HTTP_UNAUTHORIZED || boxError . getError ( ) . equals ( "unauthorized_device" ) ) { error += ":" + getResources ( ) . getText ( R . string . boxsdk_Authentication_fail_forbidden ) + "\n" ; } else { error += ":" ; } error += boxError . getErrorDescription ( ) ; return new OAuthWebView . AuthFailure ( OAuthWebView . AuthFailure . TYPE_AUTHENTICATION_UNAUTHORIZED , error ) ; } } error += ":" + ex ; } return new OAuthWebView . AuthFailure ( OAuthWebView . AuthFailure . TYPE_GENERIC , error ) ; }
Takes an auth exception and converts it to an AuthFailure so it can be properly handled
314
18
152,243
public BoxRequestsSearch . Search getSearchRequest ( String query ) { BoxRequestsSearch . Search request = new BoxRequestsSearch . Search ( query , getSearchUrl ( ) , mSession ) ; return request ; }
Gets a request to search
47
6
152,244
protected void importRequestContentMapsFrom ( BoxRequest source ) { this . mQueryMap = new HashMap < String , String > ( source . mQueryMap ) ; this . mBodyMap = new LinkedHashMap < String , Object > ( source . mBodyMap ) ; }
Copies data from query and body maps into the current request .
60
13
152,245
public final T send ( ) throws BoxException { Exception ex = null ; T result = null ; try { result = onSend ( ) ; } catch ( Exception e ) { ex = e ; } // We catch the exception so that onSendCompleted can be called in case additional actions need to be taken onSendCompleted ( new BoxResponse ( result , ex , this ) ) ; if ( ex != null ) { if ( ex instanceof BoxException ) { throw ( BoxException ) ex ; } else { throw new BoxException ( "unexpected exception " , ex ) ; } } return result ; }
Synchronously make the request to Box and handle the response appropriately .
124
14
152,246
public String getStringBody ( ) throws UnsupportedEncodingException { if ( mStringBody != null ) return mStringBody ; if ( mContentType != null ) { switch ( mContentType ) { case JSON : JsonObject jsonBody = new JsonObject ( ) ; for ( Map . Entry < String , Object > entry : mBodyMap . entrySet ( ) ) { parseHashMapEntry ( jsonBody , entry ) ; } mStringBody = jsonBody . toString ( ) ; break ; case URL_ENCODED : HashMap < String , String > stringMap = new HashMap < String , String > ( ) ; for ( Map . Entry < String , Object > entry : mBodyMap . entrySet ( ) ) { stringMap . put ( entry . getKey ( ) , ( String ) entry . getValue ( ) ) ; } mStringBody = createQuery ( stringMap ) ; break ; case JSON_PATCH : mStringBody = ( ( BoxArray ) mBodyMap . get ( JSON_OBJECT ) ) . toJson ( ) ; break ; } } return mStringBody ; }
Gets the string body for the request .
238
9
152,247
protected < R extends BoxRequest & BoxCacheableRequest > BoxFutureTask < T > handleToTaskForCachedResult ( ) throws BoxException { BoxCache cache = BoxConfig . getCache ( ) ; if ( cache == null ) { throw new BoxException . CacheImplementationNotFound ( ) ; } return new BoxCacheFutureTask < T , R > ( mClazz , ( R ) getCacheableRequest ( ) , cache ) ; }
Default implementation for getting a task to execute the request .
94
11
152,248
protected void handleUpdateCache ( BoxResponse < T > response ) throws BoxException { BoxCache cache = BoxConfig . getCache ( ) ; if ( cache != null ) { cache . put ( response ) ; } }
If available makes a call to update the cache with the provided result
45
13
152,249
protected Socket getSocket ( ) { if ( mSocketFactoryRef != null && mSocketFactoryRef . get ( ) != null ) { return ( ( SSLSocketFactoryWrapper ) mSocketFactoryRef . get ( ) ) . getSocket ( ) ; } return null ; }
This method requires mRequiresSocket to be set to true before connecting .
58
14
152,250
public BoxAuthenticationInfo getAuthInfo ( String userId , Context context ) { return userId == null ? null : getAuthInfoMap ( context ) . get ( userId ) ; }
Get the BoxAuthenticationInfo for a given user .
40
11
152,251
public void onAuthenticated ( BoxAuthenticationInfo infoOriginal , Context context ) { BoxAuthenticationInfo info = BoxAuthenticationInfo . unmodifiableObject ( infoOriginal ) ; if ( ! SdkUtils . isBlank ( info . accessToken ( ) ) && ( info . getUser ( ) == null || SdkUtils . isBlank ( info . getUser ( ) . getId ( ) ) ) ) { // insufficient information so we need to fetch the user info first. doUserRefresh ( context , info ) ; return ; } getAuthInfoMap ( context ) . put ( info . getUser ( ) . getId ( ) , info . clone ( ) ) ; authStorage . storeLastAuthenticatedUserId ( info . getUser ( ) . getId ( ) , context ) ; authStorage . storeAuthInfoMap ( mCurrentAccessInfo , context ) ; // if accessToken has not already been refreshed, issue refresh request and cache result Set < AuthListener > listeners = getListeners ( ) ; for ( AuthListener listener : listeners ) { listener . onAuthCreated ( info ) ; } }
Callback method to be called when authentication process finishes .
236
10
152,252
public void onAuthenticationFailure ( BoxAuthenticationInfo infoOriginal , Exception ex ) { String msg = "failure:" ; if ( getAuthStorage ( ) != null ) { msg += "auth storage :" + getAuthStorage ( ) . toString ( ) ; } BoxAuthenticationInfo info = BoxAuthenticationInfo . unmodifiableObject ( infoOriginal ) ; if ( info != null ) { msg += info . getUser ( ) == null ? "null user" : info . getUser ( ) . getId ( ) == null ? "null user id" : info . getUser ( ) . getId ( ) . length ( ) ; } BoxLogUtils . nonFatalE ( "BoxAuthfail" , msg , ex ) ; Set < AuthListener > listeners = getListeners ( ) ; for ( AuthListener listener : listeners ) { listener . onAuthFailure ( info , ex ) ; } }
Callback method to be called if authentication process fails .
193
10
152,253
public void onLoggedOut ( BoxAuthenticationInfo infoOriginal , Exception ex ) { BoxAuthenticationInfo info = BoxAuthenticationInfo . unmodifiableObject ( infoOriginal ) ; Set < AuthListener > listeners = getListeners ( ) ; for ( AuthListener listener : listeners ) { listener . onLoggedOut ( info , ex ) ; } }
Callback method to be called on logout .
74
9
152,254
public synchronized void logout ( final BoxSession session ) { BoxUser user = session . getUser ( ) ; if ( user == null ) { return ; } session . clearCache ( ) ; Context context = session . getApplicationContext ( ) ; String userId = user . getId ( ) ; getAuthInfoMap ( session . getApplicationContext ( ) ) ; BoxAuthenticationInfo info = mCurrentAccessInfo . get ( userId ) ; Exception ex = null ; try { BoxApiAuthentication api = new BoxApiAuthentication ( session ) ; BoxApiAuthentication . BoxRevokeAuthRequest request = api . revokeOAuth ( info . refreshToken ( ) , session . getClientId ( ) , session . getClientSecret ( ) ) ; request . send ( ) ; } catch ( Exception e ) { ex = e ; BoxLogUtils . e ( TAG , "logout" , e ) ; // Do nothing as we want to continue wiping auth info } mCurrentAccessInfo . remove ( userId ) ; String lastUserId = authStorage . getLastAuthentictedUserId ( context ) ; if ( lastUserId != null ) { authStorage . storeLastAuthenticatedUserId ( null , context ) ; } authStorage . storeAuthInfoMap ( mCurrentAccessInfo , context ) ; onLoggedOut ( info , ex ) ; info . wipeOutAuth ( ) ; }
Log out current BoxSession . After logging out the authentication information related to the Box user in this session will be gone .
295
24
152,255
public synchronized void logoutAllUsers ( Context context ) { getAuthInfoMap ( context ) ; for ( String userId : mCurrentAccessInfo . keySet ( ) ) { BoxSession session = new BoxSession ( context , userId ) ; logout ( session ) ; } authStorage . clearAuthInfoMap ( context ) ; }
Log out all users . After logging out all authentication information will be gone .
70
15
152,256
public synchronized FutureTask < BoxAuthenticationInfo > create ( BoxSession session , final String code ) { FutureTask < BoxAuthenticationInfo > task = doCreate ( session , code ) ; BoxAuthentication . AUTH_EXECUTOR . submit ( task ) ; return task ; }
Create Oauth for the first time . This method should be called by ui to authenticate the user for the first time .
59
26
152,257
public synchronized FutureTask < BoxAuthenticationInfo > refresh ( BoxSession session ) { BoxUser user = session . getUser ( ) ; if ( user == null ) { return doRefresh ( session , session . getAuthInfo ( ) ) ; } // Fetch auth info map from storage if not present. getAuthInfoMap ( session . getApplicationContext ( ) ) ; BoxAuthenticationInfo info = mCurrentAccessInfo . get ( user . getId ( ) ) ; if ( info == null ) { // session has info that we do not. ? is there any other situation we want to update our info based on session info? we can do checks against // refresh time. mCurrentAccessInfo . put ( user . getId ( ) , session . getAuthInfo ( ) ) ; info = mCurrentAccessInfo . get ( user . getId ( ) ) ; } // No need to refresh if we have already refreshed within 15 seconds or have a newer access token already. if ( session . getAuthInfo ( ) . accessToken ( ) == null || ( ! session . getAuthInfo ( ) . accessToken ( ) . equals ( info . accessToken ( ) ) && info . getRefreshTime ( ) != null && System . currentTimeMillis ( ) - info . getRefreshTime ( ) < 15000 ) ) { final BoxAuthenticationInfo latestInfo = info ; // this session is probably using old information. Give it our information. BoxAuthenticationInfo . cloneInfo ( session . getAuthInfo ( ) , info ) ; FutureTask task = new FutureTask <> ( new Callable < BoxAuthenticationInfo > ( ) { @ Override public BoxAuthenticationInfo call ( ) throws Exception { return latestInfo ; } } ) ; AUTH_EXECUTOR . execute ( task ) ; return task ; } FutureTask task = mRefreshingTasks . get ( user . getId ( ) ) ; if ( task != null && ! ( task . isCancelled ( ) || task . isDone ( ) ) ) { // We already have a refreshing task for this user. No need to do anything. return task ; } // long currentTime = System.currentTimeMillis(); // if ((currentTime - info.refreshTime) > info.refreshTime - EXPIRATION_GRACE) { // this access info is close to expiration or has passed expiration time needs to be refreshed before usage. // } // create the task to do the refresh and put it in mRefreshingTasks and execute it. return doRefresh ( session , info ) ; }
Refresh the OAuth in the given BoxSession . This method is called when OAuth token expires .
544
21
152,258
public synchronized void addListener ( AuthListener listener ) { if ( getListeners ( ) . contains ( listener ) ) { return ; } mListeners . add ( new WeakReference <> ( listener ) ) ; }
Add listener to listen to the authentication process for this BoxSession .
45
13
152,259
private synchronized void startAuthenticateUI ( BoxSession session ) { Context context = session . getApplicationContext ( ) ; Intent intent = OAuthActivity . createOAuthActivityIntent ( context , session , BoxAuthentication . isBoxAuthAppAvailable ( context ) && session . isEnabledBoxAppAuthentication ( ) ) ; intent . addFlags ( Intent . FLAG_ACTIVITY_NEW_TASK ) ; context . startActivity ( intent ) ; }
Start authentication UI .
96
4
152,260
public static boolean isBoxAuthAppAvailable ( final Context context ) { Intent intent = new Intent ( BoxConstants . REQUEST_BOX_APP_FOR_AUTH_INTENT_ACTION ) ; List < ResolveInfo > infos = context . getPackageManager ( ) . queryIntentActivities ( intent , PackageManager . MATCH_DEFAULT_ONLY | PackageManager . GET_RESOLVED_FILTER ) ; return infos . size ( ) > 0 ; }
A check to see if an official box application supporting third party authentication is available . This lets users authenticate without re - entering credentials .
104
27
152,261
public boolean removeHeaderView ( View v ) { if ( mHeaderViewInfos . size ( ) > 0 ) { boolean result = false ; ListAdapter adapter = getAdapter ( ) ; if ( adapter != null && ( ( HeaderViewGridAdapter ) adapter ) . removeHeader ( v ) ) { result = true ; } removeFixedViewInfo ( v , mHeaderViewInfos ) ; return result ; } return false ; }
Removes a previously - added header view .
89
9
152,262
public ListJobsResponse listJobs ( String marker , int maxKeys ) { return listJobs ( new ListJobsRequest ( ) . withMaxKeys ( maxKeys ) . withMarker ( marker ) ) ; }
List Batch - Compute jobs owned by the authenticated user .
47
13
152,263
public CreateJobResponse createJob ( CreateJobRequest request ) { checkNotNull ( request , "request should not be null." ) ; checkStringNotEmpty ( request . getName ( ) , "The name should not be null or empty string." ) ; checkStringNotEmpty ( request . getVmType ( ) , "The vmType should not be null or empty string." ) ; checkStringNotEmpty ( request . getJobDagJson ( ) , "The jobDagJson should not be null or empty string." ) ; checkIsTrue ( request . getVmCount ( ) > 0 , "The vmCount should greater than 0" ) ; StringWriter writer = new StringWriter ( ) ; try { JsonGenerator jsonGenerator = JsonUtils . jsonGeneratorOf ( writer ) ; jsonGenerator . writeStartObject ( ) ; jsonGenerator . writeStringField ( "name" , request . getName ( ) ) ; jsonGenerator . writeStringField ( "vmType" , request . getVmType ( ) ) ; jsonGenerator . writeNumberField ( "vmCount" , request . getVmCount ( ) ) ; jsonGenerator . writeStringField ( "jobDagJson" , request . getJobDagJson ( ) ) ; if ( request . getJobTimeoutInSeconds ( ) != null ) { jsonGenerator . writeNumberField ( "jobTimeoutInSeconds" , request . getJobTimeoutInSeconds ( ) ) ; } if ( request . getMemo ( ) != null ) { jsonGenerator . writeStringField ( "memo" , request . getMemo ( ) ) ; } jsonGenerator . writeEndObject ( ) ; jsonGenerator . close ( ) ; } catch ( IOException e ) { throw new BceClientException ( "Fail to generate json" , e ) ; } byte [ ] json = null ; try { json = writer . toString ( ) . getBytes ( DEFAULT_ENCODING ) ; } catch ( UnsupportedEncodingException e ) { throw new BceClientException ( "Fail to get UTF-8 bytes" , e ) ; } InternalRequest internalRequest = this . createRequest ( request , HttpMethodName . POST , JOB ) ; internalRequest . addHeader ( Headers . CONTENT_LENGTH , String . valueOf ( json . length ) ) ; internalRequest . addHeader ( Headers . CONTENT_TYPE , "application/json" ) ; internalRequest . setContent ( RestartableInputStream . wrap ( json ) ) ; internalRequest . addParameter ( "run" , "immediate" ) ; if ( request . getClientToken ( ) != null ) { internalRequest . addParameter ( "clientToken" , request . getClientToken ( ) ) ; } return this . invokeHttpClient ( internalRequest , CreateJobResponse . class ) ; }
Create a Batch - Compute job with the specified options .
619
13
152,264
public void cancelJob ( CancelJobRequest request ) { checkNotNull ( request , "request should not be null." ) ; checkStringNotEmpty ( request . getJobId ( ) , "The parameter jobId should not be null or empty string." ) ; InternalRequest internalRequest = this . createRequest ( request , HttpMethodName . PUT , JOB , request . getJobId ( ) ) ; internalRequest . addParameter ( "cancel" , null ) ; this . invokeHttpClient ( internalRequest , AbstractBceResponse . class ) ; }
Cancel a Batch - Compute job .
118
10
152,265
private InternalRequest createRequest ( AbstractBceRequest bceRequest , HttpMethodName httpMethod , String ... pathVariables ) { List < String > path = new ArrayList < String > ( ) ; path . add ( VERSION ) ; if ( pathVariables != null ) { for ( String pathVariable : pathVariables ) { path . add ( pathVariable ) ; } } URI uri = HttpUtils . appendUri ( this . getEndpoint ( ) , path . toArray ( new String [ path . size ( ) ] ) ) ; InternalRequest request = new InternalRequest ( httpMethod , uri ) ; SignOptions signOptions = new SignOptions ( ) ; signOptions . setHeadersToSign ( new HashSet < String > ( Arrays . asList ( HEADERS_TO_SIGN ) ) ) ; request . setSignOptions ( signOptions ) ; request . setCredentials ( bceRequest . getRequestCredentials ( ) ) ; return request ; }
Creates and initializes a new request object for the specified resource .
211
14
152,266
public ListRuleResponse listRules ( ListRuleRequest request ) { InternalRequest internalRequest = createRequest ( request , HttpMethodName . GET , RULES ) ; if ( request . getPageNo ( ) > 0 ) { internalRequest . addParameter ( "pageNo" , String . valueOf ( request . getPageNo ( ) ) ) ; } if ( request . getPageSize ( ) > 0 ) { internalRequest . addParameter ( "pageSize" , String . valueOf ( request . getPageSize ( ) ) ) ; } return this . invokeHttpClient ( internalRequest , ListRuleResponse . class ) ; }
list all the rules under this account
133
7
152,267
private InternalRequest createRequest ( AbstractBceRequest bceRequest , HttpMethodName httpMethod , String ... pathVariables ) { List < String > path = new ArrayList < String > ( ) ; path . add ( VERSION ) ; if ( pathVariables != null ) { for ( String pathVariable : pathVariables ) { path . add ( pathVariable ) ; } } URI uri = HttpUtils . appendUri ( this . getEndpoint ( ) , path . toArray ( new String [ path . size ( ) ] ) ) ; InternalRequest request = new InternalRequest ( httpMethod , uri ) ; request . setCredentials ( bceRequest . getRequestCredentials ( ) ) ; return request ; }
Creates and initializes a new request object for the specified bcc resource . This method is responsible for determining the right way to address resources .
158
29
152,268
private void fillPayload ( InternalRequest internalRequest , AbstractBceRequest bceRequest ) { if ( internalRequest . getHttpMethod ( ) == HttpMethodName . POST || internalRequest . getHttpMethod ( ) == HttpMethodName . PUT ) { String strJson = JsonUtils . toJsonString ( bceRequest ) ; byte [ ] requestJson = null ; try { requestJson = strJson . getBytes ( DEFAULT_ENCODING ) ; } catch ( UnsupportedEncodingException e ) { throw new BceClientException ( "Unsupported encode." , e ) ; } internalRequest . addHeader ( Headers . CONTENT_LENGTH , String . valueOf ( requestJson . length ) ) ; internalRequest . addHeader ( Headers . CONTENT_TYPE , DEFAULT_CONTENT_TYPE ) ; internalRequest . setContent ( RestartableInputStream . wrap ( requestJson ) ) ; } }
The method to fill the internalRequest s content field with bceRequest . Only support HttpMethodName . POST or HttpMethodName . PUT
207
31
152,269
private String aes128WithFirst16Char ( String content , String privateKey ) throws GeneralSecurityException { byte [ ] crypted = null ; SecretKeySpec skey = new SecretKeySpec ( privateKey . substring ( 0 , 16 ) . getBytes ( ) , "AES" ) ; Cipher cipher = Cipher . getInstance ( "AES/ECB/PKCS5Padding" ) ; cipher . init ( Cipher . ENCRYPT_MODE , skey ) ; crypted = cipher . doFinal ( content . getBytes ( ) ) ; return new String ( Hex . encodeHex ( crypted ) ) ; }
The encryption implement for AES - 128 algorithm for BCE password encryption . Only the first 16 bytes of privateKey will be used to encrypt the content .
135
29
152,270
public ListInstancesResponse listInstances ( ListInstancesRequest request ) { checkNotNull ( request , "request should not be null." ) ; InternalRequest internalRequest = this . createRequest ( request , HttpMethodName . GET , INSTANCE_PREFIX ) ; if ( request . getMarker ( ) != null ) { internalRequest . addParameter ( "marker" , request . getMarker ( ) ) ; } if ( request . getMaxKeys ( ) > 0 ) { internalRequest . addParameter ( "maxKeys" , String . valueOf ( request . getMaxKeys ( ) ) ) ; } if ( ! Strings . isNullOrEmpty ( request . getInternalIp ( ) ) ) { internalRequest . addParameter ( "internalIp" , request . getInternalIp ( ) ) ; } if ( ! Strings . isNullOrEmpty ( request . getDedicatedHostId ( ) ) ) { internalRequest . addParameter ( "dedicatedHostId" , request . getDedicatedHostId ( ) ) ; } if ( ! Strings . isNullOrEmpty ( request . getZoneName ( ) ) ) { internalRequest . addParameter ( "zoneName" , request . getZoneName ( ) ) ; } return invokeHttpClient ( internalRequest , ListInstancesResponse . class ) ; }
Return a list of instances owned by the authenticated user .
286
11
152,271
public GetInstanceResponse getInstance ( GetInstanceRequest request ) { checkNotNull ( request , "request should not be null." ) ; checkNotNull ( request . getInstanceId ( ) , "request instanceId should not be null." ) ; InternalRequest internalRequest = this . createRequest ( request , HttpMethodName . GET , INSTANCE_PREFIX , request . getInstanceId ( ) ) ; return this . invokeHttpClient ( internalRequest , GetInstanceResponse . class ) ; }
Get the detail information of specified instance .
104
8
152,272
public void startInstance ( StartInstanceRequest request ) { checkNotNull ( request , "request should not be null." ) ; checkStringNotEmpty ( request . getInstanceId ( ) , "request instanceId should not be empty." ) ; InternalRequest internalRequest = this . createRequest ( request , HttpMethodName . PUT , INSTANCE_PREFIX , request . getInstanceId ( ) ) ; internalRequest . addParameter ( InstanceAction . start . name ( ) , null ) ; fillPayload ( internalRequest , request ) ; this . invokeHttpClient ( internalRequest , AbstractBceResponse . class ) ; }
Starting the instance owned by the user .
133
8
152,273
public void modifyInstanceAttributes ( ModifyInstanceAttributesRequest request ) { checkNotNull ( request , "request should not be null." ) ; checkStringNotEmpty ( request . getInstanceId ( ) , "request instanceId should not be empty." ) ; checkStringNotEmpty ( request . getName ( ) , "request name should not be empty." ) ; InternalRequest internalRequest = this . createRequest ( request , HttpMethodName . PUT , INSTANCE_PREFIX , request . getInstanceId ( ) ) ; internalRequest . addParameter ( InstanceAction . modifyAttribute . name ( ) , null ) ; fillPayload ( internalRequest , request ) ; this . invokeHttpClient ( internalRequest , AbstractBceResponse . class ) ; }
Modifying the special attribute to new value of the instance .
159
12
152,274
public void rebuildInstance ( String instanceId , String imageId , String adminPass ) throws BceClientException { this . rebuildInstance ( new RebuildInstanceRequest ( ) . withInstanceId ( instanceId ) . withImageId ( imageId ) . withAdminPass ( adminPass ) ) ; }
Rebuilding the instance owned by the user .
62
9
152,275
public void releaseInstance ( ReleaseInstanceRequest request ) { checkNotNull ( request , "request should not be null." ) ; checkStringNotEmpty ( request . getInstanceId ( ) , "request instanceId should not be empty." ) ; InternalRequest internalRequest = this . createRequest ( request , HttpMethodName . DELETE , INSTANCE_PREFIX , request . getInstanceId ( ) ) ; this . invokeHttpClient ( internalRequest , AbstractBceResponse . class ) ; }
Releasing the instance owned by the user .
105
9
152,276
public void resizeInstance ( ResizeInstanceRequest request ) { checkNotNull ( request , "request should not be null." ) ; if ( Strings . isNullOrEmpty ( request . getClientToken ( ) ) ) { request . setClientToken ( this . generateClientToken ( ) ) ; } checkStringNotEmpty ( request . getInstanceId ( ) , "request instanceId should not be empty." ) ; if ( request . getCpuCount ( ) <= 0 ) { throw new IllegalArgumentException ( "request cpuCount should be positive." ) ; } if ( request . getMemoryCapacityInGB ( ) <= 0 ) { throw new IllegalArgumentException ( "request memoryCapacityInGB should be positive." ) ; } InternalRequest internalRequest = this . createRequest ( request , HttpMethodName . PUT , INSTANCE_PREFIX , request . getInstanceId ( ) ) ; internalRequest . addParameter ( InstanceAction . resize . name ( ) , null ) ; internalRequest . addParameter ( "clientToken" , request . getClientToken ( ) ) ; fillPayload ( internalRequest , request ) ; this . invokeHttpClient ( internalRequest , AbstractBceResponse . class ) ; }
Resizing the instance owned by the user .
259
9
152,277
public GetInstanceVncResponse getInstanceVnc ( GetInstanceVncRequest request ) { checkNotNull ( request , "request should not be null." ) ; checkStringNotEmpty ( request . getInstanceId ( ) , "request instanceId should not be empty." ) ; InternalRequest internalRequest = this . createRequest ( request , HttpMethodName . GET , INSTANCE_PREFIX , request . getInstanceId ( ) , "vnc" ) ; return this . invokeHttpClient ( internalRequest , GetInstanceVncResponse . class ) ; }
Getting the vnc url to access the instance .
118
10
152,278
public void purchaseReservedInstance ( PurchaseReservedInstanceRequeset request ) { checkNotNull ( request , "request should not be null." ) ; if ( Strings . isNullOrEmpty ( request . getClientToken ( ) ) ) { request . setClientToken ( this . generateClientToken ( ) ) ; } if ( null == request . getBilling ( ) ) { request . setBilling ( generateDefaultBillingWithReservation ( ) ) ; } checkStringNotEmpty ( request . getInstanceId ( ) , "request instanceId should not be empty." ) ; InternalRequest internalRequest = this . createRequest ( request , HttpMethodName . PUT , INSTANCE_PREFIX , request . getInstanceId ( ) ) ; internalRequest . addParameter ( InstanceAction . purchaseReserved . name ( ) , null ) ; internalRequest . addParameter ( "clientToken" , request . getClientToken ( ) ) ; fillPayload ( internalRequest , request ) ; this . invokeHttpClient ( internalRequest , AbstractBceResponse . class ) ; }
Renewing the instance with fixed duration .
228
9
152,279
public CreateVolumeResponse createVolume ( CreateVolumeRequest request ) { checkNotNull ( request , "request should not be null." ) ; if ( Strings . isNullOrEmpty ( request . getClientToken ( ) ) ) { request . setClientToken ( this . generateClientToken ( ) ) ; } if ( null == request . getBilling ( ) ) { request . setBilling ( generateDefaultBilling ( ) ) ; } InternalRequest internalRequest = this . createRequest ( request , HttpMethodName . POST , VOLUME_PREFIX ) ; internalRequest . addParameter ( "clientToken" , request . getClientToken ( ) ) ; fillPayload ( internalRequest , request ) ; return invokeHttpClient ( internalRequest , CreateVolumeResponse . class ) ; }
Create a volume with the specified options .
165
8
152,280
public ListVolumesResponse listVolumes ( ListVolumesRequest request ) { InternalRequest internalRequest = this . createRequest ( request , HttpMethodName . GET , VOLUME_PREFIX ) ; if ( request . getMarker ( ) != null ) { internalRequest . addParameter ( "marker" , request . getMarker ( ) ) ; } if ( request . getMaxKeys ( ) > 0 ) { internalRequest . addParameter ( "maxKeys" , String . valueOf ( request . getMaxKeys ( ) ) ) ; } if ( ! Strings . isNullOrEmpty ( request . getInstanceId ( ) ) ) { internalRequest . addParameter ( "instanceId" , request . getInstanceId ( ) ) ; } if ( ! Strings . isNullOrEmpty ( request . getZoneName ( ) ) ) { internalRequest . addParameter ( "zoneName" , request . getZoneName ( ) ) ; } return invokeHttpClient ( internalRequest , ListVolumesResponse . class ) ; }
Listing volumes owned by the authenticated user .
218
9
152,281
public GetVolumeResponse getVolume ( GetVolumeRequest request ) { checkNotNull ( request , "request should not be null." ) ; checkStringNotEmpty ( request . getVolumeId ( ) , "request volumeId should not be empty." ) ; InternalRequest internalRequest = this . createRequest ( request , HttpMethodName . GET , VOLUME_PREFIX , request . getVolumeId ( ) ) ; return invokeHttpClient ( internalRequest , GetVolumeResponse . class ) ; }
Get the detail information of specified volume .
103
8
152,282
public void releaseVolume ( ReleaseVolumeRequest request ) { checkNotNull ( request , "request should not be null." ) ; checkStringNotEmpty ( request . getVolumeId ( ) , "request volumeId should not be empty." ) ; InternalRequest internalRequest = this . createRequest ( request , HttpMethodName . DELETE , VOLUME_PREFIX , request . getVolumeId ( ) ) ; invokeHttpClient ( internalRequest , AbstractBceResponse . class ) ; }
Releasing the specified volume owned by the user .
103
10
152,283
public CreateImageResponse createImageFromInstance ( String imageName , String instanceId ) { return createImage ( new CreateImageRequest ( ) . withImageName ( imageName ) . withInstanceId ( instanceId ) ) ; }
Creating a customized image from the instance ..
47
8
152,284
public CreateImageResponse createImageFromSnapshot ( String imageName , String snapshotId ) { return createImage ( new CreateImageRequest ( ) . withImageName ( imageName ) . withSnapshotId ( snapshotId ) ) ; }
Creating a customized image from specified snapshot .
49
8
152,285
public CreateImageResponse createImage ( CreateImageRequest request ) { checkNotNull ( request , "request should not be null." ) ; if ( Strings . isNullOrEmpty ( request . getClientToken ( ) ) ) { request . setClientToken ( this . generateClientToken ( ) ) ; } checkStringNotEmpty ( request . getImageName ( ) , "request imageName should not be empty." ) ; if ( Strings . isNullOrEmpty ( request . getInstanceId ( ) ) && Strings . isNullOrEmpty ( request . getSnapshotId ( ) ) ) { throw new IllegalArgumentException ( "request instanceId or snapshotId should not be empty ." ) ; } InternalRequest internalRequest = this . createRequest ( request , HttpMethodName . POST , IMAGE_PREFIX ) ; internalRequest . addParameter ( "clientToken" , request . getClientToken ( ) ) ; fillPayload ( internalRequest , request ) ; return invokeHttpClient ( internalRequest , CreateImageResponse . class ) ; }
Creating a customized image which can be used for creating instance in the future .
221
15
152,286
public ListImagesResponse listImages ( ListImagesRequest request ) { checkNotNull ( request , "request should not be null." ) ; InternalRequest internalRequest = this . createRequest ( request , HttpMethodName . GET , IMAGE_PREFIX ) ; if ( ! Strings . isNullOrEmpty ( request . getMarker ( ) ) ) { internalRequest . addParameter ( "marker" , request . getMarker ( ) ) ; } if ( request . getMaxKeys ( ) > 0 ) { internalRequest . addParameter ( "maxKeys" , String . valueOf ( request . getMaxKeys ( ) ) ) ; } if ( ! Strings . isNullOrEmpty ( request . getImageType ( ) ) ) { internalRequest . addParameter ( "imageType" , request . getImageType ( ) ) ; } return invokeHttpClient ( internalRequest , ListImagesResponse . class ) ; }
Listing images owned by the authenticated user .
195
9
152,287
public GetImageResponse getImage ( GetImageRequest request ) { checkNotNull ( request , "request should not be null." ) ; checkStringNotEmpty ( request . getImageId ( ) , "request imageId should not be empty." ) ; InternalRequest internalRequest = this . createRequest ( request , HttpMethodName . GET , IMAGE_PREFIX , request . getImageId ( ) ) ; return invokeHttpClient ( internalRequest , GetImageResponse . class ) ; }
Get the detail information of specified image .
103
8
152,288
public void deleteImage ( DeleteImageRequest request ) { checkNotNull ( request , "request should not be null." ) ; checkStringNotEmpty ( request . getImageId ( ) , "request imageId should not be empty." ) ; InternalRequest internalRequest = this . createRequest ( request , HttpMethodName . DELETE , IMAGE_PREFIX , request . getImageId ( ) ) ; invokeHttpClient ( internalRequest , AbstractBceResponse . class ) ; }
Deleting the specified image .
103
7
152,289
public ListSnapshotsResponse listSnapshots ( ListSnapshotsRequest request ) { checkNotNull ( request , "request should not be null." ) ; InternalRequest internalRequest = this . createRequest ( request , HttpMethodName . GET , SNAPSHOT_PREFIX ) ; if ( ! Strings . isNullOrEmpty ( request . getMarker ( ) ) ) { internalRequest . addParameter ( "marker" , request . getMarker ( ) ) ; } if ( request . getMaxKeys ( ) > 0 ) { internalRequest . addParameter ( "maxKeys" , String . valueOf ( request . getMaxKeys ( ) ) ) ; } if ( ! Strings . isNullOrEmpty ( request . getVolumeId ( ) ) ) { internalRequest . addParameter ( "volumeId" , request . getVolumeId ( ) ) ; } return invokeHttpClient ( internalRequest , ListSnapshotsResponse . class ) ; }
Listing snapshots owned by the authenticated user .
200
9
152,290
public GetSnapshotResponse getSnapshot ( GetSnapshotRequest request ) { checkNotNull ( request , "request should not be null." ) ; checkStringNotEmpty ( request . getSnapshotId ( ) , "request snapshotId should no be empty." ) ; InternalRequest internalRequest = this . createRequest ( request , HttpMethodName . GET , SNAPSHOT_PREFIX , request . getSnapshotId ( ) ) ; return invokeHttpClient ( internalRequest , GetSnapshotResponse . class ) ; }
Getting the detail information of specified snapshot .
110
8
152,291
public void deleteSnapshot ( DeleteSnapshotRequest request ) { checkNotNull ( request , "request should not be null." ) ; checkStringNotEmpty ( request . getSnapshotId ( ) , "request snapshotId should no be empty." ) ; InternalRequest internalRequest = this . createRequest ( request , HttpMethodName . DELETE , SNAPSHOT_PREFIX , request . getSnapshotId ( ) ) ; invokeHttpClient ( internalRequest , AbstractBceResponse . class ) ; }
Deleting the specified snapshot .
108
7
152,292
public ListSecurityGroupsResponse listSecurityGroups ( ListSecurityGroupsRequest request ) { checkNotNull ( request , "request should not be null." ) ; InternalRequest internalRequest = this . createRequest ( request , HttpMethodName . GET , SECURITYGROUP_PREFIX ) ; if ( ! Strings . isNullOrEmpty ( request . getMarker ( ) ) ) { internalRequest . addParameter ( "marker" , request . getMarker ( ) ) ; } if ( request . getMaxKeys ( ) > 0 ) { internalRequest . addParameter ( "maxKeys" , String . valueOf ( request . getMaxKeys ( ) ) ) ; } if ( ! Strings . isNullOrEmpty ( request . getInstanceId ( ) ) ) { internalRequest . addParameter ( "instanceId" , request . getInstanceId ( ) ) ; } if ( ! Strings . isNullOrEmpty ( request . getVpcId ( ) ) ) { internalRequest . addParameter ( "vpcId" , request . getVpcId ( ) ) ; } return invokeHttpClient ( internalRequest , ListSecurityGroupsResponse . class ) ; }
Listing SecurityGroup owned by the authenticated user .
250
10
152,293
public CreateSecurityGroupResponse createSecurityGroup ( CreateSecurityGroupRequest request ) { checkNotNull ( request , "request should not be null." ) ; if ( Strings . isNullOrEmpty ( request . getClientToken ( ) ) ) { request . setClientToken ( this . generateClientToken ( ) ) ; } checkStringNotEmpty ( request . getName ( ) , "request name should not be empty." ) ; if ( null == request . getRules ( ) || request . getRules ( ) . isEmpty ( ) ) { throw new IllegalArgumentException ( "request rules should not be empty" ) ; } InternalRequest internalRequest = this . createRequest ( request , HttpMethodName . POST , SECURITYGROUP_PREFIX ) ; internalRequest . addParameter ( "clientToken" , request . getClientToken ( ) ) ; fillPayload ( internalRequest , request ) ; return invokeHttpClient ( internalRequest , CreateSecurityGroupResponse . class ) ; }
Creating a newly SecurityGroup with specified rules .
207
9
152,294
public void authorizeSecurityGroupRule ( SecurityGroupRuleOperateRequest request ) { checkNotNull ( request , "request should not be null." ) ; checkStringNotEmpty ( request . getSecurityGroupId ( ) , "securityGroupId should not be empty." ) ; if ( Strings . isNullOrEmpty ( request . getClientToken ( ) ) ) { request . setClientToken ( this . generateClientToken ( ) ) ; } if ( null == request . getRule ( ) ) { throw new IllegalArgumentException ( "request rule should not be null" ) ; } InternalRequest internalRequest = this . createRequest ( request , HttpMethodName . PUT , SECURITYGROUP_PREFIX , request . getSecurityGroupId ( ) ) ; internalRequest . addParameter ( "authorizeRule" , null ) ; internalRequest . addParameter ( "clientToken" , request . getClientToken ( ) ) ; fillPayload ( internalRequest , request ) ; invokeHttpClient ( internalRequest , AbstractBceResponse . class ) ; }
authorizing a security group rule to a specified security group
222
11
152,295
public void deleteSecurityGroup ( DeleteSecurityGroupRequest request ) { checkNotNull ( request , "request should not be null." ) ; checkStringNotEmpty ( request . getSecurityGroupId ( ) , "request securityGroupId should not be empty." ) ; InternalRequest internalRequest = this . createRequest ( request , HttpMethodName . DELETE , SECURITYGROUP_PREFIX , request . getSecurityGroupId ( ) ) ; invokeHttpClient ( internalRequest , AbstractBceResponse . class ) ; }
Deleting the specified SecurityGroup .
110
8
152,296
public String getUserMetaDataOf ( String key ) { return this . userMetadata == null ? null : this . userMetadata . get ( key ) ; }
For internal use only . Returns the value of the userMetadata for the specified key .
35
18
152,297
public ListMediaResourceResponse listMediaResources ( int pageNo , int pageSize , String status , Date begin , Date end , String title ) { ListMediaResourceRequest request = new ListMediaResourceRequest ( ) . withPageNo ( pageNo ) . withPageSize ( pageSize ) . withStatus ( status ) . withBegin ( begin ) . withEnd ( end ) . withTitle ( title ) ; return listMediaResources ( request ) ; }
List the properties of all media resource managed by VOD service . recommend use marker mode to get high performance
93
21
152,298
public ListMediaResourceByMarkerResponse listMediaResourcesByMarker ( String marker , int maxSize , String status , Date begin , Date end , String title ) { ListMediaResourceByMarkerRequest request = new ListMediaResourceByMarkerRequest ( ) . withMarker ( marker ) . withMaxSize ( maxSize ) . withStatus ( status ) . withBegin ( begin ) . withEnd ( end ) . withTitle ( title ) ; return listMediaResourcesByMarker ( request ) ; }
Use marker mode to List the properties of all media resource managed by VOD service . If media size beyond 1000 strongly recommend to use marker mode
106
28
152,299
public GetMediaSourceDownloadResponse getMediaSourceDownload ( String mediaId , long expiredInSeconds ) { GetMediaSourceDownloadRequest request = new GetMediaSourceDownloadRequest ( ) . withMediaId ( mediaId ) . withExpiredInSeconds ( expiredInSeconds ) ; return getMediaSourceDownload ( request ) ; }
get media source download url .
69
6