1. /*
  2. * Copyright 2001-2004 The Apache Software Foundation
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package org.apache.commons.net.io;
  17. import java.util.EventObject;
  18. /**
  19. * A CopyStreamEvent is triggered after every write performed by a
  20. * stream copying operation. The event stores the number of bytes
  21. * transferred by the write triggering the event as well as the total
  22. * number of bytes transferred so far by the copy operation.
  23. * <p>
  24. * <p>
  25. * @see CopyStreamListener
  26. * @see CopyStreamAdapter
  27. * @see Util
  28. * @author <a href="mailto:savarese@apache.org">Daniel F. Savarese</a>
  29. * @version $Id: CopyStreamEvent.java,v 1.9 2004/02/29 10:26:55 scolebourne Exp $
  30. */
  31. public class CopyStreamEvent extends EventObject
  32. {
  33. /**
  34. * Constant used to indicate the stream size is unknown.
  35. */
  36. public static final long UNKNOWN_STREAM_SIZE = -1;
  37. private int bytesTransferred;
  38. private long totalBytesTransferred;
  39. private long streamSize;
  40. /**
  41. * Creates a new CopyStreamEvent instance.
  42. * @param source The source of the event.
  43. * @param totalBytesTransferred The total number of bytes transferred so
  44. * far during a copy operation.
  45. * @param bytesTransferred The number of bytes transferred during the
  46. * write that triggered the CopyStreamEvent.
  47. * @param streamSize The number of bytes in the stream being copied.
  48. * This may be set to <code>UNKNOWN_STREAM_SIZE</code> if the
  49. * size is unknown.
  50. */
  51. public CopyStreamEvent(Object source, long totalBytesTransferred,
  52. int bytesTransferred, long streamSize)
  53. {
  54. super(source);
  55. this.bytesTransferred = bytesTransferred;
  56. this.totalBytesTransferred = totalBytesTransferred;
  57. this.streamSize = streamSize;
  58. }
  59. /**
  60. * Returns the number of bytes transferred by the write that triggered
  61. * the event.
  62. * @return The number of bytes transferred by the write that triggered
  63. * the vent.
  64. */
  65. public int getBytesTransferred()
  66. {
  67. return bytesTransferred;
  68. }
  69. /**
  70. * Returns the total number of bytes transferred so far by the copy
  71. * operation.
  72. * @return The total number of bytes transferred so far by the copy
  73. * operation.
  74. */
  75. public long getTotalBytesTransferred()
  76. {
  77. return totalBytesTransferred;
  78. }
  79. /**
  80. * Returns the size of the stream being copied.
  81. * This may be set to <code>UNKNOWN_STREAM_SIZE</code> if the
  82. * size is unknown.
  83. * @return The size of the stream being copied.
  84. */
  85. public long getStreamSize()
  86. {
  87. return streamSize;
  88. }
  89. }