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

PrintWriter et al have no way to get downstream object

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 1.2.0
    • core-libs
    • None
    • sparc
    • solaris_2.6

      I am having the following problem -- I want to write a subclass of PrintWriter
      that uses a downstream Writer object. The only way to provide that downstream
      object is in the PrintWriter constructor, so I must provide it in my super()
      constructor invocation. To do so, I must create it during that invocation.
      But during that invocation I cannot store its value anywhere I can use (a local
      variable would require an illegal access to "this").

      (see example in workaround)

      So to actually do this I need a method on PrintWriter that lets me get the
      downstream Writer (or OutputStream) (if any). Without that, the workaround
      is ugly and, in some cases, completely wrong as can expose an internal workhorse
      object (the downstream writer) to the user of the PrintWriter subclass (or
      at the least add a very odd construction mechanism).

      Adding a getWriter and getOutputStream method would be far perferable to
      either workaround.

      I'm sure this applies to almost all of the streams that take downstream
      streams.

            mmcclosksunw Michael Mccloskey (Inactive)
            karnoldsunw Kenneth Arnold (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: