• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package com.googlecode.mp4parser.boxes.piff;
2 
3 
4 import com.coremedia.iso.Hex;
5 
6 import java.lang.Class;
7 import java.lang.IllegalAccessException;
8 import java.lang.InstantiationException;
9 import java.lang.Object;
10 import java.lang.Override;
11 import java.lang.RuntimeException;
12 import java.lang.String;
13 import java.lang.StringBuilder;
14 import java.nio.ByteBuffer;
15 import java.util.HashMap;
16 import java.util.Map;
17 import java.util.UUID;
18 
19 
20 public 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
equals(Object obj)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 
createFor(UUID systemId, ByteBuffer bufferWrapper)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 
parse(ByteBuffer buffer)57     public void parse(ByteBuffer buffer) {
58         data = buffer;
59 
60     }
61 
getData()62     public ByteBuffer getData() {
63         return data;
64     }
65 
66     @Override
toString()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