Class OutputStreamSelector
- java.lang.Object
-
- java.io.OutputStream
-
- com.cloudbees.jenkins.support.util.OutputStreamSelector
-
- All Implemented Interfaces:
WrapperOutputStream
,Closeable
,Flushable
,AutoCloseable
@Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) public class OutputStreamSelector extends OutputStream implements WrapperOutputStream
Dynamically selects either a textual or binary OutputStream destination based on simple content type probing.- Since:
- TODO
-
-
Constructor Summary
Constructors Constructor Description OutputStreamSelector(Supplier<OutputStream> binaryOutputStreamProvider, Supplier<OutputStream> textOutputStreamProvider)
Constructs an OutputStreamSelector using the provided streams.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
void
flush()
void
reset()
Resets the state of this stream to allow for contents to be probed again.OutputStream
unwrap()
Unwraps this stream, potentially forcing unwritten data to be flushed.void
write(byte[] b, int off, int len)
void
write(int b)
-
Methods inherited from class java.io.OutputStream
nullOutputStream, write
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.cloudbees.jenkins.support.util.WrapperOutputStream
unwrapRecursively
-
-
-
-
Constructor Detail
-
OutputStreamSelector
public OutputStreamSelector(@NonNull Supplier<OutputStream> binaryOutputStreamProvider, @NonNull Supplier<OutputStream> textOutputStreamProvider)
Constructs an OutputStreamSelector using the provided streams.- Parameters:
binaryOutputStreamProvider
- a provider of an OutputStream to use if the contents written appear to be binarytextOutputStreamProvider
- a provider of an OutputStream to use if the contents written appear to be textual
-
-
Method Detail
-
write
public void write(int b) throws IOException
- Specified by:
write
in classOutputStream
- Throws:
IOException
-
write
public void write(@NonNull byte[] b, int off, int len) throws IOException
- Overrides:
write
in classOutputStream
- Throws:
IOException
-
flush
public void flush() throws IOException
- Specified by:
flush
in interfaceFlushable
- Overrides:
flush
in classOutputStream
- Throws:
IOException
-
reset
public void reset()
Resets the state of this stream to allow for contents to be probed again.
-
close
public void close() throws IOException
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Overrides:
close
in classOutputStream
- Throws:
IOException
-
unwrap
@NonNull public OutputStream unwrap() throws IOException
Description copied from interface:WrapperOutputStream
Unwraps this stream, potentially forcing unwritten data to be flushed.- Specified by:
unwrap
in interfaceWrapperOutputStream
- Returns:
- the underlying stream being wrapped
- Throws:
IOException
- if an exception occurs preparing the unwrapped reference
-
-