Java Code Examples for java.io.OutputStream.getClass()

The following are Jave code examples for showing how to use getClass() of the java.io.OutputStream class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: openjdk-jdk10   File: Channels.java   View Source Code Vote up 4 votes
/**
 * Constructs a channel that writes bytes to the given stream.
 *
 * <p> The resulting channel will not be buffered; it will simply redirect
 * its I/O operations to the given stream.  Closing the channel will in
 * turn cause the stream to be closed.  </p>
 *
 * @param  out
 *         The stream to which bytes are to be written
 *
 * @return  A new writable byte channel
 */
public static WritableByteChannel newChannel(OutputStream out) {
    Objects.requireNonNull(out, "out");

    if (out.getClass() == FileOutputStream.class) {
        return ((FileOutputStream) out).getChannel();
    }

    return new WritableByteChannelImpl(out);
}