//----------------------------BEGIN LICENSE----------------------------
/* 
 * Willow : the Open Source WorkFlow Project
 * Distributable under GNU LGPL license by gun.org
 *
 * Copyright (C) 2004-2010  huihoo.org 
 * Copyright (C) 2004-2010  ZosaTapo <dertyang@hotmail.com> 
 * 
 * ====================================================================
 * Project Homepage : http://www.huihoo.org/willow
 * Source Forge     : http://sourceforge.net/projects/huihoo
 * Mailing list     : willow@lists.sourceforge.net 
 */
//----------------------------END  LICENSE-----------------------------

package org.huihoo.willow.naming.resources;

import java.io.InputStream;
import java.io.ByteArrayInputStream;
import java.io.IOException;

public class Resource
{
	public Resource()
	{
	}

	public Resource(InputStream inputStream)
	{
		setContent(inputStream);
	}

	public Resource(byte[] binaryContent)
	{
		setContent(binaryContent);
	}

	// ----------------------------------------------------- Instance Variables

	/**
	 * Binary content.
	 */
	protected byte[] binaryContent = null;

	/**
	 * Input stream.
	 */
	protected InputStream inputStream = null;

	// ------------------------------------------------------------- Properties

	/**
	 * Content accessor.
	 * 
	 * @return InputStream
	 */
	public InputStream streamContent() throws IOException
	{
		if (binaryContent != null)
		{
			return new ByteArrayInputStream(binaryContent);
		}
		return inputStream;
	}

	/**
	 * Content accessor.
	 * 
	 * @return binary content
	 */
	public byte[] getContent()
	{
		return binaryContent;
	}

	/**
	 * Content mutator.
	 * 
	 * @param inputStream New input stream
	 */
	public void setContent(InputStream inputStream)
	{
		this.inputStream = inputStream;
	}

	/**
	 * Content mutator.
	 * 
	 * @param binaryContent New bin content
	 */
	public void setContent(byte[] binaryContent)
	{
		this.binaryContent = binaryContent;
	}

}
