| 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.ContentDescription; |
| 23 | |
import org.jaudiotagger.audio.asf.data.GUID; |
| 24 | |
import org.jaudiotagger.audio.asf.util.Utils; |
| 25 | |
|
| 26 | |
import java.io.IOException; |
| 27 | |
import java.io.InputStream; |
| 28 | |
import java.math.BigInteger; |
| 29 | |
|
| 30 | |
|
| 31 | |
|
| 32 | |
|
| 33 | |
|
| 34 | |
|
| 35 | |
|
| 36 | |
public class ContentDescriptionReader implements ChunkReader { |
| 37 | |
|
| 38 | |
|
| 39 | |
|
| 40 | |
|
| 41 | 4 | private final static GUID[] APPLYING = { GUID.GUID_CONTENTDESCRIPTION }; |
| 42 | |
|
| 43 | |
|
| 44 | |
|
| 45 | |
|
| 46 | 24 | protected ContentDescriptionReader() { |
| 47 | |
|
| 48 | 24 | } |
| 49 | |
|
| 50 | |
|
| 51 | |
|
| 52 | |
|
| 53 | |
public boolean canFail() { |
| 54 | 295 | return false; |
| 55 | |
} |
| 56 | |
|
| 57 | |
|
| 58 | |
|
| 59 | |
|
| 60 | |
public GUID[] getApplyingIds() { |
| 61 | 24 | return APPLYING.clone(); |
| 62 | |
} |
| 63 | |
|
| 64 | |
|
| 65 | |
|
| 66 | |
|
| 67 | |
|
| 68 | |
|
| 69 | |
|
| 70 | |
|
| 71 | |
|
| 72 | |
|
| 73 | |
private int[] getStringSizes(final InputStream stream) throws IOException { |
| 74 | 295 | final int[] result = new int[5]; |
| 75 | 1770 | for (int i = 0; i < result.length; i++) { |
| 76 | 1475 | result[i] = Utils.readUINT16(stream); |
| 77 | |
} |
| 78 | 295 | return result; |
| 79 | |
} |
| 80 | |
|
| 81 | |
|
| 82 | |
|
| 83 | |
|
| 84 | |
public Chunk read(final GUID guid, final InputStream stream, |
| 85 | |
final long chunkStart) throws IOException { |
| 86 | 295 | final BigInteger chunkSize = Utils.readBig64(stream); |
| 87 | |
|
| 88 | |
|
| 89 | |
|
| 90 | |
|
| 91 | 295 | final int[] stringSizes = getStringSizes(stream); |
| 92 | |
|
| 93 | |
|
| 94 | |
|
| 95 | |
|
| 96 | 295 | final String[] strings = new String[stringSizes.length]; |
| 97 | 1770 | for (int i = 0; i < strings.length; i++) { |
| 98 | 1475 | if (stringSizes[i] > 0) { |
| 99 | 1299 | strings[i] = Utils |
| 100 | |
.readFixedSizeUTF16Str(stream, stringSizes[i]); |
| 101 | |
} |
| 102 | |
} |
| 103 | |
|
| 104 | |
|
| 105 | |
|
| 106 | 295 | final ContentDescription result = new ContentDescription(chunkStart, |
| 107 | |
chunkSize); |
| 108 | 295 | if (stringSizes[0] > 0) { |
| 109 | 295 | result.setTitle(strings[0]); |
| 110 | |
} |
| 111 | 295 | if (stringSizes[1] > 0) { |
| 112 | 295 | result.setAuthor(strings[1]); |
| 113 | |
} |
| 114 | 295 | if (stringSizes[2] > 0) { |
| 115 | 281 | result.setCopyright(strings[2]); |
| 116 | |
} |
| 117 | 295 | if (stringSizes[3] > 0) { |
| 118 | 283 | result.setComment(strings[3]); |
| 119 | |
} |
| 120 | 295 | if (stringSizes[4] > 0) { |
| 121 | 145 | result.setRating(strings[4]); |
| 122 | |
} |
| 123 | 295 | return result; |
| 124 | |
} |
| 125 | |
} |