public static int writeContainer(Container c, OutputStream os)
throws IOException {
long time1 = System.nanoTime();
ExposedByteArrayOutputStream baos = new ExposedByteArrayOutputStream();
Block block = new CompressionHeaderBLock(c.h);
block.write(baos);
c.blockCount = 1;
List<Integer> landmarks = new ArrayList<Integer>();
SliceIO sio = new SliceIO();
for (int i = 0; i < c.slices.length; i++) {
Slice s = c.slices[i];
landmarks.add(baos.size());
sio.write(s, baos);
c.blockCount++ ;
c.blockCount++;
if (s.embeddedRefBlock != null)
c.blockCount++;
c.blockCount += s.external.size();
}
c.landmarks = new int[landmarks.size()];
for (int i = 0; i < c.landmarks.length; i++)
c.landmarks[i] = landmarks.get(i);
c.containerByteSize = baos.size();
calculateSliceOffsetsAndSizes(c);
ContainerHeaderIO chio = new ContainerHeaderIO();
int len = chio.writeContainerHeader(c, os);
os.write(baos.getBuffer(), 0, baos.size());
len += baos.size();
long time2 = System.nanoTime();
log.debug("CONTAINER WRITTEN: " + c.toString());
c.writeTime = time2 - time1;