question: public static String extractResponse ( IDiagnosticsLogger log , StringWriter sw ) { String samlResponseField = "<input type=\"hidden\" name=\"SAMLResponse\" value=\"" ; String responseAsString = sw . toString ( ) ; log . debug ( "Received response " + responseAsString ) ; int index = responseAsString . indexOf ( samlResponseField ) ; assertTrue ( index >= 0 ) ; int startIndex = index + samlResponseField . length ( ) ; int endIndex = responseAsString . indexOf ( '\"' , startIndex ) ; assertTrue ( endIndex >= 0 ) ; String encodedSamlResponse = responseAsString . substring ( startIndex , endIndex ) ; String decodedSamlResponse = new String ( Base64 . decode ( encodedSamlResponse ) ) ; return decodedSamlResponse ; }
target:  Extract Saml Response which was written to a stream