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