// Path: cubano-httpeasy/src/main/java/org/concordion/cubano/driver/http/logging/LogManager.java
// public class LogManager {
//     private boolean logRequest;
//     private boolean logRequestDetails;
// 
//     private LogWriter logWriter;
//     private LogBuffer logBuffer = null;
// 
//     public LogManager(LogWriter logWriter, boolean logRequestDetails) {
//         if (logWriter == null) {
//             this.logRequest = false;
//             this.logRequestDetails = false;
//         } else {
//             this.logRequest = HttpEasyDefaults.getLogRequest() || logRequestDetails;
//             this.logRequestDetails = logRequestDetails;
//         }
// 
//         this.logWriter = logWriter;
//     }
// 
//     public boolean isLogRequestDetails() {
//         return logRequestDetails;
//     }
// 
//     public void info(String msg, Object... args) {
//         if (logWriter == null)
//             return;
// 
//         if (logRequest) {
//             logWriter.info(msg, args);
//         }
//     }
// 
//     public void error(String message, Throwable t) {
//         if (logWriter == null)
//             return;
// 
//         logWriter.error(message, t);
//     }
// 
//     public void flushInfo() {
//         if (logWriter != null) {
//             if (this.logRequest && logBuffer != null) {
//                 if (logBuffer.length() > 0) {
//                     logBuffer.trimNewLine();
// 
//                     String[] lines = logBuffer.toString().split("\\r?\\n");
// 
//                     for (String line : lines) {
//                         logWriter.info(line);
//                     }
//                 }
//             }
//         }
// 
//         logBuffer = null;
//     }
// 
//     public void flushRequest() {
//         if (logWriter != null) {
//             if (this.logRequestDetails && logBuffer != null) {
//                 if (logBuffer.length() > 0) {
//                     logBuffer.trimNewLine();
//                     logWriter.request(logBuffer.toString());
//                 }
//             }
//         }
// 
//         logBuffer = null;
//     }
// 
//     public void flushResponse() {
//         if (logWriter != null) {
//             if (this.logRequestDetails && logBuffer != null) {
//                 if (logBuffer.length() > 0) {
//                     logBuffer.trimNewLine();
//                     logWriter.response(logBuffer.toString());
//                 }
//             }
//         }
// 
//         logBuffer = null;
//     }
// 
//     public LogBuffer getBuffer() {
//         if (this.logBuffer == null) {
//             this.logBuffer = new LogBuffer();
//         }
// 
//         return this.logBuffer;
//     }
// }


import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.nio.charset.StandardCharsets;
import org.concordion.cubano.driver.http.logging.LogManager;
import com.google.common.net.MediaType;
package org.concordion.cubano.driver.http.dataWriter;




/**
 * Attach a File or data to an http request.
 *
 * @author Andrew Sumner
 */
public class RawDataWriter implements DataWriter {
    private HttpURLConnection connection;
    private String mediaType;
    private byte[] postEndcoded = null;
    private File uploadFile = null;
    private InputStream uploadStream = null;
    private String uploadFileName;

    /**
     * Constructor.
     *
     * @param connection       The connection
     * @param rawData          data (File or String)
     * @param rawDataMediaType Type of attachment
     * @param fileName         file name for InputStream
     */
    public RawDataWriter(HttpURLConnection connection, Object rawData, MediaType rawDataMediaType, String fileName) {
        this.connection = connection;
        this.mediaType = rawDataMediaType.toString();

        if (rawData instanceof File) {
            uploadFile = (File) rawData;
            connection.setRequestProperty("Content-Type", rawDataMediaType.toString());
            connection.setRequestProperty("Content-Length", Long.toString(uploadFile.length()));
            connection.setFixedLengthStreamingMode(uploadFile.length());

        } else if (rawData instanceof InputStream) {
            uploadStream = (InputStream) rawData;
            uploadFileName = fileName;

            connection.setRequestProperty("Content-Type", rawDataMediaType.toString());
        } else {
            // Assume data is encoded correctly
            this.postEndcoded = String.valueOf(rawData).getBytes(StandardCharsets.UTF_8);

            connection.setRequestProperty("charset", StandardCharsets.UTF_8.name());
            connection.setRequestProperty("Content-Type", rawDataMediaType.toString());
            connection.setRequestProperty("Content-Length", Integer.toString(postEndcoded.length));
        }
    }

    @Override
// Path: cubano-httpeasy/src/main/java/org/concordion/cubano/driver/http/logging/LogManager.java
// public class LogManager {
//     private boolean logRequest;
//     private boolean logRequestDetails;
// 
//     private LogWriter logWriter;
//     private LogBuffer logBuffer = null;
// 
//     public LogManager(LogWriter logWriter, boolean logRequestDetails) {
//         if (logWriter == null) {
//             this.logRequest = false;
//             this.logRequestDetails = false;
//         } else {
//             this.logRequest = HttpEasyDefaults.getLogRequest() || logRequestDetails;
//             this.logRequestDetails = logRequestDetails;
//         }
// 
//         this.logWriter = logWriter;
//     }
// 
//     public boolean isLogRequestDetails() {
//         return logRequestDetails;
//     }
// 
//     public void info(String msg, Object... args) {
//         if (logWriter == null)
//             return;
// 
//         if (logRequest) {
//             logWriter.info(msg, args);
//         }
//     }
// 
//     public void error(String message, Throwable t) {
//         if (logWriter == null)
//             return;
// 
//         logWriter.error(message, t);
//     }
// 
//     public void flushInfo() {
//         if (logWriter != null) {
//             if (this.logRequest && logBuffer != null) {
//                 if (logBuffer.length() > 0) {
//                     logBuffer.trimNewLine();
// 
//                     String[] lines = logBuffer.toString().split("\\r?\\n");
// 
//                     for (String line : lines) {
//                         logWriter.info(line);
//                     }
//                 }
//             }
//         }
// 
//         logBuffer = null;
//     }
// 
//     public void flushRequest() {
//         if (logWriter != null) {
//             if (this.logRequestDetails && logBuffer != null) {
//                 if (logBuffer.length() > 0) {
//                     logBuffer.trimNewLine();
//                     logWriter.request(logBuffer.toString());
//                 }
//             }
//         }
// 
//         logBuffer = null;
//     }
// 
//     public void flushResponse() {
//         if (logWriter != null) {
//             if (this.logRequestDetails && logBuffer != null) {
//                 if (logBuffer.length() > 0) {
//                     logBuffer.trimNewLine();
//                     logWriter.response(logBuffer.toString());
//                 }
//             }
//         }
// 
//         logBuffer = null;
//     }
// 
//     public LogBuffer getBuffer() {
//         if (this.logBuffer == null) {
//             this.logBuffer = new LogBuffer();
//         }
// 
//         return this.logBuffer;
//     }
// }


// Path: cubano-httpeasy/src/main/java/org/concordion/cubano/driver/http/dataWriter/RawDataWriter.java
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.nio.charset.StandardCharsets;
import org.concordion.cubano.driver.http.logging.LogManager;
import com.google.common.net.MediaType;

package org.concordion.cubano.driver.http.dataWriter;




/**
 * Attach a File or data to an http request.
 *
 * @author Andrew Sumner
 */
public class RawDataWriter implements DataWriter {
    private HttpURLConnection connection;
    private String mediaType;
    private byte[] postEndcoded = null;
    private File uploadFile = null;
    private InputStream uploadStream = null;
    private String uploadFileName;

    /**
     * Constructor.
     *
     * @param connection       The connection
     * @param rawData          data (File or String)
     * @param rawDataMediaType Type of attachment
     * @param fileName         file name for InputStream
     */
    public RawDataWriter(HttpURLConnection connection, Object rawData, MediaType rawDataMediaType, String fileName) {
        this.connection = connection;
        this.mediaType = rawDataMediaType.toString();

        if (rawData instanceof File) {
            uploadFile = (File) rawData;
            connection.setRequestProperty("Content-Type", rawDataMediaType.toString());
            connection.setRequestProperty("Content-Length", Long.toString(uploadFile.length()));
            connection.setFixedLengthStreamingMode(uploadFile.length());

        } else if (rawData instanceof InputStream) {
            uploadStream = (InputStream) rawData;
            uploadFileName = fileName;

            connection.setRequestProperty("Content-Type", rawDataMediaType.toString());
        } else {
            // Assume data is encoded correctly
            this.postEndcoded = String.valueOf(rawData).getBytes(StandardCharsets.UTF_8);

            connection.setRequestProperty("charset", StandardCharsets.UTF_8.name());
            connection.setRequestProperty("Content-Type", rawDataMediaType.toString());
            connection.setRequestProperty("Content-Length", Integer.toString(postEndcoded.length));
        }
    }

    @Override
    public void write(LogManager logger) throws IOException {