// Path: segment/src/main/java/net/loomchild/segment/util/IORuntimeException.java
// public class IORuntimeException extends RuntimeException {
// 
// 	private static final long serialVersionUID = -6587044052300876023L;
// 
// 	public IORuntimeException(IOException exception) {
// 		super(exception);
// 	}
// 
// 	public void rethrow() throws IOException {
// 		throw (IOException) getCause();
// 	}
// 
// }
// 
// Path: segment/src/main/java/net/loomchild/segment/util/XmlException.java
// public class XmlException extends RuntimeException {
// 
// 	private static final long serialVersionUID = -143693366659133245L;
// 
// 	public XmlException(String message) {
// 		super(message);
// 	}
// 
// 	public XmlException(String message, Throwable cause) {
// 		super(message, cause);
// 	}
// 
// 	public XmlException(Throwable cause) {
// 		super(cause);
// 	}
// 
// }


import java.io.BufferedReader;
import java.io.IOException;
import java.io.Reader;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import net.loomchild.segment.util.IORuntimeException;
import net.loomchild.segment.util.XmlException;
	}

	/**
	 * Returns SRX document version. Works simply by looking in document header
	 * of length {@link #HEADER_BUFFER_LENGHT} 
	 * and trying to match version regular expression, so it is imperfect.
	 * It must be possible to mark the given reader ({@link Reader#mark(int)}).
	 * 
	 * @param reader buffered reader containing SRX document with unknown version
	 * @return version string
	 * @throws IORuntimeException if IO error occurs
	 * @throws IllegalArgumentException if reader does not support marking 
	 */
	public static SrxVersion parse(BufferedReader reader) {
		try {
			if (!reader.markSupported()) {
				throw new IllegalArgumentException("Mark not supported for reader.");
			}
			reader.mark(HEADER_BUFFER_LENGHT);
			char[] headerBuffer = new char[HEADER_BUFFER_LENGHT];
			int count = reader.read(headerBuffer);
			String header = new String(headerBuffer, 0, count);
			reader.reset();
			Matcher matcher = VERSION_PATTERN.matcher(header);
			String versionString = null;
			if (matcher.find()) {
				versionString = matcher.group(1);
			}
			return parse(versionString);
		} catch (IOException e) {
// Path: segment/src/main/java/net/loomchild/segment/util/IORuntimeException.java
// public class IORuntimeException extends RuntimeException {
// 
// 	private static final long serialVersionUID = -6587044052300876023L;
// 
// 	public IORuntimeException(IOException exception) {
// 		super(exception);
// 	}
// 
// 	public void rethrow() throws IOException {
// 		throw (IOException) getCause();
// 	}
// 
// }
// 
// Path: segment/src/main/java/net/loomchild/segment/util/XmlException.java
// public class XmlException extends RuntimeException {
// 
// 	private static final long serialVersionUID = -143693366659133245L;
// 
// 	public XmlException(String message) {
// 		super(message);
// 	}
// 
// 	public XmlException(String message, Throwable cause) {
// 		super(message, cause);
// 	}
// 
// 	public XmlException(Throwable cause) {
// 		super(cause);
// 	}
// 
// }


// Path: segment/src/main/java/net/loomchild/segment/srx/io/SrxVersion.java
import java.io.BufferedReader;
import java.io.IOException;
import java.io.Reader;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import net.loomchild.segment.util.IORuntimeException;
import net.loomchild.segment.util.XmlException;

	}

	/**
	 * Returns SRX document version. Works simply by looking in document header
	 * of length {@link #HEADER_BUFFER_LENGHT} 
	 * and trying to match version regular expression, so it is imperfect.
	 * It must be possible to mark the given reader ({@link Reader#mark(int)}).
	 * 
	 * @param reader buffered reader containing SRX document with unknown version
	 * @return version string
	 * @throws IORuntimeException if IO error occurs
	 * @throws IllegalArgumentException if reader does not support marking 
	 */
	public static SrxVersion parse(BufferedReader reader) {
		try {
			if (!reader.markSupported()) {
				throw new IllegalArgumentException("Mark not supported for reader.");
			}
			reader.mark(HEADER_BUFFER_LENGHT);
			char[] headerBuffer = new char[HEADER_BUFFER_LENGHT];
			int count = reader.read(headerBuffer);
			String header = new String(headerBuffer, 0, count);
			reader.reset();
			Matcher matcher = VERSION_PATTERN.matcher(header);
			String versionString = null;
			if (matcher.find()) {
				versionString = matcher.group(1);
			}
			return parse(versionString);
		} catch (IOException e) {
			throw new IORuntimeException(e);