
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

import javax.activation.FileDataSource;
import javax.activation.FileTypeMap;

import org.apache.axis.attachments.ContentLength;

/**
 * This class defines a read-only FileDataDataSource that can be used to 
 * wrap in-memory document data that is not on disk that we would like to 
 * post via Apache Axis. The class implements org.apache.axis.attachments.ContentLength
 * which Apache can use to determine the length of the docuement data without
 * attempting to look for the data on disk. 
 *   
 * @author smasse01
 */
public class VirtualFileDataSource extends FileDataSource implements ContentLength 
{

	private String name = null;
	private String contentType = null;
	private InputStream inputStream = null;
	private int length = -1;
	
	public VirtualFileDataSource(String name, String contentType, InputStream inputStream, int length ) {
		super("");
		this.name = name;
		this.contentType = contentType;
		this.inputStream = inputStream;
		this.length = length;
	}

	@Override
	public String getContentType() {
		return this.contentType;
	}

	@Override
	public File getFile() {
		throw new AssertionError("operation not supported");
	}

	@Override
	public InputStream getInputStream() throws IOException {
		return this.inputStream;
	}

	@Override
	public String getName() {
		return this.name;
	}

	@Override
	public OutputStream getOutputStream() throws IOException {
		throw new AssertionError("operation not supported");
	}

	@Override
	public void setFileTypeMap(FileTypeMap map) {
		throw new AssertionError("operation not supported");
	}

	public int getContentLength() {
		return this.length;
	}


}
