Package net.sf.cram.structure

Examples of net.sf.cram.structure.Block


      throws IOException {

    long time1 = System.nanoTime();
    ExposedByteArrayOutputStream baos = new ExposedByteArrayOutputStream();

    Block block = new CompressionHeaderBLock(c.h);
    block.write(baos);
    c.blockCount = 1;

    List<Integer> landmarks = new ArrayList<Integer>();
    SliceIO sio = new SliceIO();
    for (int i = 0; i < c.slices.length; i++) {
View Full Code Here


    return headerOS.toByteArray();
  }

  private static long writeContainer(SAMFileHeader samFileHeader,
      OutputStream os) throws IOException {
    Block block = new Block();
    block.setRawContent(toByteArray(samFileHeader));
    block.method = BlockCompressionMethod.RAW.ordinal();
    block.contentId = 0;
    block.contentType = BlockContentType.FILE_HEADER;
    block.compress();

    Container c = new Container();
    c.blockCount = 1;
    c.blocks = new Block[] { block };
    c.landmarks = new int[0];
    c.slices = new Slice[0];
    c.alignmentSpan = 0;
    c.alignmentStart = 0;
    c.bases = 0;
    c.globalRecordCounter = 0;
    c.nofRecords = 0;
    c.sequenceId = 0;

    ExposedByteArrayOutputStream baos = new ExposedByteArrayOutputStream();
    block.write(baos);
    c.containerByteSize = baos.size();

    ContainerHeaderIO chio = new ContainerHeaderIO();
    int len = chio.writeContainerHeader(c, os);
    os.write(baos.getBuffer(), 0, baos.size());
View Full Code Here

  }

  private static SAMFileHeader readSAMFileHeader(String id, InputStream is)
      throws IOException {
    Container readContainerHeader = readContainerHeader(is);
    Block b = new Block(is, true, true);

    is = new ByteArrayInputStream(b.getRawContent());

    ByteBuffer buf = ByteBuffer.allocate(4);
    buf.order(ByteOrder.LITTLE_ENDIAN);
    for (int i = 0; i < 4; i++)
      buf.put((byte) is.read());
View Full Code Here

    slice.contentType = slice.alignmentSpan > -1 ? BlockContentType.MAPPED_SLICE
        : BlockContentType.RESERVED;

    bos.close();
    slice.coreBlock = new Block();
    slice.coreBlock.method = BlockCompressionMethod.RAW.ordinal();
    slice.coreBlock.setRawContent(bitBAOS.toByteArray());
    slice.coreBlock.contentType = BlockContentType.CORE;

    slice.external = new HashMap<Integer, Block>();
    for (Integer i : map.keySet()) {
      ExposedByteArrayOutputStream os = map.get(i);

      Block externalBlock = new Block();
      externalBlock.contentType = BlockContentType.EXTERNAL;
      externalBlock.method = BlockCompressionMethod.GZIP.ordinal();
      externalBlock.contentId = i;

      externalBlock.setRawContent(os.toByteArray());
      slice.external.put(i, externalBlock);
    }

    return slice;
  }
View Full Code Here

  public static byte[] BYTES = new byte[1024 * 1024];

  @Test
  public void testBlock() throws IOException {
    Block b = new Block(BlockCompressionMethod.GZIP.ordinal(),
        BlockContentType.CORE, 0, "123457890".getBytes(), null);

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    b.write(baos);

    ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
    Block b2 = new Block(bais, true, true);

    assertArrayEquals(b.getRawContent(), b2.getRawContent());
  }
View Full Code Here

    s.embeddedRefBlockContentID = -1;
    s.globalRecordCounter = 16;
    s.nofRecords = 17;
    s.sequenceId = 18;
    s.refMD5 = "1234567890123456".getBytes();
    s.coreBlock = new Block(BlockCompressionMethod.GZIP.ordinal(),
        BlockContentType.CORE, 0, "core123457890".getBytes(), null);

    s.external = new HashMap<Integer, Block>();
    for (int i = 1; i < 5; i++) {
      Block e1 = new Block(BlockCompressionMethod.GZIP.ordinal(),
          BlockContentType.EXTERNAL, i,
          "external123457890".getBytes(), null);
      s.external.put(i, e1);
    }

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    SliceIO sio = new SliceIO();
    sio.write(s, baos);

    ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
    Slice s2 = new Slice();
    sio.read(s2, bais);

    assertEquals(s.contentIDs.length, s2.external.size());
    assertArrayEquals(s.headerBlock.getRawContent(),
        s2.headerBlock.getRawContent());
    assertArrayEquals(s.coreBlock.getRawContent(),
        s2.coreBlock.getRawContent());

    for (int id : s.contentIDs) {
      Block e1 = s.external.get(id);
      Block e2 = s2.external.get(id);
      assertArrayEquals(e1.getRawContent(), e2.getRawContent());

    }
  }
View Full Code Here

TOP

Related Classes of net.sf.cram.structure.Block

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.