MessageOutputStream implements AutoCloseable { public OutputStream asStream() throws StreamingException { if (requestStream instanceof OutputStream) { if (log.isDebugEnabled()) log.debug(getLogPrefix() + "returning OutputStream as OutputStream"); return (OutputStream) requestStream; } if (requestStream instanceof Writer) { if (log.isDebugEnabled()) log.debug(getLogPrefix() + "returning Writer as OutputStream"); return new WriterOutputStream((Writer) requestStream, StreamUtil.DEFAULT_INPUT_STREAM_ENCODING); } if (requestStream instanceof ContentHandler) { if (log.isDebugEnabled()) log.debug(getLogPrefix() + "returning ContentHandler as OutputStream"); return new ContentHandlerOutputStream((ContentHandler) requestStream, threadConnector); } return null; } protected  MessageOutputStream(INamedObject owner, IForwardTarget next); protected  MessageOutputStream(INamedObject owner, MessageOutputStream nextStream);  MessageOutputStream(INamedObject owner, OutputStream stream, IForwardTarget next);  MessageOutputStream(INamedObject owner, OutputStream stream, MessageOutputStream nextStream);  MessageOutputStream(INamedObject owner, Writer writer, IForwardTarget next);  MessageOutputStream(INamedObject owner, Writer writer, MessageOutputStream nextStream);  MessageOutputStream(INamedObject owner, ContentHandler handler, IForwardTarget next, ThreadLifeCycleEventListener<Object> threadLifeCycleEventListener, IPipeLineSession session);  MessageOutputStream(INamedObject owner, ContentHandler handler, MessageOutputStream nextStream, ThreadLifeCycleEventListener<Object> threadLifeCycleEventListener, IPipeLineSession session); void closeRequestStream(); void afterClose(); @Override final void close(); Object asNative(); OutputStream asStream(); Writer asWriter(); ContentHandler asContentHandler(); void setResponse(Object response); Object getResponse(); void setForward(PipeForward forward); PipeRunResult getPipeRunResult(); PipeForward getForward(); static MessageOutputStream getTargetStream(INamedObject owner, IPipeLineSession session, IForwardTarget next);  }
@Test public void test11StreamAsStream() throws Exception { CloseObservableOutputStream target = new CloseObservableOutputStream(); try (MessageOutputStream stream = new MessageOutputStream(null, target, (IForwardTarget)null)) { try (OutputStream outputstream = stream.asStream()) { outputstream.write(testString.getBytes()); } } String actual = new String (target.toByteArray()); assertEquals(testString, actual); assertTrue(target.isCloseCalled()); }
@Test public void test21WriterAsStream() throws Exception { CloseObservableWriter target = new CloseObservableWriter(); try (MessageOutputStream stream = new MessageOutputStream(null, target, (IForwardTarget)null)) { try (OutputStream outputstream = stream.asStream()) { outputstream.write(testString.getBytes()); } } String actual = new String (target.toString()); assertEquals(testString, actual); assertTrue(target.isCloseCalled()); }
@Test public void test31ContentHandlerAsStream() throws Exception { CloseObservableXmlWriter target = new CloseObservableXmlWriter(); try (MessageOutputStream stream = new MessageOutputStream(null, target, (IForwardTarget)null, null, null)) { try (OutputStream outputstream = stream.asStream()) { outputstream.write(testString.getBytes()); } } String actual = new String (target.toString()); assertEquals(testString, actual); assertTrue(target.isCloseCalled()); }