// Path: src/main/java/com/siemens/ct/exi/main/api/sax/EXIResult.java
// public class EXIResult extends SAXResult {
// 
// 	protected SAXEncoder handler;
// 
// 	public EXIResult() throws IOException, EXIException {
// 		// use default exi-factory
// 		this(DefaultEXIFactory.newInstance());
// 	}
// 
// 	public EXIResult(EXIFactory exiFactory) throws EXIException {
// 		// DefaultHandler2 handler = exiFactory.createEXIWriter(os);
// 		handler = new SAXFactory(exiFactory).createEXIWriter();
// 		// set internal states
// 		setHandler(handler);
// 		setLexicalHandler(handler);
// 	}
// 
// 	public void setOutputStream(OutputStream os) throws EXIException,
// 			IOException {
// 		handler.setOutputStream(os);
// 	}
// 
// }
// 
// Path: src/main/java/com/siemens/ct/exi/main/api/sax/SAXFactory.java
// public class SAXFactory {
// 
// 	protected final EXIFactory exiFactory;
// 
// 	public SAXFactory(EXIFactory exiFactory) {
// 		this.exiFactory = exiFactory;
// 	}
// 
// 	/**
// 	 * Returns an <code>EXIReader</code>
// 	 * 
// 	 * @return reader using the previously set coding options.
// 	 * @throws EXIException
// 	 *             EXI exception
// 	 * 
// 	 */
// 	public XMLReader createEXIReader() throws EXIException {
// 		return new SAXDecoder(exiFactory);
// 	}
// 
// 	/**
// 	 * Returns a <code>SAXEncoder</code> that implements
// 	 * <code>DefaultHandler2</code>
// 	 * 
// 	 * <p>
// 	 * Note that the output stream MUST be set.
// 	 * </p>
// 	 * 
// 	 * @return writer using the previously set coding options.
// 	 * @throws EXIException
// 	 *             EXI exception
// 	 * 
// 	 */
// 	public SAXEncoder createEXIWriter() throws EXIException {
// 		final FidelityOptions fidelityOptions = exiFactory.getFidelityOptions();
// 		if (fidelityOptions.isFidelityEnabled(FidelityOptions.FEATURE_PREFIX)
// 				|| fidelityOptions
// 						.isFidelityEnabled(FidelityOptions.FEATURE_COMMENT)
// 				|| fidelityOptions
// 						.isFidelityEnabled(FidelityOptions.FEATURE_PI)
// 				|| fidelityOptions
// 						.isFidelityEnabled(FidelityOptions.FEATURE_DTD)) {
// 			return new SAXEncoderExtendedHandler(exiFactory);
// 		} else {
// 			return new SAXEncoder(exiFactory);
// 		}
// 	}
// 
// }


import java.io.BufferedInputStream;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PushbackInputStream;
import java.math.BigInteger;
import java.security.SecureRandom;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.zip.Deflater;
import java.util.zip.DeflaterOutputStream;
import java.util.zip.Inflater;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.Result;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.sax.SAXSource;
import javax.xml.transform.stream.StreamResult;
import junit.framework.AssertionFailedError;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.XMLReader;
import org.xml.sax.helpers.XMLReaderFactory;
import com.siemens.ct.exi.core.CodingMode;
import com.siemens.ct.exi.core.DecodingOptions;
import com.siemens.ct.exi.core.EXIFactory;
import com.siemens.ct.exi.core.EncodingOptions;
import com.siemens.ct.exi.core.FidelityOptions;
import com.siemens.ct.exi.core.exceptions.EXIException;
import com.siemens.ct.exi.core.helpers.DefaultEXIFactory;
import com.siemens.ct.exi.core.io.compression.EXIInflaterInputStream;
import com.siemens.ct.exi.main.api.sax.EXIResult;
import com.siemens.ct.exi.main.api.sax.SAXFactory;

		//
		String sXML = "./data/general/randj.xml";
		InputStream is = new FileInputStream(sXML);
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		int b;
		while ((b = is.read()) != -1) {
			baos.write(b);
		}
		is.close();

		ByteArrayOutputStream osEXI = new ByteArrayOutputStream();
		_testEncode(exiFactory, baos.toByteArray(), 3, osEXI);

		// add some bytes after EXI
		osEXI.write(31);
		osEXI.write(2);
		osEXI.write(99);
		osEXI.write(200);

		InputStream isEXI = new ByteArrayInputStream(osEXI.toByteArray());
		isEXI = new BufferedInputStream(isEXI);
		isEXI = new PushbackInputStream(isEXI,
				DecodingOptions.PUSHBACK_BUFFER_SIZE);
		_testDecode(exiFactory, baos.toByteArray(), 3, isEXI);

		// System.out.println(isEXI.read());
		assertTrue(isEXI.read() == 31);
		assertTrue(isEXI.read() == 2);
		assertTrue(isEXI.read() == 99);
		assertTrue(isEXI.read() == 200);

// Path: src/main/java/com/siemens/ct/exi/main/api/sax/EXIResult.java
// public class EXIResult extends SAXResult {
// 
// 	protected SAXEncoder handler;
// 
// 	public EXIResult() throws IOException, EXIException {
// 		// use default exi-factory
// 		this(DefaultEXIFactory.newInstance());
// 	}
// 
// 	public EXIResult(EXIFactory exiFactory) throws EXIException {
// 		// DefaultHandler2 handler = exiFactory.createEXIWriter(os);
// 		handler = new SAXFactory(exiFactory).createEXIWriter();
// 		// set internal states
// 		setHandler(handler);
// 		setLexicalHandler(handler);
// 	}
// 
// 	public void setOutputStream(OutputStream os) throws EXIException,
// 			IOException {
// 		handler.setOutputStream(os);
// 	}
// 
// }
// 
// Path: src/main/java/com/siemens/ct/exi/main/api/sax/SAXFactory.java
// public class SAXFactory {
// 
// 	protected final EXIFactory exiFactory;
// 
// 	public SAXFactory(EXIFactory exiFactory) {
// 		this.exiFactory = exiFactory;
// 	}
// 
// 	/**
// 	 * Returns an <code>EXIReader</code>
// 	 * 
// 	 * @return reader using the previously set coding options.
// 	 * @throws EXIException
// 	 *             EXI exception
// 	 * 
// 	 */
// 	public XMLReader createEXIReader() throws EXIException {
// 		return new SAXDecoder(exiFactory);
// 	}
// 
// 	/**
// 	 * Returns a <code>SAXEncoder</code> that implements
// 	 * <code>DefaultHandler2</code>
// 	 * 
// 	 * <p>
// 	 * Note that the output stream MUST be set.
// 	 * </p>
// 	 * 
// 	 * @return writer using the previously set coding options.
// 	 * @throws EXIException
// 	 *             EXI exception
// 	 * 
// 	 */
// 	public SAXEncoder createEXIWriter() throws EXIException {
// 		final FidelityOptions fidelityOptions = exiFactory.getFidelityOptions();
// 		if (fidelityOptions.isFidelityEnabled(FidelityOptions.FEATURE_PREFIX)
// 				|| fidelityOptions
// 						.isFidelityEnabled(FidelityOptions.FEATURE_COMMENT)
// 				|| fidelityOptions
// 						.isFidelityEnabled(FidelityOptions.FEATURE_PI)
// 				|| fidelityOptions
// 						.isFidelityEnabled(FidelityOptions.FEATURE_DTD)) {
// 			return new SAXEncoderExtendedHandler(exiFactory);
// 		} else {
// 			return new SAXEncoder(exiFactory);
// 		}
// 	}
// 
// }


// Path: src/test/java/com/siemens/ct/exi/main/data/MultipleStreamTest.java
import java.io.BufferedInputStream;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PushbackInputStream;
import java.math.BigInteger;
import java.security.SecureRandom;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.zip.Deflater;
import java.util.zip.DeflaterOutputStream;
import java.util.zip.Inflater;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.Result;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.sax.SAXSource;
import javax.xml.transform.stream.StreamResult;
import junit.framework.AssertionFailedError;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.XMLReader;
import org.xml.sax.helpers.XMLReaderFactory;
import com.siemens.ct.exi.core.CodingMode;
import com.siemens.ct.exi.core.DecodingOptions;
import com.siemens.ct.exi.core.EXIFactory;
import com.siemens.ct.exi.core.EncodingOptions;
import com.siemens.ct.exi.core.FidelityOptions;
import com.siemens.ct.exi.core.exceptions.EXIException;
import com.siemens.ct.exi.core.helpers.DefaultEXIFactory;
import com.siemens.ct.exi.core.io.compression.EXIInflaterInputStream;
import com.siemens.ct.exi.main.api.sax.EXIResult;
import com.siemens.ct.exi.main.api.sax.SAXFactory;

		//
		String sXML = "./data/general/randj.xml";
		InputStream is = new FileInputStream(sXML);
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		int b;
		while ((b = is.read()) != -1) {
			baos.write(b);
		}
		is.close();

		ByteArrayOutputStream osEXI = new ByteArrayOutputStream();
		_testEncode(exiFactory, baos.toByteArray(), 3, osEXI);

		// add some bytes after EXI
		osEXI.write(31);
		osEXI.write(2);
		osEXI.write(99);
		osEXI.write(200);

		InputStream isEXI = new ByteArrayInputStream(osEXI.toByteArray());
		isEXI = new BufferedInputStream(isEXI);
		isEXI = new PushbackInputStream(isEXI,
				DecodingOptions.PUSHBACK_BUFFER_SIZE);
		_testDecode(exiFactory, baos.toByteArray(), 3, isEXI);

		// System.out.println(isEXI.read());
		assertTrue(isEXI.read() == 31);
		assertTrue(isEXI.read() == 2);
		assertTrue(isEXI.read() == 99);
		assertTrue(isEXI.read() == 200);

		assertTrue(isEXI.read() == -1);
