2362N/A * Copyright (c) 1995, 2006, Oracle and/or its affiliates. All rights reserved. 0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 0N/A * This code is free software; you can redistribute it and/or modify it 0N/A * under the terms of the GNU General Public License version 2 only, as 2362N/A * published by the Free Software Foundation. Oracle designates this 0N/A * particular file as subject to the "Classpath" exception as provided 2362N/A * by Oracle in the LICENSE file that accompanied this code. 0N/A * This code is distributed in the hope that it will be useful, but WITHOUT 0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 0N/A * version 2 for more details (a copy is included in the LICENSE file that 0N/A * accompanied this code). 0N/A * You should have received a copy of the GNU General Public License version 0N/A * 2 along with this work; if not, write to the Free Software Foundation, 0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2362N/A * or visit www.oracle.com if you need additional information or have any 0N/A * The <code>DataOutput</code> interface provides 0N/A * for converting data from any of the Java 0N/A * primitive types to a series of bytes and 0N/A * writing these bytes to a binary stream. 0N/A * There is also a facility for converting 0N/A * a <code>String</code> into 0N/A * format and writing the resulting series 0N/A * For all the methods in this interface that 0N/A * write bytes, it is generally true that if 0N/A * a byte cannot be written for any reason, 0N/A * an <code>IOException</code> is thrown. 0N/A * @author Frank Yellin 0N/A * @see java.io.DataInput 0N/A * @see java.io.DataOutputStream 0N/A * Writes to the output stream the eight 0N/A * low-order bits of the argument <code>b</code>. 0N/A * The 24 high-order bits of <code>b</code> 0N/A * @param b the byte to be written. 0N/A * @throws IOException if an I/O error occurs. 0N/A * Writes to the output stream all the bytes in array <code>b</code>. 0N/A * If <code>b</code> is <code>null</code>, 0N/A * a <code>NullPointerException</code> is thrown. 0N/A * If <code>b.length</code> is zero, then 0N/A * no bytes are written. Otherwise, the byte 0N/A * <code>b[0]</code> is written first, then 0N/A * <code>b[1]</code>, and so on; the last byte 0N/A * written is <code>b[b.length-1]</code>. 0N/A * @param b the data. 0N/A * @throws IOException if an I/O error occurs. 0N/A * Writes <code>len</code> bytes from array 0N/A * <code>b</code>, in order, to 0N/A * the output stream. If <code>b</code> 0N/A * is <code>null</code>, a <code>NullPointerException</code> 0N/A * is thrown. If <code>off</code> is negative, 0N/A * or <code>len</code> is negative, or <code>off+len</code> 0N/A * is greater than the length of the array 0N/A * <code>b</code>, then an <code>IndexOutOfBoundsException</code> 0N/A * is thrown. If <code>len</code> is zero, 0N/A * then no bytes are written. Otherwise, the 0N/A * byte <code>b[off]</code> is written first, 0N/A * then <code>b[off+1]</code>, and so on; the 0N/A * last byte written is <code>b[off+len-1]</code>. 0N/A * @param b the data. 0N/A * @param off the start offset in the data. 0N/A * @param len the number of bytes to write. 0N/A * @throws IOException if an I/O error occurs. 0N/A * Writes a <code>boolean</code> value to this output stream. 0N/A * If the argument <code>v</code> 0N/A * is <code>true</code>, the value <code>(byte)1</code> 0N/A * is written; if <code>v</code> is <code>false</code>, 0N/A * the value <code>(byte)0</code> is written. 0N/A * The byte written by this method may 0N/A * be read by the <code>readBoolean</code> 0N/A * method of interface <code>DataInput</code>, 0N/A * which will then return a <code>boolean</code> 0N/A * equal to <code>v</code>. 0N/A * @param v the boolean to be written. 0N/A * @throws IOException if an I/O error occurs. 0N/A * Writes to the output stream the eight low- 0N/A * order bits of the argument <code>v</code>. 0N/A * The 24 high-order bits of <code>v</code> 0N/A * are ignored. (This means that <code>writeByte</code> 0N/A * does exactly the same thing as <code>write</code> 0N/A * for an integer argument.) The byte written 0N/A * by this method may be read by the <code>readByte</code> 0N/A * method of interface <code>DataInput</code>, 0N/A * which will then return a <code>byte</code> 0N/A * equal to <code>(byte)v</code>. 0N/A * @param v the byte value to be written. 0N/A * @throws IOException if an I/O error occurs. 0N/A * Writes two bytes to the output 0N/A * stream to represent the value of the argument. 0N/A * The byte values to be written, in the order 0N/A * (byte)(0xff & (v >> 8)) 0N/A * (byte)(0xff & v) 0N/A * </code> </pre> <p> 0N/A * The bytes written by this method may be 0N/A * read by the <code>readShort</code> method 0N/A * of interface <code>DataInput</code> , which 0N/A * will then return a <code>short</code> equal 0N/A * to <code>(short)v</code>. 0N/A * @param v the <code>short</code> value to be written. 0N/A * @throws IOException if an I/O error occurs. 0N/A * Writes a <code>char</code> value, which 0N/A * is comprised of two bytes, to the 0N/A * The byte values to be written, in the order 0N/A * (byte)(0xff & (v >> 8)) 0N/A * (byte)(0xff & v) 0N/A * The bytes written by this method may be 0N/A * read by the <code>readChar</code> method 0N/A * of interface <code>DataInput</code> , which 0N/A * will then return a <code>char</code> equal 0N/A * to <code>(char)v</code>. 0N/A * @param v the <code>char</code> value to be written. 0N/A * @throws IOException if an I/O error occurs. 0N/A * Writes an <code>int</code> value, which is 0N/A * comprised of four bytes, to the output stream. 0N/A * The byte values to be written, in the order 0N/A * (byte)(0xff & (v >> 24)) 0N/A * (byte)(0xff & (v >> 16)) 0N/A * (byte)(0xff & (v >>    8)) 0N/A * (byte)(0xff & v) 0N/A * The bytes written by this method may be read 0N/A * by the <code>readInt</code> method of interface 0N/A * <code>DataInput</code> , which will then 0N/A * return an <code>int</code> equal to <code>v</code>. 0N/A * @param v the <code>int</code> value to be written. 0N/A * @throws IOException if an I/O error occurs. 0N/A * Writes a <code>long</code> value, which is 0N/A * comprised of eight bytes, to the output stream. 0N/A * The byte values to be written, in the order 0N/A * (byte)(0xff & (v >> 56)) 0N/A * (byte)(0xff & (v >> 48)) 0N/A * (byte)(0xff & (v >> 40)) 0N/A * (byte)(0xff & (v >> 32)) 0N/A * (byte)(0xff & (v >> 24)) 0N/A * (byte)(0xff & (v >> 16)) 0N/A * (byte)(0xff & (v >> 8)) 0N/A * (byte)(0xff & v) 0N/A * The bytes written by this method may be 0N/A * read by the <code>readLong</code> method 0N/A * of interface <code>DataInput</code> , which 0N/A * will then return a <code>long</code> equal 0N/A * to <code>v</code>. 0N/A * @param v the <code>long</code> value to be written. 0N/A * @throws IOException if an I/O error occurs. 0N/A * Writes a <code>float</code> value, 0N/A * which is comprised of four bytes, to the output stream. 0N/A * It does this as if it first converts this 0N/A * <code>float</code> value to an <code>int</code> 0N/A * in exactly the manner of the <code>Float.floatToIntBits</code> 0N/A * method and then writes the <code>int</code> 0N/A * value in exactly the manner of the <code>writeInt</code> 0N/A * method. The bytes written by this method 0N/A * may be read by the <code>readFloat</code> 0N/A * method of interface <code>DataInput</code>, 0N/A * which will then return a <code>float</code> 0N/A * equal to <code>v</code>. 0N/A * @param v the <code>float</code> value to be written. 0N/A * @throws IOException if an I/O error occurs. 0N/A * Writes a <code>double</code> value, 0N/A * which is comprised of eight bytes, to the output stream. 0N/A * It does this as if it first converts this 0N/A * <code>double</code> value to a <code>long</code> 0N/A * in exactly the manner of the <code>Double.doubleToLongBits</code> 0N/A * method and then writes the <code>long</code> 0N/A * value in exactly the manner of the <code>writeLong</code> 0N/A * method. The bytes written by this method 0N/A * may be read by the <code>readDouble</code> 0N/A * method of interface <code>DataInput</code>, 0N/A * which will then return a <code>double</code> 0N/A * equal to <code>v</code>. 0N/A * @param v the <code>double</code> value to be written. 0N/A * @throws IOException if an I/O error occurs. 0N/A * Writes a string to the output stream. 0N/A * For every character in the string 0N/A * <code>s</code>, taken in order, one byte 0N/A * is written to the output stream. If 0N/A * <code>s</code> is <code>null</code>, a <code>NullPointerException</code> 0N/A * is thrown.<p> If <code>s.length</code> 0N/A * is zero, then no bytes are written. Otherwise, 0N/A * the character <code>s[0]</code> is written 0N/A * first, then <code>s[1]</code>, and so on; 0N/A * the last character written is <code>s[s.length-1]</code>. 0N/A * For each character, one byte is written, 0N/A * the low-order byte, in exactly the manner 0N/A * of the <code>writeByte</code> method . The 0N/A * high-order eight bits of each character 0N/A * in the string are ignored. 0N/A * @param s the string of bytes to be written. 0N/A * @throws IOException if an I/O error occurs. 0N/A * Writes every character in the string <code>s</code>, 0N/A * to the output stream, in order, 0N/A * two bytes per character. If <code>s</code> 0N/A * is <code>null</code>, a <code>NullPointerException</code> 0N/A * is thrown. If <code>s.length</code> 0N/A * is zero, then no characters are written. 0N/A * Otherwise, the character <code>s[0]</code> 0N/A * is written first, then <code>s[1]</code>, 0N/A * and so on; the last character written is 0N/A * <code>s[s.length-1]</code>. For each character, 0N/A * two bytes are actually written, high-order 0N/A * byte first, in exactly the manner of the 0N/A * <code>writeChar</code> method. 0N/A * @param s the string value to be written. 0N/A * @throws IOException if an I/O error occurs. 0N/A * Writes two bytes of length information 0N/A * to the output stream, followed 0N/A * of every character in the string <code>s</code>. 0N/A * If <code>s</code> is <code>null</code>, 0N/A * a <code>NullPointerException</code> is thrown. 0N/A * Each character in the string <code>s</code> 0N/A * is converted to a group of one, two, or 0N/A * three bytes, depending on the value of the 0N/A * If a character <code>c</code> 0N/A * is in the range <code>\u0001</code> through 0N/A * <code>\u007f</code>, it is represented 0N/A * <pre>(byte)c </pre> <p> 0N/A * If a character <code>c</code> is <code>\u0000</code> 0N/A * or is in the range <code>\u0080</code> 0N/A * through <code>\u07ff</code>, then it is 0N/A * represented by two bytes, to be written 0N/A * in the order shown:<p> <pre><code> 0N/A * (byte)(0xc0 | (0x1f & (c >> 6))) 0N/A * (byte)(0x80 | (0x3f & c)) 0N/A * </code></pre> <p> If a character 0N/A * <code>c</code> is in the range <code>\u0800</code> 0N/A * through <code>uffff</code>, then it is 0N/A * represented by three bytes, to be written 0N/A * in the order shown:<p> <pre><code> 0N/A * (byte)(0xe0 | (0x0f & (c >> 12))) 0N/A * (byte)(0x80 | (0x3f & (c >> 6))) 0N/A * (byte)(0x80 | (0x3f & c)) 0N/A * </code></pre> <p> First, 0N/A * the total number of bytes needed to represent 0N/A * all the characters of <code>s</code> is 0N/A * calculated. If this number is larger than 0N/A * <code>65535</code>, then a <code>UTFDataFormatException</code> 0N/A * is thrown. Otherwise, this length is written 0N/A * to the output stream in exactly the manner 0N/A * of the <code>writeShort</code> method; 0N/A * after this, the one-, two-, or three-byte 0N/A * representation of each character in the 0N/A * string <code>s</code> is written.<p> The 0N/A * bytes written by this method may be read 0N/A * by the <code>readUTF</code> method of interface 0N/A * <code>DataInput</code> , which will then 0N/A * return a <code>String</code> equal to <code>s</code>. 0N/A * @param s the string value to be written. 0N/A * @throws IOException if an I/O error occurs.