// Path: src/main/java/net/sf/cram/CramTools.java
// public static class LevelConverter implements IStringConverter<Log.LogLevel> {
// 
// 	@Override
// 	public Log.LogLevel convert(String s) {
// 		return Log.LogLevel.valueOf(s.toUpperCase());
// 	}
// 
// }


import htsjdk.samtools.SAMFileHeader;
import htsjdk.samtools.SAMSequenceRecord;
import htsjdk.samtools.SamReader;
import htsjdk.samtools.SamReaderFactory;
import htsjdk.samtools.cram.build.CramIO;
import htsjdk.samtools.cram.structure.CramHeader;
import htsjdk.samtools.util.Log;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.zip.GZIPOutputStream;
import net.sf.cram.CramTools.LevelConverter;
import com.beust.jcommander.JCommander;
import com.beust.jcommander.Parameter;
import com.beust.jcommander.Parameters;
import com.beust.jcommander.converters.FileConverter;

	private static void copy(InputStream in, OutputStream out, int lineLength) throws IOException {
		int count;
		byte[] buffer = new byte[8192];
		int posInLine = 0, posInBuf = 0;
		while ((count = in.read(buffer)) > -1) {
			posInBuf = 0;
			while (posInBuf < count) {
				for (; posInLine < lineLength && posInBuf < count; posInLine++) {
					out.write(buffer[posInBuf++]);
				}
				if (posInLine >= lineLength) {
					posInLine = 0;
					out.write('\n');
				}
			}
		}
		if (posInLine > 0)
			out.write('\n');
	}

	private static InputStream getInputStreamForMD5(String md5) throws IOException {
		String urlString = String.format("http://www.ebi.ac.uk/ena/cram/md5/%s", md5);
		URL url = new URL(urlString);
		return url.openStream();
	}

	@Parameters(commandDescription = "Download reference sequences.")
	static class Params {

// Path: src/main/java/net/sf/cram/CramTools.java
// public static class LevelConverter implements IStringConverter<Log.LogLevel> {
// 
// 	@Override
// 	public Log.LogLevel convert(String s) {
// 		return Log.LogLevel.valueOf(s.toUpperCase());
// 	}
// 
// }


// Path: src/main/java/net/sf/cram/DownloadReferences.java
import htsjdk.samtools.SAMFileHeader;
import htsjdk.samtools.SAMSequenceRecord;
import htsjdk.samtools.SamReader;
import htsjdk.samtools.SamReaderFactory;
import htsjdk.samtools.cram.build.CramIO;
import htsjdk.samtools.cram.structure.CramHeader;
import htsjdk.samtools.util.Log;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.zip.GZIPOutputStream;
import net.sf.cram.CramTools.LevelConverter;
import com.beust.jcommander.JCommander;
import com.beust.jcommander.Parameter;
import com.beust.jcommander.Parameters;
import com.beust.jcommander.converters.FileConverter;


	private static void copy(InputStream in, OutputStream out, int lineLength) throws IOException {
		int count;
		byte[] buffer = new byte[8192];
		int posInLine = 0, posInBuf = 0;
		while ((count = in.read(buffer)) > -1) {
			posInBuf = 0;
			while (posInBuf < count) {
				for (; posInLine < lineLength && posInBuf < count; posInLine++) {
					out.write(buffer[posInBuf++]);
				}
				if (posInLine >= lineLength) {
					posInLine = 0;
					out.write('\n');
				}
			}
		}
		if (posInLine > 0)
			out.write('\n');
	}

	private static InputStream getInputStreamForMD5(String md5) throws IOException {
		String urlString = String.format("http://www.ebi.ac.uk/ena/cram/md5/%s", md5);
		URL url = new URL(urlString);
		return url.openStream();
	}

	@Parameters(commandDescription = "Download reference sequences.")
	static class Params {

		@Parameter(names = { "-l", "--log-level" }, description = "Change log level: DEBUG, INFO, WARNING, ERROR.", converter = LevelConverter.class)