- * If a file is supplied then it will be wrapped into a SeekableStream. If - * file is null, then the fromIS argument will be used or System.in if null. - * Optionally the input can be decrypted using provided password or the - * password read from the console. - *
- * The method also checks for EOF marker and raise error if the marker is
- * not found for files with version 2.1 or greater. For version below 2.1 a
- * warning will be issued.
- *
- * @param cramFile
- * CRAM file to be read
- * @param fromIS
- * input stream to be read
- * @param decrypt
- * decrypt the input stream
- * @param password
- * a password to use for decryption
- * @return an InputStream ready to be used for reading CRAM file definition
- * @throws IOException
- * @throws URISyntaxException
- */
- public static InputStream openCramInputStream(String cramURL, boolean decrypt, String password) throws IOException,
- URISyntaxException {
-
- InputStream is = null;
- if (cramURL == null)
- is = new BufferedInputStream(System.in);
- else
- is = openInputStreamFromURL(cramURL);
-
- if (decrypt) {
- //disabled due to unresolved dependency to SeekableCipherStream_256 and CipherInputStream_256
- throw new SAMException("Encryption not supported in this version.") ;
-// char[] pass = null;
-// if (password == null) {
-// if (System.console() == null)
-// throw new RuntimeException("Cannot access console.");
-// pass = System.console().readPassword();
-// } else
-// pass = password.toCharArray();
-//
-// if (is instanceof SeekableStream)
-// is = new SeekableCipherStream_256((SeekableStream) is, pass, 1, 128);
-// else
-// is = new CipherInputStream_256(is, pass, 128).getCipherInputStream();
-
- }
-
- if (is instanceof SeekableStream) {
- CramHeader cramHeader = CramIO.readFormatDefinition(is, new CramHeader());
- SeekableStream s = (SeekableStream) is;
- if (!CramIO.hasZeroB_EOF_marker(s))
- eofNotFound(cramHeader.getMajorVersion(), cramHeader.getMinorVersion());
- s.seek(0);
- } else
- log.warn("CRAM file/stream completion cannot be verified.");
-
- return is;
- }
-
- private static void eofNotFound(byte major, byte minor) {
- if (major >= 2 && minor >= 1) {
- log.error("Incomplete data: EOF marker not found.");
- System.exit(1);
- } else {
- log.warn("EOF marker not found, possibly incomplete file/stream.");
- }
- }
-
- /**
- * Reads a CRAM container from the input stream. Returns an EOF container
- * when there is no more data or the EOF marker found.
- *
- * @param cramHeader
- * @param is
- * @return
- * @throws IOException
- */
- public static Container readContainer(CramHeader cramHeader, InputStream is) throws IOException {
- Container c = CramIO.readContainer(is);
- if (c == null) {
- // this will cause System.exit(1):
- eofNotFound(cramHeader.getMajorVersion(), cramHeader.getMinorVersion());
- return CramIO.readContainer(new ByteArrayInputStream(CramIO.ZERO_B_EOF_MARKER));
- }
- if (c.isEOF())
- log.debug("EOF marker found, file/stream is complete.");
-
- return c;
- }
-
- public static long issueZeroB_EOF_marker(OutputStream os) throws IOException {
- os.write(ZERO_B_EOF_MARKER);
- return ZERO_B_EOF_MARKER.length;
- }
-
- public static boolean hasZeroB_EOF_marker(SeekableStream s) throws IOException {
- byte[] tail = new byte[ZERO_B_EOF_MARKER.length];
-
- s.seek(s.length() - ZERO_B_EOF_MARKER.length);
- ByteBufferUtils.readFully(tail, s);
-
- // relaxing the ITF8 hanging bits:
- tail[8] |= 0xf0;
- return Arrays.equals(tail, ZERO_B_EOF_MARKER);
- }
-
- public static boolean hasZeroB_EOF_marker(File file) throws IOException {
- byte[] tail = new byte[ZERO_B_EOF_MARKER.length];
-
- RandomAccessFile raf = new RandomAccessFile(file, "r");
- try {
- raf.seek(file.length() - ZERO_B_EOF_MARKER.length);
- raf.readFully(tail);
- } catch (IOException e) {
- throw e;
- } finally {
- raf.close();
- }
-
- // relaxing the ITF8 hanging bits:
- tail[8] |= 0xf0;
- return Arrays.equals(tail, ZERO_B_EOF_MARKER);
- }
-
- public static long writeCramHeader(CramHeader h, OutputStream os) throws IOException {
- os.write("CRAM".getBytes("US-ASCII"));
- os.write(h.getMajorVersion());
- os.write(h.getMinorVersion());
- os.write(h.id);
- for (int i = h.id.length; i < 20; i++)
- os.write(0);
-
- long len = writeContainerForSamFileHeader(h.getSamFileHeader(), os);
-
- return DEFINITION_LENGTH + len;
- }
-
- private static CramHeader readFormatDefinition(InputStream is, CramHeader header) throws IOException {
- for (byte b : CramHeader.magick) {
- if (b != is.read())
- throw new RuntimeException("Unknown file format.");
- }
-
- header.setMajorVersion((byte) is.read());
- header.setMinorVersion((byte) is.read());
-
- DataInputStream dis = new DataInputStream(is);
- dis.readFully(header.id);
-
- return header;
- }
-
- public static CramHeader readCramHeader(InputStream is) throws IOException {
- CramHeader header = new CramHeader();
-
- readFormatDefinition(is, header);
-
- header.setSamFileHeader(readSAMFileHeader(new String(header.id), is));
- return header;
- }
-
- public static int writeContainer(Container c, OutputStream os) throws IOException {
-
- long time1 = System.nanoTime();
- ExposedByteArrayOutputStream baos = new ExposedByteArrayOutputStream();
-
- Block block = new CompressionHeaderBLock(c.h);
- block.write(baos);
- c.blockCount = 1;
-
- List
* A hash map that uses primitive ints for the key rather than objects.
*
* Note that this class is for internal optimization purposes only, and may not
* be supported in future releases of Apache Commons Lang. Utilities of this
* sort may be included in future releases of Apache Commons Collections.
*
- * Innerclass that acts as a datastructure to create a new entry in the
- * table.
- *
- * Create a new entry with the given values.
- *
- * Constructs a new, empty hashtable with a default capacity and load
- * factor, which is
- * Constructs a new, empty hashtable with the specified initial capacity and
- * default load factor, which is
- * Constructs a new, empty hashtable with the specified initial capacity and
- * the specified load factor.
- *
- * Returns the number of keys in this hashtable.
- *
- * Tests if this hashtable maps no keys to values.
- *
- * Tests if some key maps into the specified value in this hashtable. This
- * operation is more expensive than the
- * Note that this method is identical in functionality to containsValue,
- * (which is part of the Map interface in the collections framework).
- *
- * Returns
- * Note that this method is identical in functionality to contains (which
- * predates the Map interface).
- *
- * Tests if the specified object is a key in this hashtable.
- *
- * Returns the value to which the specified key is mapped in this map.
- *
- * Increases the capacity of and internally reorganizes this hashtable, in
- * order to accommodate and access its entries more efficiently.
- *
- * This method is called automatically when the number of keys in the
- * hashtable exceeds this hashtable's capacity and load factor.
- *
- * Maps the specified
- * The value can be retrieved by calling the
- * Removes the key (and its corresponding value) from this hashtable.
- *
- * This method does nothing if the key is not present in the hashtable.
- *
- * Clears this hashtable so that it contains no keys.
- * 20
and 0.75
respectively.
- * 0.75
.
- * true
if this hashtable maps no keys to values;
- * false
otherwise.
- */
- public boolean isEmpty() {
- return count == 0;
- }
-
- /**
- * containsKey
method.
- * true
if and only if some key maps to the
- * value
argument in this hashtable as determined by
- * the equals method; false
otherwise.
- * @throws NullPointerException
- * if the value is null
.
- * @see #containsKey(int)
- * @see #containsValue(Object)
- * @see java.util.Map
- */
- public boolean contains(Object value) {
- if (value == null) {
- throw new NullPointerException();
- }
-
- Entrytrue
if this HashMap maps one or more keys to this
- * value.
- * true
if the value is contained
- * @see java.util.Map
- * @since JDK1.2
- */
- public boolean containsValue(Object value) {
- return contains(value);
- }
-
- /**
- * true
if and only if the specified object is a key in
- * this hashtable, as determined by the equals method;
- * false
otherwise.
- * @see #contains(Object)
- */
- public boolean containsKey(int key) {
- Entrynull
if the key is not mapped to any value in this
- * hashtable.
- * @see #put(int, Object)
- */
- public T get(int key) {
- Entrykey
to the specified value
- * in this hashtable. The key cannot be null
.
- * get
method with a
- * key that is equal to the original key.
- * null
if it did not have one.
- * @throws NullPointerException
- * if the key is null
.
- * @see #get(int)
- */
- public Object put(int key, T value) {
- // Makes sure the key is not already in the hashtable.
- Entrynull
if the key did not have a mapping.
- */
- public Object remove(int key) {
- Entry