Package java.io

Class DataOutputStream

    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected int written
      The number of bytes written out so far.
    • Constructor Summary

      Constructors 
      Constructor Description
      DataOutputStream​(OutputStream out)
      Constructs a new DataOutputStream on the OutputStream out.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void flush()
      Flushes this stream to ensure all pending data is sent out to the target stream.
      int size()
      Returns the total number of bytes written to the target stream so far.
      void write​(byte[] buffer, int offset, int count)
      Writes count bytes from the byte array buffer starting at offset to the target stream.
      void write​(int oneByte)
      Writes a byte to the target stream.
      void writeBoolean​(boolean val)
      Writes a boolean to the target stream.
      void writeByte​(int val)
      Writes an 8-bit byte to the target stream.
      void writeBytes​(String str)
      Writes the low order 8-bit bytes from the specified string.
      void writeChar​(int val)
      Writes the specified 16-bit character in big-endian order.
      void writeChars​(String str)
      Writes the 16-bit characters contained in str in big-endian order.
      void writeDouble​(double val)
      Writes the specified 64-bit double in big-endian order.
      void writeFloat​(float val)
      Writes the specified 32-bit float in big-endian order.
      void writeInt​(int val)
      Writes the specified 32-bit int in big-endian order.
      void writeLong​(long val)
      Writes the specified 64-bit long in big-endian order.
      void writeShort​(int val)
      Writes the specified 16-bit short in big-endian order.
      void writeUTF​(String str)
      Writes the specified string encoded in modified UTF-8.
    • Field Detail

      • written

        protected int written
        The number of bytes written out so far.
    • Constructor Detail

      • DataOutputStream

        public DataOutputStream​(OutputStream out)
        Constructs a new DataOutputStream on the OutputStream out. Note that data written by this stream is not in a human readable form but can be reconstructed by using a DataInputStream on the resulting output.
        Parameters:
        out - the target stream for writing.
    • Method Detail

      • flush

        public void flush()
                   throws IOException
        Flushes this stream to ensure all pending data is sent out to the target stream. This implementation then also flushes the target stream.
        Specified by:
        flush in interface Flushable
        Overrides:
        flush in class FilterOutputStream
        Throws:
        IOException - if an error occurs attempting to flush this stream.
      • size

        public final int size()
        Returns the total number of bytes written to the target stream so far.
        Returns:
        the number of bytes written to the target stream.
      • write

        public void write​(byte[] buffer,
                          int offset,
                          int count)
                   throws IOException
        Writes count bytes from the byte array buffer starting at offset to the target stream.
        Specified by:
        write in interface DataOutput
        Overrides:
        write in class FilterOutputStream
        Parameters:
        buffer - the buffer to write to the target stream.
        offset - the index of the first byte in buffer to write.
        count - the number of bytes from the buffer to write.
        Throws:
        IOException - if an error occurs while writing to the target stream.
        NullPointerException - if buffer is null.
      • write

        public void write​(int oneByte)
                   throws IOException
        Writes a byte to the target stream. Only the least significant byte of the integer oneByte is written.
        Specified by:
        write in interface DataOutput
        Overrides:
        write in class FilterOutputStream
        Parameters:
        oneByte - the byte to write to the target stream.
        Throws:
        IOException - if an error occurs while writing to the target stream.
        See Also:
        DataInputStream.readByte()
      • writeBytes

        public final void writeBytes​(String str)
                              throws IOException
        Description copied from interface: DataOutput
        Writes the low order 8-bit bytes from the specified string.
        Specified by:
        writeBytes in interface DataOutput
        Parameters:
        str - the string containing the bytes to write.
        Throws:
        IOException - if an I/O error occurs while writing.
      • writeChar

        public final void writeChar​(int val)
                             throws IOException
        Description copied from interface: DataOutput
        Writes the specified 16-bit character in big-endian order. Only the two least significant bytes of the integer oneByte are written.
        Specified by:
        writeChar in interface DataOutput
        Parameters:
        val - the character to write.
        Throws:
        IOException - if an I/O error occurs while writing.
        See Also:
        DataInput.readChar()
      • writeChars

        public final void writeChars​(String str)
                              throws IOException
        Description copied from interface: DataOutput
        Writes the 16-bit characters contained in str in big-endian order.
        Specified by:
        writeChars in interface DataOutput
        Parameters:
        str - the string that contains the characters to write.
        Throws:
        IOException - if an I/O error occurs while writing.
        See Also:
        DataInput.readChar()
      • writeInt

        public final void writeInt​(int val)
                            throws IOException
        Description copied from interface: DataOutput
        Writes the specified 32-bit int in big-endian order.
        Specified by:
        writeInt in interface DataOutput
        Parameters:
        val - the int to write.
        Throws:
        IOException - if an I/O error occurs while writing.
        See Also:
        DataInput.readInt()