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