public long[] decodeBandLong(String name, InputStream in, BHSDCodec codec,
int count) throws IOException, Pack200Exception {
if (codec.getB() == 1 || count == 0) {
return codec.decode(count, in);
}
Codec codecUsed = codec;
long[] band;
long[] getFirst = codec.decode(1, in);
if (getFirst.length == 0) {
return getFirst;
}
long first = getFirst[0];
if (codec.isSigned() && first >= -256 && first <= -1) {
// Non-default codec should be used
codecUsed = CodecEncoding.getCodec((int) (-1 - first), header
.getBandHeadersInputStream(), codec);
band = codecUsed.decode(count, in);
} else if (!codec.isSigned() && first >= codec.getL()
&& first <= codec.getL() + 255) {
// Non-default codec should be used
codecUsed = CodecEncoding.getCodec((int) first - codec.getL(),
header.getBandHeadersInputStream(), codec);
band = codecUsed.decode(count, in);
} else {
// First element should not be discarded
band = codec.decode(count - 1, in, first);
}
if (codecUsed instanceof BHSDCodec && ((BHSDCodec) codecUsed).isDelta()) {
BHSDCodec bhsd = (BHSDCodec) codecUsed;
long cardinality = bhsd.cardinality();
for (int i = 0; i < band.length; i++) {
while (band[i] > bhsd.largest()) {
band[i] -= cardinality;
}
while (band[i] < bhsd.smallest()) {
band[i] += cardinality;
}
}
} else if (codecUsed instanceof PopulationCodec) {
PopulationCodec popCodec = (PopulationCodec) codecUsed;
long[] favoured = (long[]) popCodec.getFavoured().clone();
Arrays.sort(favoured);
for (int i = 0; i < band.length; i++) {
boolean favouredValue = Arrays.binarySearch(favoured, band[i]) > -1;
Codec theCodec = favouredValue ? popCodec.getFavouredCodec()
: popCodec.getUnvafouredCodec();
if (theCodec instanceof BHSDCodec
&& ((BHSDCodec) theCodec).isDelta()) {
BHSDCodec bhsd = (BHSDCodec) theCodec;
long cardinality = bhsd.cardinality();