| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
|
| 18 | |
|
| 19 | |
package org.jaudiotagger.audio.asf.io; |
| 20 | |
|
| 21 | |
import org.jaudiotagger.audio.asf.data.Chunk; |
| 22 | |
import org.jaudiotagger.audio.asf.data.ContentDescriptor; |
| 23 | |
import org.jaudiotagger.audio.asf.data.ExtendedContentDescription; |
| 24 | |
import org.jaudiotagger.audio.asf.data.GUID; |
| 25 | |
import org.jaudiotagger.audio.asf.util.Utils; |
| 26 | |
|
| 27 | |
import java.io.IOException; |
| 28 | |
import java.io.InputStream; |
| 29 | |
import java.math.BigInteger; |
| 30 | |
|
| 31 | |
|
| 32 | |
|
| 33 | |
|
| 34 | |
|
| 35 | |
|
| 36 | |
|
| 37 | |
|
| 38 | |
public class ExtContentDescReader implements ChunkReader |
| 39 | |
{ |
| 40 | |
|
| 41 | |
|
| 42 | |
|
| 43 | |
|
| 44 | |
protected ExtContentDescReader() |
| 45 | 252 | { |
| 46 | |
|
| 47 | 252 | } |
| 48 | |
|
| 49 | |
|
| 50 | |
|
| 51 | |
|
| 52 | |
public boolean canFail() |
| 53 | |
{ |
| 54 | 48 | return false; |
| 55 | |
} |
| 56 | |
|
| 57 | |
|
| 58 | |
|
| 59 | |
|
| 60 | |
public GUID getApplyingId() |
| 61 | |
{ |
| 62 | 252 | return GUID.GUID_EXTENDED_CONTENT_DESCRIPTION; |
| 63 | |
} |
| 64 | |
|
| 65 | |
|
| 66 | |
|
| 67 | |
|
| 68 | |
public Chunk read(final GUID guid, final InputStream stream, final long chunkStart) throws IOException |
| 69 | |
{ |
| 70 | 48 | BigInteger chunkLen = Utils.readBig64(stream); |
| 71 | |
|
| 72 | |
|
| 73 | 48 | long descriptorCount = Utils.readUINT16(stream); |
| 74 | |
|
| 75 | |
|
| 76 | 48 | final ExtendedContentDescription result = new ExtendedContentDescription(chunkLen); |
| 77 | 1311 | for (long i = 0; i < descriptorCount; i++) |
| 78 | |
{ |
| 79 | 1263 | String tagElement = Utils.readUTF16LEStr(stream); |
| 80 | 1263 | int type = Utils.readUINT16(stream); |
| 81 | 1263 | ContentDescriptor prop = new ContentDescriptor(tagElement, type); |
| 82 | 1263 | switch (type) |
| 83 | |
{ |
| 84 | |
case ContentDescriptor.TYPE_STRING: |
| 85 | 1184 | prop.setStringValue(Utils.readUTF16LEStr(stream)); |
| 86 | 1184 | break; |
| 87 | |
case ContentDescriptor.TYPE_BINARY: |
| 88 | 26 | prop.setBinaryValue(readBinaryData(stream)); |
| 89 | 26 | break; |
| 90 | |
case ContentDescriptor.TYPE_BOOLEAN: |
| 91 | 24 | prop.setBooleanValue(readBoolean(stream)); |
| 92 | 24 | break; |
| 93 | |
case ContentDescriptor.TYPE_DWORD: |
| 94 | 27 | stream.skip(2); |
| 95 | 27 | prop.setDWordValue(Utils.readUINT32(stream)); |
| 96 | 27 | break; |
| 97 | |
case ContentDescriptor.TYPE_WORD: |
| 98 | 0 | stream.skip(2); |
| 99 | 0 | prop.setWordValue(Utils.readUINT16(stream)); |
| 100 | 0 | break; |
| 101 | |
case ContentDescriptor.TYPE_QWORD: |
| 102 | 2 | stream.skip(2); |
| 103 | 2 | prop.setQWordValue(Utils.readUINT64(stream)); |
| 104 | 2 | break; |
| 105 | |
default: |
| 106 | |
|
| 107 | |
|
| 108 | |
|
| 109 | 0 | prop.setStringValue("Invalid datatype: " + new String(readBinaryData(stream))); |
| 110 | |
} |
| 111 | 1263 | result.addDescriptor(prop); |
| 112 | |
} |
| 113 | 48 | result.setPosition(chunkStart); |
| 114 | 48 | return result; |
| 115 | |
} |
| 116 | |
|
| 117 | |
|
| 118 | |
|
| 119 | |
|
| 120 | |
|
| 121 | |
|
| 122 | |
|
| 123 | |
|
| 124 | |
private byte[] readBinaryData(InputStream stream) throws IOException |
| 125 | |
{ |
| 126 | 26 | int size = Utils.readUINT16(stream); |
| 127 | 26 | byte[] bytes = new byte[size]; |
| 128 | 26 | stream.read(bytes); |
| 129 | 26 | return bytes; |
| 130 | |
} |
| 131 | |
|
| 132 | |
|
| 133 | |
|
| 134 | |
|
| 135 | |
|
| 136 | |
|
| 137 | |
|
| 138 | |
|
| 139 | |
|
| 140 | |
|
| 141 | |
|
| 142 | |
|
| 143 | |
|
| 144 | |
private boolean readBoolean(InputStream stream) throws IOException |
| 145 | |
{ |
| 146 | 24 | int size = Utils.readUINT16(stream); |
| 147 | 24 | if (size != 4) |
| 148 | |
{ |
| 149 | 0 | throw new IllegalStateException("Boolean value do require 4 Bytes. (Size value is: " + size + ")"); |
| 150 | |
} |
| 151 | 24 | long value = Utils.readUINT32(stream); |
| 152 | 24 | boolean result = value == 1; |
| 153 | 24 | return result; |
| 154 | |
} |
| 155 | |
|
| 156 | |
} |