/*
 * Copyright (C) The Apache Software Foundation. All rights reserved.
 *
 * This software is published under the terms of the Apache Software License
 * version 1.1, a copy of which has been included with this distribution in
 * the LICENSE file.
 */
package org.apache.james.mailrepository;

import org.apache.james.core.MimeMessageSource;

import java.io.IOException;
import java.io.InputStream;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.util.Map;

public class MimeMessageMemorySource extends MimeMessageSource {

    //Define how to get to the data
    Map streamMap = null;
    String repositoryName = null;
    String key = null;

    public MimeMessageMemorySource(Map streamMap,  String repositoryName, String key) {
        this.streamMap = streamMap;
        this.repositoryName = repositoryName;
        this.key = key;
    }

    public String getSourceId() {
        return repositoryName + "/" + key;
    }

    public InputStream getInputStream() throws IOException {
        ByteArrayOutputStream out = (ByteArrayOutputStream)streamMap.get(key);
        return new ByteArrayInputStream(out.toByteArray());
    }

}
