CompressionHeaderBuilder(final boolean coordinateSorted) { header = new CompressionHeader(); header.externalIds = new ArrayList<>(); header.tMap = new TreeMap<>(); header.encodingMap = new TreeMap<>(); header.APDelta = coordinateSorted; }
/** * Write this CompressionHeader out to an internal OutputStream, wrap it in a Block, and write that * Block out to the passed-in OutputStream. * * @param cramVersion the CRAM major version number * @param blockStream the stream to write to */ public void write(final Version cramVersion, final OutputStream blockStream) { try (final ByteArrayOutputStream internalOutputStream = new ByteArrayOutputStream()) { internalWrite(internalOutputStream); final Block block = Block.createRawCompressionHeaderBlock(internalOutputStream.toByteArray()); block.write(cramVersion.major, blockStream); } catch (final IOException e) { throw new RuntimeIOException(e); } }
/** * Read a COMPRESSION_HEADER Block from an InputStream and return its contents as a CompressionHeader * We do this instead of reading the InputStream directly because the Block content may be compressed * * @param cramVersion the CRAM version * @param blockStream the stream to read from * @return a new CompressionHeader from the input */ public static CompressionHeader read(final int cramVersion, final InputStream blockStream) { final Block block = Block.read(cramVersion, blockStream); if (block.getContentType() != BlockContentType.COMPRESSION_HEADER) throw new RuntimeIOException("Compression Header Block expected, found: " + block.getContentType().name()); try (final ByteArrayInputStream internalStream = new ByteArrayInputStream(block.getUncompressedContent())) { final CompressionHeader header = new CompressionHeader(); header.internalRead(internalStream); return header; } catch (final IOException e) { throw new RuntimeIOException(e); } }
@SuppressWarnings("SameParameterValue") private static Container readContainer(final int major, final InputStream inputStream, final int fromSlice, int howManySlices) throws IOException { final Container container = readContainerHeader(major, inputStream); if (container.isEOF()) { return container; } container.header = CompressionHeader.read(major, inputStream); howManySlices = Math.min(container.landmarks.length, howManySlices); if (fromSlice > 0) //noinspection ResultOfMethodCallIgnored inputStream.skip(container.landmarks[fromSlice]); final List<Slice> slices = new ArrayList<Slice>(); for (int sliceCount = fromSlice; sliceCount < howManySlices - fromSlice; sliceCount++) { final Slice slice = new Slice(); SliceIO.read(major, slice, inputStream); slice.index = sliceCount; slices.add(slice); } container.slices = slices.toArray(new Slice[slices.size()]); calculateSliceOffsetsAndSizes(container); log.debug("READ CONTAINER: " + container.toString()); return container; }
container.header.write(version, byteArrayOutputStream); container.blockCount = 1;
final byte[] dictionaryBytes = new byte[size]; buffer.get(dictionaryBytes); dictionary = parseDictionary(dictionaryBytes); } else if (SM_substitutionMatrix.equals(key)) {
final byte[] dictionaryBytes = dictionaryToByteArray(); ITF8.writeUnsignedITF8(dictionaryBytes.length, mapBuffer); mapBuffer.put(dictionaryBytes);
/** * Read a COMPRESSION_HEADER Block from an InputStream and return its contents as a CompressionHeader * We do this instead of reading the InputStream directly because the Block content may be compressed * * @param cramVersion the CRAM version * @param blockStream the stream to read from * @return a new CompressionHeader from the input */ public static CompressionHeader read(final int cramVersion, final InputStream blockStream) { final Block block = Block.read(cramVersion, blockStream); if (block.getContentType() != BlockContentType.COMPRESSION_HEADER) throw new RuntimeIOException("Compression Header Block expected, found: " + block.getContentType().name()); try (final ByteArrayInputStream internalStream = new ByteArrayInputStream(block.getUncompressedContent())) { final CompressionHeader header = new CompressionHeader(); header.internalRead(internalStream); return header; } catch (final IOException e) { throw new RuntimeIOException(e); } }
@SuppressWarnings("SameParameterValue") private static Container readContainer(final int major, final InputStream inputStream, final int fromSlice, int howManySlices) { final Container container = readContainerHeader(major, inputStream); if (container.isEOF()) { return container; } container.header = CompressionHeader.read(major, inputStream); howManySlices = Math.min(container.landmarks.length, howManySlices); try { if (fromSlice > 0) //noinspection ResultOfMethodCallIgnored inputStream.skip(container.landmarks[fromSlice]); } catch (final IOException e) { throw new RuntimeIOException(e); } final List<Slice> slices = new ArrayList<Slice>(); for (int sliceCount = fromSlice; sliceCount < howManySlices - fromSlice; sliceCount++) { final Slice slice = new Slice(); SliceIO.read(major, slice, inputStream); slice.index = sliceCount; slices.add(slice); } container.slices = slices.toArray(new Slice[slices.size()]); calculateSliceOffsetsAndSizes(container); log.debug("READ CONTAINER: " + container.toString()); return container; }
container.header.write(version, byteArrayOutputStream); container.blockCount = 1;
final byte[] dictionaryBytes = new byte[size]; buffer.get(dictionaryBytes); dictionary = parseDictionary(dictionaryBytes); } else if (SM_substitutionMatrix.equals(key)) {
final byte[] dictionaryBytes = dictionaryToByteArray(); ITF8.writeUnsignedITF8(dictionaryBytes.length, mapBuffer); mapBuffer.put(dictionaryBytes);
CompressionHeaderBuilder(final boolean coordinateSorted) { header = new CompressionHeader(); header.externalIds = new ArrayList<>(); header.tMap = new TreeMap<>(); header.encodingMap = new TreeMap<>(); header.APDelta = coordinateSorted; }
/** * Write this CompressionHeader out to an internal OutputStream, wrap it in a Block, and write that * Block out to the passed-in OutputStream. * * @param cramVersion the CRAM major version number * @param blockStream the stream to write to */ public void write(final Version cramVersion, final OutputStream blockStream) { try (final ByteArrayOutputStream internalOutputStream = new ByteArrayOutputStream()) { internalWrite(internalOutputStream); final Block block = Block.createRawCompressionHeaderBlock(internalOutputStream.toByteArray()); block.write(cramVersion.major, blockStream); } catch (final IOException e) { throw new RuntimeIOException(e); } }