Question

I was studying some code for a java ftp-client, in one method this.-operator is used and I don't know what is meant. What does "this.processFtpRequest" stand for?

     * Initializes the FTP control connection.
 * @param alias the user-ID
 * @param binaryMode true for binary transmission, false for ASCII
 * @throws SecurityException if the given alias or password is invalid
 * @throws IOException if there is an I/O related problem
 */
private synchronized void initialize(final String alias, final String password, final boolean binaryMode) throws IOException {
    FtpResponse ftpResponse = FtpResponse.parse(this.controlConnectionSource);
    Logger.getGlobal().log(Level.INFO, ftpResponse.toString());
    if (ftpResponse.getCode() != 220) throw new ProtocolException(ftpResponse.toString());

    ftpResponse = this.processFtpRequest("USER " + (alias == null ? "guest" : alias));
    if (ftpResponse.getCode() == 331) {
        ftpResponse = this.processFtpRequest("PASS " + (password == null ? "" : password));
    }
    if (ftpResponse.getCode() != 230) throw new SecurityException(ftpResponse.toString());

    ftpResponse = this.processFtpRequest("TYPE " + (binaryMode ? "I" : "A"));
    if (ftpResponse.getCode() != 200) throw new ProtocolException(ftpResponse.toString());
}
Was it helpful?

Solution

From The Java Tutorial:

Within an instance method or a constructor, this is a reference to the current object — the object whose method or constructor is being called. You can refer to any member of the current object from within an instance method or a constructor by using this.

So this.processFtpRequest(...) calls an instance method on the current object.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top