/*******************************************************************************
 *  Copyright 2017 Centre for Development of Advanced Computing(C-DAC), Pune
 *  
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *  
 *    http://www.apache.org/licenses/LICENSE-2.0
 *  
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *******************************************************************************/
package cdac.medinfo.sdk.hl7282.hl7streams;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;

/**
 * This class is specialized in the reading/writing operations on the file.
 */
public class HL7FileStream extends HL7Stream 
{
	/**
	 * Sets the file FileInputStream to the FileStream.
	 * @param objFileInputStream object of FileInputStream
	 * @return int - Succes or Faliure.
	 */
	public int setInputStream(FileInputStream objFileInputStream)
	{
		BufferedInputStream objBufferedInputStream = null;
		
		if(objFileInputStream == null)
			return 0;
		objBufferedInputStream = new BufferedInputStream(objFileInputStream);
		objInputStream  = objBufferedInputStream;
		return 1;
	}
	
	/**
	 * Sets the file FileOutputStream to the FileStream.
	 * @param objFileOutputStream object of FileOutputStream
	 * @return int - Succes or Failure.
	 */
	public int setOutputStream(FileOutputStream objFileOutputStream)
	{
		BufferedOutputStream objBufferedOutputStream = null;
		if(objFileOutputStream == null)
			return 0;
		objBufferedOutputStream = new BufferedOutputStream(objFileOutputStream);
		objOutputStream = objBufferedOutputStream;
		return 1;
	}
	
	/**
	 * This method sets the file Streams to the FileStream.
	 * @param objFileInputStream object of FileInputStream
	 * @param objFileOutputStream object of FileOutputStream
	 * @return int - Success or Failure
	 */
	public int setStream(FileInputStream objFileInputStream, FileOutputStream objFileOutputStream)
	{
		BufferedInputStream objBufferedInputStream = null;
		BufferedOutputStream objBufferedOutputStream = null;
		if(objFileInputStream == null || objFileOutputStream == null)
			return 0;   // throw exception if any of the stream is set to null
		objBufferedInputStream = new BufferedInputStream(objFileInputStream);
		objBufferedOutputStream = new BufferedOutputStream(objFileOutputStream);
		objInputStream  =objBufferedInputStream;
		objOutputStream = objBufferedOutputStream;
		return 1;
	}
}
