Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8311882

DataOuputStream should clarify that it might write primitive types as multiple byte groups

XMLWordPrintable

    • Icon: CSR CSR
    • Resolution: Approved
    • Icon: P4 P4
    • 22
    • core-libs
    • None
    • behavioral
    • minimal
    • This is a verbiage change only to describe current behavior.
    • Java API
    • SE

      Summary

      Add verbiage clarifying that a primitive Java type written to a java.io.DataOutputStream may be written by the underlying output stream as more than one group of bytes.

      Problem

      There is no guarantee that a DataOutputStream will for example write an int as a single sequence of four bytes. It could be written as more than one group of bytes whose total byte count equals four. The same situation applies for other types.

      Solution

      Specify that data types consisting of multiple bytes might not have all their bytes written at once.

      Specification

      --- a/src/java.base/share/classes/java/io/DataOutputStream.java
      +++ b/src/java.base/share/classes/java/io/DataOutputStream.java
      @@ -30,7 +30,10 @@ import jdk.internal.util.ByteArray;
       /**
        * A data output stream lets an application write primitive Java data
        * types to an output stream in a portable way. An application can
      - * then use a data input stream to read the data back in.
      + * then use a data input stream to read the data back in. A data output
      + * stream wraps another output stream and delegates writing bytes to the
      + * write methods of that output stream. Writing data consisting of more than
      + * a single byte may cause several writes to the underlying output stream.
        * <p>
        * A DataOutputStream is not safe for use by multiple concurrent
        * threads. If a DataOutputStream is to be used by more than one

            bpb Brian Burkhalter
            webbuggrp Webbug Group
            Alan Bateman
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: