public final int numCycles;
public final int numClusters;
public ClusterIntensityFileHeader(final byte[] headerBytes, final File file) {
if(headerBytes.length < HEADER_SIZE) {
throw new PicardException("Bytes past to header constructor are too short excpected(" + HEADER_SIZE + ") received (" + headerBytes.length);
}
ByteBuffer buf = ByteBuffer.allocate(headerBytes.length); //for doing some byte conversions
buf.order(ByteOrder.LITTLE_ENDIAN);
buf.put(headerBytes);
buf.position(0);
final byte[] identifierBuf = new byte[IDENTIFIER.length];
buf.get(identifierBuf);
if (!Arrays.equals(identifierBuf, IDENTIFIER)) {
throw new PicardException("Cluster intensity file " + file + " contains unexpected header: " +
StringUtil.bytesToString(identifierBuf));
}
final byte fileVersion = buf.get();
if (fileVersion != FILE_VERSION) {
throw new PicardException("Cluster intensity file " + file + " contains unexpected version: " + fileVersion);
}
elementSize = buf.get();
if (elementSize < 1 || elementSize > 2) {
throw new PicardException("Cluster intensity file " + file + " contains unexpected element size: " + elementSize);
}
// convert these to unsigned
firstCycle = UnsignedTypeUtil.uShortToInt(buf.getShort());
numCycles = UnsignedTypeUtil.uShortToInt(buf.getShort());
if (numCycles == 0) {
throw new PicardException("Cluster intensity file " + file + " has zero cycles.");
}
numClusters = buf.getInt();
if (numClusters < 0) {
// It is possible for there to be no clusters in a tile.
throw new PicardException("Cluster intensity file " + file + " has negative number of clusters: " +numClusters);
}
}