All Downloads are FREE. Search and download functionalities are using the official Maven repository.

htsjdk.samtools.cram.encoding.ByteArrayLenCodec Maven / Gradle / Ivy

There is a newer version: 4.3.0
Show newest version
package htsjdk.samtools.cram.encoding;

/**
 * Encode byte arrays by specifying encodings for array lengths and contents.
 *
 * NOTE: this codec is a hybrid codec in that it splits it's data between the core block
 * (where it stores the byte array length), and an external block (where it stores the actual
 * bytes). This has implications for data access, since some of it's data is interleaved with
 * other data in the core block.
 */
class ByteArrayLenCodec implements CRAMCodec {
    private final CRAMCodec lenCodec;
    private final CRAMCodec byteCodec;

    /**
     * Construct a Byte Array Len Codec by supplying a codec for length and a codec for values
     *
     * @param lenCodec the length codec, for Integers
     * @param byteCodec the value codec, for byte[]
     */
    public ByteArrayLenCodec(final CRAMCodec lenCodec,
                             final CRAMCodec byteCodec) {
        this.lenCodec = lenCodec;
        this.byteCodec = byteCodec;
    }

    @Override
    public byte[] read() {
        final int length = lenCodec.read();
        return byteCodec.read(length);
    }

    @Override
    public byte[] read(final int length) {
        throw new RuntimeException("Not implemented.");
    }

    @Override
    public void write(final byte[] object) {
        lenCodec.write(object.length);
        byteCodec.write(object);
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy