// Path: zap-client-api/src/main/java/br/com/softplan/security/zap/api/exception/ZapClientException.java
// public class ZapClientException extends RuntimeException {
// 
// 	private static final long serialVersionUID = -4867749606526224619L;
// 	
// 	public ZapClientException(String message) {
// 		super(message);
// 	}
// 	
// 	public ZapClientException(Throwable e) {
// 		super(e);
// 	}
// 	
// 	public ZapClientException(String message, Throwable e) {
// 		super(message, e);
// 	}
// 	
// }


import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.nio.file.Files;
import java.nio.file.Paths;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import br.com.softplan.security.zap.api.exception.ZapClientException;
	 * Saves the XML Spider results report to the default path (target/zap-reports/).
	 * 
	 * @param report the {@link ZapReport} holding the report to be saved.
	 * @return the saved XML Spider results report as a {@code File} instance.
	 */
	public static File saveXmlSpiderResults(ZapReport report) {
		return saveXmlSpiderResults(report, DEFAULT_REPORTS_PATH);
	}
	
	/**
	 * Saves the XML Spider results report to the given path.
	 * 
	 * @param report the {@link ZapReport} holding the report to be saved.
	 * @param path the path to save the XML Spider results report.
	 * @return the saved XML Spider results report as a {@code File} instance.
	 */
	public static File saveXmlSpiderResults(ZapReport report, String path) {
		return saveReport(report.getXmlSpiderResults(), "zapSpiderResults.xml", path);
	}
	
	private static File saveReport(byte[] report, String name, String path) {
		createReportsFolder(path);
		File reportFile = new File(path, name);
		
		try (OutputStream fos = new FileOutputStream(reportFile)) {
			fos.write(report);
			LOGGER.info("{} saved to {}", name, path);
		} catch(IOException e) {
			String message = "Error saving reports.";
			LOGGER.error(message, e);
// Path: zap-client-api/src/main/java/br/com/softplan/security/zap/api/exception/ZapClientException.java
// public class ZapClientException extends RuntimeException {
// 
// 	private static final long serialVersionUID = -4867749606526224619L;
// 	
// 	public ZapClientException(String message) {
// 		super(message);
// 	}
// 	
// 	public ZapClientException(Throwable e) {
// 		super(e);
// 	}
// 	
// 	public ZapClientException(String message, Throwable e) {
// 		super(message, e);
// 	}
// 	
// }


// Path: zap-client-api/src/main/java/br/com/softplan/security/zap/api/report/ZapReportUtil.java
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.nio.file.Files;
import java.nio.file.Paths;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import br.com.softplan.security.zap.api.exception.ZapClientException;

	 * Saves the XML Spider results report to the default path (target/zap-reports/).
	 * 
	 * @param report the {@link ZapReport} holding the report to be saved.
	 * @return the saved XML Spider results report as a {@code File} instance.
	 */
	public static File saveXmlSpiderResults(ZapReport report) {
		return saveXmlSpiderResults(report, DEFAULT_REPORTS_PATH);
	}
	
	/**
	 * Saves the XML Spider results report to the given path.
	 * 
	 * @param report the {@link ZapReport} holding the report to be saved.
	 * @param path the path to save the XML Spider results report.
	 * @return the saved XML Spider results report as a {@code File} instance.
	 */
	public static File saveXmlSpiderResults(ZapReport report, String path) {
		return saveReport(report.getXmlSpiderResults(), "zapSpiderResults.xml", path);
	}
	
	private static File saveReport(byte[] report, String name, String path) {
		createReportsFolder(path);
		File reportFile = new File(path, name);
		
		try (OutputStream fos = new FileOutputStream(reportFile)) {
			fos.write(report);
			LOGGER.info("{} saved to {}", name, path);
		} catch(IOException e) {
			String message = "Error saving reports.";
			LOGGER.error(message, e);
			throw new ZapClientException(message, e);