ChunkOffset64BitBox.java revision dd9eb897ee7c7b507cbdcf80263bb4b5de6966bf
1package com.coremedia.iso.boxes;
2
3import com.coremedia.iso.IsoTypeReader;
4import com.coremedia.iso.IsoTypeWriter;
5
6import java.nio.ByteBuffer;
7
8import static com.googlecode.mp4parser.util.CastUtils.l2i;
9
10/**
11 * Abstract Chunk Offset Box
12 */
13public class ChunkOffset64BitBox extends ChunkOffsetBox {
14    public static final String TYPE = "co64";
15    private long[] chunkOffsets;
16
17    public ChunkOffset64BitBox() {
18        super(TYPE);
19    }
20
21    @Override
22    public long[] getChunkOffsets() {
23        return chunkOffsets;
24    }
25
26    @Override
27    protected long getContentSize() {
28        return 8 + 8 * chunkOffsets.length;
29    }
30
31    @Override
32    public void _parseDetails(ByteBuffer content) {
33        parseVersionAndFlags(content);
34        int entryCount = l2i(IsoTypeReader.readUInt32(content));
35        chunkOffsets = new long[entryCount];
36        for (int i = 0; i < entryCount; i++) {
37            chunkOffsets[i] = IsoTypeReader.readUInt64(content);
38        }
39    }
40
41    @Override
42    protected void getContent(ByteBuffer byteBuffer) {
43        writeVersionAndFlags(byteBuffer);
44        IsoTypeWriter.writeUInt32(byteBuffer, chunkOffsets.length);
45        for (long chunkOffset : chunkOffsets) {
46            IsoTypeWriter.writeUInt64(byteBuffer, chunkOffset);
47        }
48    }
49
50
51}
52