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

Add ByteArrayOutputStream.writeTo(DataOutput out)

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Unresolved
    • Icon: P4 P4
    • None
    • 1.3.0
    • core-libs
    • Fix Understood
    • generic
    • generic



      Name: rmT116609 Date: 01/25/2001


      java version "1.3.0"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0)
      Java HotSpot(TM) Client VM (build 1.3.0, mixed mode)


      It would be nice to have a method writeTo in class ByteArrayOutputStream with
      the same functionality as the current writeTo, but with a parameter of type
      DataOutput in stead of OutputStream. This would be particularly useful for use
      with RandomAccessFile.

      Example:

      Suppose you want to store binary data in a random access file which is
      structured in 8KB pages, but you want to minimize disk access (think of
      a database implementation). You could do this as follows

      - Create a ByteArrayOutputStream of 8192 bytes
      - Convert it to a DataOutputStream
      - write your binary data to the DataOutputStream (and hence to the
      ByteArrayOutputStream)
      - seek to the correct position in the random access file
      - write the underlying byte array to the random access file in a single
      operation

      With the current API the last step requires converting the
      ByteArrayOutputStream to a byte array (with toByteArray) and then
      writing the byte array to the random access file. This results in an
      unneccessary copy of the buffer that underlies the ByteArrayOutputStream.

      If we used an output stream (e.g., a network connection) in stead of a
      random access file, we could avoid this unneccessary cloning by using
      the method writeTo of ByteArrayOutputStream. A RandomAccessFile is
      however not an OutputStream (and therefore cannot be used with the
      current writeTo) but implements the interface DataOutput.

      Hence my suggestion of adding a method writeTo with argument
      of type DataOutput with the same functionality as the current writeTo.
      My guess is that the implementation of the new method would be
      an almost verbatim copy of the implementation of the current method.

      (Review ID: 115666)
      ======================================================================

            Unassigned Unassigned
            rmandalasunw Ranjith Mandala (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Imported:
              Indexed: