Uploaded image for project: 'Commons Net'
  1. Commons Net
  2. NET-717

FTPClient: Encapsulate completePendingCommand in returned outputstream

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Open
    • Major
    • Resolution: Unresolved
    • None
    • None
    • FTP
    • None

    Description

      Most store / retrieve methods in FTPClient class requires a call to completePendingCommand method in order to make sure that the operation completed successfully, and allow additional operations to go on.

      This is clearly documented, but often lead to clumsy code as 99% of the time we just need to know if the file operation executed successfully or not (and in some case, the completePendingCommand is simply forgotten leading to, as documented, unexpected behavior of subsequent commands.

      The idea would be to return a FilterOutputStream / FilterInputStream that would encapsulates the returned OutputStream/InputStream returned by methods that need a subsequent call to completePendingCommand. These filter implementations would call the completePendingCommand method on close, throwing an IOException if it returns false.

      package org.apache.commons.net.ftp;
      
      import java.io.FilterOutputStream;
      import java.io.IOException;
      import java.io.OutputStream;
      
      public class FTPOutputStream extends FilterOutputStream {
        private final FTPClient ftpClient;
        public FTPOutputStream(OutputStream out, FTPClient ftpClient) {
          super(out);
          this.ftpClient = ftpClient;
        }
      
        @Override
        public void close() throws IOException {
          super.close();
          if(!ftpClient.completePendingCommand()) {
            throw new IOException("FTP Client was unable to complete pending command");
          }
        }
      }
      

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              motofix Julien B├ęti
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated: