idx
int64
0
41.2k
question
stringlengths
74
4.21k
target
stringlengths
5
888
39,400
private void transfer ( OutputStream os , String path ) throws IOException { path = decodeUrlPath ( path ) ; File f = new File ( path ) ; FileInputStream file = new FileInputStream ( f ) ; long length = f . length ( ) ; StringBuffer buf = new StringBuffer ( OKHEADER ) . append ( CONNECTION_CLOSE ) . append ( SERVER ) . append ( CONTENT_BINARY ) . append ( CONTENT_LENGTH ) . append ( " " ) . append ( length ) . append ( CRLF ) . append ( CRLF ) ; os . write ( buf . toString ( ) . getBytes ( ) ) ; os . flush ( ) ; byte [ ] buffer = new byte [ BUFFER_SIZE ] ; int read ; while ( length != 0 ) { read = file . read ( buffer ) ; if ( read == - 1 ) break ; os . write ( buffer , 0 , read ) ; length -= read ; } file . close ( ) ; os . flush ( ) ; os . close ( ) ; }
Transfer from a file given its path to the given OutputStream . The BufferedWriter points to the same stream but is used to write HTTP header information .
39,401
private long fromHex ( String s ) { long result = 0 ; int size = s . length ( ) ; for ( int i = 0 ; i < size ; i ++ ) { char c = s . charAt ( i ) ; result *= 16 ; switch ( c ) { case '0' : case '1' : case '2' : case '3' : case '4' : case '5' : case '6' : case '7' : case '8' : case '9' : result += ( c - '0' ) ; break ; case 'a' : case 'b' : case 'c' : case 'd' : case 'e' : case 'f' : result += ( c - 'a' + 10 ) ; break ; case 'A' : case 'B' : case 'C' : case 'D' : case 'E' : case 'F' : result += ( c - 'A' + 10 ) ; break ; default : } } return result ; }
Convert a String representing a hex number to a long .
39,402
protected String makeRequest ( boolean includePassword ) { StringBuffer buf = new StringBuffer ( ) ; buf . append ( VERSION ) . append ( CRLF ) ; buf . append ( COMMAND ) . append ( String . valueOf ( command ) ) . append ( CRLF ) ; buf . append ( USERNAME ) . append ( this . username ) . append ( CRLF ) ; String pwd = getPassphrase ( ) ; buf . append ( PASSPHRASE ) ; if ( includePassword ) { if ( pwd != null ) { buf . append ( pwd ) ; } } else { for ( int i = 0 ; pwd != null && i < pwd . length ( ) ; i ++ ) { buf . append ( '*' ) ; } } buf . append ( CRLF ) ; buf . append ( LIFETIME ) . append ( String . valueOf ( lifetime ) ) . append ( CRLF ) ; return buf . toString ( ) ; }
Serializes the parameters into a MyProxy request . Subclasses should overwrite this function and append the custom parameters to the output of this function .
39,403
protected void engineInit ( KeyStore keyStore ) throws KeyStoreException { try { this . engineInit ( new CertPathTrustManagerParameters ( new X509ProxyCertPathParameters ( keyStore , null , null , false ) ) ) ; } catch ( InvalidAlgorithmParameterException e ) { throw new KeyStoreException ( e ) ; } }
Initializes this factory with a source of certificate authorities and related trust material .
39,404
public void setProtection ( int protection ) { switch ( protection ) { case GridFTPSession . PROTECTION_CLEAR : throw new IllegalArgumentException ( "Unsupported protection: " + protection ) ; case GridFTPSession . PROTECTION_SAFE : case GridFTPSession . PROTECTION_CONFIDENTIAL : case GridFTPSession . PROTECTION_PRIVATE : break ; default : throw new IllegalArgumentException ( "Bad protection: " + protection ) ; } this . protection = protection ; }
Sets data channel protection level .
39,405
public boolean isValidSubject ( X500Principal subject ) { if ( subject == null ) { throw new IllegalArgumentException ( ) ; } String subjectDN = CertificateUtil . toGlobusID ( subject ) ; if ( ( this . allowedDNs == null ) || ( this . allowedDNs . size ( ) < 1 ) ) { return false ; } int size = this . allowedDNs . size ( ) ; for ( int i = 0 ; i < size ; i ++ ) { Pattern pattern = allowedDNs . get ( i ) ; Matcher matcher = pattern . matcher ( subjectDN ) ; boolean valid = matcher . matches ( ) ; if ( valid ) { return true ; } } return false ; }
Ascertains if the subjectDN is valid against this policy .
39,406
public static String getIdentity ( X509Certificate cert ) { if ( cert == null ) { return null ; } String subjectDN = cert . getSubjectX500Principal ( ) . getName ( X500Principal . RFC2253 ) ; X509Name name = new X509Name ( true , subjectDN ) ; return X509NameHelper . toString ( name ) ; }
Returns the subject DN of the given certificate in the Globus format .
39,407
public static byte [ ] getExtensionValue ( byte [ ] certExtValue ) throws IOException { ByteArrayInputStream inStream = new ByteArrayInputStream ( certExtValue ) ; ASN1InputStream derInputStream = new ASN1InputStream ( inStream ) ; ASN1Primitive object = derInputStream . readObject ( ) ; if ( object instanceof ASN1OctetString ) { return ( ( ASN1OctetString ) object ) . getOctets ( ) ; } else { throw new IOException ( i18n . getMessage ( "octectExp" ) ) ; } }
Retrieves the actual value of the X . 509 extension .
39,408
public static byte [ ] getExtensionValue ( X509Certificate cert , String oid ) throws IOException { if ( cert == null ) { throw new IllegalArgumentException ( i18n . getMessage ( "certNull" ) ) ; } if ( oid == null ) { throw new IllegalArgumentException ( i18n . getMessage ( "oidNull" ) ) ; } byte [ ] value = cert . getExtensionValue ( oid ) ; if ( value == null ) { return null ; } return getExtensionValue ( value ) ; }
Returns the actual value of the extension .
39,409
protected void parse ( ) throws IOException { String line ; line = _reader . readLine ( ) ; if ( logger . isTraceEnabled ( ) ) { logger . trace ( line ) ; } parseHead ( line ) ; while ( ( line = _reader . readLine ( ) ) . length ( ) != 0 ) { if ( logger . isTraceEnabled ( ) ) { logger . trace ( line ) ; } if ( line . startsWith ( HTTPProtocol . CONNECTION ) ) { _connection = getRest ( line , HTTPProtocol . CONNECTION . length ( ) ) ; } else if ( line . startsWith ( HTTPProtocol . SERVER ) ) { _server = getRest ( line , HTTPProtocol . SERVER . length ( ) ) ; } else if ( line . startsWith ( HTTPProtocol . CONTENT_TYPE ) ) { _contentType = getRest ( line , HTTPProtocol . CONTENT_TYPE . length ( ) ) ; } else if ( line . startsWith ( HTTPProtocol . CONTENT_LENGTH ) ) { _contentLength = Long . parseLong ( getRest ( line , HTTPProtocol . CONTENT_LENGTH . length ( ) ) ) ; } else if ( line . startsWith ( HTTPProtocol . HOST ) ) { _host = getRest ( line , HTTPProtocol . HOST . length ( ) ) ; } else if ( line . startsWith ( HTTPProtocol . CHUNKED ) ) { _chunked = true ; } } }
Parses the typical HTTP header .
39,410
public long getSize ( String filename ) throws IOException , ServerException { if ( filename == null ) { throw new IllegalArgumentException ( "Required argument missing" ) ; } Command cmd = new Command ( "SIZE" , filename ) ; Reply reply = null ; try { reply = controlChannel . execute ( cmd ) ; return Long . parseLong ( reply . getMessage ( ) ) ; } catch ( NumberFormatException e ) { throw ServerException . embedFTPReplyParseException ( new FTPReplyParseException ( FTPReplyParseException . MESSAGE_UNPARSABLE , "Could not parse size: " + reply . getMessage ( ) ) ) ; } catch ( UnexpectedReplyCodeException urce ) { throw ServerException . embedUnexpectedReplyCodeException ( urce ) ; } catch ( FTPReplyParseException rpe ) { throw ServerException . embedFTPReplyParseException ( rpe ) ; } }
Returns the remote file size .
39,411
public Date getLastModified ( String filename ) throws IOException , ServerException { if ( filename == null ) { throw new IllegalArgumentException ( "Required argument missing" ) ; } Command cmd = new Command ( "MDTM" , filename ) ; Reply reply = null ; try { reply = controlChannel . execute ( cmd ) ; } catch ( FTPReplyParseException rpe ) { throw ServerException . embedFTPReplyParseException ( rpe ) ; } catch ( UnexpectedReplyCodeException urce ) { throw ServerException . embedUnexpectedReplyCodeException ( urce , "Server refused changing transfer mode" ) ; } if ( dateFormat == null ) { dateFormat = new SimpleDateFormat ( "yyyyMMddHHmmss" ) ; dateFormat . setTimeZone ( TimeZone . getTimeZone ( "GMT" ) ) ; } try { return dateFormat . parse ( reply . getMessage ( ) ) ; } catch ( ParseException e ) { throw ServerException . embedFTPReplyParseException ( new FTPReplyParseException ( 0 , "Invalid file modification time reply: " + reply ) ) ; } }
Returns last modification time of the specifed file .
39,412
public void changeDir ( String dir ) throws IOException , ServerException { if ( dir == null ) { throw new IllegalArgumentException ( "Required argument missing" ) ; } Command cmd = new Command ( "CWD" , dir ) ; try { controlChannel . execute ( cmd ) ; } catch ( FTPReplyParseException rpe ) { throw ServerException . embedFTPReplyParseException ( rpe ) ; } catch ( UnexpectedReplyCodeException urce ) { throw ServerException . embedUnexpectedReplyCodeException ( urce , "Server refused changing directory" ) ; } }
Changes the remote current working directory .
39,413
public void deleteFile ( String filename ) throws IOException , ServerException { if ( filename == null ) { throw new IllegalArgumentException ( "Required argument missing" ) ; } Command cmd = new Command ( "DELE" , filename ) ; try { controlChannel . execute ( cmd ) ; } catch ( FTPReplyParseException rpe ) { throw ServerException . embedFTPReplyParseException ( rpe ) ; } catch ( UnexpectedReplyCodeException urce ) { throw ServerException . embedUnexpectedReplyCodeException ( urce , "Server refused deleting file" ) ; } }
Deletes the remote file .
39,414
public void rename ( String oldName , String newName ) throws IOException , ServerException { if ( oldName == null || newName == null ) { throw new IllegalArgumentException ( "Required argument missing" ) ; } Command cmd = new Command ( "RNFR" , oldName ) ; try { Reply reply = controlChannel . exchange ( cmd ) ; if ( ! Reply . isPositiveIntermediate ( reply ) ) { throw new UnexpectedReplyCodeException ( reply ) ; } controlChannel . execute ( new Command ( "RNTO" , newName ) ) ; } catch ( FTPReplyParseException rpe ) { throw ServerException . embedFTPReplyParseException ( rpe ) ; } catch ( UnexpectedReplyCodeException urce ) { throw ServerException . embedUnexpectedReplyCodeException ( urce , "Server refused renaming file" ) ; } }
Renames remote directory .
39,415
public String getCurrentDir ( ) throws IOException , ServerException { Reply reply = null ; try { reply = controlChannel . execute ( Command . PWD ) ; } catch ( FTPReplyParseException rpe ) { throw ServerException . embedFTPReplyParseException ( rpe ) ; } catch ( UnexpectedReplyCodeException urce ) { throw ServerException . embedUnexpectedReplyCodeException ( urce , "Server refused returning current directory" ) ; } String strReply = reply . getMessage ( ) ; if ( strReply . length ( ) > 0 && strReply . charAt ( 0 ) == '"' ) { return strReply . substring ( 1 , strReply . indexOf ( '"' , 1 ) ) ; } else { throw ServerException . embedFTPReplyParseException ( new FTPReplyParseException ( 0 , "Cannot parse 'PWD' reply: " + reply ) ) ; } }
Returns remote current working directory .
39,416
public void goUpDir ( ) throws IOException , ServerException { try { controlChannel . execute ( Command . CDUP ) ; } catch ( FTPReplyParseException rpe ) { throw ServerException . embedFTPReplyParseException ( rpe ) ; } catch ( UnexpectedReplyCodeException urce ) { throw ServerException . embedUnexpectedReplyCodeException ( urce , "Server refused changing current directory" ) ; } }
Changes remote current working directory to the higher level .
39,417
public Vector list ( String filter , String modifier ) throws ServerException , ClientException , IOException { ByteArrayDataSink sink = new ByteArrayDataSink ( ) ; list ( filter , modifier , sink ) ; ByteArrayOutputStream received = sink . getData ( ) ; BufferedReader reader = new BufferedReader ( new StringReader ( received . toString ( ) ) ) ; Vector fileList = new Vector ( ) ; FileInfo fileInfo = null ; String line = null ; while ( ( line = reader . readLine ( ) ) != null ) { line = line . trim ( ) ; if ( logger . isDebugEnabled ( ) ) { logger . debug ( "line ->" + line ) ; } if ( line . equals ( "" ) ) { continue ; } if ( line . startsWith ( "total" ) ) continue ; try { fileInfo = new FileInfo ( line ) ; } catch ( FTPException e ) { ClientException ce = new ClientException ( ClientException . UNSPECIFIED , "Could not create FileInfo" ) ; ce . setRootCause ( e ) ; throw ce ; } fileList . addElement ( fileInfo ) ; } return fileList ; }
Performs remote directory listing with the specified filter and modifier . Sends LIST &lt ; modifier&gt ; &lt ; filter&gt ; command .
39,418
public void list ( String filter , String modifier , DataSink sink ) throws ServerException , ClientException , IOException { String arg = null ; if ( modifier != null ) { arg = modifier ; } if ( filter != null ) { arg = ( arg == null ) ? filter : arg + " " + filter ; } Command cmd = new Command ( "LIST" , arg ) ; performTransfer ( cmd , sink ) ; }
Performs directory listing and writes the result to the supplied data sink . This method is allowed in ASCII mode only .
39,419
public Vector nlist ( String path ) throws ServerException , ClientException , IOException { ByteArrayDataSink sink = new ByteArrayDataSink ( ) ; nlist ( path , sink ) ; ByteArrayOutputStream received = sink . getData ( ) ; BufferedReader reader = new BufferedReader ( new StringReader ( received . toString ( ) ) ) ; Vector fileList = new Vector ( ) ; FileInfo fileInfo = null ; String line = null ; while ( ( line = reader . readLine ( ) ) != null ) { if ( logger . isDebugEnabled ( ) ) { logger . debug ( "line ->" + line ) ; } fileInfo = new FileInfo ( ) ; fileInfo . setName ( line ) ; fileInfo . setFileType ( FileInfo . UNKNOWN_TYPE ) ; fileList . addElement ( fileInfo ) ; } return fileList ; }
Performs remote directory listing on the given path . Sends NLST &lt ; path&gt ; command .
39,420
public MlsxEntry mlst ( String fileName ) throws IOException , ServerException { try { Reply reply = controlChannel . execute ( new Command ( "MLST" , fileName ) ) ; String replyMessage = reply . getMessage ( ) ; StringTokenizer replyLines = new StringTokenizer ( replyMessage , System . getProperty ( "line.separator" ) ) ; if ( replyLines . hasMoreElements ( ) ) { replyLines . nextElement ( ) ; } else { throw new FTPException ( FTPException . UNSPECIFIED , "Expected multiline reply" ) ; } if ( replyLines . hasMoreElements ( ) ) { String line = ( String ) replyLines . nextElement ( ) ; return new MlsxEntry ( line ) ; } else { throw new FTPException ( FTPException . UNSPECIFIED , "Expected multiline reply" ) ; } } catch ( FTPReplyParseException rpe ) { throw ServerException . embedFTPReplyParseException ( rpe ) ; } catch ( UnexpectedReplyCodeException urce ) { throw ServerException . embedUnexpectedReplyCodeException ( urce , "Server refused MLST command" ) ; } catch ( FTPException e ) { ServerException ce = new ServerException ( ClientException . UNSPECIFIED , "Could not create MlsxEntry" ) ; ce . setRootCause ( e ) ; throw ce ; } }
Get info of a certain remote file in Mlsx format .
39,421
public void setType ( int type ) throws IOException , ServerException { localServer . setTransferType ( type ) ; String typeStr = null ; switch ( type ) { case Session . TYPE_IMAGE : typeStr = "I" ; break ; case Session . TYPE_ASCII : typeStr = "A" ; break ; case Session . TYPE_LOCAL : typeStr = "E" ; break ; case Session . TYPE_EBCDIC : typeStr = "L" ; break ; default : throw new IllegalArgumentException ( "Bad type: " + type ) ; } Command cmd = new Command ( "TYPE" , typeStr ) ; try { controlChannel . execute ( cmd ) ; } catch ( FTPReplyParseException rpe ) { throw ServerException . embedFTPReplyParseException ( rpe ) ; } catch ( UnexpectedReplyCodeException urce ) { throw ServerException . embedUnexpectedReplyCodeException ( urce , "Server refused changing transfer mode" ) ; } this . session . transferType = type ; }
Sets transfer type .
39,422
public void close ( boolean ignoreQuitReply ) throws IOException , ServerException { try { if ( ignoreQuitReply ) { controlChannel . write ( Command . QUIT ) ; } else { controlChannel . execute ( Command . QUIT ) ; } } catch ( FTPReplyParseException rpe ) { throw ServerException . embedFTPReplyParseException ( rpe ) ; } catch ( UnexpectedReplyCodeException urce ) { throw ServerException . embedUnexpectedReplyCodeException ( urce , "Server refused closing" ) ; } finally { try { controlChannel . close ( ) ; } finally { localServer . close ( ) ; } } }
Closes connection . Sends QUIT and closes connection even if the server reply was not positive . Also closes the local server .
39,423
public FeatureList getFeatureList ( ) throws IOException , ServerException { if ( this . session . featureList != null ) { return this . session . featureList ; } Reply featReply = null ; try { featReply = controlChannel . execute ( Command . FEAT ) ; if ( featReply . getCode ( ) != 211 ) { throw ServerException . embedUnexpectedReplyCodeException ( new UnexpectedReplyCodeException ( featReply ) , "Server refused returning features" ) ; } } catch ( FTPReplyParseException rpe ) { throw ServerException . embedFTPReplyParseException ( rpe ) ; } catch ( UnexpectedReplyCodeException urce ) { throw ServerException . embedUnexpectedReplyCodeException ( urce , "Server refused returning features" ) ; } this . session . featureList = new FeatureList ( featReply . getMessage ( ) ) ; return session . featureList ; }
Returns list of features supported by remote server .
39,424
public HostPort setPassive ( ) throws IOException , ServerException { Reply reply = null ; try { reply = controlChannel . execute ( ( controlChannel . isIPv6 ( ) ) ? Command . EPSV : Command . PASV ) ; } catch ( UnexpectedReplyCodeException urce ) { throw ServerException . embedUnexpectedReplyCodeException ( urce ) ; } catch ( FTPReplyParseException rpe ) { throw ServerException . embedFTPReplyParseException ( rpe ) ; } String pasvReplyMsg = null ; pasvReplyMsg = reply . getMessage ( ) ; int openBracket = pasvReplyMsg . indexOf ( "(" ) ; int closeBracket = pasvReplyMsg . indexOf ( ")" , openBracket ) ; String bracketContent = pasvReplyMsg . substring ( openBracket + 1 , closeBracket ) ; this . session . serverMode = Session . SERVER_PASSIVE ; HostPort hp = null ; if ( controlChannel . isIPv6 ( ) ) { hp = new HostPort6 ( bracketContent ) ; if ( hp . getHost ( ) == null ) { ( ( HostPort6 ) hp ) . setVersion ( HostPort6 . IPv6 ) ; ( ( HostPort6 ) hp ) . setHost ( controlChannel . getHost ( ) ) ; } } else { hp = new HostPort ( bracketContent ) ; } this . session . serverAddress = hp ; return hp ; }
Sets remote server to passive server mode .
39,425
public void setActive ( HostPort hostPort ) throws IOException , ServerException { Command cmd = new Command ( ( controlChannel . isIPv6 ( ) ) ? "EPRT" : "PORT" , hostPort . toFtpCmdArgument ( ) ) ; try { controlChannel . execute ( cmd ) ; } catch ( UnexpectedReplyCodeException urce ) { throw ServerException . embedUnexpectedReplyCodeException ( urce ) ; } catch ( FTPReplyParseException rpe ) { throw ServerException . embedFTPReplyParseException ( rpe ) ; } this . session . serverMode = Session . SERVER_ACTIVE ; }
Sets remote server active telling it to connect to the given address .
39,426
public void setLocalActive ( ) throws ClientException , IOException { if ( session . serverAddress == null ) { throw new ClientException ( ClientException . CALL_PASSIVE_FIRST ) ; } try { localServer . setActive ( session . serverAddress ) ; } catch ( java . net . UnknownHostException e ) { throw new ClientException ( ClientException . UNKNOWN_HOST ) ; } }
Starts local server in active server mode .
39,427
public void setOptions ( Options opts ) throws IOException , ServerException { Command cmd = new Command ( "OPTS" , opts . toFtpCmdArgument ( ) ) ; try { controlChannel . execute ( cmd ) ; } catch ( FTPReplyParseException rpe ) { throw ServerException . embedFTPReplyParseException ( rpe ) ; } catch ( UnexpectedReplyCodeException urce ) { throw ServerException . embedUnexpectedReplyCodeException ( urce , "Server refused setting options" ) ; } localServer . setOptions ( opts ) ; }
Sets the supplied options to the server .
39,428
public void setRestartMarker ( RestartData restartData ) throws IOException , ServerException { Command cmd = new Command ( "REST" , restartData . toFtpCmdArgument ( ) ) ; Reply reply = null ; try { reply = controlChannel . exchange ( cmd ) ; } catch ( FTPReplyParseException e ) { throw ServerException . embedFTPReplyParseException ( e ) ; } if ( ! Reply . isPositiveIntermediate ( reply ) ) { throw ServerException . embedUnexpectedReplyCodeException ( new UnexpectedReplyCodeException ( reply ) ) ; } }
Sets restart parameter of the next transfer .
39,429
public void authorize ( String user , String password ) throws IOException , ServerException { Reply userReply = null ; try { userReply = controlChannel . exchange ( new Command ( "USER" , user ) ) ; } catch ( FTPReplyParseException rpe ) { throw ServerException . embedFTPReplyParseException ( rpe ) ; } if ( Reply . isPositiveIntermediate ( userReply ) ) { Reply passReply = null ; try { passReply = controlChannel . exchange ( new Command ( "PASS" , password ) ) ; } catch ( FTPReplyParseException rpe ) { throw ServerException . embedFTPReplyParseException ( rpe ) ; } if ( ! Reply . isPositiveCompletion ( passReply ) ) { throw ServerException . embedUnexpectedReplyCodeException ( new UnexpectedReplyCodeException ( passReply ) , "Bad password." ) ; } } else if ( Reply . isPositiveCompletion ( userReply ) ) { } else { throw ServerException . embedUnexpectedReplyCodeException ( new UnexpectedReplyCodeException ( userReply ) , "Bad user." ) ; } this . session . authorized = true ; this . username = user ; }
Performs user authorization with specified user and password .
39,430
public void transfer ( String remoteSrcFile , FTPClient destination , String remoteDstFile , boolean append , MarkerListener mListener ) throws IOException , ServerException , ClientException { session . matches ( destination . session ) ; if ( session . serverMode == Session . SERVER_DEFAULT ) { HostPort hp = destination . setPassive ( ) ; setActive ( hp ) ; } destination . controlChannel . write ( new Command ( ( append ) ? "APPE" : "STOR" , remoteDstFile ) ) ; controlChannel . write ( new Command ( "RETR" , remoteSrcFile ) ) ; transferRunSingleThread ( destination . controlChannel , mListener ) ; }
Performs third - party transfer between two servers .
39,431
protected void transferRun ( BasicClientControlChannel other , MarkerListener mListener ) throws IOException , ServerException , ClientException { TransferState transferState = transferBegin ( other , mListener ) ; transferWait ( transferState ) ; }
Actual transfer management . Transfer is controlled by two new threads listening to the two servers .
39,432
public Reply quote ( String command ) throws IOException , ServerException { Command cmd = new Command ( command ) ; return doCommand ( cmd ) ; }
Executes arbitrary operation on the server .
39,433
public void allocate ( long size ) throws IOException , ServerException { Command cmd = new Command ( "ALLO" , String . valueOf ( size ) ) ; Reply reply = null ; try { reply = controlChannel . execute ( cmd ) ; } catch ( UnexpectedReplyCodeException urce ) { throw ServerException . embedUnexpectedReplyCodeException ( urce ) ; } catch ( FTPReplyParseException rpe ) { throw ServerException . embedFTPReplyParseException ( rpe ) ; } }
Reserve sufficient storage to accommodate the new file to be transferred .
39,434
protected void checkGETPUTSupport ( ) throws ServerException , IOException { if ( ! isFeatureSupported ( FeatureList . GETPUT ) ) { throw new ServerException ( ServerException . UNSUPPORTED_FEATURE ) ; } if ( controlChannel . isIPv6 ( ) ) { throw new ServerException ( ServerException . UNSUPPORTED_FEATURE , "Cannot use GridFTP2 with IP 6" ) ; } }
Throws ServerException if GFD . 47 GETPUT is not supported or cannot be used .
39,435
protected HostPort get127Reply ( ) throws ServerException , IOException , FTPReplyParseException { Reply reply = controlChannel . read ( ) ; if ( Reply . isTransientNegativeCompletion ( reply ) || Reply . isPermanentNegativeCompletion ( reply ) ) { throw ServerException . embedUnexpectedReplyCodeException ( new UnexpectedReplyCodeException ( reply ) , reply . getMessage ( ) ) ; } if ( reply . getCode ( ) != 127 ) { throw new ServerException ( ServerException . WRONG_PROTOCOL , reply . getMessage ( ) ) ; } Matcher matcher = portPattern . matcher ( reply . getMessage ( ) ) ; if ( ! matcher . find ( ) ) { throw new ServerException ( ServerException . WRONG_PROTOCOL , "Cannot parse 127 reply: " + reply . getMessage ( ) ) ; } return new HostPort ( matcher . group ( ) ) ; }
Reads a GFD . 47 compliant 127 reply and extracts the port information from it .
39,436
private void issueGETPUT ( String command , boolean passive , HostPort port , int mode , String path ) throws IOException { Command cmd = new Command ( command , ( passive ? "pasv" : ( "port=" + port . toFtpCmdArgument ( ) ) ) + ";" + "path=" + path + ";" + ( mode > 0 ? "mode=" + getModeStr ( mode ) + ";" : "" ) ) ; controlChannel . write ( cmd ) ; }
Writes a GFD . 47 compliant GET or PUT command to the control channel .
39,437
public String getChecksum ( String algorithm , String path ) throws ClientException , ServerException , IOException { return getChecksum ( algorithm , 0 , - 1 , path ) ; }
GridFTP v2 CKSM command for the whole file
39,438
public int getDelegationKeyCacheLifetime ( ) { int valueInt = 0 ; String valueStr = System . getProperty ( DELEGATION_KEY_CACHE_LIFETIME ) ; if ( valueStr != null && valueStr . length ( ) > 0 ) { int parsedvalueInt = Integer . parseInt ( valueStr ) ; if ( parsedvalueInt > 0 ) { valueInt = parsedvalueInt ; } } if ( valueInt == - 1 ) { valueStr = getProperty ( DELEGATION_KEY_CACHE_LIFETIME ) ; if ( valueStr != null && valueStr . length ( ) > 0 ) { int parsedvalueInt = Integer . parseInt ( valueStr ) ; if ( parsedvalueInt > 0 ) { valueInt = parsedvalueInt ; } } } return valueInt ; }
Returns the delegation key cache lifetime for all delegations from this JVM . If this property is not set or set to zero or less no caching is done .
39,439
public long getCRLCacheLifetime ( ) { long value = getCertCacheLifetime ( ) ; String property = getProperty ( CRL_CACHE_LIFETIME ) ; if ( property != null && property . length ( ) > 0 ) { long parsedValue = Long . parseLong ( property ) ; if ( parsedValue > 0 ) { value = parsedValue ; } } property = System . getProperty ( CRL_CACHE_LIFETIME ) ; if ( property != null && property . length ( ) > 0 ) { long parsedValue = Long . parseLong ( property ) ; if ( parsedValue > 0 ) { value = parsedValue ; } } return value ; }
Returns the CRL cache lifetime . If this property is set to zero or less no caching is done . The value is the number of milliseconds the CRLs are cached without checking for modifications on disk .
39,440
public long getCertCacheLifetime ( ) throws NumberFormatException { long value = 60 * 1000 ; String property = getProperty ( CERT_CACHE_LIFETIME ) ; if ( property != null && property . length ( ) > 0 ) { long parsedValue = Long . parseLong ( property ) ; if ( parsedValue > 0 ) { value = parsedValue ; } } property = System . getProperty ( CERT_CACHE_LIFETIME ) ; if ( property != null && property . length ( ) > 0 ) { long parsedValue = Long . parseLong ( property ) ; if ( parsedValue > 0 ) { value = parsedValue ; } } return value ; }
Returns the Cert cache lifetime . If this property is set to zero or less no caching is done . The value is the number of milliseconds the certificates are cached without checking for modifications on disk .
39,441
public long getReveseDNSCacheLifetime ( ) throws NumberFormatException { long value = 60 * 60 * 1000 ; String property = getProperty ( REVERSE_DNS_CACHE_LIFETIME ) ; if ( property != null && property . length ( ) > 0 ) { long parsedValue = Long . parseLong ( property ) ; if ( parsedValue > 0 ) { value = parsedValue ; } } property = System . getProperty ( REVERSE_DNS_CACHE_LIFETIME ) ; if ( property != null && property . length ( ) > 0 ) { long parsedValue = Long . parseLong ( property ) ; if ( parsedValue > 0 ) { value = parsedValue ; } } return value ; }
Returns the reverse DNS cache time .
39,442
public String getReverseDNSCacheType ( ) { String value = System . getProperty ( REVERSE_DNS_CACHETYPE ) ; if ( value != null ) { return value ; } return getProperty ( REVERSE_DNS_CACHETYPE , THREADED_CACHE ) ; }
Returns the reverse DNS cache type . Defaults to a threaded chache .
39,443
public void add ( Binding binding ) { if ( values == null ) values = new LinkedList ( ) ; values . add ( binding ) ; }
Adds a new variable definition to the list .
39,444
public Bindings evaluate ( Map symbolTable ) throws RslEvaluationException { if ( symbolTable == null ) { throw new IllegalArgumentException ( "Symbol table must be initialized." ) ; } List newValues = new LinkedList ( ) ; Iterator iter = values . iterator ( ) ; Object vl ; Binding binding ; while ( iter . hasNext ( ) ) { vl = iter . next ( ) ; if ( vl instanceof Binding ) { binding = ( ( Binding ) vl ) . evaluate ( symbolTable ) ; symbolTable . put ( binding . getName ( ) , binding . getValue ( ) . getValue ( ) ) ; newValues . add ( binding ) ; } else { throw new RuntimeException ( "Invalid object in binding" ) ; } } Bindings bind = new Bindings ( getAttribute ( ) ) ; bind . setValues ( newValues ) ; return bind ; }
Evaluates the variable definitions as variable definitions can reference each other against the symbol table . The evaluation process updates the symbol table .
39,445
protected TrustManager [ ] getTrustManagers ( String keystoreType , String keystoreProvider , String algorithm ) throws Exception { KeyStore trustStore = getTrustStore ( keystoreType , keystoreProvider ) ; CertStore crlStore = null ; if ( crlLocation != null ) { crlStore = GlobusSSLHelper . findCRLStore ( ( String ) crlLocation ) ; } ResourceSigningPolicyStore policyStore = null ; if ( signingPolicyLocation != null ) { policyStore = Stores . getSigningPolicyStore ( ( String ) signingPolicyLocation ) ; } boolean rejectLimitedProxy = rejectLimitedProxyEntry != null && Boolean . parseBoolean ( ( String ) rejectLimitedProxyEntry ) ; X509ProxyCertPathParameters parameters = new X509ProxyCertPathParameters ( trustStore , crlStore , policyStore , rejectLimitedProxy ) ; TrustManager trustManager = new PKITrustManager ( new X509ProxyCertPathValidator ( ) , parameters ) ; return new TrustManager [ ] { trustManager } ; }
Create a Globus trust manager which supports proxy certificates . This requires that the CRL store and signing policy store be configured .
39,446
public static synchronized PortRange getTcpInstance ( ) { if ( tcpPortRange == null ) { tcpPortRange = new PortRange ( ) ; tcpPortRange . init ( CoGProperties . getDefault ( ) . getTcpPortRange ( ) ) ; } return tcpPortRange ; }
Returns PortRange instance for TCP listening sockets . If the tcp . port . range property is set the class will be initialized with the specified port ranges .
39,447
public static synchronized PortRange getTcpSourceInstance ( ) { if ( tcpSourcePortRange == null ) { tcpSourcePortRange = new PortRange ( ) ; tcpSourcePortRange . init ( CoGProperties . getDefault ( ) . getTcpSourcePortRange ( ) ) ; } return tcpSourcePortRange ; }
Returns PortRange instance for TCP source sockets . If the tcp . source . port . range property is set the class will be initialized with the specified port ranges .
39,448
public static synchronized PortRange getUdpSourceInstance ( ) { if ( udpSourcePortRange == null ) { udpSourcePortRange = new PortRange ( ) ; udpSourcePortRange . init ( CoGProperties . getDefault ( ) . getUdpSourcePortRange ( ) ) ; } return udpSourcePortRange ; }
Returns PortRange instance for UDP source sockets . If the udp . source . port . range property is set the class will be initialized with the specified port ranges .
39,449
public synchronized int getFreePort ( int lastPortNumber ) throws IOException { int id = 0 ; if ( lastPortNumber != 0 ) { id = lastPortNumber - minPort ; if ( id < 0 ) { throw new IOException ( "Port number out of range." ) ; } } for ( int i = id ; i < ports . length ; i ++ ) { if ( ports [ i ] == USED ) continue ; return minPort + i ; } throw new IOException ( "No free ports available." ) ; }
Returns first available port .
39,450
public void save ( OutputStream out ) throws IOException { try { cred . save ( out ) ; } catch ( CertificateEncodingException e ) { throw new ChainedIOException ( e . getMessage ( ) , e ) ; } }
Saves the credential into a specified output stream . The self - signed certificates in the certificate chain will not be saved . The output stream should always be closed after calling this function .
39,451
public ASN1Primitive toASN1Primitive ( ) { ASN1EncodableVector vec = new ASN1EncodableVector ( ) ; if ( this . pathLenConstraint != null ) { vec . add ( this . pathLenConstraint ) ; } vec . add ( this . proxyPolicy . toASN1Primitive ( ) ) ; return new DERSequence ( vec ) ; }
Returns the DER - encoded ASN . 1 representation of the extension .
39,452
public void invoke ( X509Certificate cert , GSIConstants . CertificateType certType ) throws CertPathValidatorException { if ( ! requireSigningPolicyCheck ( certType ) ) { return ; } X500Principal caPrincipal = cert . getIssuerX500Principal ( ) ; SigningPolicy policy ; try { policy = this . policyStore . getSigningPolicy ( caPrincipal ) ; } catch ( CertStoreException e ) { throw new CertPathValidatorException ( e ) ; } if ( policy == null ) { throw new CertPathValidatorException ( "No signing policy for " + cert . getIssuerDN ( ) ) ; } boolean valid = policy . isValidSubject ( cert . getSubjectX500Principal ( ) ) ; if ( ! valid ) { throw new CertPathValidatorException ( "Certificate " + cert . getSubjectDN ( ) + " violates signing policy for CA " + caPrincipal . getName ( ) ) ; } }
Validate DN against the signing policy
39,453
private boolean requireSigningPolicyCheck ( GSIConstants . CertificateType certType ) { return ! ProxyCertificateUtil . isProxy ( certType ) && certType != GSIConstants . CertificateType . CA ; }
if a certificate is not a CA or if it is not a proxy return true .
39,454
public DataChannelReader getDataChannelSource ( TransferContext context ) throws Exception { String id = getHandlerID ( session . transferMode , session . transferType , SOURCE ) ; logger . debug ( "type/mode: " + id ) ; Class clazz = ( Class ) dataHandlers . get ( id ) ; if ( clazz == null ) { throw new Exception ( "No data reader for type/mode" + id ) ; } DataChannelReader reader = ( DataChannelReader ) clazz . newInstance ( ) ; if ( reader instanceof EBlockAware ) { ( ( EBlockAware ) reader ) . setTransferContext ( ( EBlockParallelTransferContext ) context ) ; } return reader ; }
currently context is only needed in case of EBlock mode
39,455
public void invoke ( X509Certificate cert , GSIConstants . CertificateType certType ) throws CertPathValidatorException { X500Principal certIssuer = cert . getIssuerX500Principal ( ) ; X509CRLSelector crlSelector = new X509CRLSelector ( ) ; crlSelector . addIssuer ( certIssuer ) ; Collection < ? extends CRL > crls ; if ( crlsList != null ) { crls = crlsList . getCRLs ( crlSelector ) ; } else { try { crls = this . certStore . getCRLs ( crlSelector ) ; } catch ( CertStoreException e ) { throw new CertPathValidatorException ( "Error accessing CRL from certificate store: " + e . getMessage ( ) , e ) ; } } if ( crls . size ( ) < 1 ) { return ; } X509CertSelector certSelector = new X509CertSelector ( ) ; certSelector . setSubject ( certIssuer ) ; Collection < ? extends Certificate > caCerts ; try { caCerts = KeyStoreUtil . getTrustedCertificates ( this . keyStore , certSelector ) ; } catch ( KeyStoreException e ) { throw new CertPathValidatorException ( "Error accessing CA certificate from certificate store for CRL validation" , e ) ; } if ( caCerts . size ( ) < 1 ) { return ; } Certificate caCert = caCerts . iterator ( ) . next ( ) ; for ( CRL o : crls ) { X509CRL crl = ( X509CRL ) o ; if ( checkDateValidity ) { checkCRLDateValidity ( crl ) ; } verifyCRL ( caCert , crl ) ; if ( crl . isRevoked ( cert ) ) { throw new CertPathValidatorException ( "Certificate " + cert . getSubjectDN ( ) + " has been revoked" ) ; } } }
Method that checks the if the certificate is in a CRL if CRL is available If no CRL is found then no error is thrown If an expired CRL is found an error is thrown
39,456
public static ServerException embedFTPReplyParseException ( FTPReplyParseException rpe , String message ) { ServerException se = new ServerException ( WRONG_PROTOCOL , message ) ; se . setRootCause ( rpe ) ; return se ; }
Constructs server exception with FTPReplyParseException nested in it .
39,457
public static ServerException embedUnexpectedReplyCodeException ( UnexpectedReplyCodeException urce , String message ) { ServerException se = new ServerException ( SERVER_REFUSED , message ) ; se . setRootCause ( urce ) ; return se ; }
Constructs server exception with UnexpectedReplyCodeException nested in it .
39,458
public static synchronized I18n getI18n ( String resource ) { I18n instance = ( I18n ) mapping . get ( resource ) ; if ( instance == null ) { instance = new I18n ( ResourceBundle . getBundle ( resource , Locale . getDefault ( ) , getClassLoader ( ) ) ) ; mapping . put ( resource , instance ) ; } return instance ; }
Retrieve a I18n instance by resource name .
39,459
public String toFtpCmdArgument ( ) { if ( this . sporCommandParam == null && this . vector != null ) { StringBuffer cmd = new StringBuffer ( ) ; for ( int i = 0 ; i < this . vector . size ( ) ; i ++ ) { HostPort hp = ( HostPort ) this . vector . get ( i ) ; if ( i != 0 ) { cmd . append ( ' ' ) ; } cmd . append ( hp . toFtpCmdArgument ( ) ) ; } this . sporCommandParam = cmd . toString ( ) ; } return this . sporCommandParam ; }
Returns the host - port infromation in the format used by SPOR command .
39,460
public synchronized void transferError ( Exception e ) { logger . debug ( "intercepted exception" , e ) ; if ( transferException == null ) { transferException = e ; } else if ( transferException instanceof InterruptedException || transferException instanceof InterruptedIOException ) { transferException = e ; } notifyAll ( ) ; }
this is called when an error occurs during transfer
39,461
public synchronized void waitForEnd ( ) throws ServerException , ClientException , IOException { try { while ( ! isDone ( ) && ! hasError ( ) ) { wait ( ) ; } } catch ( InterruptedException e ) { } checkError ( ) ; }
Blocks until the transfer is complete or the transfer fails .
39,462
public synchronized void waitForStart ( ) throws ServerException , ClientException , IOException { try { while ( ! isStarted ( ) && ! hasError ( ) ) { wait ( ) ; } } catch ( InterruptedException e ) { } checkError ( ) ; }
Blocks until the transfer begins or the transfer fails to start .
39,463
public void add ( ASN1ObjectIdentifier oid , String value ) { ASN1EncodableVector v = new ASN1EncodableVector ( ) ; v . add ( oid ) ; v . add ( new DERPrintableString ( value ) ) ; add ( new DERSet ( new DERSequence ( v ) ) ) ; }
Appends the specified OID and value pair name component to the end of the current name .
39,464
public void add ( ASN1Set entry ) { ASN1EncodableVector v = new ASN1EncodableVector ( ) ; int size = seq . size ( ) ; for ( int i = 0 ; i < size ; i ++ ) { v . add ( seq . getObjectAt ( i ) ) ; } v . add ( entry ) ; seq = new DERSequence ( v ) ; }
Appends the specified name component entry to the current name . This can be used to add handle multiple AVAs in one name component .
39,465
public static String GET ( String path , String host ) { return HTTPProtocol . createGETHeader ( "/" + path , host , USER_AGENT ) ; }
This method concatenates a properly formatted header for performing Globus Gass GETs with the given information .
39,466
public static String PUT ( String path , String host , long length , boolean append ) { String newPath = null ; if ( append ) { newPath = APPEND_URI + "/" + path ; } else { newPath = "/" + path ; } return HTTPProtocol . createPUTHeader ( newPath , host , USER_AGENT , TYPE , length , append ) ; }
This method concatenates a properly formatted header for performing Globus Gass PUTs with the given information .
39,467
public void close ( ) throws IOException { logger . debug ( "ftp socket closed" ) ; if ( ftpIn != null ) ftpIn . close ( ) ; if ( ftpOut != null ) ftpOut . close ( ) ; if ( socket != null ) socket . close ( ) ; hasBeenOpened = false ; }
Closes the control channel
39,468
public Reply read ( ) throws ServerException , IOException , FTPReplyParseException , EOFException { Reply reply = new Reply ( ftpIn ) ; if ( logger . isDebugEnabled ( ) ) { logger . debug ( "Control channel received: " + reply ) ; } lastReply = reply ; return reply ; }
Block until a reply is available in the control channel .
39,469
public void write ( Command cmd ) throws IOException , IllegalArgumentException { if ( cmd == null ) { throw new IllegalArgumentException ( "null argument: cmd" ) ; } if ( logger . isDebugEnabled ( ) ) { logger . debug ( "Control channel sending: " + cmd ) ; } writeStr ( cmd . toString ( ) ) ; }
Sends the command over the control channel . Do not wait for reply .
39,470
public Reply exchange ( Command cmd ) throws ServerException , IOException , FTPReplyParseException { write ( cmd ) ; return read ( ) ; }
Write the command to the control channel block until reply arrives and return the reply . Before calling this method make sure that no old replies are waiting on the control channel . Otherwise the reply returned may not be the reply to this command .
39,471
public static Class getClassContextAt ( int i ) { Class [ ] classes = MANAGER . getClassContext ( ) ; if ( classes != null && classes . length > i ) { return classes [ i ] ; } return null ; }
Returns a class at specified depth of the current execution stack .
39,472
public static ClassLoader getClassLoaderContextAt ( int i ) { Class [ ] classes = MANAGER . getClassContext ( ) ; if ( classes != null && classes . length > i ) { return classes [ i ] . getClassLoader ( ) ; } return null ; }
Returns a classloader at specified depth of the current execution stack .
39,473
public static InputStream getResourceAsStream ( String name ) { ClassLoader loader = getClassLoaderContextAt ( 3 ) ; InputStream in = ( loader == null ) ? null : loader . getResourceAsStream ( name ) ; if ( in == null ) { ClassLoader contextLoader = Thread . currentThread ( ) . getContextClassLoader ( ) ; if ( contextLoader != null && contextLoader != loader ) { in = contextLoader . getResourceAsStream ( name ) ; } } return in ; }
Gets an InputStream to a resource of a specified name . First the caller s classloader is used to load the resource and if it fails the thread s context classloader is used to load the resource .
39,474
public static Class forName ( String name ) throws ClassNotFoundException { ClassLoader loader = getClassLoaderContextAt ( 3 ) ; try { return Class . forName ( name , true , loader ) ; } catch ( ClassNotFoundException e ) { ClassLoader contextLoader = Thread . currentThread ( ) . getContextClassLoader ( ) ; if ( contextLoader == null || contextLoader == loader ) { throw e ; } else { return Class . forName ( name , true , contextLoader ) ; } } }
Loads a specified class . First the caller s classloader is used to load the class and if it fails the thread s context classloader is used to load the specified class .
39,475
public void start ( String rmc ) throws GassException { if ( rmc == null ) { throw new IllegalArgumentException ( "Resource manager contact not specified" ) ; } GassServer gassServer = null ; String error = null ; try { gassServer = new GassServer ( this . cred , 0 ) ; String gassURL = gassServer . getURL ( ) ; String rsl = getRSL ( gassURL ) ; logger . debug ( "RSL: " + rsl ) ; stderrListener = new OutputListener ( ) ; stdoutListener = new OutputListener ( ) ; gassServer . registerJobOutputStream ( "err-rgs" , new JobOutputStream ( stderrListener ) ) ; gassServer . registerJobOutputStream ( "out-rgs" , new JobOutputStream ( stdoutListener ) ) ; job = new GramJob ( this . cred , rsl ) ; gassJobListener = new GassServerListener ( ) ; job . addListener ( gassJobListener ) ; job . request ( rmc ) ; int status = gassJobListener . waitFor ( 1000 * 60 * 2 ) ; if ( status == GramJob . STATUS_ACTIVE ) { while ( true ) { if ( stderrListener . hasData ( ) ) { error = stderrListener . getOutput ( ) ; break ; } else if ( stdoutListener . hasData ( ) ) { String fl = stdoutListener . getOutput ( ) ; if ( fl . startsWith ( "https://" ) || fl . startsWith ( "http://" ) ) { url = fl . trim ( ) ; break ; } else { error = "Unable to extract gass url : " + fl ; break ; } } else { logger . debug ( "waiting for stdout/err" ) ; sleep ( 500 ) ; } } } else if ( status == GramJob . STATUS_FAILED || status == GramJob . STATUS_DONE ) { int errorCode = gassJobListener . getError ( ) ; if ( stderrListener . hasData ( ) ) { error = stderrListener . getOutput ( ) ; } else if ( errorCode != 0 ) { error = "Remote gass server stopped with error : " + errorCode ; } else { error = "Remote gass server stopped and returned no error" ; } } else { error = "Unexpected state or received no notification" ; } } catch ( Exception e ) { throw new GassException ( e . getMessage ( ) ) ; } finally { if ( gassServer != null ) { gassServer . shutdown ( ) ; } } if ( error != null ) { throw new GassException ( error ) ; } }
Starts the gass server on the remote machine .
39,476
public boolean shutdown ( ) { if ( url != null ) { logger . debug ( "Trying to shutdown gass server directly..." ) ; try { GlobusURL u = new GlobusURL ( url ) ; GassServer . shutdown ( this . cred , u ) ; } catch ( Exception e ) { logger . debug ( "gass server shutdown failed" , e ) ; } try { gassJobListener . reset ( ) ; int status = gassJobListener . waitFor ( 1000 * 60 ) ; if ( status == GramJob . STATUS_FAILED || status == GramJob . STATUS_DONE ) { reset ( ) ; return true ; } } catch ( InterruptedException e ) { logger . debug ( "" , e ) ; } } if ( job == null ) return true ; logger . debug ( "Canceling gass server job." ) ; try { job . cancel ( ) ; reset ( ) ; return true ; } catch ( Exception e ) { return false ; } }
Shutdowns remotely running gass server .
39,477
public static File createFile ( String filename ) throws SecurityException , IOException { File f = new File ( filename ) ; if ( ! f . createNewFile ( ) ) { if ( ! destroy ( f ) ) { throw new SecurityException ( "Could not destroy existing file" ) ; } if ( ! f . createNewFile ( ) ) { throw new SecurityException ( "Failed to atomically create new file" ) ; } } return f ; }
Attempts to create a new file in an atomic way . If the file already exists it if first deleted .
39,478
public static boolean destroy ( File file ) { if ( ! file . exists ( ) ) return false ; RandomAccessFile f = null ; long size = file . length ( ) ; try { f = new RandomAccessFile ( file , "rw" ) ; long rec = size / DMSG . length ( ) ; int left = ( int ) ( size - rec * DMSG . length ( ) ) ; while ( rec != 0 ) { f . write ( DMSG . getBytes ( ) , 0 , DMSG . length ( ) ) ; rec -- ; } if ( left > 0 ) { f . write ( DMSG . getBytes ( ) , 0 , left ) ; } } catch ( Exception e ) { return false ; } finally { try { if ( f != null ) f . close ( ) ; } catch ( Exception e ) { } } return file . delete ( ) ; }
Overwrites the contents of the file with a random string and then deletes the file .
39,479
public static String getInput ( String prompt ) { System . out . print ( prompt ) ; try { BufferedReader in = new BufferedReader ( new InputStreamReader ( System . in ) ) ; return in . readLine ( ) ; } catch ( IOException e ) { return null ; } }
Displays a prompt and then reads in the input from System . in .
39,480
public static String getPrivateInput ( String prompt ) { System . out . print ( prompt ) ; PrivateInputThread privateInput = new PrivateInputThread ( ) ; BufferedReader in = new BufferedReader ( new InputStreamReader ( System . in ) ) ; privateInput . start ( ) ; try { return in . readLine ( ) ; } catch ( Exception e ) { return null ; } finally { privateInput . kill ( ) ; } }
Displays a prompt and then reads in private input from System . in . Characters typed by the user are replaced with a space on the screen .
39,481
public static String quote ( String str ) { int len = str . length ( ) ; StringBuffer buf = new StringBuffer ( len + 2 ) ; buf . append ( "\"" ) ; char c ; for ( int i = 0 ; i < len ; i ++ ) { c = str . charAt ( i ) ; if ( c == '"' || c == '\\' ) { buf . append ( "\\" ) ; } buf . append ( c ) ; } buf . append ( "\"" ) ; return buf . toString ( ) ; }
Quotifies a specified string . The entire string is encompassed by double quotes and each is replaced with \ \ is replaced with \\ .
39,482
public static String unquote ( String str ) throws Exception { int len = str . length ( ) ; StringBuffer buf = new StringBuffer ( len ) ; boolean inQuotes = false ; char c ; int i = 0 ; if ( str . charAt ( i ) == '"' ) { inQuotes = true ; i ++ ; } while ( i < len ) { c = str . charAt ( i ) ; if ( inQuotes ) { if ( c == '"' ) { inQuotes = false ; } else if ( c == '\\' ) { buf . append ( str . charAt ( ++ i ) ) ; } else { buf . append ( c ) ; } } else { if ( c == '\r' ) { if ( str . charAt ( i ++ ) != '\n' ) { throw new Exception ( "Malformed string." ) ; } } else if ( c == '"' ) { inQuotes = true ; i ++ ; } else { buf . append ( c ) ; } } i ++ ; } return buf . toString ( ) ; }
Dequotifies a specified string . The quotes are removed and each \ is replaced with and each \\ is replaced with \ .
39,483
public X509Credential createCredential ( X509Certificate [ ] certs , PrivateKey privateKey , int bits , int lifetime , GSIConstants . CertificateType certType , X509ExtensionSet extSet , String cnValue ) throws GeneralSecurityException { X509Certificate [ ] bcCerts = getX509CertificateObjectChain ( certs ) ; KeyPairGenerator keyGen = null ; keyGen = KeyPairGenerator . getInstance ( "RSA" , "BC" ) ; keyGen . initialize ( bits ) ; KeyPair keyPair = keyGen . genKeyPair ( ) ; X509Certificate newCert = createProxyCertificate ( bcCerts [ 0 ] , privateKey , keyPair . getPublic ( ) , lifetime , certType , extSet , cnValue ) ; X509Certificate [ ] newCerts = new X509Certificate [ bcCerts . length + 1 ] ; newCerts [ 0 ] = newCert ; System . arraycopy ( certs , 0 , newCerts , 1 , certs . length ) ; return new X509Credential ( keyPair . getPrivate ( ) , newCerts ) ; }
Creates a new proxy credential from the specified certificate chain and a private key . A set of X . 509 extensions can be optionally included in the new proxy certificate . This function automatically creates a RSA - based key pair .
39,484
public X509Certificate loadCertificate ( InputStream in ) throws IOException , GeneralSecurityException { ASN1InputStream derin = new ASN1InputStream ( in ) ; ASN1Primitive certInfo = derin . readObject ( ) ; ASN1Sequence seq = ASN1Sequence . getInstance ( certInfo ) ; return new X509CertificateObject ( Certificate . getInstance ( seq ) ) ; }
Loads a X509 certificate from the specified input stream . Input stream must contain DER - encoded certificate .
39,485
public byte [ ] createCertificateRequest ( X509Name subjectDN , String sigAlgName , KeyPair keyPair ) throws GeneralSecurityException { DERSet attrs = null ; PKCS10CertificationRequest certReq = null ; certReq = new PKCS10CertificationRequest ( sigAlgName , subjectDN , keyPair . getPublic ( ) , attrs , keyPair . getPrivate ( ) ) ; return certReq . getEncoded ( ) ; }
Creates a certificate request from the specified subject name signing algorithm and a key pair .
39,486
public static GSIConstants . CertificateType decideProxyType ( X509Certificate issuerCert , GSIConstants . DelegationType delegType ) throws CertificateException { GSIConstants . CertificateType proxyType = GSIConstants . CertificateType . UNDEFINED ; if ( delegType == GSIConstants . DelegationType . LIMITED ) { GSIConstants . CertificateType type = BouncyCastleUtil . getCertificateType ( issuerCert ) ; if ( ProxyCertificateUtil . isGsi4Proxy ( type ) ) { proxyType = GSIConstants . CertificateType . GSI_4_LIMITED_PROXY ; } else if ( ProxyCertificateUtil . isGsi3Proxy ( type ) ) { proxyType = GSIConstants . CertificateType . GSI_3_LIMITED_PROXY ; } else if ( ProxyCertificateUtil . isGsi2Proxy ( type ) ) { proxyType = GSIConstants . CertificateType . GSI_2_LIMITED_PROXY ; } else { if ( VersionUtil . isGsi2Enabled ( ) ) { proxyType = GSIConstants . CertificateType . GSI_2_LIMITED_PROXY ; } else { proxyType = VersionUtil . isGsi3Enabled ( ) ? GSIConstants . CertificateType . GSI_3_LIMITED_PROXY : GSIConstants . CertificateType . GSI_4_LIMITED_PROXY ; } } } else if ( delegType == GSIConstants . DelegationType . FULL ) { GSIConstants . CertificateType type = BouncyCastleUtil . getCertificateType ( issuerCert ) ; if ( ProxyCertificateUtil . isGsi4Proxy ( type ) ) { proxyType = GSIConstants . CertificateType . GSI_4_IMPERSONATION_PROXY ; } else if ( ProxyCertificateUtil . isGsi3Proxy ( type ) ) { proxyType = GSIConstants . CertificateType . GSI_3_IMPERSONATION_PROXY ; } else if ( ProxyCertificateUtil . isGsi2Proxy ( type ) ) { proxyType = GSIConstants . CertificateType . GSI_2_PROXY ; } else { if ( VersionUtil . isGsi2Enabled ( ) ) { proxyType = GSIConstants . CertificateType . GSI_2_PROXY ; } else { proxyType = ( VersionUtil . isGsi3Enabled ( ) ) ? GSIConstants . CertificateType . GSI_3_IMPERSONATION_PROXY : GSIConstants . CertificateType . GSI_4_IMPERSONATION_PROXY ; } } } return proxyType ; }
Given a delegation mode and an issuing certificate decides an appropriate certificate type to use for proxies
39,487
public NameOpValue getParam ( String attribute ) { if ( _relations == null || attribute == null ) return null ; return ( NameOpValue ) _relations . get ( canonicalize ( attribute ) ) ; }
Returns the relation associated with the given attribute .
39,488
public Bindings removeBindings ( String attribute ) { if ( _relations == null || attribute == null ) return null ; return ( Bindings ) _bindings . remove ( canonicalize ( attribute ) ) ; }
Removes a bindings list for the specified attribute .
39,489
public void toRSL ( StringBuffer buf , boolean explicitConcat ) { Iterator iter ; buf . append ( getOperatorAsString ( ) ) ; if ( _bindings != null && _bindings . size ( ) > 0 ) { iter = _bindings . keySet ( ) . iterator ( ) ; Bindings binds ; while ( iter . hasNext ( ) ) { binds = getBindings ( ( String ) iter . next ( ) ) ; binds . toRSL ( buf , explicitConcat ) ; } } if ( _relations != null && _relations . size ( ) > 0 ) { iter = _relations . keySet ( ) . iterator ( ) ; NameOpValue nov ; while ( iter . hasNext ( ) ) { nov = getParam ( ( String ) iter . next ( ) ) ; nov . toRSL ( buf , explicitConcat ) ; } } if ( _specifications != null && _specifications . size ( ) > 0 ) { iter = _specifications . iterator ( ) ; AbstractRslNode node ; while ( iter . hasNext ( ) ) { node = ( AbstractRslNode ) iter . next ( ) ; buf . append ( " (" ) ; node . toRSL ( buf , explicitConcat ) ; buf . append ( " )" ) ; } } }
Produces a RSL representation of node .
39,490
public String getSingle ( String attribute ) { NameOpValue nv = rslTree . getParam ( attribute ) ; if ( nv == null || nv . getOperator ( ) != NameOpValue . EQ ) return null ; Object obj = nv . getFirstValue ( ) ; if ( obj != null && obj instanceof Value ) { return ( ( Value ) obj ) . getCompleteValue ( ) ; } else { return null ; } }
Returns a string value of the specified attribute . If the attribute contains multiple values the first one is returned .
39,491
public List getMulti ( String attribute ) { NameOpValue nv = rslTree . getParam ( attribute ) ; if ( nv == null || nv . getOperator ( ) != NameOpValue . EQ ) return null ; List values = nv . getValues ( ) ; List list = new LinkedList ( ) ; Iterator iter = values . iterator ( ) ; Object obj ; while ( iter . hasNext ( ) ) { obj = iter . next ( ) ; if ( obj instanceof Value ) { list . add ( ( ( Value ) obj ) . getCompleteValue ( ) ) ; } } return list ; }
Returns a list of strings for a specified attribute . For example for arguments attribute .
39,492
public void addVariable ( String attribute , String varName , String value ) { Bindings binds = rslTree . getBindings ( attribute ) ; if ( binds == null ) { binds = new Bindings ( attribute ) ; rslTree . put ( binds ) ; } binds . add ( new Binding ( varName , value ) ) ; }
Adds a new variable definition to the specified variable definitions attribute .
39,493
public boolean removeVariable ( String attribute , String varName ) { Bindings binds = rslTree . getBindings ( attribute ) ; if ( binds == null ) return false ; return binds . removeVariable ( varName ) ; }
Removes a specific variable definition given a variable name .
39,494
public boolean remove ( String attribute , String value ) { NameOpValue nv = rslTree . getParam ( attribute ) ; if ( nv == null || nv . getOperator ( ) != NameOpValue . EQ ) return false ; return nv . remove ( new Value ( value ) ) ; }
Removes a specific value from a list of values of the specified attribute .
39,495
public boolean removeMap ( String attribute , String key ) { NameOpValue nv = rslTree . getParam ( attribute ) ; if ( nv == null || nv . getOperator ( ) != NameOpValue . EQ ) return false ; List values = nv . getValues ( ) ; Iterator iter = values . iterator ( ) ; Object obj ; int i = 0 ; int found = - 1 ; while ( iter . hasNext ( ) ) { obj = iter . next ( ) ; if ( obj instanceof List ) { List vr = ( List ) obj ; if ( vr . size ( ) > 0 ) { Object var = vr . get ( 0 ) ; if ( var instanceof Value && ( ( Value ) var ) . getValue ( ) . equals ( key ) ) { found = i ; break ; } } } i ++ ; } if ( found != - 1 ) { values . remove ( found ) ; return true ; } else { return false ; } }
Removes a specific key from a list of values of the specified attribute . The attribute values must be in the right form . See the environment rsl attribute .
39,496
public void add ( String attribute , String value ) { NameOpValue nv = getRelation ( attribute ) ; nv . add ( new Value ( value ) ) ; }
Adds a simple value to the list of values of a given attribute .
39,497
public void setMulti ( String attribute , String [ ] values ) { NameOpValue nv = getRelation ( attribute ) ; nv . clear ( ) ; List list = new LinkedList ( ) ; for ( int i = 0 ; i < values . length ; i ++ ) { list . add ( new Value ( values [ i ] ) ) ; } nv . add ( list ) ; }
Sets the attribute value to the given list of values . The list of values is added as a single value .
39,498
public void invoke ( X509Certificate cert , GSIConstants . CertificateType certType ) throws CertPathValidatorException { if ( proxyCertValidator . getIdentityCertificate ( ) == null ) { if ( ProxyCertificateUtil . isLimitedProxy ( certType ) ) { proxyCertValidator . setLimited ( true ) ; if ( proxyCertValidator . isRejectLimitedProxy ( ) ) { throw new CertPathValidatorException ( "Limited proxy not accepted" ) ; } } if ( ! ProxyCertificateUtil . isImpersonationProxy ( certType ) ) { proxyCertValidator . setIdentityCert ( cert ) ; } } }
Method that sets the identity of the certificate path . Also checks if limited proxy is acceptable .
39,499
private void notReflexive ( List < String > conditions , QueryNode node , QueryNode target ) { Validate . isTrue ( node != target , "notReflexive(...) implies that source " + "and target node are not the same, but someone is violating this constraint!" ) ; Validate . notNull ( node ) ; Validate . notNull ( target ) ; if ( node . getNodeAnnotations ( ) . isEmpty ( ) && target . getNodeAnnotations ( ) . isEmpty ( ) ) { joinOnNode ( conditions , node , target , "<>" , "id" , "id" ) ; } else if ( ! node . getNodeAnnotations ( ) . isEmpty ( ) && ! target . getNodeAnnotations ( ) . isEmpty ( ) ) { TableAccessStrategy tasNode = tables ( node ) ; TableAccessStrategy tasTarget = tables ( target ) ; String nodeDifferent = join ( "<>" , tasNode . aliasedColumn ( NODE_TABLE , "id" ) , tasTarget . aliasedColumn ( NODE_TABLE , "id" ) ) ; String annoCatDifferent = join ( "IS DISTINCT FROM" , tasNode . aliasedColumn ( NODE_ANNOTATION_TABLE , "category" ) , tasTarget . aliasedColumn ( NODE_ANNOTATION_TABLE , "category" ) ) ; conditions . add ( "(" + Joiner . on ( " OR " ) . join ( nodeDifferent , annoCatDifferent ) + ")" ) ; } }
Explicitly disallow reflexivity .