// Path: src/main/java/org/seqdoop/hadoop_bam/util/WrapSeekable.java
// public class WrapSeekable<S extends InputStream & Seekable>
// 	extends SeekableStream
// {
// 	private final S    stm;
// 	private final long len;
// 	private final Path path;
// 
// 	public WrapSeekable(final S s, long length, Path p) {
// 		stm  = s;
// 		len  = length;
// 		path = p;
// 	}
// 
// 	/** A helper for the common use case. */
// 	public static WrapSeekable<FSDataInputStream> openPath(
// 		FileSystem fs, Path p) throws IOException
// 	{
// 		return new WrapSeekable<FSDataInputStream>(
// 			fs.open(p), fs.getFileStatus(p).getLen(), p);
// 	}
// 	public static WrapSeekable<FSDataInputStream> openPath(
// 		Configuration conf, Path path) throws IOException
// 	{
// 		return openPath(path.getFileSystem(conf), path);
// 	}
// 
// 	@Override public String getSource() { return path.toString(); }
// 	@Override public long   length   () { return len; }
// 
// 	@Override public long position() throws IOException { return stm.getPos(); }
// 	@Override public void    close() throws IOException { stm.close(); }
// 	@Override public boolean eof  () throws IOException {
// 		return stm.getPos() == length();
// 	}
// 	@Override public void seek(long pos) throws IOException {
// 		stm.seek(pos);
// 	}
// 	@Override public int read() throws IOException {
// 		return stm.read();
// 	}
// 	@Override public int read(byte[] buf, int offset, int len)
// 		throws IOException
// 	{
// 		return stm.read(buf, offset, len);
// 	}
// }


import org.apache.hadoop.io.IOUtils;
import org.apache.hadoop.util.GenericOptionsParser;
import htsjdk.samtools.FileTruncatedException;
import htsjdk.samtools.seekablestream.SeekableStream;
import htsjdk.samtools.util.BlockCompressedInputStream;
import htsjdk.samtools.util.RuntimeEOFException;
import htsjdk.tribble.TribbleException;
import htsjdk.tribble.readers.PositionalBufferedStream;
import htsjdk.variant.bcf2.BCF2Codec;
import htsjdk.variant.vcf.VCFHeader;
import org.seqdoop.hadoop_bam.util.WrapSeekable;
import htsjdk.samtools.seekablestream.ByteArraySeekableStream;
import java.io.BufferedInputStream;
import java.io.InputStream;
import java.io.IOException;
import java.util.Arrays;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
		try {
			parser = new GenericOptionsParser(args);

		// This should be IOException but Hadoop 0.20.2 doesn't throw it...
		} catch (Exception e) {
			System.err.printf("Error in Hadoop arguments: %s\n", e.getMessage());
			System.exit(1);
			return;
		}

		args = parser.getRemainingArgs();
                final Configuration conf = parser.getConfiguration();

		long beg = 0;

		if (args.length < 2 || args.length > 3) {
			System.err.println(
				"Usage: BCFSplitGuesser path-or-uri header-path-or-uri [beg]");
			System.exit(2);
		}

		try {
			if (args.length > 2) beg = Long.decode(args[2]);
		} catch (NumberFormatException e) {
			System.err.println("Invalid beg offset.");
			if (e.getMessage() != null)
				System.err.println(e.getMessage());
			System.exit(2);
		}

// Path: src/main/java/org/seqdoop/hadoop_bam/util/WrapSeekable.java
// public class WrapSeekable<S extends InputStream & Seekable>
// 	extends SeekableStream
// {
// 	private final S    stm;
// 	private final long len;
// 	private final Path path;
// 
// 	public WrapSeekable(final S s, long length, Path p) {
// 		stm  = s;
// 		len  = length;
// 		path = p;
// 	}
// 
// 	/** A helper for the common use case. */
// 	public static WrapSeekable<FSDataInputStream> openPath(
// 		FileSystem fs, Path p) throws IOException
// 	{
// 		return new WrapSeekable<FSDataInputStream>(
// 			fs.open(p), fs.getFileStatus(p).getLen(), p);
// 	}
// 	public static WrapSeekable<FSDataInputStream> openPath(
// 		Configuration conf, Path path) throws IOException
// 	{
// 		return openPath(path.getFileSystem(conf), path);
// 	}
// 
// 	@Override public String getSource() { return path.toString(); }
// 	@Override public long   length   () { return len; }
// 
// 	@Override public long position() throws IOException { return stm.getPos(); }
// 	@Override public void    close() throws IOException { stm.close(); }
// 	@Override public boolean eof  () throws IOException {
// 		return stm.getPos() == length();
// 	}
// 	@Override public void seek(long pos) throws IOException {
// 		stm.seek(pos);
// 	}
// 	@Override public int read() throws IOException {
// 		return stm.read();
// 	}
// 	@Override public int read(byte[] buf, int offset, int len)
// 		throws IOException
// 	{
// 		return stm.read(buf, offset, len);
// 	}
// }


// Path: src/main/java/org/seqdoop/hadoop_bam/BCFSplitGuesser.java
import org.apache.hadoop.io.IOUtils;
import org.apache.hadoop.util.GenericOptionsParser;
import htsjdk.samtools.FileTruncatedException;
import htsjdk.samtools.seekablestream.SeekableStream;
import htsjdk.samtools.util.BlockCompressedInputStream;
import htsjdk.samtools.util.RuntimeEOFException;
import htsjdk.tribble.TribbleException;
import htsjdk.tribble.readers.PositionalBufferedStream;
import htsjdk.variant.bcf2.BCF2Codec;
import htsjdk.variant.vcf.VCFHeader;
import org.seqdoop.hadoop_bam.util.WrapSeekable;
import htsjdk.samtools.seekablestream.ByteArraySeekableStream;
import java.io.BufferedInputStream;
import java.io.InputStream;
import java.io.IOException;
import java.util.Arrays;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;

		try {
			parser = new GenericOptionsParser(args);

		// This should be IOException but Hadoop 0.20.2 doesn't throw it...
		} catch (Exception e) {
			System.err.printf("Error in Hadoop arguments: %s\n", e.getMessage());
			System.exit(1);
			return;
		}

		args = parser.getRemainingArgs();
                final Configuration conf = parser.getConfiguration();

		long beg = 0;

		if (args.length < 2 || args.length > 3) {
			System.err.println(
				"Usage: BCFSplitGuesser path-or-uri header-path-or-uri [beg]");
			System.exit(2);
		}

		try {
			if (args.length > 2) beg = Long.decode(args[2]);
		} catch (NumberFormatException e) {
			System.err.println("Invalid beg offset.");
			if (e.getMessage() != null)
				System.err.println(e.getMessage());
			System.exit(2);
		}

		SeekableStream ss = WrapSeekable.openPath(conf, new Path(args[0]));