/**
 * Copyright © World Wide Web Consortium, (Massachusetts Institute of
 * Technology, Institut National de Recherche en Informatique et en
 * Automatique, Keio University).
 *
 * All Rights Reserved.
 *
 * Please see the full Copyright clause at
 * <http://www.w3.org/Consortium/Legal/copyright-software.html>
 *
 * RDFSource class
 *
 * $Log: RDFSource.java,v $
 * Revision 1.3  1999/05/21 13:02:32  jsaarela
 * Distribution release V1.14 on 21-May-99.
 *
 * Revision 1.1  1999/04/26 14:51:27  jsaarela
 * URI resolution improved.
 *
 *
 * @author	Janne Saarela <jsaarela@w3.org>
 */
package org.w3c.rdf;

import java.io.InputStream;
import java.io.Reader;
import java.io.IOException;
import java.net.URL;

public class RDFSource
{
    private String	m_sContent = null;
    private String	m_sURL = null;

    public RDFSource (URL url) {
	m_sURL = url.toString();
	try {
	    fetchByteStream (url.openStream());
	} catch (IOException ex) {
	    m_sContent = null;
	}
    }

    public RDFSource (InputStream is) {
	fetchByteStream(is);
    }

    public RDFSource (String sContent) {
	m_sContent = sContent;
    }

    public String content () {
	return m_sContent;
    }

    public String url() {
	return m_sURL;
    }

    public void fetchByteStream (InputStream is) {
	m_sContent = new String();
	try {
	    int len = is.available();
	    is.mark(len);
	    int c;

	    while ((c = is.read()) != -1) {
		m_sContent += (char)c;
	    }
	} catch (IOException ex) {
	    m_sContent = null;
	}
    }
}
