class HttpUtil {

  public static String decodeBase64ZippedString( String loggingString64 ) throws IOException {
    if ( loggingString64 == null || loggingString64.isEmpty() ) {
      return "";
    }
    StringWriter writer = new StringWriter();
    // base 64 decode
    byte[] bytes64 = Base64.decodeBase64( loggingString64.getBytes() );
    // unzip to string encoding-wise
    ByteArrayInputStream zip = new ByteArrayInputStream( bytes64 );

    GZIPInputStream unzip = null;
    InputStreamReader reader = null;
    BufferedInputStream in = null;
    try {
      unzip = new GZIPInputStream( zip, HttpUtil.ZIP_BUFFER_SIZE );
      in = new BufferedInputStream( unzip, HttpUtil.ZIP_BUFFER_SIZE );
      // PDI-4325 originally used xml encoding in servlet
      reader = new InputStreamReader( in, Const.XML_ENCODING );
      writer = new StringWriter();

      // use same buffer size
      char[] buff = new char[ HttpUtil.ZIP_BUFFER_SIZE ];
      for ( int length = 0; ( length = reader.read( buff ) ) > 0; ) {
        writer.write( buff, 0, length );
      }
    } finally {
      // close resources
      if ( reader != null ) {
        try {
          reader.close();
        } catch ( IOException e ) {
          // Suppress
        }
      }
      if ( in != null ) {
        try {
          in.close();
        } catch ( IOException e ) {
          // Suppress
        }
      }
      if ( unzip != null ) {
        try {
          unzip.close();
        } catch ( IOException e ) {
          // Suppress
        }
      }
    }
    return writer.toString();
  }

}