@@ -0,0 +1,2476 @@
+package org.seqdoop.hadoop_bam;%0A%0Aimport htsjdk.samtools.util.BlockCompressedInputStream;%0Aimport htsjdk.samtools.util.BlockCompressedOutputStream;%0Aimport htsjdk.samtools.util.BlockCompressedStreamConstants;%0Aimport java.io.File;%0Aimport java.util.ArrayList;%0Aimport java.util.List;%0Aimport java.util.Random;%0Aimport org.apache.hadoop.conf.Configuration;%0Aimport org.apache.hadoop.fs.FSDataInputStream;%0Aimport org.apache.hadoop.fs.Path;%0Aimport org.junit.Test;%0Aimport org.seqdoop.hadoop_bam.util.BGZFSplitGuesser;%0A%0Aimport static org.junit.Assert.assertEquals;%0Aimport static org.junit.Assert.assertTrue;%0A%0Apublic class TestBGZFSplitGuesser %7B%0A  @Test%0A  public void test() throws Exception %7B%0A    File bgzf = File.createTempFile(%22TestBGZFSplitGuesser%22, %22.bgzf%22);%0A    BlockCompressedOutputStream bgzfOut = new BlockCompressedOutputStream(bgzf);%0A    String chars = %220123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz%22;%0A    StringBuilder data = new StringBuilder();%0A    Random r = new Random();%0A    r.setSeed(100);%0A    for (int i = 0; i %3C 1024 * 150; i++) %7B%0A      char rc = chars.charAt(r.nextInt(chars.length()));%0A      bgzfOut.write(rc);%0A      data.append(rc);%0A    %7D%0A    bgzfOut.close();%0A%0A    Configuration conf = new Configuration();%0A    Path path = new Path(bgzf.toURI());%0A    FSDataInputStream fsDataInputStream = path.getFileSystem(conf).open(path);%0A    BGZFSplitGuesser bgzfSplitGuesser = new BGZFSplitGuesser(fsDataInputStream);%0A    List%3CLong%3E boundaries = new ArrayList%3C%3E();%0A    long start = 1;%0A    while (true) %7B%0A      long end = bgzf.length();%0A      long nextStart = bgzfSplitGuesser.guessNextBGZFBlockStart(start, end);%0A      if (nextStart == end) %7B%0A        break;%0A      %7D%0A      boundaries.add(nextStart);%0A      start = nextStart + 1;%0A    %7D%0A%0A    assertEquals(3, boundaries.size());%0A%0A    for (int i = 0; i %3C boundaries.size() - 1; i++) %7B%0A      long boundary = boundaries.get(i);%0A      BlockCompressedInputStream blockCompressedInputStream = new%0A          BlockCompressedInputStream(bgzf);%0A      blockCompressedInputStream.setCheckCrcs(true);%0A      blockCompressedInputStream.seek(boundary %3C%3C 16);%0A      byte%5B%5D b = new byte%5B5%5D; // check 5 bytes after boundary%0A      blockCompressedInputStream.read(b);%0A      assertTrue(data.toString().contains(new String(b)));%0A    %7D%0A%0A    assertEquals(%22Last block start is terminator gzip block%22,%0A        bgzf.length() - BlockCompressedStreamConstants.EMPTY_GZIP_BLOCK.length,%0A        (long) boundaries.get(boundaries.size() - 1));%0A  %7D%0A%7D%0A

Add test for BGZFSplitGuesser.