/plugins/FTP/tags/release-0-8-0/com/fooware/net/FtpWriter.java

# · Java · 65 lines · 15 code · 11 blank · 39 comment · 0 complexity · 2c9d606d3ac3baf891c020f8eca36ffb MD5 · raw file

  1. /*************************************************************************
  2. * Copyright (C) 1998, Chris Cheetham, fooware *
  3. * Distributed under the GNU General Public License *
  4. * http://www.fsf.org/copyleft/gpl.html *
  5. *************************************************************************/
  6. package com.fooware.net;
  7. import java.io.FilterWriter;
  8. import java.io.Writer;
  9. import java.io.IOException;
  10. /**
  11. * This is an object that can be used as a java.io.Writer for the
  12. * writing of data to an FTP server. You do not construct one
  13. * explicitly, but via an FtpClient:<BR>
  14. * <CODE><PRE>
  15. * FtpClient ftp = new FtpClient();
  16. * ftp.connect(someServer);
  17. * ftp.userName(myName);
  18. * ftp.password(myPassword);
  19. * ftp.dataPort();
  20. * <B>FtpWriter out = ftp.store(targetFile);
  21. * while (someReader.ready())
  22. * out.write(someReader.read());
  23. * in.close();</B>
  24. * </PRE></CODE>
  25. * Note: unlike other Writers, it is important to explicitly close this
  26. * Writer when through. This signals the FtpClient to get a response
  27. * from the FTP server.
  28. * @author <A HREF="mailto:cheetham@fooware.com">Chris Cheetham</A>
  29. * @version $Revision: 1842 $
  30. **/
  31. public class FtpWriter extends FilterWriter {
  32. //
  33. // constructors
  34. //
  35. /**
  36. * Contruct an FtpWriter for the specified FtpClient.
  37. **/
  38. FtpWriter(Writer out, FtpClient client) throws IOException {
  39. super(out);
  40. this.client = client;
  41. }
  42. /**
  43. * Close the underlying Writer and signal the FtpClient that
  44. * Writer processing has completed.
  45. **/
  46. public void close() throws IOException {
  47. super.close();
  48. client.closeTransferSocket();
  49. }
  50. //
  51. // member variables
  52. //
  53. private FtpClient client;
  54. }