<commit_before>package org.apache.james.mailrepository;

import java.io.*;
import com.workingdogs.town.*;
import org.apache.james.core.*;

public class TownMimeMessageInputStream extends JamesMimeMessageInputStream {
    //Define how to get to the data
    String connDefinition = null;
    String table = null;
    String key = null;
    String repository = null;

    public TownMimeMessageInputStream(String connDefinition, String table, String key, String repository) throws IOException {
        if (connDefinition == null) {
            throw new IOException("Conn definition is null");
        }
        if (table == null) {
            throw new IOException("Table is null");
        }
        if (key == null) {
            throw new IOException("Message name (key) was not defined");
        }
        if (repository == null) {
            throw new IOException("Repository is null");
        }
        this.connDefinition = connDefinition;
        this.table = table;
        this.key = key;
        this.repository = repository;
    }

    public String getConnDefinition() {
        return connDefinition;
    }

    public String getTable() {
        return table;
    }

    public String getMessageName() {
        return key;
    }

    public String getRepository() {
        return repository;
    }

    protected synchronized InputStream openStream() throws IOException {
        //System.err.println("loading data for " + key + "/" + repository);

        //TableDataSet messages = new TableDataSet(ConnDefinition.getInstance(connDefinition), table);
        //messages.setWhere("message_name='" + key + "' and repository_name='" + repository + "'");
        //messages.setColumns("message_body");
        QueryDataSet messages = new QueryDataSet(ConnDefinition.getInstance(connDefinition),
                "SELECT message_body "
                + " FROM " + table
                + " WHERE message_name='" + key + "' AND repository_name='" + repository + "'");
        if (messages.size() == 0) {
            throw new IOException("Could not find message");
        }
        Record message = messages.getRecord(0);
        return new ByteArrayInputStream(message.getAsBytes("message_body"));
    }

    public boolean equals(Object obj) {
        if (obj instanceof TownMimeMessageInputStream) {
            TownMimeMessageInputStream in = (TownMimeMessageInputStream)obj;
            return in.getConnDefinition().equals(connDefinition)
                    && in.getTable().equals(table)
                    && in.getMessageName().equals(key)
                    && in.getRepository().equals(repository);
        }
        return false;
    }
}<commit_msg>Removed tabs, un-globbed imports, added copyright.<commit_after>/*
 * 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 com.workingdogs.town.ConnDefinition;
import com.workingdogs.town.QueryDataSet;
import com.workingdogs.town.Record;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import org.apache.james.core.JamesMimeMessageInputStream;

public class TownMimeMessageInputStream 
    extends JamesMimeMessageInputStream {

    //Define how to get to the data
    String connDefinition = null;
    String table = null;
    String key = null;
    String repository = null;

    public TownMimeMessageInputStream(String connDefinition, 
                                      String table, 
                                      String key, 
                                      String repository) throws IOException {
        if (connDefinition == null) {
            throw new IOException("Conn definition is null");
        }
        if (table == null) {
            throw new IOException("Table is null");
        }
        if (key == null) {
            throw new IOException("Message name (key) was not defined");
        }
        if (repository == null) {
            throw new IOException("Repository is null");
        }
        this.connDefinition = connDefinition;
        this.table = table;
        this.key = key;
        this.repository = repository;
    }

    public String getConnDefinition() {
        return connDefinition;
    }

    public String getTable() {
        return table;
    }

    public String getMessageName() {
        return key;
    }

    public String getRepository() {
        return repository;
    }

    protected synchronized InputStream openStream() throws IOException {
        //System.err.println("loading data for " + key + "/" + repository);

        //TableDataSet messages = new TableDataSet(ConnDefinition.getInstance(connDefinition), table);
        //messages.setWhere("message_name='" + key + "' and repository_name='" + repository + "'");
        //messages.setColumns("message_body");
        QueryDataSet messages = new QueryDataSet(ConnDefinition.getInstance(connDefinition),
                                                 "SELECT message_body "
                                                 + " FROM " + table
                                                 + " WHERE message_name='" + key + "' AND repository_name='" + repository + "'");
        if (messages.size() == 0) {
            throw new IOException("Could not find message");
        }
        Record message = messages.getRecord(0);
        return new ByteArrayInputStream(message.getAsBytes("message_body"));
    }

    public boolean equals(Object obj) {
        if (obj instanceof TownMimeMessageInputStream) {
            TownMimeMessageInputStream in = (TownMimeMessageInputStream)obj;
            return in.getConnDefinition().equals(connDefinition)
                && in.getTable().equals(table)
                && in.getMessageName().equals(key)
                && in.getRepository().equals(repository);
        }
        return false;
    }
}
{'fraction_non_alphanumeric': 0.09760528488852188, 'fraction_numerical': 0.000990916597853014, 'mean_word_length': 2.224707135250266, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 9, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6203135', 'n_tokens_mistral': 1459, 'n_tokens_neox': 1427, 'n_words': 403}