1package com.googlecode.mp4parser.boxes.piff;
2
3
4import com.coremedia.iso.Hex;
5
6import java.lang.Class;
7import java.lang.IllegalAccessException;
8import java.lang.InstantiationException;
9import java.lang.Object;
10import java.lang.Override;
11import java.lang.RuntimeException;
12import java.lang.String;
13import java.lang.StringBuilder;
14import java.nio.ByteBuffer;
15import java.util.HashMap;
16import java.util.Map;
17import java.util.UUID;
18
19
20public class ProtectionSpecificHeader {
21    protected static Map<UUID, Class<? extends ProtectionSpecificHeader>> uuidRegistry = new HashMap<UUID, Class<? extends ProtectionSpecificHeader>>();
22    ByteBuffer data;
23
24    static {
25        uuidRegistry.put(UUID.fromString("9A04F079-9840-4286-AB92-E65BE0885F95"), PlayReadyHeader.class);
26    }
27
28    @Override
29    public boolean equals(Object obj) {
30        if (obj instanceof ProtectionSpecificHeader) {
31            if (this.getClass().equals(obj.getClass())) {
32                return data.equals(((ProtectionSpecificHeader) obj).data);
33            }
34        }
35        return false;
36    }
37
38    public static ProtectionSpecificHeader createFor(UUID systemId, ByteBuffer bufferWrapper) {
39        final Class<? extends ProtectionSpecificHeader> aClass = uuidRegistry.get(systemId);
40
41        ProtectionSpecificHeader protectionSpecificHeader = new ProtectionSpecificHeader();
42        if (aClass != null) {
43            try {
44                protectionSpecificHeader = aClass.newInstance();
45
46            } catch (InstantiationException e) {
47                throw new RuntimeException(e);
48            } catch (IllegalAccessException e) {
49                throw new RuntimeException(e);
50            }
51        }
52        protectionSpecificHeader.parse(bufferWrapper);
53        return protectionSpecificHeader;
54
55    }
56
57    public void parse(ByteBuffer buffer) {
58        data = buffer;
59
60    }
61
62    public ByteBuffer getData() {
63        return data;
64    }
65
66    @Override
67    public String toString() {
68        final StringBuilder sb = new StringBuilder();
69        sb.append("ProtectionSpecificHeader");
70        sb.append("{data=");
71        ByteBuffer data = getData().duplicate();
72        data.rewind();
73        byte[] bytes = new byte[data.limit()];
74        data.get(bytes);
75        sb.append(Hex.encodeHex(bytes));
76        sb.append('}');
77        return sb.toString();
78    }
79}
80