// Path: src/main/java/com/feedzai/fos/impl/weka/utils/pmml/PMMLConsumers.java
// public class PMMLConsumers {
// 
//     /**
//      * The logger.
//      */
//     private final static Logger logger = LoggerFactory.getLogger(PMMLConsumers.class);
// 
// 
//     /**
//      * Consumes the PMML in the given file and converts it to a Weka {@link Classifier}.
//      *
//      * @param file The file with the PMML representation of the classifier.
//      * @return A Weka {@link Classifier}.
//      * @throws PMMLConversionException If if fails to consume the PMML file.
//      */
//     public static Classifier consume(File file) throws PMMLConversionException {
//         PMML pmml = null;
//         try {
//             if (isGzipped(file)) {
//                 logger.debug("Consuming GZipped PMML file '{}'.", file.getAbsolutePath());
// 
//                 try (FileInputStream fis = new FileInputStream(file);
//                      GZIPInputStream gzipInputStream = new GZIPInputStream(fis))
//                 {
//                     pmml = JAXBUtil.unmarshalPMML(new StreamSource(gzipInputStream));
//                 }
//             } else {
//                 logger.debug("Consuming PMML file '{}'.", file.getAbsolutePath());
// 
//                 try (FileInputStream fis = new FileInputStream(file)) {
//                     pmml = JAXBUtil.unmarshalPMML(new StreamSource(fis));
//                 }
//             }
//         } catch (Exception e) {
//             throw new PMMLConversionException("Failed to unmarshal PMML file '" + file + "'. Make sure the file is a valid PMML.", e);
//         }
// 
//         Algorithm algorithm = getAlgorithm(pmml);
// 
//         logger.debug("Consumed PMML file using algorithm {}.", algorithm);
// 
//         return algorithm.getPMMLConsumer().consume(pmml);
//     }
// 
//     /**
//      * Checks if the given file is in GZIP format.
//      * <p/>
//      * It checks this by checking the head for the {@link java.util.zip.GZIPInputStream#GZIP_MAGIC} number.
//      *
//      * @param file The file to check.
//      * @return {@code true} if the file is in GZIP format, or {@code false}
//      * @throws IOException
//      */
//     private static boolean isGzipped(File file) throws IOException {
//         FileInputStream fileInputStream = new FileInputStream(file);
// 
//         int head = (fileInputStream.read() & 0xff) | ((fileInputStream.read() << 8 ) & 0xff00 );
// 
//         return GZIPInputStream.GZIP_MAGIC == head;
//     }
// 
//     /**
//      * Retrieves the {@link com.feedzai.fos.impl.weka.utils.pmml.PMMLConversionCommons.Algorithm} represented
//      * as a PMML extension named {@link com.feedzai.fos.impl.weka.utils.pmml.PMMLConversionCommons#ALGORITHM_EXTENSION_ELEMENT}.
//      *
//      * @param pmml The {@link PMML}.
//      * @return The {@link com.feedzai.fos.impl.weka.utils.pmml.PMMLConversionCommons.Algorithm} in the PMML.
//      * @throws PMMLConversionException If it fails to retrieve the algorithm from the given PPML.
//      */
//     private static Algorithm getAlgorithm(PMML pmml) throws PMMLConversionException {
//         for (Extension extension : pmml.getExtensions()) {
//             if (ALGORITHM_EXTENSION_ELEMENT.equals(extension.getName())) {
//                 return Algorithm.valueOf(extension.getValue());
//             }
//         }
// 
//         throw new PMMLConversionException("Couldn't find '" + ALGORITHM_EXTENSION_ELEMENT + "' extension element in PMML.");
//     }
// }


import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import com.feedzai.fos.api.FOSException;
import com.feedzai.fos.api.ModelDescriptor;
import com.feedzai.fos.common.validation.NotNull;
import com.feedzai.fos.impl.weka.utils.pmml.PMMLConsumers;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.SerializationUtils;
import java.io.*;
            oos = new ObjectOutputStream(baos);
            oos.writeObject(serializable);
            oos.flush();

            this.serializedObject = baos.toByteArray();
        } finally {
            IOUtils.closeQuietly(baos);
            IOUtils.closeQuietly(oos);
        }
    }

    /**
     * Creates a clonner by reading a serialized object from file.
     *
     * @param descriptor A {@link com.feedzai.fos.api.ModelDescriptor} with the information about the classifier.
     * @throws IOException when there were problems reading the file
     */
    public Cloner(ModelDescriptor descriptor) throws IOException {
        checkNotNull(descriptor.getModelFilePath(), "Source file cannot be null");

        File file = new File(descriptor.getModelFilePath());

        checkArgument(file.exists(), "Source file '"+ file.getAbsolutePath() + "' must exist");

        switch (descriptor.getFormat()) {
            case BINARY:
                this.serializedObject = FileUtils.readFileToByteArray(file);
                break;
            case PMML:
                try {
// Path: src/main/java/com/feedzai/fos/impl/weka/utils/pmml/PMMLConsumers.java
// public class PMMLConsumers {
// 
//     /**
//      * The logger.
//      */
//     private final static Logger logger = LoggerFactory.getLogger(PMMLConsumers.class);
// 
// 
//     /**
//      * Consumes the PMML in the given file and converts it to a Weka {@link Classifier}.
//      *
//      * @param file The file with the PMML representation of the classifier.
//      * @return A Weka {@link Classifier}.
//      * @throws PMMLConversionException If if fails to consume the PMML file.
//      */
//     public static Classifier consume(File file) throws PMMLConversionException {
//         PMML pmml = null;
//         try {
//             if (isGzipped(file)) {
//                 logger.debug("Consuming GZipped PMML file '{}'.", file.getAbsolutePath());
// 
//                 try (FileInputStream fis = new FileInputStream(file);
//                      GZIPInputStream gzipInputStream = new GZIPInputStream(fis))
//                 {
//                     pmml = JAXBUtil.unmarshalPMML(new StreamSource(gzipInputStream));
//                 }
//             } else {
//                 logger.debug("Consuming PMML file '{}'.", file.getAbsolutePath());
// 
//                 try (FileInputStream fis = new FileInputStream(file)) {
//                     pmml = JAXBUtil.unmarshalPMML(new StreamSource(fis));
//                 }
//             }
//         } catch (Exception e) {
//             throw new PMMLConversionException("Failed to unmarshal PMML file '" + file + "'. Make sure the file is a valid PMML.", e);
//         }
// 
//         Algorithm algorithm = getAlgorithm(pmml);
// 
//         logger.debug("Consumed PMML file using algorithm {}.", algorithm);
// 
//         return algorithm.getPMMLConsumer().consume(pmml);
//     }
// 
//     /**
//      * Checks if the given file is in GZIP format.
//      * <p/>
//      * It checks this by checking the head for the {@link java.util.zip.GZIPInputStream#GZIP_MAGIC} number.
//      *
//      * @param file The file to check.
//      * @return {@code true} if the file is in GZIP format, or {@code false}
//      * @throws IOException
//      */
//     private static boolean isGzipped(File file) throws IOException {
//         FileInputStream fileInputStream = new FileInputStream(file);
// 
//         int head = (fileInputStream.read() & 0xff) | ((fileInputStream.read() << 8 ) & 0xff00 );
// 
//         return GZIPInputStream.GZIP_MAGIC == head;
//     }
// 
//     /**
//      * Retrieves the {@link com.feedzai.fos.impl.weka.utils.pmml.PMMLConversionCommons.Algorithm} represented
//      * as a PMML extension named {@link com.feedzai.fos.impl.weka.utils.pmml.PMMLConversionCommons#ALGORITHM_EXTENSION_ELEMENT}.
//      *
//      * @param pmml The {@link PMML}.
//      * @return The {@link com.feedzai.fos.impl.weka.utils.pmml.PMMLConversionCommons.Algorithm} in the PMML.
//      * @throws PMMLConversionException If it fails to retrieve the algorithm from the given PPML.
//      */
//     private static Algorithm getAlgorithm(PMML pmml) throws PMMLConversionException {
//         for (Extension extension : pmml.getExtensions()) {
//             if (ALGORITHM_EXTENSION_ELEMENT.equals(extension.getName())) {
//                 return Algorithm.valueOf(extension.getValue());
//             }
//         }
// 
//         throw new PMMLConversionException("Couldn't find '" + ALGORITHM_EXTENSION_ELEMENT + "' extension element in PMML.");
//     }
// }


// Path: src/main/java/com/feedzai/fos/impl/weka/utils/Cloner.java
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import com.feedzai.fos.api.FOSException;
import com.feedzai.fos.api.ModelDescriptor;
import com.feedzai.fos.common.validation.NotNull;
import com.feedzai.fos.impl.weka.utils.pmml.PMMLConsumers;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.SerializationUtils;
import java.io.*;

            oos = new ObjectOutputStream(baos);
            oos.writeObject(serializable);
            oos.flush();

            this.serializedObject = baos.toByteArray();
        } finally {
            IOUtils.closeQuietly(baos);
            IOUtils.closeQuietly(oos);
        }
    }

    /**
     * Creates a clonner by reading a serialized object from file.
     *
     * @param descriptor A {@link com.feedzai.fos.api.ModelDescriptor} with the information about the classifier.
     * @throws IOException when there were problems reading the file
     */
    public Cloner(ModelDescriptor descriptor) throws IOException {
        checkNotNull(descriptor.getModelFilePath(), "Source file cannot be null");

        File file = new File(descriptor.getModelFilePath());

        checkArgument(file.exists(), "Source file '"+ file.getAbsolutePath() + "' must exist");

        switch (descriptor.getFormat()) {
            case BINARY:
                this.serializedObject = FileUtils.readFileToByteArray(file);
                break;
            case PMML:
                try {
                    this.serializedObject = SerializationUtils.serialize(PMMLConsumers.consume(file));