idx
int64
0
165k
question
stringlengths
73
5.81k
target
stringlengths
5
918
11,800
public MediaCreditList getSeasonCredits ( int tvID , int seasonNumber ) throws MovieDbException { TmdbParameters parameters = new TmdbParameters ( ) ; parameters . add ( Param . ID , tvID ) ; parameters . add ( Param . SEASON_NUMBER , seasonNumber ) ; URL url = new ApiUrl ( apiKey , MethodBase . SEASON ) . subMethod ( MethodSub . CREDITS ) . buildUrl ( parameters ) ; String webpage = httpTools . getRequest ( url ) ; try { return MAPPER . readValue ( webpage , MediaCreditList . class ) ; } catch ( IOException ex ) { throw new MovieDbException ( ApiExceptionType . MAPPING_FAILED , "Failed to get credits" , url , ex ) ; } }
Get the cast & crew credits for a TV season by season number .
11,801
public URL buildUrl ( final TmdbParameters params ) { StringBuilder urlString = new StringBuilder ( TMDB_API_BASE ) ; LOG . trace ( "Method: '{}', Sub-method: '{}', Params: {}" , method . getValue ( ) , submethod . getValue ( ) , ToStringBuilder . reflectionToString ( params , ToStringStyle . SHORT_PREFIX_STYLE ) ) ; if ( method == MethodBase . SEASON || method == MethodBase . EPISODE ) { urlString . append ( MethodBase . TV . getValue ( ) ) ; } else { urlString . append ( method . getValue ( ) ) ; } if ( params . has ( Param . QUERY ) ) { urlString . append ( queryProcessing ( params ) ) ; } else { urlString . append ( idProcessing ( params ) ) ; } urlString . append ( otherProcessing ( params ) ) ; try { LOG . trace ( "URL: {}" , urlString . toString ( ) ) ; return new URL ( urlString . toString ( ) ) ; } catch ( MalformedURLException ex ) { LOG . warn ( "Failed to create URL {} - {}" , urlString . toString ( ) , ex . getMessage ( ) ) ; return null ; } }
Build the URL from the pre - created parameters .
11,802
private StringBuilder queryProcessing ( TmdbParameters params ) { StringBuilder urlString = new StringBuilder ( ) ; if ( submethod != MethodSub . NONE ) { urlString . append ( "/" ) . append ( submethod . getValue ( ) ) ; } urlString . append ( DELIMITER_FIRST ) . append ( Param . API_KEY . getValue ( ) ) . append ( apiKey ) . append ( DELIMITER_SUBSEQUENT ) . append ( Param . QUERY . getValue ( ) ) ; String query = ( String ) params . get ( Param . QUERY ) ; try { urlString . append ( URLEncoder . encode ( query , "UTF-8" ) ) ; } catch ( UnsupportedEncodingException ex ) { LOG . trace ( "Unable to encode query: '{}' trying raw." , query , ex ) ; urlString . append ( query ) ; } return urlString ; }
Create the query based URL portion
11,803
private StringBuilder idProcessing ( final TmdbParameters params ) { StringBuilder urlString = new StringBuilder ( ) ; if ( params . has ( Param . ID ) ) { urlString . append ( "/" ) . append ( params . get ( Param . ID ) ) ; } if ( params . has ( Param . SEASON_NUMBER ) ) { urlString . append ( "/season/" ) . append ( params . get ( Param . SEASON_NUMBER ) ) ; } if ( params . has ( Param . EPISODE_NUMBER ) ) { urlString . append ( "/episode/" ) . append ( params . get ( Param . EPISODE_NUMBER ) ) ; } if ( submethod != MethodSub . NONE ) { urlString . append ( "/" ) . append ( submethod . getValue ( ) ) ; } urlString . append ( DELIMITER_FIRST ) . append ( Param . API_KEY . getValue ( ) ) . append ( apiKey ) ; return urlString ; }
Create the ID based URL portion
11,804
private StringBuilder otherProcessing ( final TmdbParameters params ) { StringBuilder urlString = new StringBuilder ( ) ; for ( Map . Entry < Param , String > argEntry : params . getEntries ( ) ) { if ( IGNORE_PARAMS . contains ( argEntry . getKey ( ) ) ) { continue ; } urlString . append ( DELIMITER_SUBSEQUENT ) . append ( argEntry . getKey ( ) . getValue ( ) ) . append ( argEntry . getValue ( ) ) ; } return urlString ; }
Create a string of the remaining parameters
11,805
public Review getReview ( String reviewId ) throws MovieDbException { TmdbParameters parameters = new TmdbParameters ( ) ; parameters . add ( Param . ID , reviewId ) ; URL url = new ApiUrl ( apiKey , MethodBase . REVIEW ) . buildUrl ( parameters ) ; String webpage = httpTools . getRequest ( url ) ; try { return MAPPER . readValue ( webpage , Review . class ) ; } catch ( IOException ex ) { throw new MovieDbException ( ApiExceptionType . MAPPING_FAILED , "Failed to get review" , url , ex ) ; } }
Get the full details of a review by ID .
11,806
private String convertToJson ( Map < String , ? > map ) throws MovieDbException { try { return MAPPER . writeValueAsString ( map ) ; } catch ( JsonProcessingException ex ) { throw new MovieDbException ( ApiExceptionType . MAPPING_FAILED , "JSON conversion failed" , "" , ex ) ; } }
Use Jackson to convert Map to JSON string .
11,807
public ResultList < ChangeListItem > getChangeList ( MethodBase method , Integer page , String startDate , String endDate ) throws MovieDbException { TmdbParameters params = new TmdbParameters ( ) ; params . add ( Param . PAGE , page ) ; params . add ( Param . START_DATE , startDate ) ; params . add ( Param . END_DATE , endDate ) ; URL url = new ApiUrl ( apiKey , method ) . subMethod ( MethodSub . CHANGES ) . buildUrl ( params ) ; WrapperGenericList < ChangeListItem > wrapper = processWrapper ( getTypeReference ( ChangeListItem . class ) , url , "changes" ) ; return wrapper . getResultsList ( ) ; }
Get a list of Media IDs that have been edited .
11,808
public Discover year ( int year ) { if ( checkYear ( year ) ) { params . add ( Param . YEAR , year ) ; } return this ; }
Filter the results release dates to matches that include this value .
11,809
public Discover primaryReleaseYear ( int primaryReleaseYear ) { if ( checkYear ( primaryReleaseYear ) ) { params . add ( Param . PRIMARY_RELEASE_YEAR , primaryReleaseYear ) ; } return this ; }
Filter the results so that only the primary release date year has this value
11,810
public Discover firstAirDateYear ( int year ) { if ( checkYear ( year ) ) { params . add ( Param . FIRST_AIR_DATE_YEAR , year ) ; } return this ; }
Filter the air dates that match this year
11,811
public Discover firstAirDateYearGte ( int year ) { if ( checkYear ( year ) ) { params . add ( Param . FIRST_AIR_DATE_GTE , year ) ; } return this ; }
Filter the air dates to years that are greater than or equal to this year
11,812
public Discover firstAirDateYearLte ( int year ) { if ( checkYear ( year ) ) { params . add ( Param . FIRST_AIR_DATE_LTE , year ) ; } return this ; }
Filter the air dates to years that are less than or equal to this year
11,813
public boolean isValidPosterSize ( String posterSize ) { if ( StringUtils . isBlank ( posterSize ) || posterSizes . isEmpty ( ) ) { return false ; } return posterSizes . contains ( posterSize ) ; }
Check that the poster size is valid
11,814
public boolean isValidBackdropSize ( String backdropSize ) { if ( StringUtils . isBlank ( backdropSize ) || backdropSizes . isEmpty ( ) ) { return false ; } return backdropSizes . contains ( backdropSize ) ; }
Check that the backdrop size is valid
11,815
public boolean isValidProfileSize ( String profileSize ) { if ( StringUtils . isBlank ( profileSize ) || profileSizes . isEmpty ( ) ) { return false ; } return profileSizes . contains ( profileSize ) ; }
Check that the profile size is valid
11,816
public boolean isValidLogoSize ( String logoSize ) { if ( StringUtils . isBlank ( logoSize ) || logoSizes . isEmpty ( ) ) { return false ; } return logoSizes . contains ( logoSize ) ; }
Check that the logo size is valid
11,817
public boolean isValidSize ( String sizeToCheck ) { return isValidPosterSize ( sizeToCheck ) || isValidBackdropSize ( sizeToCheck ) || isValidProfileSize ( sizeToCheck ) || isValidLogoSize ( sizeToCheck ) ; }
Check to see if the size is valid for any of the images types
11,818
public ListItem < MovieInfo > getList ( String listId ) throws MovieDbException { TmdbParameters parameters = new TmdbParameters ( ) ; parameters . add ( Param . ID , listId ) ; URL url = new ApiUrl ( apiKey , MethodBase . LIST ) . buildUrl ( parameters ) ; String webpage = httpTools . getRequest ( url ) ; try { return MAPPER . readValue ( webpage , new TypeReference < ListItem < MovieInfo > > ( ) { } ) ; } catch ( IOException ex ) { throw new MovieDbException ( ApiExceptionType . MAPPING_FAILED , "Failed to get list" , url , ex ) ; } }
Get a list by its ID
11,819
public boolean checkItemStatus ( String listId , int mediaId ) throws MovieDbException { TmdbParameters parameters = new TmdbParameters ( ) ; parameters . add ( Param . ID , listId ) ; parameters . add ( Param . MOVIE_ID , mediaId ) ; URL url = new ApiUrl ( apiKey , MethodBase . LIST ) . subMethod ( MethodSub . ITEM_STATUS ) . buildUrl ( parameters ) ; String webpage = httpTools . getRequest ( url ) ; try { return MAPPER . readValue ( webpage , ListItemStatus . class ) . isItemPresent ( ) ; } catch ( IOException ex ) { throw new MovieDbException ( ApiExceptionType . MAPPING_FAILED , "Failed to get item status" , url , ex ) ; } }
Check to see if an ID is already on a list .
11,820
private StatusCode modifyMovieList ( String sessionId , String listId , int movieId , MethodSub operation ) throws MovieDbException { TmdbParameters parameters = new TmdbParameters ( ) ; parameters . add ( Param . SESSION_ID , sessionId ) ; parameters . add ( Param . ID , listId ) ; String jsonBody = new PostTools ( ) . add ( PostBody . MEDIA_ID , movieId ) . build ( ) ; URL url = new ApiUrl ( apiKey , MethodBase . LIST ) . subMethod ( operation ) . buildUrl ( parameters ) ; String webpage = httpTools . postRequest ( url , jsonBody ) ; try { return MAPPER . readValue ( webpage , StatusCode . class ) ; } catch ( IOException ex ) { throw new MovieDbException ( ApiExceptionType . MAPPING_FAILED , "Failed to remove item from list" , url , ex ) ; } }
Modify a list
11,821
public StatusCode removeItem ( String sessionId , String listId , int mediaId ) throws MovieDbException { return modifyMovieList ( sessionId , listId , mediaId , MethodSub . REMOVE_ITEM ) ; }
This method lets users delete items from a list that they created .
11,822
public StatusCode clear ( String sessionId , String listId , boolean confirm ) throws MovieDbException { TmdbParameters parameters = new TmdbParameters ( ) ; parameters . add ( Param . SESSION_ID , sessionId ) ; parameters . add ( Param . ID , listId ) ; parameters . add ( Param . CONFIRM , confirm ) ; URL url = new ApiUrl ( apiKey , MethodBase . LIST ) . subMethod ( MethodSub . CLEAR ) . buildUrl ( parameters ) ; String webpage = httpTools . postRequest ( url , "" ) ; try { return MAPPER . readValue ( webpage , StatusCode . class ) ; } catch ( IOException ex ) { throw new MovieDbException ( ApiExceptionType . MAPPING_FAILED , "Failed to clear list" , url , ex ) ; } }
Clear all of the items within a list .
11,823
public Keyword getKeyword ( String keywordId ) throws MovieDbException { TmdbParameters parameters = new TmdbParameters ( ) ; parameters . add ( Param . ID , keywordId ) ; URL url = new ApiUrl ( apiKey , MethodBase . KEYWORD ) . buildUrl ( parameters ) ; String webpage = httpTools . getRequest ( url ) ; try { return MAPPER . readValue ( webpage , Keyword . class ) ; } catch ( IOException ex ) { throw new MovieDbException ( ApiExceptionType . MAPPING_FAILED , "Failed to get keyword " + keywordId , url , ex ) ; } }
Get the basic information for a specific keyword id .
11,824
public String getRequest ( final URL url ) throws MovieDbException { try { HttpGet httpGet = new HttpGet ( url . toURI ( ) ) ; httpGet . addHeader ( HttpHeaders . ACCEPT , APPLICATION_JSON ) ; DigestedResponse response = DigestedResponseReader . requestContent ( httpClient , httpGet , CHARSET ) ; long retryCount = 0L ; while ( response . getStatusCode ( ) == STATUS_TOO_MANY_REQUESTS && retryCount ++ <= RETRY_MAX ) { delay ( retryCount ) ; response = DigestedResponseReader . requestContent ( httpClient , httpGet , CHARSET ) ; } return validateResponse ( response , url ) ; } catch ( URISyntaxException | IOException ex ) { throw new MovieDbException ( ApiExceptionType . CONNECTION_ERROR , null , url , ex ) ; } catch ( RuntimeException ex ) { throw new MovieDbException ( ApiExceptionType . HTTP_503_ERROR , "Service Unavailable" , url , ex ) ; } }
GET data from the URL
11,825
private void delay ( long multiplier ) { try { Thread . sleep ( TimeUnit . SECONDS . toMillis ( RETRY_DELAY * multiplier ) ) ; } catch ( InterruptedException ex ) { } }
Sleep for a period of time
11,826
public String deleteRequest ( final URL url ) throws MovieDbException { try { HttpDelete httpDel = new HttpDelete ( url . toURI ( ) ) ; return validateResponse ( DigestedResponseReader . deleteContent ( httpClient , httpDel , CHARSET ) , url ) ; } catch ( URISyntaxException | IOException ex ) { throw new MovieDbException ( ApiExceptionType . CONNECTION_ERROR , null , url , ex ) ; } }
Execute a DELETE on the URL
11,827
public String postRequest ( final URL url , final String jsonBody ) throws MovieDbException { try { HttpPost httpPost = new HttpPost ( url . toURI ( ) ) ; httpPost . addHeader ( HTTP . CONTENT_TYPE , APPLICATION_JSON ) ; httpPost . addHeader ( HttpHeaders . ACCEPT , APPLICATION_JSON ) ; StringEntity params = new StringEntity ( jsonBody , ContentType . APPLICATION_JSON ) ; httpPost . setEntity ( params ) ; return validateResponse ( DigestedResponseReader . postContent ( httpClient , httpPost , CHARSET ) , url ) ; } catch ( URISyntaxException | IOException ex ) { throw new MovieDbException ( ApiExceptionType . CONNECTION_ERROR , null , url , ex ) ; } }
POST content to the URL with the specified body
11,828
private String validateResponse ( final DigestedResponse response , final URL url ) throws MovieDbException { if ( response . getStatusCode ( ) == 0 ) { throw new MovieDbException ( ApiExceptionType . CONNECTION_ERROR , response . getContent ( ) , response . getStatusCode ( ) , url , null ) ; } else if ( response . getStatusCode ( ) >= HttpStatus . SC_INTERNAL_SERVER_ERROR ) { throw new MovieDbException ( ApiExceptionType . HTTP_503_ERROR , response . getContent ( ) , response . getStatusCode ( ) , url , null ) ; } else if ( response . getStatusCode ( ) >= HttpStatus . SC_MULTIPLE_CHOICES ) { throw new MovieDbException ( ApiExceptionType . HTTP_404_ERROR , response . getContent ( ) , response . getStatusCode ( ) , url , null ) ; } return response . getContent ( ) ; }
Check the status codes of the response and throw exceptions if needed
11,829
public void add ( final Param key , final String [ ] value ) { if ( value != null && value . length > 0 ) { parameters . put ( key , toList ( value ) ) ; } }
Add an array parameter to the collection
11,830
public void add ( final Param key , final String value ) { if ( StringUtils . isNotBlank ( value ) ) { parameters . put ( key , value ) ; } }
Add a string parameter to the collection
11,831
public void add ( final Param key , final Integer value ) { if ( value != null && value > 0 ) { parameters . put ( key , String . valueOf ( value ) ) ; } }
Add an integer parameter to the collection
11,832
public String toList ( final String [ ] appendToResponse ) { StringBuilder sb = new StringBuilder ( ) ; boolean first = Boolean . TRUE ; for ( String append : appendToResponse ) { if ( first ) { first = Boolean . FALSE ; } else { sb . append ( "," ) ; } sb . append ( append ) ; } return sb . toString ( ) ; }
Append any optional parameters to the URL
11,833
protected static TypeReference getTypeReference ( Class aClass ) throws MovieDbException { if ( TYPE_REFS . containsKey ( aClass ) ) { return TYPE_REFS . get ( aClass ) ; } else { throw new MovieDbException ( ApiExceptionType . UNKNOWN_CAUSE , "Class type reference for '" + aClass . getSimpleName ( ) + "' not found!" ) ; } }
Helper function to get a pre - generated TypeReference for a class
11,834
protected < T > List < T > processWrapperList ( TypeReference typeRef , URL url , String errorMessageSuffix ) throws MovieDbException { WrapperGenericList < T > val = processWrapper ( typeRef , url , errorMessageSuffix ) ; return val . getResults ( ) ; }
Process the wrapper list and return the results
11,835
protected < T > WrapperGenericList < T > processWrapper ( TypeReference typeRef , URL url , String errorMessageSuffix ) throws MovieDbException { String webpage = httpTools . getRequest ( url ) ; try { return MAPPER . readValue ( webpage , typeRef ) ; } catch ( IOException ex ) { throw new MovieDbException ( ApiExceptionType . MAPPING_FAILED , "Failed to get " + errorMessageSuffix , url , ex ) ; } }
Process the wrapper list and return the whole wrapper
11,836
public ResultList < JobDepartment > getJobs ( ) throws MovieDbException { URL url = new ApiUrl ( apiKey , MethodBase . JOB ) . subMethod ( MethodSub . LIST ) . buildUrl ( ) ; String webpage = httpTools . getRequest ( url ) ; try { WrapperJobList wrapper = MAPPER . readValue ( webpage , WrapperJobList . class ) ; ResultList < JobDepartment > results = new ResultList < > ( wrapper . getJobs ( ) ) ; wrapper . setResultProperties ( results ) ; return results ; } catch ( IOException ex ) { throw new MovieDbException ( ApiExceptionType . MAPPING_FAILED , "Failed to get job list" , url , ex ) ; } }
Get a list of valid jobs
11,837
public ResultsMap < String , List < String > > getTimezones ( ) throws MovieDbException { URL url = new ApiUrl ( apiKey , MethodBase . TIMEZONES ) . subMethod ( MethodSub . LIST ) . buildUrl ( ) ; String webpage = httpTools . getRequest ( url ) ; List < Map < String , List < String > > > tzList ; try { tzList = MAPPER . readValue ( webpage , new TypeReference < List < Map < String , List < String > > > > ( ) { } ) ; } catch ( IOException ex ) { throw new MovieDbException ( ApiExceptionType . MAPPING_FAILED , "Failed to get timezone list" , url , ex ) ; } ResultsMap < String , List < String > > timezones = new ResultsMap < > ( ) ; for ( Map < String , List < String > > tzMap : tzList ) { for ( Map . Entry < String , List < String > > x : tzMap . entrySet ( ) ) { timezones . put ( x . getKey ( ) , x . getValue ( ) ) ; } } return timezones ; }
Get the list of supported timezones for the API methods that support them
11,838
public ResultList < Genre > getGenreMovieList ( String language ) throws MovieDbException { return getGenreList ( language , MethodSub . MOVIE_LIST ) ; }
Get the list of movie genres .
11,839
public ResultList < Genre > getGenreTVList ( String language ) throws MovieDbException { return getGenreList ( language , MethodSub . TV_LIST ) ; }
Get the list of TV genres .
11,840
private ResultList < Genre > getGenreList ( String language , MethodSub sub ) throws MovieDbException { TmdbParameters parameters = new TmdbParameters ( ) ; parameters . add ( Param . LANGUAGE , language ) ; URL url = new ApiUrl ( apiKey , MethodBase . GENRE ) . subMethod ( sub ) . buildUrl ( parameters ) ; String webpage = httpTools . getRequest ( url ) ; try { WrapperGenres wrapper = MAPPER . readValue ( webpage , WrapperGenres . class ) ; ResultList < Genre > results = new ResultList < > ( wrapper . getGenres ( ) ) ; wrapper . setResultProperties ( results ) ; return results ; } catch ( IOException ex ) { throw new MovieDbException ( ApiExceptionType . MAPPING_FAILED , "Failed to get genre " + sub . toString ( ) , url , ex ) ; } }
Get the list of genres for movies or TV
11,841
public ResultList < MovieBasic > getGenreMovies ( int genreId , String language , Integer page , Boolean includeAllMovies , Boolean includeAdult ) throws MovieDbException { TmdbParameters parameters = new TmdbParameters ( ) ; parameters . add ( Param . ID , genreId ) ; parameters . add ( Param . LANGUAGE , language ) ; parameters . add ( Param . PAGE , page ) ; parameters . add ( Param . INCLUDE_ALL_MOVIES , includeAllMovies ) ; parameters . add ( Param . INCLUDE_ADULT , includeAdult ) ; URL url = new ApiUrl ( apiKey , MethodBase . GENRE ) . subMethod ( MethodSub . MOVIES ) . buildUrl ( parameters ) ; String webpage = httpTools . getRequest ( url ) ; WrapperGenericList < MovieBasic > wrapper = processWrapper ( getTypeReference ( MovieBasic . class ) , url , webpage ) ; return wrapper . getResultsList ( ) ; }
Get the list of movies for a particular genre by id .
11,842
public ResultList < ChangeKeyItem > getEpisodeChanges ( int episodeID , String startDate , String endDate ) throws MovieDbException { return getMediaChanges ( episodeID , startDate , endDate ) ; }
Look up a TV episode s changes by episode ID
11,843
public Account getAccount ( String sessionId ) throws MovieDbException { TmdbParameters parameters = new TmdbParameters ( ) ; parameters . add ( Param . SESSION_ID , sessionId ) ; URL url = new ApiUrl ( apiKey , MethodBase . ACCOUNT ) . buildUrl ( parameters ) ; String webpage = httpTools . getRequest ( url ) ; try { return MAPPER . readValue ( webpage , Account . class ) ; } catch ( IOException ex ) { throw new MovieDbException ( ApiExceptionType . MAPPING_FAILED , "Failed to get Account" , url , ex ) ; } }
Get the basic information for an account . You will need to have a valid session id .
11,844
public StatusCode modifyWatchList ( String sessionId , int accountId , MediaType mediaType , Integer movieId , boolean addToWatchlist ) throws MovieDbException { TmdbParameters parameters = new TmdbParameters ( ) ; parameters . add ( Param . SESSION_ID , sessionId ) ; parameters . add ( Param . ID , accountId ) ; String jsonBody = new PostTools ( ) . add ( PostBody . MEDIA_TYPE , mediaType . toString ( ) . toLowerCase ( ) ) . add ( PostBody . MEDIA_ID , movieId ) . add ( PostBody . WATCHLIST , addToWatchlist ) . build ( ) ; URL url = new ApiUrl ( apiKey , MethodBase . ACCOUNT ) . subMethod ( MethodSub . WATCHLIST ) . buildUrl ( parameters ) ; String webpage = httpTools . postRequest ( url , jsonBody ) ; try { return MAPPER . readValue ( webpage , StatusCode . class ) ; } catch ( IOException ex ) { throw new MovieDbException ( ApiExceptionType . MAPPING_FAILED , "Failed to modify watch list" , url , ex ) ; } }
Add or remove a movie to an accounts watch list .
11,845
public Company getCompanyInfo ( int companyId ) throws MovieDbException { TmdbParameters parameters = new TmdbParameters ( ) ; parameters . add ( Param . ID , companyId ) ; URL url = new ApiUrl ( apiKey , MethodBase . COMPANY ) . buildUrl ( parameters ) ; String webpage = httpTools . getRequest ( url ) ; try { return MAPPER . readValue ( webpage , Company . class ) ; } catch ( IOException ex ) { throw new MovieDbException ( ApiExceptionType . MAPPING_FAILED , "Failed to get company information" , url , ex ) ; } }
This method is used to retrieve the basic information about a production company on TMDb .
11,846
public ResultList < AlternativeTitle > getTVAlternativeTitles ( int tvID ) throws MovieDbException { TmdbParameters parameters = new TmdbParameters ( ) ; parameters . add ( Param . ID , tvID ) ; URL url = new ApiUrl ( apiKey , MethodBase . TV ) . subMethod ( MethodSub . ALT_TITLES ) . buildUrl ( parameters ) ; WrapperGenericList < AlternativeTitle > wrapper = processWrapper ( getTypeReference ( AlternativeTitle . class ) , url , "alternative titles" ) ; return wrapper . getResultsList ( ) ; }
Get the alternative titles for a specific show ID .
11,847
public ResultList < ChangeKeyItem > getTVChanges ( int tvID , String startDate , String endDate ) throws MovieDbException { return getMediaChanges ( tvID , startDate , endDate ) ; }
Get the changes for a specific TV show id .
11,848
public ResultList < ContentRating > getTVContentRatings ( int tvID ) throws MovieDbException { TmdbParameters parameters = new TmdbParameters ( ) ; parameters . add ( Param . ID , tvID ) ; URL url = new ApiUrl ( apiKey , MethodBase . TV ) . subMethod ( MethodSub . CONTENT_RATINGS ) . buildUrl ( parameters ) ; WrapperGenericList < ContentRating > wrapper = processWrapper ( getTypeReference ( ContentRating . class ) , url , "content rating" ) ; return wrapper . getResultsList ( ) ; }
Get the content ratings for a specific TV show id .
11,849
public ResultList < Keyword > getTVKeywords ( int tvID ) throws MovieDbException { TmdbParameters parameters = new TmdbParameters ( ) ; parameters . add ( Param . ID , tvID ) ; URL url = new ApiUrl ( apiKey , MethodBase . TV ) . subMethod ( MethodSub . KEYWORDS ) . buildUrl ( parameters ) ; WrapperGenericList < Keyword > wrapper = processWrapper ( getTypeReference ( Keyword . class ) , url , "keywords" ) ; return wrapper . getResultsList ( ) ; }
Get the plot keywords for a specific TV show id .
11,850
protected void init ( ) { Log . d ( TAG , "init" ) ; if ( isInEditMode ( ) ) return ; this . mediaPlayer = null ; this . shouldAutoplay = false ; this . fullscreen = false ; this . initialConfigOrientation = - 1 ; this . videoIsReady = false ; this . surfaceIsReady = false ; this . initialMovieHeight = - 1 ; this . initialMovieWidth = - 1 ; this . setBackgroundColor ( Color . BLACK ) ; initObjects ( ) ; }
Initializes the default configuration
11,851
protected void release ( ) { Log . d ( TAG , "release" ) ; releaseObjects ( ) ; if ( this . mediaPlayer != null ) { this . mediaPlayer . setOnBufferingUpdateListener ( null ) ; this . mediaPlayer . setOnPreparedListener ( null ) ; this . mediaPlayer . setOnErrorListener ( null ) ; this . mediaPlayer . setOnSeekCompleteListener ( null ) ; this . mediaPlayer . setOnCompletionListener ( null ) ; this . mediaPlayer . setOnInfoListener ( null ) ; this . mediaPlayer . setOnVideoSizeChangedListener ( null ) ; this . mediaPlayer . release ( ) ; this . mediaPlayer = null ; } this . currentState = State . END ; }
Releases and ends the current Object
11,852
protected void initObjects ( ) { Log . d ( TAG , "initObjects" ) ; if ( this . mediaPlayer == null ) { this . mediaPlayer = new MediaPlayer ( ) ; this . mediaPlayer . setOnInfoListener ( this ) ; this . mediaPlayer . setOnErrorListener ( this ) ; this . mediaPlayer . setOnPreparedListener ( this ) ; this . mediaPlayer . setOnCompletionListener ( this ) ; this . mediaPlayer . setOnSeekCompleteListener ( this ) ; this . mediaPlayer . setOnBufferingUpdateListener ( this ) ; this . mediaPlayer . setOnVideoSizeChangedListener ( this ) ; this . mediaPlayer . setAudioStreamType ( AudioManager . STREAM_MUSIC ) ; } RelativeLayout . LayoutParams layoutParams ; View view ; if ( android . os . Build . VERSION . SDK_INT >= Build . VERSION_CODES . ICE_CREAM_SANDWICH ) { if ( this . textureView == null ) { this . textureView = new TextureView ( this . context ) ; this . textureView . setSurfaceTextureListener ( this ) ; } view = this . textureView ; } else { if ( this . surfaceView == null ) { this . surfaceView = new SurfaceView ( context ) ; } view = this . surfaceView ; if ( this . surfaceHolder == null ) { this . surfaceHolder = this . surfaceView . getHolder ( ) ; this . surfaceHolder . setType ( SurfaceHolder . SURFACE_TYPE_PUSH_BUFFERS ) ; this . surfaceHolder . addCallback ( this ) ; } } layoutParams = new RelativeLayout . LayoutParams ( LayoutParams . MATCH_PARENT , LayoutParams . MATCH_PARENT ) ; layoutParams . addRule ( CENTER_IN_PARENT ) ; view . setLayoutParams ( layoutParams ) ; addView ( view ) ; if ( this . onProgressView == null ) this . onProgressView = new ProgressBar ( context ) ; layoutParams = new RelativeLayout . LayoutParams ( LayoutParams . WRAP_CONTENT , LayoutParams . WRAP_CONTENT ) ; layoutParams . addRule ( CENTER_IN_PARENT ) ; this . onProgressView . setLayoutParams ( layoutParams ) ; addView ( this . onProgressView ) ; stopLoading ( ) ; this . currentState = State . IDLE ; }
Initializes all objects FullscreenVideoView depends on It does not interfere with configuration properties because it is supposed to be called when this Object still exists
11,853
protected void releaseObjects ( ) { Log . d ( TAG , "releaseObjects" ) ; if ( this . mediaPlayer != null ) { this . mediaPlayer . setSurface ( null ) ; this . mediaPlayer . reset ( ) ; } this . videoIsReady = false ; this . surfaceIsReady = false ; this . initialMovieHeight = - 1 ; this . initialMovieWidth = - 1 ; if ( android . os . Build . VERSION . SDK_INT >= Build . VERSION_CODES . ICE_CREAM_SANDWICH ) { if ( this . textureView != null ) { this . textureView . setSurfaceTextureListener ( null ) ; removeView ( this . textureView ) ; this . textureView = null ; } } else { if ( this . surfaceHolder != null ) { this . surfaceHolder . removeCallback ( this ) ; this . surfaceHolder = null ; } if ( this . surfaceView != null ) { removeView ( this . surfaceView ) ; this . surfaceView = null ; } } if ( this . onProgressView != null ) { removeView ( this . onProgressView ) ; } }
Releases all objects FullscreenVideoView depends on It does not interfere with configuration properties because it is supposed to be called when this Object still exists
11,854
protected void tryToPrepare ( ) { Log . d ( TAG , "tryToPrepare" ) ; if ( this . surfaceIsReady && this . videoIsReady ) { if ( this . mediaPlayer != null && this . mediaPlayer . getVideoWidth ( ) != 0 && this . mediaPlayer . getVideoHeight ( ) != 0 ) { this . initialMovieWidth = this . mediaPlayer . getVideoWidth ( ) ; this . initialMovieHeight = this . mediaPlayer . getVideoHeight ( ) ; } resize ( ) ; stopLoading ( ) ; currentState = State . PREPARED ; if ( shouldAutoplay ) start ( ) ; if ( this . preparedListener != null ) this . preparedListener . onPrepared ( mediaPlayer ) ; } }
Try to call state PREPARED Only if SurfaceView is already created and MediaPlayer is prepared Video is loaded and is ok to play .
11,855
public void setFullscreen ( final boolean fullscreen ) throws RuntimeException { if ( mediaPlayer == null ) throw new RuntimeException ( "Media Player is not initialized" ) ; if ( this . currentState != State . ERROR ) { if ( FullscreenVideoView . this . fullscreen == fullscreen ) return ; FullscreenVideoView . this . fullscreen = fullscreen ; final boolean wasPlaying = mediaPlayer . isPlaying ( ) ; if ( wasPlaying ) pause ( ) ; if ( FullscreenVideoView . this . fullscreen ) { if ( activity != null ) activity . setRequestedOrientation ( ActivityInfo . SCREEN_ORIENTATION_UNSPECIFIED ) ; View rootView = getRootView ( ) ; View v = rootView . findViewById ( android . R . id . content ) ; ViewParent viewParent = getParent ( ) ; if ( viewParent instanceof ViewGroup ) { if ( parentView == null ) parentView = ( ViewGroup ) viewParent ; detachedByFullscreen = true ; currentLayoutParams = FullscreenVideoView . this . getLayoutParams ( ) ; parentView . removeView ( FullscreenVideoView . this ) ; } else Log . e ( TAG , "Parent View is not a ViewGroup" ) ; if ( v instanceof ViewGroup ) { ( ( ViewGroup ) v ) . addView ( FullscreenVideoView . this ) ; } else Log . e ( TAG , "RootView is not a ViewGroup" ) ; } else { if ( activity != null ) activity . setRequestedOrientation ( initialConfigOrientation ) ; ViewParent viewParent = getParent ( ) ; if ( viewParent instanceof ViewGroup ) { boolean parentHasParent = false ; if ( parentView != null && parentView . getParent ( ) != null ) { parentHasParent = true ; detachedByFullscreen = true ; } ( ( ViewGroup ) viewParent ) . removeView ( FullscreenVideoView . this ) ; if ( parentHasParent ) { parentView . addView ( FullscreenVideoView . this ) ; FullscreenVideoView . this . setLayoutParams ( currentLayoutParams ) ; } } } resize ( ) ; Handler handler = new Handler ( Looper . getMainLooper ( ) ) ; handler . post ( new Runnable ( ) { public void run ( ) { if ( wasPlaying && mediaPlayer != null ) start ( ) ; } } ) ; } }
Turn VideoView fulllscreen mode on or off .
11,856
public void onClick ( View v ) { if ( v . getId ( ) == R . id . vcv_img_play ) { if ( isPlaying ( ) ) { pause ( ) ; } else { start ( ) ; } } else { setFullscreen ( ! isFullscreen ( ) ) ; } }
Onclick action Controls play button and fullscreen button .
11,857
public void populate ( final AnnotationData data , final Annotation annotation , final Class < ? extends Annotation > expectedAnnotationClass , final Method targetMethod ) throws Exception { if ( support ( expectedAnnotationClass ) ) { build ( data , annotation , expectedAnnotationClass , targetMethod ) ; } }
Populates additional data into annotation data .
11,858
protected Cache createCache ( ) throws IOException { if ( cache != null ) { throw new IllegalStateException ( String . format ( "This factory has already created memcached client for cache %s" , cacheName ) ) ; } if ( isCacheDisabled ( ) ) { LOGGER . warn ( "Cache {} is disabled" , cacheName ) ; cache = ( Cache ) Proxy . newProxyInstance ( Cache . class . getClassLoader ( ) , new Class [ ] { Cache . class } , new DisabledCacheInvocationHandler ( cacheName , cacheAliases ) ) ; return cache ; } if ( configuration == null ) { throw new RuntimeException ( String . format ( "The MemcachedConnectionBean for cache %s must be defined!" , cacheName ) ) ; } List < InetSocketAddress > addrs = addressProvider . getAddresses ( ) ; cache = new CacheImpl ( cacheName , cacheAliases , createClient ( addrs ) , defaultSerializationType , jsonTranscoder , javaTranscoder , customTranscoder , new CacheProperties ( configuration . isUseNameAsKeyPrefix ( ) , configuration . getKeyPrefixSeparator ( ) ) ) ; return cache ; }
Only one cache is created .
11,859
public String getCacheKey ( final Object keyObject , final String namespace ) { return namespace + SEPARATOR + defaultKeyProvider . generateKey ( keyObject ) ; }
Builds cache key from one key object .
11,860
private String buildCacheKey ( final String [ ] objectIds , final String namespace ) { if ( objectIds . length == 1 ) { checkKeyPart ( objectIds [ 0 ] ) ; return namespace + SEPARATOR + objectIds [ 0 ] ; } StringBuilder cacheKey = new StringBuilder ( namespace ) ; cacheKey . append ( SEPARATOR ) ; for ( String id : objectIds ) { checkKeyPart ( id ) ; cacheKey . append ( id ) ; cacheKey . append ( ID_SEPARATOR ) ; } cacheKey . deleteCharAt ( cacheKey . length ( ) - 1 ) ; return cacheKey . toString ( ) ; }
Build cache key .
11,861
public void removeCache ( final String nameOrAlias ) { final Cache cache = cacheMap . get ( nameOrAlias ) ; if ( cache == null ) { return ; } final SSMCache ssmCache = ( SSMCache ) cache ; if ( ssmCache . isRegisterAliases ( ) ) { ssmCache . getCache ( ) . getAliases ( ) . forEach ( this :: unregisterCache ) ; } unregisterCache ( nameOrAlias ) ; unregisterCache ( cache . getName ( ) ) ; caches . removeIf ( c -> c . getName ( ) . equals ( cache . getName ( ) ) ) ; }
Removes given cache and related aliases .
11,862
protected Object deserialize ( final byte [ ] in ) { Object o = null ; ByteArrayInputStream bis = null ; ConfigurableObjectInputStream is = null ; try { if ( in != null ) { bis = new ByteArrayInputStream ( in ) ; is = new ConfigurableObjectInputStream ( bis , Thread . currentThread ( ) . getContextClassLoader ( ) ) ; o = is . readObject ( ) ; is . close ( ) ; bis . close ( ) ; } } catch ( IOException e ) { LOGGER . warn ( String . format ( "Caught IOException decoding %d bytes of data" , in . length ) , e ) ; } catch ( ClassNotFoundException e ) { LOGGER . warn ( String . format ( "Caught CNFE decoding %d bytes of data" , in . length ) , e ) ; } finally { close ( is ) ; close ( bis ) ; } return o ; }
Deserialize given stream using java deserialization .
11,863
@ SuppressWarnings ( "unchecked" ) public < T > T get ( final Object key , final Class < T > type ) { if ( ! cache . isEnabled ( ) ) { LOGGER . warn ( "Cache {} is disabled. Cannot get {} from cache" , cache . getName ( ) , key ) ; return null ; } Object value = getValue ( key ) ; if ( value == null ) { LOGGER . info ( "Cache miss. Get by key {} and type {} from cache {}" , new Object [ ] { key , type , cache . getName ( ) } ) ; return null ; } if ( value instanceof PertinentNegativeNull ) { return null ; } if ( type != null && ! type . isInstance ( value ) ) { String msg = "Cached value is not of required type [" + type . getName ( ) + "]: " + value ; LOGGER . error ( msg , new IllegalStateException ( msg ) ) ; return null ; } LOGGER . info ( "Cache hit. Get by key {} and type {} from cache {} value '{}'" , new Object [ ] { key , type , cache . getName ( ) , value } ) ; return ( T ) value ; }
Required by Spring 4 . 0
11,864
@ SuppressWarnings ( "unchecked" ) public < T > T get ( final Object key , final Callable < T > valueLoader ) { if ( ! cache . isEnabled ( ) ) { LOGGER . warn ( "Cache {} is disabled. Cannot get {} from cache" , cache . getName ( ) , key ) ; return loadValue ( key , valueLoader ) ; } final ValueWrapper valueWrapper = get ( key ) ; if ( valueWrapper != null ) { return ( T ) valueWrapper . get ( ) ; } synchronized ( key . toString ( ) . intern ( ) ) { final T value = loadValue ( key , valueLoader ) ; put ( key , value ) ; return value ; } }
Required by Spring 4 . 3
11,865
public ValueWrapper putIfAbsent ( final Object key , final Object value ) { if ( ! cache . isEnabled ( ) ) { LOGGER . warn ( "Cache {} is disabled. Cannot put value under key {}" , cache . getName ( ) , key ) ; return null ; } if ( key != null ) { final String cacheKey = getKey ( key ) ; try { LOGGER . info ( "Put '{}' under key {} to cache {}" , new Object [ ] { value , key , cache . getName ( ) } ) ; final Object store = toStoreValue ( value ) ; final boolean added = cache . add ( cacheKey , expiration , store , null ) ; return added ? null : get ( key ) ; } catch ( TimeoutException | CacheException | RuntimeException e ) { logOrThrow ( e , "An error has ocurred for cache {} and key {}" , getName ( ) , cacheKey , e ) ; } } else { LOGGER . info ( "Cannot put to cache {} because key is null" , cache . getName ( ) ) ; } return null ; }
Required by Spring 4 . 1
11,866
@ SuppressWarnings ( { "rawtypes" , "unchecked" } ) public static Seq toScalaSeq ( Object [ ] o ) { ArrayList list = new ArrayList ( ) ; for ( int i = 0 ; i < o . length ; i ++ ) { list . add ( o [ i ] ) ; } return scala . collection . JavaConversions . asScalaBuffer ( list ) . toList ( ) ; }
Takes an array of objects and returns a scala Seq
11,867
public static UnsignedInteger64 add ( UnsignedInteger64 x , UnsignedInteger64 y ) { return new UnsignedInteger64 ( x . bigInt . add ( y . bigInt ) ) ; }
Add an unsigned integer to another unsigned integer .
11,868
public static UnsignedInteger64 add ( UnsignedInteger64 x , int y ) { return new UnsignedInteger64 ( x . bigInt . add ( BigInteger . valueOf ( y ) ) ) ; }
Add an unsigned integer to an int .
11,869
public byte [ ] toByteArray ( ) { byte [ ] raw = new byte [ 8 ] ; byte [ ] bi = bigIntValue ( ) . toByteArray ( ) ; System . arraycopy ( bi , 0 , raw , raw . length - bi . length , bi . length ) ; return raw ; }
Returns a byte array encoded with the unsigned integer .
11,870
public void remove ( SshPublicKey key ) throws SshException , PublicKeySubsystemException { try { Packet msg = createPacket ( ) ; msg . writeString ( "remove" ) ; msg . writeString ( key . getAlgorithm ( ) ) ; msg . writeBinaryString ( key . getEncoded ( ) ) ; sendMessage ( msg ) ; readStatusResponse ( ) ; } catch ( IOException ex ) { throw new SshException ( ex ) ; } }
Remove a public key from the users list of acceptable keys .
11,871
public SshPublicKey [ ] list ( ) throws SshException , PublicKeySubsystemException { try { Packet msg = createPacket ( ) ; msg . writeString ( "list" ) ; sendMessage ( msg ) ; Vector < SshPublicKey > keys = new Vector < SshPublicKey > ( ) ; while ( true ) { ByteArrayReader response = new ByteArrayReader ( nextMessage ( ) ) ; try { String type = response . readString ( ) ; if ( type . equals ( "publickey" ) ) { @ SuppressWarnings ( "unused" ) String comment = response . readString ( ) ; String algorithm = response . readString ( ) ; keys . addElement ( SshPublicKeyFileFactory . decodeSSH2PublicKey ( algorithm , response . readBinaryString ( ) ) ) ; } else if ( type . equals ( "status" ) ) { int status = ( int ) response . readInt ( ) ; String desc = response . readString ( ) ; if ( status != PublicKeySubsystemException . SUCCESS ) { throw new PublicKeySubsystemException ( status , desc ) ; } SshPublicKey [ ] array = new SshPublicKey [ keys . size ( ) ] ; keys . copyInto ( array ) ; return array ; } else { throw new SshException ( "The server sent an invalid response to a list command" , SshException . PROTOCOL_VIOLATION ) ; } } finally { try { response . close ( ) ; } catch ( IOException e ) { } } } } catch ( IOException ex ) { throw new SshException ( ex ) ; } }
List all of the users acceptable keys .
11,872
public void associateCommand ( SshPublicKey key , String command ) throws SshException , PublicKeySubsystemException { try { Packet msg = createPacket ( ) ; msg . writeString ( "command" ) ; msg . writeString ( key . getAlgorithm ( ) ) ; msg . writeBinaryString ( key . getEncoded ( ) ) ; msg . writeString ( command ) ; sendMessage ( msg ) ; readStatusResponse ( ) ; } catch ( IOException ex ) { throw new SshException ( ex ) ; } }
Associate a command with an accepted public key . The request will fail if the public key is not currently in the users acceptable list . Also some server implementations may choose not to support this feature .
11,873
void readStatusResponse ( ) throws SshException , PublicKeySubsystemException { ByteArrayReader msg = new ByteArrayReader ( nextMessage ( ) ) ; try { msg . readString ( ) ; int status = ( int ) msg . readInt ( ) ; String desc = msg . readString ( ) ; if ( status != PublicKeySubsystemException . SUCCESS ) { throw new PublicKeySubsystemException ( status , desc ) ; } } catch ( IOException ex ) { throw new SshException ( ex ) ; } finally { try { msg . close ( ) ; } catch ( IOException e ) { } } }
Read a status response and throw an exception if an error has occurred .
11,874
public void setTerminalMode ( int mode , int value ) throws SshException { try { encodedModes . write ( mode ) ; if ( version == 1 && mode <= 127 ) { encodedModes . write ( value ) ; } else { encodedModes . writeInt ( value ) ; } } catch ( IOException ex ) { throw new SshException ( SshException . INTERNAL_ERROR , ex ) ; } }
Set an integer value mode
11,875
protected ProxyMessage exchange ( ProxyMessage request ) throws SocksException { ProxyMessage reply ; try { request . write ( out ) ; reply = formMessage ( in ) ; } catch ( SocksException s_ex ) { throw s_ex ; } catch ( IOException ioe ) { throw ( new SocksException ( SOCKS_PROXY_IO_ERROR , "" + ioe ) ) ; } return reply ; }
Sends the request reads reply and returns it throws exception if something wrong with IO or the reply code is not zero
11,876
public String [ ] matchFileNamesWithPattern ( File [ ] files , String fileNameRegExp ) throws SshException , SftpStatusException { String [ ] thefile = new String [ 1 ] ; thefile [ 0 ] = files [ 0 ] . getName ( ) ; return thefile ; }
opens and returns the requested filename string
11,877
public synchronized void addListener ( String threadPrefix , EventListener listener ) { if ( threadPrefix . trim ( ) . equals ( "" ) ) { globalListeners . addElement ( listener ) ; } else { keyedListeners . put ( threadPrefix . trim ( ) , listener ) ; } }
Add a J2SSH Listener to the list of listeners that will be sent events
11,878
public synchronized void fireEvent ( Event evt ) { if ( evt == null ) { return ; } for ( Enumeration < EventListener > keys = globalListeners . elements ( ) ; keys . hasMoreElements ( ) ; ) { EventListener mListener = keys . nextElement ( ) ; try { mListener . processEvent ( evt ) ; } catch ( Throwable t ) { } } String sourceThread = Thread . currentThread ( ) . getName ( ) ; for ( Enumeration < String > keys = keyedListeners . keys ( ) ; keys . hasMoreElements ( ) ; ) { String key = ( String ) keys . nextElement ( ) ; try { String prefix = "" ; if ( sourceThread . indexOf ( '-' ) > - 1 ) { prefix = sourceThread . substring ( 0 , sourceThread . indexOf ( '-' ) ) ; if ( key . startsWith ( prefix ) ) { EventListener mListener = keyedListeners . get ( key ) ; mListener . processEvent ( evt ) ; } } } catch ( Throwable thr ) { } } }
Send an SSH Event to each registered listener
11,879
public void close ( ) throws IOException { try { while ( processNextResponse ( 0 ) ) ; file . close ( ) ; } catch ( SshException ex ) { throw new SshIOException ( ex ) ; } catch ( SftpStatusException ex ) { throw new IOException ( ex . getMessage ( ) ) ; } }
Closes the file s handle
11,880
public static void setCharsetEncoding ( String charset ) { try { String test = "123456890" ; test . getBytes ( charset ) ; CHARSET_ENCODING = charset ; encode = true ; } catch ( UnsupportedEncodingException ex ) { CHARSET_ENCODING = "" ; encode = false ; } }
Allows the default encoding to be overriden for String variables processed by the class . This currently defaults to UTF - 8 .
11,881
public BigInteger readBigInteger ( ) throws IOException { int len = ( int ) readInt ( ) ; byte [ ] raw = new byte [ len ] ; readFully ( raw ) ; return new BigInteger ( raw ) ; }
Read a BigInteger from the array .
11,882
public String readString ( String charset ) throws IOException { long len = readInt ( ) ; if ( len > available ( ) ) throw new IOException ( "Cannot read string of length " + len + " bytes when only " + available ( ) + " bytes are available" ) ; byte [ ] raw = new byte [ ( int ) len ] ; readFully ( raw ) ; if ( encode ) { return new String ( raw , charset ) ; } return new String ( raw ) ; }
Read a String from the array converting using the given character set .
11,883
public BigInteger readMPINT32 ( ) throws IOException { int bits = ( int ) readInt ( ) ; byte [ ] raw = new byte [ ( bits + 7 ) / 8 + 1 ] ; raw [ 0 ] = 0 ; readFully ( raw , 1 , raw . length - 1 ) ; return new BigInteger ( raw ) ; }
Reads an MPINT using the first 32 bits as the length prefix
11,884
public BigInteger readMPINT ( ) throws IOException { short bits = readShort ( ) ; byte [ ] raw = new byte [ ( bits + 7 ) / 8 + 1 ] ; raw [ 0 ] = 0 ; readFully ( raw , 1 , raw . length - 1 ) ; return new BigInteger ( raw ) ; }
Reads a standard SSH1 MPINT using the first 16 bits as the length prefix
11,885
public static SocksProxyTransport connectViaSocks4Proxy ( String remoteHost , int remotePort , String proxyHost , int proxyPort , String userId ) throws IOException , UnknownHostException { SocksProxyTransport proxySocket = new SocksProxyTransport ( remoteHost , remotePort , proxyHost , proxyPort , SOCKS4 ) ; proxySocket . username = userId ; try { InputStream proxyIn = proxySocket . getInputStream ( ) ; OutputStream proxyOut = proxySocket . getOutputStream ( ) ; InetAddress hostAddr = InetAddress . getByName ( remoteHost ) ; proxyOut . write ( SOCKS4 ) ; proxyOut . write ( CONNECT ) ; proxyOut . write ( ( remotePort >>> 8 ) & 0xff ) ; proxyOut . write ( remotePort & 0xff ) ; proxyOut . write ( hostAddr . getAddress ( ) ) ; proxyOut . write ( userId . getBytes ( ) ) ; proxyOut . write ( NULL_TERMINATION ) ; proxyOut . flush ( ) ; int res = proxyIn . read ( ) ; if ( res == - 1 ) { throw new IOException ( "SOCKS4 server " + proxyHost + ":" + proxyPort + " disconnected" ) ; } if ( res != 0x00 ) { throw new IOException ( "Invalid response from SOCKS4 server (" + res + ") " + proxyHost + ":" + proxyPort ) ; } int code = proxyIn . read ( ) ; if ( code != 90 ) { if ( ( code > 90 ) && ( code < 93 ) ) { throw new IOException ( "SOCKS4 server unable to connect, reason: " + SOCKSV4_ERROR [ code - 91 ] ) ; } throw new IOException ( "SOCKS4 server unable to connect, reason: " + code ) ; } byte [ ] data = new byte [ 6 ] ; if ( proxyIn . read ( data , 0 , 6 ) != 6 ) { throw new IOException ( "SOCKS4 error reading destination address/port" ) ; } proxySocket . setProviderDetail ( data [ 2 ] + "." + data [ 3 ] + "." + data [ 4 ] + "." + data [ 5 ] + ":" + ( ( data [ 0 ] << 8 ) | data [ 1 ] ) ) ; } catch ( SocketException e ) { throw new SocketException ( "Error communicating with SOCKS4 server " + proxyHost + ":" + proxyPort + ", " + e . getMessage ( ) ) ; } return proxySocket ; }
Connect the socket to a SOCKS 4 proxy and request forwarding to our remote host .
11,886
protected void sendMessage ( byte [ ] msg ) throws SshException { try { Packet pkt = createPacket ( ) ; pkt . write ( msg ) ; sendMessage ( pkt ) ; } catch ( IOException ex ) { throw new SshException ( SshException . UNEXPECTED_TERMINATION , ex ) ; } }
Send a byte array as a message .
11,887
protected Packet createPacket ( ) throws IOException { synchronized ( packets ) { if ( packets . size ( ) == 0 ) return new Packet ( ) ; Packet p = ( Packet ) packets . elementAt ( 0 ) ; packets . removeElementAt ( 0 ) ; return p ; } }
Get a packet from the available pool or create if non available
11,888
public static SshKeyPair generateKeyPair ( String algorithm , int bits ) throws IOException , SshException { if ( ! SSH2_RSA . equalsIgnoreCase ( algorithm ) && ! SSH2_DSA . equalsIgnoreCase ( algorithm ) ) { throw new IOException ( algorithm + " is not a supported key algorithm!" ) ; } SshKeyPair pair = new SshKeyPair ( ) ; if ( SSH2_RSA . equalsIgnoreCase ( algorithm ) ) { pair = ComponentManager . getInstance ( ) . generateRsaKeyPair ( bits ) ; } else { pair = ComponentManager . getInstance ( ) . generateDsaKeyPair ( bits ) ; } return pair ; }
Generates a new key pair .
11,889
public void setUID ( String uid ) { if ( version > 3 ) { flags |= SSH_FILEXFER_ATTR_OWNERGROUP ; } else flags |= SSH_FILEXFER_ATTR_UIDGID ; this . uid = uid ; }
Set the UID of the owner .
11,890
public void setGID ( String gid ) { if ( version > 3 ) { flags |= SSH_FILEXFER_ATTR_OWNERGROUP ; } else flags |= SSH_FILEXFER_ATTR_UIDGID ; this . gid = gid ; }
Set the GID of this file .
11,891
public void setSize ( UnsignedInteger64 size ) { this . size = size ; if ( size != null ) { flags |= SSH_FILEXFER_ATTR_SIZE ; } else { flags ^= SSH_FILEXFER_ATTR_SIZE ; } }
Set the size of the file .
11,892
public void setPermissions ( UnsignedInteger32 permissions ) { this . permissions = permissions ; if ( permissions != null ) { flags |= SSH_FILEXFER_ATTR_PERMISSIONS ; } else { flags ^= SSH_FILEXFER_ATTR_PERMISSIONS ; } }
Set the permissions of the file . This value should be a valid mask of the permissions flags defined within this class .
11,893
public void setPermissionsFromMaskString ( String mask ) { if ( mask . length ( ) != 4 ) { throw new IllegalArgumentException ( "Mask length must be 4" ) ; } try { setPermissions ( new UnsignedInteger32 ( String . valueOf ( Integer . parseInt ( mask , 8 ) ) ) ) ; } catch ( NumberFormatException nfe ) { throw new IllegalArgumentException ( "Mask must be 4 digit octal number." ) ; } }
Set permissions given a UNIX style mask for example 0644
11,894
public void setPermissionsFromUmaskString ( String umask ) { if ( umask . length ( ) != 4 ) { throw new IllegalArgumentException ( "umask length must be 4" ) ; } try { setPermissions ( new UnsignedInteger32 ( String . valueOf ( Integer . parseInt ( umask , 8 ) ^ 0777 ) ) ) ; } catch ( NumberFormatException ex ) { throw new IllegalArgumentException ( "umask must be 4 digit octal number" ) ; } }
Set the permissions given a UNIX style umask for example 0022 will result in 0022 ^ 0777 .
11,895
public String getMaskString ( ) { StringBuffer buf = new StringBuffer ( ) ; if ( permissions != null ) { int i = ( int ) permissions . longValue ( ) ; buf . append ( '0' ) ; buf . append ( octal ( i , 6 ) ) ; buf . append ( octal ( i , 3 ) ) ; buf . append ( octal ( i , 0 ) ) ; } else { buf . append ( "----" ) ; } return buf . toString ( ) ; }
Return the UNIX style mode mask
11,896
public boolean isDirectory ( ) { if ( sftp . getVersion ( ) > 3 ) { return type == SSH_FILEXFER_TYPE_DIRECTORY ; } else if ( permissions != null && ( permissions . longValue ( ) & SftpFileAttributes . S_IFDIR ) == SftpFileAttributes . S_IFDIR ) { return true ; } else { return false ; } }
Determine whether these attributes refer to a directory
11,897
public boolean isLink ( ) { if ( sftp . getVersion ( ) > 3 ) { return type == SSH_FILEXFER_TYPE_SYMLINK ; } else if ( permissions != null && ( permissions . longValue ( ) & SftpFileAttributes . S_IFLNK ) == SftpFileAttributes . S_IFLNK ) { return true ; } else { return false ; } }
Determine whether these attributes refer to a symbolic link .
11,898
public boolean isFifo ( ) { if ( permissions != null && ( permissions . longValue ( ) & SftpFileAttributes . S_IFIFO ) == SftpFileAttributes . S_IFIFO ) { return true ; } return false ; }
Determine whether these attributes refer to a pipe .
11,899
public boolean isBlock ( ) { if ( permissions != null && ( permissions . longValue ( ) & SftpFileAttributes . S_IFBLK ) == SftpFileAttributes . S_IFBLK ) { return true ; } return false ; }
Determine whether these attributes refer to a block special file .