1
1
package htsjdk .samtools .cram .compression .range ;
2
2
3
3
import htsjdk .samtools .cram .CRAMException ;
4
+ import htsjdk .samtools .cram .compression .BZIP2ExternalCompressor ;
4
5
import java .nio .ByteBuffer ;
5
6
import java .nio .ByteOrder ;
6
7
import java .util .ArrayList ;
@@ -15,7 +16,7 @@ public ByteBuffer compress(final ByteBuffer inBuffer, final RangeParams rangePar
15
16
return EMPTY_BUFFER ;
16
17
}
17
18
18
- final ByteBuffer outBuffer = allocateOutputBuffer (inBuffer .remaining ());
19
+ ByteBuffer outBuffer = allocateOutputBuffer (inBuffer .remaining ());
19
20
outBuffer .order (ByteOrder .BIG_ENDIAN );
20
21
final int formatFlags = rangeParams .getFormatFlags ();
21
22
outBuffer .put ((byte ) (formatFlags ));
@@ -67,8 +68,14 @@ public ByteBuffer compress(final ByteBuffer inBuffer, final RangeParams rangePar
67
68
outBuffer .rewind (); // set position to 0
68
69
return outBuffer ;
69
70
} else if (rangeParams .isExternalCompression ()){
70
-
71
- // TODO
71
+ byte [] rawBytes = new byte [inputBuffer .remaining ()];
72
+ inputBuffer .get ( rawBytes ,inBuffer .position (), inputBuffer .remaining ());
73
+ final BZIP2ExternalCompressor compressor = new BZIP2ExternalCompressor ();
74
+ final byte [] extCompressedBytes = compressor .compress (rawBytes );
75
+ outBuffer .put (extCompressedBytes );
76
+ outBuffer .limit (outBuffer .position ());
77
+ outBuffer .rewind (); // set position to 0
78
+ return outBuffer ;
72
79
} else if (rangeParams .isRLE ()){
73
80
switch (rangeParams .getOrder ()) {
74
81
case ZERO :
@@ -85,17 +92,7 @@ public ByteBuffer compress(final ByteBuffer inBuffer, final RangeParams rangePar
85
92
}
86
93
87
94
}
88
-
89
- // // step 1: Encode meta-data
90
- // var pack_meta
91
- // if (flags & ARITH_PACK)
92
- // [pack_meta, src, e_len] = this.encodePack(src)
93
- //
94
- // // step 2: Write any meta data
95
- // if (flags & ARITH_PACK)
96
- // this.stream.WriteStream(pack_meta)
97
-
98
- return inBuffer ;
95
+ return outBuffer ;
99
96
}
100
97
101
98
private ByteBuffer compressOrder0 (
@@ -268,7 +265,6 @@ private ByteBuffer compressRLEOrder1 (
268
265
return outBuffer ;
269
266
}
270
267
271
-
272
268
protected ByteBuffer allocateOutputBuffer (final int inSize ) {
273
269
274
270
// same as the allocateOutputBuffer in RANS4x8Encode and RANSNx16Encode
0 commit comments