Module java.base
Package java.io

Interface DataOutput

    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and TypeMethodDescription
      voidwrite​(byte[] b)
      Writes to the output stream all the bytes in arrayb.
      voidwrite​(byte[] b, int off, int len)
      Writeslen bytes from arrayb, in order, to the output stream.
      voidwrite​(int b)
      Writes to the output stream the eight low-order bits of the argumentb.
      voidwriteBoolean​(boolean v)
      Writes aboolean value to this output stream.
      voidwriteByte​(int v)
      Writes to the output stream the eight low- order bits of the argumentv.
      voidwriteBytes​(String s)
      Writes a string to the output stream.
      voidwriteChar​(int v)
      Writes achar value, which is comprised of two bytes, to the output stream.
      voidwriteChars​(String s)
      Writes every character in the strings, to the output stream, in order, two bytes per character.
      voidwriteDouble​(double v)
      Writes adouble value, which is comprised of eight bytes, to the output stream.
      voidwriteFloat​(float v)
      Writes afloat value, which is comprised of four bytes, to the output stream.
      voidwriteInt​(int v)
      Writes anint value, which is comprised of four bytes, to the output stream.
      voidwriteLong​(long v)
      Writes along value, which is comprised of eight bytes, to the output stream.
      voidwriteShort​(int v)
      Writes two bytes to the output stream to represent the value of the argument.
      voidwriteUTF​(String s)
      Writes two bytes of length information to the output stream, followed by themodified UTF-8 representation of every character in the strings.
    • Method Detail

      • write

        void write​(int b)    throwsIOException
        Writes to the output stream the eight low-order bits of the argumentb. The 24 high-order bits ofb are ignored.
        Parameters:
        b - the byte to be written.
        Throws:
        IOException - if an I/O error occurs.
      • write

        void write​(byte[] b)    throwsIOException
        Writes to the output stream all the bytes in arrayb. Ifb isnull, aNullPointerException is thrown. Ifb.length is zero, then no bytes are written. Otherwise, the byteb[0] is written first, thenb[1], and so on; the last byte written isb[b.length-1].
        Parameters:
        b - the data.
        Throws:
        IOException - if an I/O error occurs.
      • write

        void write​(byte[] b,           int off,           int len)    throwsIOException
        Writeslen bytes from arrayb, in order, to the output stream. Ifb isnull, aNullPointerException is thrown. Ifoff is negative, orlen is negative, oroff+len is greater than the length of the arrayb, then anIndexOutOfBoundsException is thrown. Iflen is 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].
        Parameters:
        b - the data.
        off - the start offset in the data.
        len - the number of bytes to write.
        Throws:
        IOException - if an I/O error occurs.
      • writeBoolean

        void writeBoolean​(boolean v)           throwsIOException
        Writes aboolean value to this output stream. If the argumentv istrue, the value(byte)1 is written; ifv isfalse, the value(byte)0 is written. The byte written by this method may be read by thereadBoolean method of interfaceDataInput, which will then return aboolean equal tov.
        Parameters:
        v - the boolean to be written.
        Throws:
        IOException - if an I/O error occurs.
      • writeByte

        void writeByte​(int v)        throwsIOException
        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.
        Parameters:
        v - the byte value to be written.
        Throws:
        IOException - if an I/O error occurs.
      • writeShort

        void writeShort​(int v)         throwsIOException
        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 thereadShort method of interfaceDataInput , which will then return ashort equal to(short)v.

        Parameters:
        v - theshort value to be written.
        Throws:
        IOException - if an I/O error occurs.
      • writeChar

        void writeChar​(int v)        throwsIOException
        Writes achar value, 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 thereadChar method of interfaceDataInput , which will then return achar equal to(char)v.

        Parameters:
        v - thechar value to be written.
        Throws:
        IOException - if an I/O error occurs.
      • writeInt

        void writeInt​(int v)       throwsIOException
        Writes anint value, 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 thereadInt method of interfaceDataInput , which will then return anint equal tov.

        Parameters:
        v - theint value to be written.
        Throws:
        IOException - if an I/O error occurs.
      • writeLong

        void writeLong​(long v)        throwsIOException
        Writes along value, which is comprised of eight 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 thereadLong method of interfaceDataInput , which will then return along equal tov.

        Parameters:
        v - thelong value to be written.
        Throws:
        IOException - if an I/O error occurs.
      • writeFloat

        void writeFloat​(float v)         throwsIOException
        Writes afloat value, which is comprised of four bytes, to the output stream. It does this as if it first converts thisfloat value 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.
        Parameters:
        v - thefloat value to be written.
        Throws:
        IOException - if an I/O error occurs.
      • writeDouble

        void writeDouble​(double v)          throwsIOException
        Writes adouble value, which is comprised of eight bytes, to the output stream. It does this as if it first converts thisdouble value 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.
        Parameters:
        v - thedouble value to be written.
        Throws:
        IOException - if an I/O error occurs.
      • writeBytes

        void writeBytes​(String s)         throwsIOException
        Writes a string to the output stream. For every character in the strings, taken in order, one byte is written to the output stream. Ifs isnull, aNullPointerException is thrown.

        Ifs.length is zero, then no bytes are written. Otherwise, the characters[0] is written first, thens[1], and so on; the last character written iss[s.length-1]. For each character, one byte is written, the low-order byte, in exactly the manner of thewriteByte method . The high-order eight bits of each character in the string are ignored.

        Parameters:
        s - the string of bytes to be written.
        Throws:
        IOException - if an I/O error occurs.
      • writeChars

        void writeChars​(String s)         throwsIOException
        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 iss[s.length-1]. For each character, two bytes are actually written, high-order byte first, in exactly the manner of thewriteChar method.
        Parameters:
        s - the string value to be written.
        Throws:
        IOException - if an I/O error occurs.
      • writeUTF

        void writeUTF​(String s)       throwsIOException
        Writes two bytes of length information to the output stream, followed by themodified UTF-8 representation of every character in the strings. Ifs isnull, aNullPointerException is 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 characterc is in the range\u0001 through\u007f, it is represented by one byte:

        (byte)c

        If a characterc is\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 characterc is 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 ofs is calculated. If this number is larger than65535, then aUTFDataFormatException is thrown. Otherwise, this length is written to the output stream in exactly the manner of thewriteShort method; after this, the one-, two-, or three-byte representation of each character in the strings is written.

        The bytes written by this method may be read by thereadUTF method of interfaceDataInput , which will then return aString equal tos.

        Parameters:
        s - the string value to be written.
        Throws:
        IOException - if an I/O error occurs.