1 package com.coremedia.iso.boxes.apple;
2 
3 import com.googlecode.mp4parser.AbstractFullBox;
4 
5 import java.nio.ByteBuffer;
6 
7 /**
8  * Most stupid box of the world. Encapsulates actual data within
9  */
10 public final class AppleDataBox extends AbstractFullBox {
11     public static final String TYPE = "data";
12 
13     private byte[] fourBytes = new byte[4];
14     private byte[] data;
15 
getEmpty()16     private static AppleDataBox getEmpty() {
17         AppleDataBox appleDataBox = new AppleDataBox();
18         appleDataBox.setVersion(0);
19         appleDataBox.setFourBytes(new byte[4]);
20         return appleDataBox;
21     }
22 
getStringAppleDataBox()23     public static AppleDataBox getStringAppleDataBox() {
24         AppleDataBox appleDataBox = getEmpty();
25         appleDataBox.setFlags(1);
26         appleDataBox.setData(new byte[]{0});
27         return appleDataBox;
28     }
29 
getUint8AppleDataBox()30     public static AppleDataBox getUint8AppleDataBox() {
31         AppleDataBox appleDataBox = new AppleDataBox();
32         appleDataBox.setFlags(21);
33         appleDataBox.setData(new byte[]{0});
34         return appleDataBox;
35     }
36 
getUint16AppleDataBox()37     public static AppleDataBox getUint16AppleDataBox() {
38         AppleDataBox appleDataBox = new AppleDataBox();
39         appleDataBox.setFlags(21);
40         appleDataBox.setData(new byte[]{0, 0});
41         return appleDataBox;
42     }
43 
getUint32AppleDataBox()44     public static AppleDataBox getUint32AppleDataBox() {
45         AppleDataBox appleDataBox = new AppleDataBox();
46         appleDataBox.setFlags(21);
47         appleDataBox.setData(new byte[]{0, 0, 0, 0});
48         return appleDataBox;
49     }
50 
AppleDataBox()51     public AppleDataBox() {
52         super(TYPE);
53     }
54 
getContentSize()55     protected long getContentSize() {
56         return data.length + 8;
57     }
58 
setData(byte[] data)59     public void setData(byte[] data) {
60         this.data = new byte[data.length];
61         System.arraycopy(data, 0, this.data, 0, data.length);
62     }
63 
setFourBytes(byte[] fourBytes)64     public void setFourBytes(byte[] fourBytes) {
65         System.arraycopy(fourBytes, 0, this.fourBytes, 0, 4);
66     }
67 
68     @Override
_parseDetails(ByteBuffer content)69     public void _parseDetails(ByteBuffer content) {
70         parseVersionAndFlags(content);
71         fourBytes = new byte[4];
72         content.get(fourBytes);
73         data = new byte[content.remaining()];
74         content.get(data);
75     }
76 
77 
78     @Override
getContent(ByteBuffer byteBuffer)79     protected void getContent(ByteBuffer byteBuffer) {
80         writeVersionAndFlags(byteBuffer);
81         byteBuffer.put(fourBytes, 0, 4);
82         byteBuffer.put(data);
83     }
84 
getFourBytes()85     public byte[] getFourBytes() {
86         return fourBytes;
87     }
88 
getData()89     public byte[] getData() {
90         return data;
91     }
92 }
93