www.pudn.com > j2me_cldc-1_1-fcs-src-winunix.rar > DataOutput.java
/* * Copyright © 2003 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. * */ package java.io; /** * TheDataOutputinterface provides * for converting data from any of the Java * primitive types to a series of bytes and * writing these bytes to a binary stream. * There is also a facility for converting * aStringinto Java modified * UTF-8 format and writing the resulting series * of bytes. ** For all the methods in this interface that * write bytes, it is generally true that if * a byte cannot be written for any reason, * an
IOExceptionis thrown. * * @author Frank Yellin * @version 12/17/01 (CLDC 1.1) * @see java.io.DataInput * @see java.io.DataOutputStream * @since JDK1.0, CLDC 1.0 */ public interface DataOutput { /** * Writes to the output stream the eight * low-order bits of the argumentb. * The 24 high-order bits ofb* are ignored. * * @param b the byte to be written. * @exception IOException if an I/O error occurs. */ void write(int b) throws IOException; /** * Writes to the output stream all the bytes in arrayb. * Ifbisnull, * aNullPointerExceptionis thrown. * Ifb.lengthis zero, then * no bytes are written. Otherwise, the byte *b[0]is written first, then *b[1], and so on; the last byte * written isb[b.length-1]. * * @param b the data. * @exception IOException if an I/O error occurs. */ void write(byte b[]) throws IOException; /** * Writeslenbytes from array *b, in order, to * the output stream. Ifb* isnull, aNullPointerException* is thrown. Ifoffis negative, * orlenis negative, oroff+len* is greater than the length of the array *b, then anIndexOutOfBoundsException* is thrown. Iflenis zero, * then no bytes are written. Otherwise, the * byteb[off]is written first, * thenb[off+1], and so on; the * last byte written isb[off+len-1]. * * @param b the data. * @param off the start offset in the data. * @param len the number of bytes to write. * @exception IOException if an I/O error occurs. */ void write(byte b[], int off, int len) throws IOException; /** * Writes abooleanvalue to this output stream. * If the argumentv* istrue, the value(byte)1* is written; ifvisfalse, * the value(byte)0is written. * The byte written by this method may * be read by thereadBoolean* method of interfaceDataInput, * which will then return aboolean* equal tov. * * @param v the boolean to be written. * @exception IOException if an I/O error occurs. */ void writeBoolean(boolean v) throws IOException; /** * Writes to the output stream the eight low- * order bits of the argumentv. * The 24 high-order bits ofv* are ignored. (This means thatwriteByte* does exactly the same thing aswrite* for an integer argument.) The byte written * by this method may be read by thereadByte* method of interfaceDataInput, * which will then return abyte* equal to(byte)v. * * @param v the byte value to be written. * @exception IOException if an I/O error occurs. */ void writeByte(int v) throws IOException; /** * Writes two bytes to the output * stream to represent the value of the argument. * The byte values to be written, in the order * shown, are:*
* (byte)(0xff & (v >> 8)) * (byte)(0xff & v) ** The bytes written by this method may be * read by the
readShortmethod * of interfaceDataInput, which * will then return ashortequal * to(short)v. * * @param v theshortvalue to be written. * @exception IOException if an I/O error occurs. */ void writeShort(int v) throws IOException; /** * Writes acharvalue, which * is comprised of two bytes, to the * output stream. * The byte values to be written, in the order * shown, are: ** (byte)(0xff & (v >> 8)) * (byte)(0xff & v) ** The bytes written by this method may be * read by the
readCharmethod * of interfaceDataInput, which * will then return acharequal * to(char)v. * * @param v thecharvalue to be written. * @exception IOException if an I/O error occurs. */ void writeChar(int v) throws IOException; /** * Writes anintvalue, which is * comprised of four bytes, to the output stream. * The byte values to be written, in the order * shown, are: ** (byte)(0xff & (v >> 24)) * (byte)(0xff & (v >> 16)) * (byte)(0xff & (v >> 8)) * (byte)(0xff & v) ** The bytes written by this method may be read * by the
readIntmethod of interface *DataInput, which will then * return anintequal tov. * * @param v theintvalue to be written. * @exception IOException if an I/O error occurs. */ void writeInt(int v) throws IOException; /** * Writes anlongvalue, which is * comprised of four bytes, to the output stream. * The byte values to be written, in the order * shown, are: ** (byte)(0xff & (v >> 56)) * (byte)(0xff & (v >> 48)) * (byte)(0xff & (v >> 40)) * (byte)(0xff & (v >> 32)) * (byte)(0xff & (v >> 24)) * (byte)(0xff & (v >> 16)) * (byte)(0xff & (v >> 8)) * (byte)(0xff & v) ** The bytes written by this method may be * read by the
readLongmethod * of interfaceDataInput, which * will then return alongequal * tov. * * @param v thelongvalue to be written. * @exception IOException if an I/O error occurs. */ void writeLong(long v) throws IOException; /** * Writes afloatvalue, * which is comprised of four bytes, to the output stream. * It does this as if it first converts this *floatvalue to anint* in exactly the manner of theFloat.floatToIntBits* method and then writes theint* value in exactly the manner of thewriteInt* method. The bytes written by this method * may be read by thereadFloat* method of interfaceDataInput, * which will then return afloat* equal tov. * * @param v thefloatvalue to be written. * @exception IOException if an I/O error occurs. * @since CLDC 1.1 */ void writeFloat(float v) throws IOException; /** * Writes adoublevalue, * which is comprised of eight bytes, to the output stream. * It does this as if it first converts this *doublevalue to along* in exactly the manner of theDouble.doubleToLongBits* method and then writes thelong* value in exactly the manner of thewriteLong* method. The bytes written by this method * may be read by thereadDouble* method of interfaceDataInput, * which will then return adouble* equal tov. * * @param v thedoublevalue to be written. * @exception IOException if an I/O error occurs. * @since CLDC 1.1 */ void writeDouble(double v) throws IOException; /** * Writes every character in the strings, * to the output stream, in order, * two bytes per character. Ifs* isnull, aNullPointerException* is thrown. Ifs.length* is zero, then no characters are written. * Otherwise, the characters[0]* is written first, thens[1], * and so on; the last character written is *s[s.length-1]. For each character, * two bytes are actually written, high-order * byte first, in exactly the manner of the *writeCharmethod. * * @param s the string value to be written. * @exception IOException if an I/O error occurs. */ void writeChars(String s) throws IOException; /** * Writes two bytes of length information * to the output stream, followed * by the Java modified UTF representation * of every character in the strings. * Ifsisnull, * aNullPointerExceptionis thrown. * Each character in the strings* is converted to a group of one, two, or * three bytes, depending on the value of the * character.* If a character
c* is in the range\u0001through *\u007f, it is represented * by one byte:*
(byte)c* If a character
cis\u0000* or is in the range\u0080* through\u07ff, then it is * represented by two bytes, to be written * in the order shown:
* (byte)(0xc0 | (0x1f & (c >> 6))) * (byte)(0x80 | (0x3f & c)) *If a character *
cis in the range\u0800* throughuffff, then it is * represented by three bytes, to be written * in the order shown:
* (byte)(0xe0 | (0x0f & (c >> 12))) * (byte)(0x80 | (0x3f & (c >> 6))) * (byte)(0x80 | (0x3f & c)) *First, * the total number of bytes needed to represent * all the characters of
sis * calculated. If this number is larger than *65535, then aUTFDataFormatError* is thrown. Otherwise, this length is written * to the output stream in exactly the manner * of thewriteShortmethod; * after this, the one-, two-, or three-byte * representation of each character in the * stringsis written.The * bytes written by this method may be read * by the
readUTFmethod of interface *DataInput, which will then * return aStringequal tos. * * @param s the string value to be written. * @exception IOException if an I/O error occurs. */ void writeUTF(String s) throws IOException; }