1. /*
  2. * @(#)Channel.java 1.18 03/12/19
  3. *
  4. * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package java.nio.channels;
  8. import java.io.IOException;
  9. import java.io.Closeable;
  10. /**
  11. * A nexus for I/O operations.
  12. *
  13. * <p> A channel represents an open connection to an entity such as a hardware
  14. * device, a file, a network socket, or a program component that is capable of
  15. * performing one or more distinct I/O operations, for example reading or
  16. * writing.
  17. *
  18. * <p> A channel is either open or closed. A channel is open upon creation,
  19. * and once closed it remains closed. Once a channel is closed, any attempt to
  20. * invoke an I/O operation upon it will cause a {@link ClosedChannelException}
  21. * to be thrown. Whether or not a channel is open may be tested by invoking
  22. * its {@link #isOpen isOpen} method.
  23. *
  24. * <p> Channels are, in general, intended to be safe for multithreaded access
  25. * as described in the specifications of the interfaces and classes that extend
  26. * and implement this interface.
  27. *
  28. *
  29. * @author Mark Reinhold
  30. * @author JSR-51 Expert Group
  31. * @version 1.18, 03/12/19
  32. * @since 1.4
  33. */
  34. public interface Channel extends Closeable {
  35. /**
  36. * Tells whether or not this channel is open. </p>
  37. *
  38. * @return <tt>true</tt> if, and only if, this channel is open
  39. */
  40. public boolean isOpen();
  41. /**
  42. * Closes this channel.
  43. *
  44. * <p> After a channel is closed, any further attempt to invoke I/O
  45. * operations upon it will cause a {@link ClosedChannelException} to be
  46. * thrown.
  47. *
  48. * <p> If this channel is already closed then invoking this method has no
  49. * effect.
  50. *
  51. * <p> This method may be invoked at any time. If some other thread has
  52. * already invoked it, however, then another invocation will block until
  53. * the first invocation is complete, after which it will return without
  54. * effect. </p>
  55. *
  56. * @throws IOException If an I/O error occurs
  57. */
  58. public void close() throws IOException;
  59. }