1. /*
  2. * @(#)ImageOutputStream.java 1.24 04/05/13
  3. *
  4. * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package javax.imageio.stream;
  8. import java.io.DataOutput;
  9. import java.io.IOException;
  10. import java.io.UTFDataFormatException;
  11. /**
  12. * A seekable output stream interface for use by
  13. * <code>ImageWriter</code>s. Various output destinations, such as
  14. * <code>OutputStream</code>s and <code>File</code>s, as well as
  15. * future fast I/O destinations may be "wrapped" by a suitable
  16. * implementation of this interface for use by the Image I/O API.
  17. *
  18. * <p> Unlike a standard <code>OutputStream</code>, ImageOutputStream
  19. * extends its counterpart, <code>ImageInputStream</code>. Thus it is
  20. * possible to read from the stream as it is being written. The same
  21. * seek and flush positions apply to both reading and writing, although
  22. * the semantics for dealing with a non-zero bit offset before a byte-aligned
  23. * write are necessarily different from the semantics for dealing with
  24. * a non-zero bit offset before a byte-aligned read. When reading bytes,
  25. * any bit offset is set to 0 before the read; when writing bytes, a
  26. * non-zero bit offset causes the remaining bits in the byte to be written
  27. * as 0s. The byte-aligned write then starts at the next byte position.
  28. *
  29. * @see ImageInputStream
  30. *
  31. * @version 0.5
  32. */
  33. public interface ImageOutputStream extends ImageInputStream, DataOutput {
  34. /**
  35. * Writes a single byte to the stream at the current position.
  36. * The 24 high-order bits of <code>b</code> are ignored.
  37. *
  38. * <p> If the bit offset within the stream is non-zero, the
  39. * remainder of the current byte is padded with 0s
  40. * and written out first. The bit offset will be 0 after the
  41. * write. Implementers can use the
  42. * {@link ImageOutputStreamImpl#flushBits <code>flushBits</code>}
  43. * method of {@link ImageOutputStreamImpl
  44. * <code>ImageOutputStreamImpl</code>} to guarantee this.
  45. *
  46. * @param b an <code>int</code> whose lower 8 bits are to be
  47. * written.
  48. *
  49. * @exception IOException if an I/O error occurs.
  50. */
  51. void write(int b) throws IOException;
  52. /**
  53. * Writes a sequence of bytes to the stream at the current
  54. * position. If <code>b.length</code> is 0, nothing is written.
  55. * The byte <code>b[0]</code> is written first, then the byte
  56. * <code>b[1]</code>, and so on.
  57. *
  58. * <p> If the bit offset within the stream is non-zero, the
  59. * remainder of the current byte is padded with 0s
  60. * and written out first. The bit offset will be 0 after the
  61. * write.
  62. *
  63. * @param b an array of <code>byte</code>s to be written.
  64. *
  65. * @exception NullPointerException if <code>b</code> is
  66. * <code>null</code>.
  67. * @exception IOException if an I/O error occurs.
  68. */
  69. void write(byte b[]) throws IOException;
  70. /**
  71. * Writes a sequence of bytes to the stream at the current
  72. * position. If <code>len</code> is 0, nothing is written.
  73. * The byte <code>b[off]</code> is written first, then the byte
  74. * <code>b[off + 1]</code>, and so on.
  75. *
  76. * <p> If the bit offset within the stream is non-zero, the
  77. * remainder of the current byte is padded with 0s
  78. * and written out first. The bit offset will be 0 after the
  79. * write. Implementers can use the
  80. * {@link ImageOutputStreamImpl#flushBits <code>flushBits</code>}
  81. * method of {@link ImageOutputStreamImpl
  82. * <code>ImageOutputStreamImpl</code>} to guarantee this.
  83. *
  84. * @param b an array of <code>byte</code>s to be written.
  85. * @param off the start offset in the data.
  86. * @param len the number of <code>byte</code>s to write.
  87. *
  88. * @exception IndexOutOfBoundsException if <code>off</code> is
  89. * negative, <code>len</code> is negative, or <code>off +
  90. * len</code> is greater than <code>b.length</code>.
  91. * @exception NullPointerException if <code>b</code> is
  92. * <code>null</code>.
  93. * @exception IOException if an I/O error occurs.
  94. */
  95. void write(byte b[], int off, int len) throws IOException;
  96. /**
  97. * Writes a <code>boolean</code> value to the stream. If
  98. * <code>v</code> is true, the value <code>(byte)1</code> is
  99. * written; if <code>v</code> is false, the value
  100. * <code>(byte)0</code> is written.
  101. *
  102. * <p> If the bit offset within the stream is non-zero, the
  103. * remainder of the current byte is padded with 0s
  104. * and written out first. The bit offset will be 0 after the
  105. * write.
  106. *
  107. * @param v the <code>boolean</code> to be written.
  108. *
  109. * @exception IOException if an I/O error occurs.
  110. */
  111. void writeBoolean(boolean v) throws IOException;
  112. /**
  113. * Writes the 8 low-order bits of <code>v</code> to the
  114. * stream. The 24 high-order bits of <code>v</code> are ignored.
  115. * (This means that <code>writeByte</code> does exactly the same
  116. * thing as <code>write</code> for an integer argument.)
  117. *
  118. * <p> If the bit offset within the stream is non-zero, the
  119. * remainder of the current byte is padded with 0s
  120. * and written out first. The bit offset will be 0 after the
  121. * write.
  122. *
  123. * @param v an <code>int</code> containing the byte value to be
  124. * written.
  125. *
  126. * @exception IOException if an I/O error occurs.
  127. */
  128. void writeByte(int v) throws IOException;
  129. /**
  130. * Writes the 16 low-order bits of <code>v</code> to the
  131. * stream. The 16 high-order bits of <code>v</code> are ignored.
  132. * If the stream uses network byte order, the bytes written, in
  133. * order, will be:
  134. *
  135. * <pre>
  136. * (byte)((v >> 8) & 0xff)
  137. * (byte)(v & 0xff)
  138. * </pre>
  139. *
  140. * Otherwise, the bytes written will be:
  141. *
  142. * <pre>
  143. * (byte)(v & 0xff)
  144. * (byte)((v >> 8) & 0xff)
  145. * </pre>
  146. *
  147. * <p> If the bit offset within the stream is non-zero, the
  148. * remainder of the current byte is padded with 0s
  149. * and written out first. The bit offset will be 0 after the
  150. * write.
  151. *
  152. * @param v an <code>int</code> containing the short value to be
  153. * written.
  154. *
  155. * @exception IOException if an I/O error occurs.
  156. */
  157. void writeShort(int v) throws IOException;
  158. /**
  159. * This method is a synonym for
  160. * {@link #writeShort <code>writeShort</code>}.
  161. *
  162. * @param v an <code>int</code> containing the char (unsigned
  163. * short) value to be written.
  164. *
  165. * @exception IOException if an I/O error occurs.
  166. *
  167. * @see #writeShort(int)
  168. */
  169. void writeChar(int v) throws IOException;
  170. /**
  171. * Writes the 32 bits of <code>v</code> to the stream. If the
  172. * stream uses network byte order, the bytes written, in order,
  173. * will be:
  174. *
  175. * <pre>
  176. * (byte)((v >> 24) & 0xff)
  177. * (byte)((v >> 16) & 0xff)
  178. * (byte)((v >> 8) & 0xff)
  179. * (byte)(v & 0xff)
  180. * </pre>
  181. *
  182. * Otheriwse, the bytes written will be:
  183. *
  184. * <pre>
  185. * (byte)(v & 0xff)
  186. * (byte)((v >> 8) & 0xff)
  187. * (byte)((v >> 16) & 0xff)
  188. * (byte)((v >> 24) & 0xff)
  189. * </pre>
  190. *
  191. * <p> If the bit offset within the stream is non-zero, the
  192. * remainder of the current byte is padded with 0s
  193. * and written out first. The bit offset will be 0 after the
  194. * write.
  195. *
  196. * @param v an <code>int</code> containing the value to be
  197. * written.
  198. *
  199. * @exception IOException if an I/O error occurs.
  200. */
  201. void writeInt(int v) throws IOException;
  202. /**
  203. * Writes the 64 bits of <code>v</code> to the stream. If the
  204. * stream uses network byte order, the bytes written, in order,
  205. * will be:
  206. *
  207. * <pre>
  208. * (byte)((v >> 56) & 0xff)
  209. * (byte)((v >> 48) & 0xff)
  210. * (byte)((v >> 40) & 0xff)
  211. * (byte)((v >> 32) & 0xff)
  212. * (byte)((v >> 24) & 0xff)
  213. * (byte)((v >> 16) & 0xff)
  214. * (byte)((v >> 8) & 0xff)
  215. * (byte)(v & 0xff)
  216. * </pre>
  217. *
  218. * Otherwise, the bytes written will be:
  219. *
  220. * <pre>
  221. * (byte)(v & 0xff)
  222. * (byte)((v >> 8) & 0xff)
  223. * (byte)((v >> 16) & 0xff)
  224. * (byte)((v >> 24) & 0xff)
  225. * (byte)((v >> 32) & 0xff)
  226. * (byte)((v >> 40) & 0xff)
  227. * (byte)((v >> 48) & 0xff)
  228. * (byte)((v >> 56) & 0xff)
  229. * </pre>
  230. *
  231. * <p> If the bit offset within the stream is non-zero, the
  232. * remainder of the current byte is padded with 0s
  233. * and written out first. The bit offset will be 0 after the
  234. * write.
  235. *
  236. * @param v a <code>long</code> containing the value to be
  237. * written.
  238. *
  239. * @exception IOException if an I/O error occurs.
  240. */
  241. void writeLong(long v) throws IOException;
  242. /**
  243. * Writes a <code>float</code> value, which is comprised of four
  244. * bytes, to the output stream. It does this as if it first
  245. * converts this <code>float</code> value to an <code>int</code>
  246. * in exactly the manner of the <code>Float.floatToIntBits</code>
  247. * method and then writes the int value in exactly the manner of
  248. * the <code>writeInt</code> method.
  249. *
  250. * <p> If the bit offset within the stream is non-zero, the
  251. * remainder of the current byte is padded with 0s
  252. * and written out first. The bit offset will be 0 after the
  253. * write.
  254. *
  255. * @param v a <code>float</code> containing the value to be
  256. * written.
  257. *
  258. * @exception IOException if an I/O error occurs.
  259. */
  260. void writeFloat(float v) throws IOException;
  261. /**
  262. * Writes a <code>double</code> value, which is comprised of four
  263. * bytes, to the output stream. It does this as if it first
  264. * converts this <code>double</code> value to an <code>long</code>
  265. * in exactly the manner of the
  266. * <code>Double.doubleToLongBits</code> method and then writes the
  267. * long value in exactly the manner of the <code>writeLong</code>
  268. * method.
  269. *
  270. * <p> If the bit offset within the stream is non-zero, the
  271. * remainder of the current byte is padded with 0s
  272. * and written out first. The bit offset will be 0 after the
  273. * write.
  274. *
  275. * @param v a <code>double</code> containing the value to be
  276. * written.
  277. *
  278. * @exception IOException if an I/O error occurs.
  279. */
  280. void writeDouble(double v) throws IOException;
  281. /**
  282. * Writes a string to the output stream. For every character in
  283. * the string <code>s</code>, taken in order, one byte is written
  284. * to the output stream. If <code>s</code> is <code>null</code>, a
  285. * <code>NullPointerException</code> is thrown.
  286. *
  287. * <p> If <code>s.length</code> is zero, then no bytes are
  288. * written. Otherwise, the character <code>s[0]</code> is written
  289. * first, then <code>s[1]</code>, and so on; the last character
  290. * written is <code>s[s.length-1]</code>. For each character, one
  291. * byte is written, the low-order byte, in exactly the manner of
  292. * the <code>writeByte</code> method. The high-order eight bits of
  293. * each character in the string are ignored.
  294. *
  295. * <p> If the bit offset within the stream is non-zero, the
  296. * remainder of the current byte is padded with 0s
  297. * and written out first. The bit offset will be 0 after the
  298. * write.
  299. *
  300. * @param s a <code>String</code> containing the value to be
  301. * written.
  302. *
  303. * @exception NullPointerException if <code>s</code> is
  304. * <code>null</code>.
  305. * @exception IOException if an I/O error occurs.
  306. */
  307. void writeBytes(String s) throws IOException;
  308. /**
  309. * Writes a string to the output stream. For every character in
  310. * the string <code>s</code>, taken in order, two bytes are
  311. * written to the output stream, ordered according to the current
  312. * byte order setting. If network byte order is being used, the
  313. * high-order byte is written first; the order is reversed
  314. * otherwise. If <code>s</code> is <code>null</code>, a
  315. * <code>NullPointerException</code> is thrown.
  316. *
  317. * <p> If <code>s.length</code> is zero, then no bytes are
  318. * written. Otherwise, the character <code>s[0]</code> is written
  319. * first, then <code>s[1]</code>, and so on; the last character
  320. * written is <code>s[s.length-1]</code>.
  321. *
  322. * <p> If the bit offset within the stream is non-zero, the
  323. * remainder of the current byte is padded with 0s
  324. * and written out first. The bit offset will be 0 after the
  325. * write.
  326. *
  327. * @param s a <code>String</code> containing the value to be
  328. * written.
  329. *
  330. * @exception NullPointerException if <code>s</code> is
  331. * <code>null</code>.
  332. * @exception IOException if an I/O error occurs.
  333. */
  334. void writeChars(String s) throws IOException;
  335. /**
  336. * Writes two bytes of length information to the output stream in
  337. * network byte order, followed by the
  338. * <a href="../../../java/io/DataInput.html#modified-utf-8">modified
  339. * UTF-8</a>
  340. * representation of every character in the string <code>s</code>.
  341. * If <code>s</code> is <code>null</code>, a
  342. * <code>NullPointerException</code> is thrown. Each character in
  343. * the string <code>s</code> is converted to a group of one, two,
  344. * or three bytes, depending on the value of the character.
  345. *
  346. * <p> If a character <code>c</code> is in the range
  347. * <code>\u0001</code> through <code>\u007f</code>, it is
  348. * represented by one byte:
  349. *
  350. * <p><pre>
  351. * (byte)c
  352. * </pre>
  353. *
  354. * <p> If a character <code>c</code> is <code>\u0000</code> or
  355. * is in the range <code>\u0080</code> through
  356. * <code>\u07ff</code>, then it is represented by two bytes,
  357. * to be written in the order shown:
  358. *
  359. * <p> <pre><code>
  360. * (byte)(0xc0 | (0x1f & (c >> 6)))
  361. * (byte)(0x80 | (0x3f & c))
  362. * </code></pre>
  363. *
  364. * <p> If a character <code>c</code> is in the range
  365. * <code>\u0800</code> through <code>uffff</code>, then it is
  366. * represented by three bytes, to be written in the order shown:
  367. *
  368. * <p> <pre><code>
  369. * (byte)(0xe0 | (0x0f & (c >> 12)))
  370. * (byte)(0x80 | (0x3f & (c >> 6)))
  371. * (byte)(0x80 | (0x3f & c))
  372. * </code></pre>
  373. *
  374. * <p> First, the total number of bytes needed to represent all
  375. * the characters of <code>s</code> is calculated. If this number
  376. * is larger than <code>65535</code>, then a
  377. * <code>UTFDataFormatException</code> is thrown. Otherwise, this
  378. * length is written to the output stream in exactly the manner of
  379. * the <code>writeShort</code> method; after this, the one-, two-,
  380. * or three-byte representation of each character in the string
  381. * <code>s</code> is written.
  382. *
  383. * <p> The current byte order setting is ignored.
  384. *
  385. * <p> If the bit offset within the stream is non-zero, the
  386. * remainder of the current byte is padded with 0s
  387. * and written out first. The bit offset will be 0 after the
  388. * write.
  389. *
  390. * <p><strong>Note:</strong> This method should not be used in
  391. * the implementation of image formats that use standard UTF-8,
  392. * because the modified UTF-8 used here is incompatible with
  393. * standard UTF-8.
  394. *
  395. * @param s a <code>String</code> containing the value to be
  396. * written.
  397. *
  398. * @exception NullPointerException if <code>s</code> is
  399. * <code>null</code>.
  400. * @exception UTFDataFormatException if the modified UTF-8
  401. * representation of <code>s</code> requires more than 65536 bytes.
  402. * @exception IOException if an I/O error occurs.
  403. */
  404. void writeUTF(String s) throws IOException;
  405. /**
  406. * Writes a sequence of shorts to the stream at the current
  407. * position. If <code>len</code> is 0, nothing is written.
  408. * The short <code>s[off]</code> is written first, then the short
  409. * <code>s[off + 1]</code>, and so on. The byte order of the
  410. * stream is used to determine the order in which the individual
  411. * bytes are written.
  412. *
  413. * <p> If the bit offset within the stream is non-zero, the
  414. * remainder of the current byte is padded with 0s
  415. * and written out first. The bit offset will be 0 after the
  416. * write.
  417. *
  418. * @param s an array of <code>short</code>s to be written.
  419. * @param off the start offset in the data.
  420. * @param len the number of <code>short</code>s to write.
  421. *
  422. * @exception IndexOutOfBoundsException if <code>off</code> is
  423. * negative, <code>len</code> is negative, or <code>off +
  424. * len</code> is greater than <code>s.length</code>.
  425. * @exception NullPointerException if <code>s</code> is
  426. * <code>null</code>.
  427. * @exception IOException if an I/O error occurs.
  428. */
  429. void writeShorts(short[] s, int off, int len) throws IOException;
  430. /**
  431. * Writes a sequence of chars to the stream at the current
  432. * position. If <code>len</code> is 0, nothing is written.
  433. * The char <code>c[off]</code> is written first, then the char
  434. * <code>c[off + 1]</code>, and so on. The byte order of the
  435. * stream is used to determine the order in which the individual
  436. * bytes are written.
  437. *
  438. * <p> If the bit offset within the stream is non-zero, the
  439. * remainder of the current byte is padded with 0s
  440. * and written out first. The bit offset will be 0 after the
  441. * write.
  442. *
  443. * @param c an array of <code>char</code>s to be written.
  444. * @param off the start offset in the data.
  445. * @param len the number of <code>char</code>s to write.
  446. *
  447. * @exception IndexOutOfBoundsException if <code>off</code> is
  448. * negative, <code>len</code> is negative, or <code>off +
  449. * len</code> is greater than <code>c.length</code>.
  450. * @exception NullPointerException if <code>c</code> is
  451. * <code>null</code>.
  452. * @exception IOException if an I/O error occurs.
  453. */
  454. void writeChars(char[] c, int off, int len) throws IOException;
  455. /**
  456. * Writes a sequence of ints to the stream at the current
  457. * position. If <code>len</code> is 0, nothing is written.
  458. * The int <code>i[off]</code> is written first, then the int
  459. * <code>i[off + 1]</code>, and so on. The byte order of the
  460. * stream is used to determine the order in which the individual
  461. * bytes are written.
  462. *
  463. * <p> If the bit offset within the stream is non-zero, the
  464. * remainder of the current byte is padded with 0s
  465. * and written out first. The bit offset will be 0 after the
  466. * write.
  467. *
  468. * @param i an array of <code>int</code>s to be written.
  469. * @param off the start offset in the data.
  470. * @param len the number of <code>int</code>s to write.
  471. *
  472. * @exception IndexOutOfBoundsException if <code>off</code> is
  473. * negative, <code>len</code> is negative, or <code>off +
  474. * len</code> is greater than <code>i.length</code>.
  475. * @exception NullPointerException if <code>i</code> is
  476. * <code>null</code>.
  477. * @exception IOException if an I/O error occurs.
  478. */
  479. void writeInts(int[] i, int off, int len) throws IOException;
  480. /**
  481. * Writes a sequence of longs to the stream at the current
  482. * position. If <code>len</code> is 0, nothing is written.
  483. * The long <code>l[off]</code> is written first, then the long
  484. * <code>l[off + 1]</code>, and so on. The byte order of the
  485. * stream is used to determine the order in which the individual
  486. * bytes are written.
  487. *
  488. * <p> If the bit offset within the stream is non-zero, the
  489. * remainder of the current byte is padded with 0s
  490. * and written out first. The bit offset will be 0 after the
  491. * write.
  492. *
  493. * @param l an array of <code>long</code>s to be written.
  494. * @param off the start offset in the data.
  495. * @param len the number of <code>long</code>s to write.
  496. *
  497. * @exception IndexOutOfBoundsException if <code>off</code> is
  498. * negative, <code>len</code> is negative, or <code>off +
  499. * len</code> is greater than <code>l.length</code>.
  500. * @exception NullPointerException if <code>l</code> is
  501. * <code>null</code>.
  502. * @exception IOException if an I/O error occurs.
  503. */
  504. void writeLongs(long[] l, int off, int len) throws IOException;
  505. /**
  506. * Writes a sequence of floats to the stream at the current
  507. * position. If <code>len</code> is 0, nothing is written.
  508. * The float <code>f[off]</code> is written first, then the float
  509. * <code>f[off + 1]</code>, and so on. The byte order of the
  510. * stream is used to determine the order in which the individual
  511. * bytes are written.
  512. *
  513. * <p> If the bit offset within the stream is non-zero, the
  514. * remainder of the current byte is padded with 0s
  515. * and written out first. The bit offset will be 0 after the
  516. * write.
  517. *
  518. * @param f an array of <code>float</code>s to be written.
  519. * @param off the start offset in the data.
  520. * @param len the number of <code>float</code>s to write.
  521. *
  522. * @exception IndexOutOfBoundsException if <code>off</code> is
  523. * negative, <code>len</code> is negative, or <code>off +
  524. * len</code> is greater than <code>f.length</code>.
  525. * @exception NullPointerException if <code>f</code> is
  526. * <code>null</code>.
  527. * @exception IOException if an I/O error occurs.
  528. */
  529. void writeFloats(float[] f, int off, int len) throws IOException;
  530. /**
  531. * Writes a sequence of doubles to the stream at the current
  532. * position. If <code>len</code> is 0, nothing is written.
  533. * The double <code>d[off]</code> is written first, then the double
  534. * <code>d[off + 1]</code>, and so on. The byte order of the
  535. * stream is used to determine the order in which the individual
  536. * bytes are written.
  537. *
  538. * <p> If the bit offset within the stream is non-zero, the
  539. * remainder of the current byte is padded with 0s
  540. * and written out first. The bit offset will be 0 after the
  541. * write.
  542. *
  543. * @param d an array of <code>doubles</code>s to be written.
  544. * @param off the start offset in the data.
  545. * @param len the number of <code>double</code>s to write.
  546. *
  547. * @exception IndexOutOfBoundsException if <code>off</code> is
  548. * negative, <code>len</code> is negative, or <code>off +
  549. * len</code> is greater than <code>d.length</code>.
  550. * @exception NullPointerException if <code>d</code> is
  551. * <code>null</code>.
  552. * @exception IOException if an I/O error occurs.
  553. */
  554. void writeDoubles(double[] d, int off, int len) throws IOException;
  555. /**
  556. * Writes a single bit, given by the least significant bit of the
  557. * argument, to the stream at the current bit offset within the
  558. * current byte position. The upper 31 bits of the argument are
  559. * ignored. The given bit replaces the previous bit at that
  560. * position. The bit offset is advanced by one and reduced modulo
  561. * 8.
  562. *
  563. * <p> If any bits of a particular byte have never been set
  564. * at the time the byte is flushed to the destination, those
  565. * bits will be set to 0 automatically.
  566. *
  567. * @param bit an <code>int</code> whose least significant bit
  568. * is to be written to the stream.
  569. *
  570. * @exception IOException if an I/O error occurs.
  571. */
  572. void writeBit(int bit) throws IOException;
  573. /**
  574. * Writes a sequence of bits, given by the <code>numBits</code>
  575. * least significant bits of the <code>bits</code> argument in
  576. * left-to-right order, to the stream at the current bit offset
  577. * within the current byte position. The upper <code>64 -
  578. * numBits</code> bits of the argument are ignored. The bit
  579. * offset is advanced by <code>numBits</code> and reduced modulo
  580. * 8. Note that a bit offset of 0 always indicates the
  581. * most-significant bit of the byte, and bytes of bits are written
  582. * out in sequence as they are encountered. Thus bit writes are
  583. * always effectively in network byte order. The actual stream
  584. * byte order setting is ignored.
  585. *
  586. * <p> Bit data may be accumulated in memory indefinitely, until
  587. * <code>flushBefore</code> is called. At that time, all bit data
  588. * prior to the flushed position will be written.
  589. *
  590. * <p> If any bits of a particular byte have never been set
  591. * at the time the byte is flushed to the destination, those
  592. * bits will be set to 0 automatically.
  593. *
  594. * @param bits a <code>long</code> containing the bits to be
  595. * written, starting with the bit in position <code>numBits -
  596. * 1</code> down to the least significant bit.
  597. *
  598. * @param numBits an <code>int</code> between 0 and 64, inclusive.
  599. *
  600. * @exception IllegalArgumentException if <code>numBits</code> is
  601. * not between 0 and 64, inclusive.
  602. * @exception IOException if an I/O error occurs.
  603. */
  604. void writeBits(long bits, int numBits) throws IOException;
  605. /**
  606. * Flushes all data prior to the given position to the underlying
  607. * destination, such as an <code>OutputStream</code> or
  608. * <code>File</code>. Attempting to seek to the flushed portion
  609. * of the stream will result in an
  610. * <code>IndexOutOfBoundsException</code>.
  611. *
  612. * @param pos a <code>long</code> containing the length of the
  613. * file prefix that may be flushed to the destination.
  614. *
  615. * @exception IndexOutOfBoundsException if <code>pos</code> lies
  616. * in the flushed portion of the stream or past the current stream
  617. * position.
  618. * @exception IOException if an I/O error occurs.
  619. */
  620. void flushBefore(long pos) throws IOException;
  621. }