| 1 | |
package org.jaudiotagger.audio.asf.io; |
| 2 | |
|
| 3 | |
import org.jaudiotagger.audio.asf.data.Chunk; |
| 4 | |
import org.jaudiotagger.audio.asf.data.ContentBranding; |
| 5 | |
import org.jaudiotagger.audio.asf.data.GUID; |
| 6 | |
import org.jaudiotagger.audio.asf.util.Utils; |
| 7 | |
|
| 8 | |
import java.io.IOException; |
| 9 | |
import java.io.InputStream; |
| 10 | |
import java.math.BigInteger; |
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
|
| 18 | |
|
| 19 | 4 | public class ContentBrandingReader implements ChunkReader { |
| 20 | |
|
| 21 | |
|
| 22 | |
|
| 23 | 4 | private final static GUID[] APPLYING = { GUID.GUID_CONTENT_BRANDING }; |
| 24 | |
|
| 25 | |
|
| 26 | |
|
| 27 | |
|
| 28 | 24 | protected ContentBrandingReader() { |
| 29 | |
|
| 30 | 24 | } |
| 31 | |
|
| 32 | |
|
| 33 | |
|
| 34 | |
|
| 35 | |
public boolean canFail() { |
| 36 | 0 | return false; |
| 37 | |
} |
| 38 | |
|
| 39 | |
|
| 40 | |
|
| 41 | |
|
| 42 | |
public GUID[] getApplyingIds() { |
| 43 | 24 | return APPLYING.clone(); |
| 44 | |
} |
| 45 | |
|
| 46 | |
|
| 47 | |
|
| 48 | |
|
| 49 | |
public Chunk read(final GUID guid, final InputStream stream, |
| 50 | |
final long streamPosition) throws IOException { |
| 51 | 0 | assert GUID.GUID_CONTENT_BRANDING.equals(guid); |
| 52 | 0 | final BigInteger chunkSize = Utils.readBig64(stream); |
| 53 | 0 | final long imageType = Utils.readUINT32(stream); |
| 54 | 0 | assert imageType >= 0 && imageType <= 3 : imageType; |
| 55 | 0 | final long imageDataSize = Utils.readUINT32(stream); |
| 56 | 0 | assert imageType > 0 || imageDataSize == 0 : imageDataSize; |
| 57 | 0 | assert imageDataSize < Integer.MAX_VALUE; |
| 58 | 0 | final byte[] imageData = Utils.readBinary(stream, imageDataSize); |
| 59 | 0 | final long copyRightUrlLen = Utils.readUINT32(stream); |
| 60 | 0 | final String copyRight = new String(Utils.readBinary(stream, |
| 61 | |
copyRightUrlLen)); |
| 62 | 0 | final long imageUrlLen = Utils.readUINT32(stream); |
| 63 | 0 | final String imageUrl = new String(Utils |
| 64 | |
.readBinary(stream, imageUrlLen)); |
| 65 | 0 | final ContentBranding result = new ContentBranding(streamPosition, |
| 66 | |
chunkSize); |
| 67 | 0 | result.setImage(imageType, imageData); |
| 68 | 0 | result.setCopyRightURL(copyRight); |
| 69 | 0 | result.setBannerImageURL(imageUrl); |
| 70 | 0 | return result; |
| 71 | |
} |
| 72 | |
|
| 73 | |
} |