@ javax . annotation . Nonnull public PipedInputStream newInputStream ( ) throws IOException { @ javax . annotation . Nonnull final com . simiacryptus . util . io . TeeOutputStream outTee = this ; @ javax . annotation . Nonnull final AtomicReference < Runnable > onClose = new AtomicReference <> ( ) ; @ javax . annotation . Nonnull final PipedOutputStream outPipe = new PipedOutputStream ( ) ; @ javax . annotation . Nonnull final PipedInputStream in = new PipedInputStream ( ) { @ Override public void close ( ) throws IOException { outPipe . close ( ) ; super . close ( ) ; } } ; outPipe . connect ( in ) ; @ javax . annotation . Nonnull final OutputStream outAsync = new AsyncOutputStream ( outPipe ) ; new Thread ( ( ) -> { try { if ( null != heapBuffer ) { outAsync . write ( heapBuffer . toByteArray ( ) ) ; outAsync . flush ( ) ; } outTee . branches . add ( outAsync ) ; } catch ( @ javax . annotation . Nonnull final IOException e ) { e . printStackTrace ( ) ; } } ) . start ( ) ; onClose . set ( ( ) -> { outTee . branches . remove ( outAsync ) ; System . err . println ( "END HTTP Session" ) ; } ) ; return in ; }
New input stream piped input stream .