ObjectInput.java 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. /* ObjectInput.java -- Read object data from a stream
  2. Copyright (C) 1998,2003 Free Software Foundation, Inc.
  3. This file is part of GNU Classpath.
  4. GNU Classpath is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2, or (at your option)
  7. any later version.
  8. GNU Classpath is distributed in the hope that it will be useful, but
  9. WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with GNU Classpath; see the file COPYING. If not, write to the
  14. Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  15. 02110-1301 USA.
  16. Linking this library statically or dynamically with other modules is
  17. making a combined work based on this library. Thus, the terms and
  18. conditions of the GNU General Public License cover the whole
  19. combination.
  20. As a special exception, the copyright holders of this library give you
  21. permission to link this library with independent modules to produce an
  22. executable, regardless of the license terms of these independent
  23. modules, and to copy and distribute the resulting executable under
  24. terms of your choice, provided that you also meet, for each linked
  25. independent module, the terms and conditions of the license of that
  26. module. An independent module is a module which is not derived from
  27. or based on this library. If you modify this library, you may extend
  28. this exception to your version of the library, but you are not
  29. obligated to do so. If you do not wish to do so, delete this
  30. exception statement from your version. */
  31. package java.io;
  32. /**
  33. * This interface extends the <code>DataInput</code> interface to provide a
  34. * facility to read objects as well as primitive types from a stream. It
  35. * also has methods that allow input to be done in a manner similar to
  36. * <code>InputStream</code>
  37. *
  38. * @author Aaron M. Renn (arenn@urbanophile.com)
  39. *
  40. * @see DataInput
  41. */
  42. public interface ObjectInput
  43. extends DataInput, AutoCloseable
  44. {
  45. /**
  46. * This method returns the number of bytes that can be read without
  47. * blocking.
  48. *
  49. * @return The number of bytes available before blocking
  50. *
  51. * @exception IOException If an error occurs
  52. */
  53. int available() throws IOException;
  54. /**
  55. * This method reading a byte of data from a stream. It returns that byte
  56. * as an <code>int</code>. This method blocks if no data is available
  57. * to be read.
  58. *
  59. * @return The byte of data read
  60. *
  61. * @exception IOException If an error occurs
  62. */
  63. int read() throws IOException;
  64. /**
  65. * This method reads raw bytes and stores them them a byte array buffer.
  66. * Note that this method will block if no data is available. However,
  67. * it will not necessarily block until it fills the entire buffer. That is,
  68. * a "short count" is possible.
  69. *
  70. * @param buf The byte array to receive the data read
  71. *
  72. * @return The actual number of bytes read or -1 if end of stream
  73. *
  74. * @exception IOException If an error occurs
  75. */
  76. int read(byte[] buf) throws IOException;
  77. /**
  78. * This method reads raw bytes and stores them in a byte array buffer
  79. * <code>buf</code> starting at position <code>offset</code> into the
  80. * buffer. A
  81. * maximum of <code>len</code> bytes will be read. Note that this method
  82. * blocks if no data is available, but will not necessarily block until
  83. * it can read <code>len</code> bytes of data. That is, a "short count" is
  84. * possible.
  85. *
  86. * @param buf The byte array to receive the data read
  87. * @param offset The offset into <code>buf</code> to start storing data
  88. * @param len The maximum number of bytes to read
  89. *
  90. * @return The actual number of bytes read or -1 if end of stream
  91. *
  92. * @exception IOException If an error occurs
  93. */
  94. int read(byte[] buf, int offset, int len) throws IOException;
  95. /**
  96. * Reads an object instance and returns it. If the class for the object
  97. * being read cannot be found, then a <code>ClassNotFoundException</code>
  98. * will be thrown.
  99. *
  100. * @return The object instance that was read
  101. *
  102. * @exception ClassNotFoundException If a class for the object cannot be
  103. * found
  104. * @exception IOException If any other error occurs
  105. */
  106. Object readObject()
  107. throws ClassNotFoundException, IOException;
  108. /**
  109. * This method causes the specified number of bytes to be read and
  110. * discarded. It is possible that fewer than the requested number of bytes
  111. * will actually be skipped.
  112. *
  113. * @param numBytes The number of bytes to skip
  114. *
  115. * @return The actual number of bytes skipped
  116. *
  117. * @exception IOException If an error occurs
  118. */
  119. long skip(long numBytes) throws IOException;
  120. /**
  121. * This method closes the input source
  122. *
  123. * @exception IOException If an error occurs
  124. */
  125. void close() throws IOException;
  126. }