Name: stC104175 Date: 08/02/2000
java version "1.3.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0)
Classic VM (build 1.3.0, J2RE 1.3.0 IBM build cx130-20000623 (JIT enabled:
jitc))
There are various times where I would like to use methods that require as a
parameter a target OutputStream/Writer for sending output, but would like to
execute those methods silently for their other effects.
This corresponds to the ability in Unix to redirect command output to /dev/null,
or in DOS to append command output to NUL.
Right now, the only way to do this is to either pass in an OutputStream/Writer
directed to some temporary buffer that I will ignore, or create a wrapper class
to do that for me (see the workaround below for an example of a wrapper class).
Worse, I could be non-platform-independent, and create a stream directed to a
new File("/dev/null") and hope the user is running Unix.
It would be nice if it were legal to pass null as an argument to the various
java.io.* constructors to mean disabling output, rather than the current
paradigm of throwing a NullPointerException if null is passed in. With this
option, you would either create a do-nothing place-holder Writer during the
constructor (as in my wrapper example, although yours could be more efficient),
or code more conditionals into the various methods that run the risk of a
NullPointerException (back in JDK 1.1.8, the NullPointerException was not thrown
in the constructor, but in the first of write(), flush(), or close() that tried
to access the underlying stream that happened to be null).
Or, you could provide a public factory method in Writer and OutputStream, and
still require a non-null object in the constructors. The factory method could
produce a do-nothing placeholder, or be a native method that returns a valid
Java object directed to the "bit bucket" (like a FileWriter("/dev/null") in
Unix).
(Review ID: 107912)
======================================================================
java version "1.3.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0)
Classic VM (build 1.3.0, J2RE 1.3.0 IBM build cx130-20000623 (JIT enabled:
jitc))
There are various times where I would like to use methods that require as a
parameter a target OutputStream/Writer for sending output, but would like to
execute those methods silently for their other effects.
This corresponds to the ability in Unix to redirect command output to /dev/null,
or in DOS to append command output to NUL.
Right now, the only way to do this is to either pass in an OutputStream/Writer
directed to some temporary buffer that I will ignore, or create a wrapper class
to do that for me (see the workaround below for an example of a wrapper class).
Worse, I could be non-platform-independent, and create a stream directed to a
new File("/dev/null") and hope the user is running Unix.
It would be nice if it were legal to pass null as an argument to the various
java.io.* constructors to mean disabling output, rather than the current
paradigm of throwing a NullPointerException if null is passed in. With this
option, you would either create a do-nothing place-holder Writer during the
constructor (as in my wrapper example, although yours could be more efficient),
or code more conditionals into the various methods that run the risk of a
NullPointerException (back in JDK 1.1.8, the NullPointerException was not thrown
in the constructor, but in the first of write(), flush(), or close() that tried
to access the underlying stream that happened to be null).
Or, you could provide a public factory method in Writer and OutputStream, and
still require a non-null object in the constructors. The factory method could
produce a do-nothing placeholder, or be a native method that returns a valid
Java object directed to the "bit bucket" (like a FileWriter("/dev/null") in
Unix).
(Review ID: 107912)
======================================================================
- csr for
-
JDK-8192925 Add null InputStream and OutputStream
- Closed
- duplicates
-
JDK-4358775 Ability to direct output to null
- Closed
-
JDK-8190279 InputStream.nullInputStream() and OutputStream.nullOutputStream()
- Closed
- relates to
-
JDK-8196298 Add null Reader and Writer
- Resolved
- links to
(1 links to)