/*
 * Copyright (c) 2002-2009 JSCAPE
 * 1147 S. 53rd Pl., Mesa, Arizona, 85206, U.S.A.
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of
 * JSCAPE. ("Confidential Information").  You shall not disclose such
 * Confidential Information and shall use it only in accordance with
 *  the terms of the license agreement you entered into with JSCAPE.
 */

package com.jscape.util.io;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

/**
 * @author Alex Usun
 */
public class ComponentSource
        implements DataSource {

    private final InputStream in;
    private final OutputStream out;

    public ComponentSource(InputStream in, OutputStream out) {
        this.in = in;
        this.out = out;
    }

    public boolean writeAllowed() {
        return this.out != null;
    }

    public boolean readAllowed() {
        return this.in != null;
    }

    public InputStream getInputStream()
            throws IOException {
        if (this.in == null) {
            throw new IOException("Unsupported operation.");
        }
        return this.in;
    }

    public OutputStream getOutputStream()
            throws IOException {
        if (this.out == null) {
            throw new IOException("Unsupported operation.");
        }
        return this.out;
    }

    @Override
    public String toString() {
        return "StreamSource {"
                + "in=" + this.in
                + ", out=" + this.out
                + '}';
    }
}
