1/*
2 * Copyright 2009 castLabs GmbH, Berlin
3 *
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *     http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.coremedia.iso.boxes.apple;
18
19import com.coremedia.iso.IsoFile;
20import com.coremedia.iso.IsoTypeReader;
21import com.coremedia.iso.IsoTypeWriter;
22import com.coremedia.iso.Utf8;
23import com.googlecode.mp4parser.AbstractFullBox;
24
25import java.nio.ByteBuffer;
26
27import static com.googlecode.mp4parser.util.CastUtils.l2i;
28
29public class AppleDataReferenceBox extends AbstractFullBox {
30    public static final String TYPE = "rdrf";
31    private int dataReferenceSize;
32    private String dataReferenceType;
33    private String dataReference;
34
35    public AppleDataReferenceBox() {
36        super(TYPE);
37    }
38
39
40    protected long getContentSize() {
41        return 12 + dataReferenceSize;
42    }
43
44    @Override
45    public void _parseDetails(ByteBuffer content) {
46        parseVersionAndFlags(content);
47        dataReferenceType = IsoTypeReader.read4cc(content);
48        dataReferenceSize = l2i(IsoTypeReader.readUInt32(content));
49        dataReference = IsoTypeReader.readString(content, dataReferenceSize);
50    }
51
52    @Override
53    protected void getContent(ByteBuffer byteBuffer) {
54        writeVersionAndFlags(byteBuffer);
55        byteBuffer.put(IsoFile.fourCCtoBytes(dataReferenceType));
56        IsoTypeWriter.writeUInt32(byteBuffer, dataReferenceSize);
57        byteBuffer.put(Utf8.convert(dataReference));
58    }
59
60    public long getDataReferenceSize() {
61        return dataReferenceSize;
62    }
63
64    public String getDataReferenceType() {
65        return dataReferenceType;
66    }
67
68    public String getDataReference() {
69        return dataReference;
70    }
71}
72