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