| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
|
| 18 | |
|
| 19 | |
|
| 20 | |
package org.jaudiotagger.tag.vorbiscomment; |
| 21 | |
|
| 22 | |
import org.jaudiotagger.audio.exceptions.CannotReadException; |
| 23 | |
import org.jaudiotagger.audio.generic.Utils; |
| 24 | |
import org.jaudiotagger.audio.ogg.util.VorbisHeader; |
| 25 | |
import org.jaudiotagger.fix.Fix; |
| 26 | |
import org.jaudiotagger.logging.ErrorMessage; |
| 27 | |
|
| 28 | |
import java.io.IOException; |
| 29 | |
import java.util.logging.Logger; |
| 30 | |
|
| 31 | |
|
| 32 | |
|
| 33 | |
|
| 34 | |
|
| 35 | |
|
| 36 | |
|
| 37 | |
|
| 38 | |
|
| 39 | |
|
| 40 | |
|
| 41 | |
|
| 42 | |
|
| 43 | |
|
| 44 | |
|
| 45 | |
|
| 46 | |
|
| 47 | |
|
| 48 | |
|
| 49 | |
|
| 50 | |
|
| 51 | |
|
| 52 | |
public class VorbisCommentReader |
| 53 | |
{ |
| 54 | |
|
| 55 | 42 | public static Logger logger = Logger.getLogger("org.jaudiotagger.tag.vorbiscomment.VorbisCommentReader"); |
| 56 | |
|
| 57 | |
public static final int FIELD_VENDOR_LENGTH_POS = 0; |
| 58 | |
public static final int FIELD_VENDOR_STRING_POS = 4; |
| 59 | |
|
| 60 | |
public static final int FIELD_VENDOR_LENGTH_LENGTH = 4; |
| 61 | |
public static final int FIELD_USER_COMMENT_LIST_LENGTH = 4; |
| 62 | |
public static final int FIELD_COMMENT_LENGTH_LENGTH = 4; |
| 63 | |
|
| 64 | |
private Fix fix; |
| 65 | |
|
| 66 | |
public VorbisCommentReader() |
| 67 | 181 | { |
| 68 | |
|
| 69 | 181 | } |
| 70 | |
|
| 71 | |
public VorbisCommentReader(Fix fix) |
| 72 | 1 | { |
| 73 | 1 | this.fix = fix; |
| 74 | 1 | } |
| 75 | |
|
| 76 | |
|
| 77 | |
|
| 78 | |
|
| 79 | |
|
| 80 | |
|
| 81 | |
|
| 82 | |
public VorbisCommentTag read(byte[] rawdata, boolean isFramingBit) throws IOException, CannotReadException |
| 83 | |
{ |
| 84 | |
|
| 85 | 66 | VorbisCommentTag tag = new VorbisCommentTag(); |
| 86 | |
|
| 87 | 66 | byte[] b = new byte[FIELD_VENDOR_LENGTH_LENGTH]; |
| 88 | 66 | System.arraycopy(rawdata, FIELD_VENDOR_LENGTH_POS, b, FIELD_VENDOR_LENGTH_POS, FIELD_VENDOR_LENGTH_LENGTH); |
| 89 | 66 | int pos = FIELD_VENDOR_LENGTH_LENGTH; |
| 90 | 66 | int vendorStringLength = Utils.getIntLE(b); |
| 91 | |
|
| 92 | 66 | b = new byte[vendorStringLength]; |
| 93 | 66 | System.arraycopy(rawdata, pos, b, 0, vendorStringLength); |
| 94 | 66 | pos += vendorStringLength; |
| 95 | 66 | tag.setVendor(new String(b, VorbisHeader.CHARSET_UTF_8)); |
| 96 | |
|
| 97 | 66 | b = new byte[FIELD_USER_COMMENT_LIST_LENGTH]; |
| 98 | 66 | System.arraycopy(rawdata, pos, b, 0, FIELD_USER_COMMENT_LIST_LENGTH); |
| 99 | 66 | pos += FIELD_USER_COMMENT_LIST_LENGTH; |
| 100 | |
|
| 101 | 66 | int userComments = Utils.getIntLE(b); |
| 102 | 66 | logger.info("Number of user comments:" + userComments); |
| 103 | 66 | if (fix == Fix.FIX_OGG_VORBIS_COMMENT_NOT_COUNTING_EMPTY_COLUMNS) |
| 104 | |
{ |
| 105 | 1 | userComments++; |
| 106 | |
} |
| 107 | 396 | for (int i = 0; i < userComments; i++) |
| 108 | |
{ |
| 109 | 330 | b = new byte[FIELD_COMMENT_LENGTH_LENGTH]; |
| 110 | 330 | System.arraycopy(rawdata, pos, b, 0, FIELD_COMMENT_LENGTH_LENGTH); |
| 111 | 330 | pos += FIELD_COMMENT_LENGTH_LENGTH; |
| 112 | |
|
| 113 | 330 | int commentLength = Utils.getIntLE(b); |
| 114 | 330 | logger.info("Next Comment Length:" + commentLength); |
| 115 | 330 | b = new byte[commentLength]; |
| 116 | 330 | System.arraycopy(rawdata, pos, b, 0, commentLength); |
| 117 | 330 | pos += commentLength; |
| 118 | |
|
| 119 | 330 | VorbisCommentTagField fieldComment = new VorbisCommentTagField(b); |
| 120 | 330 | logger.info("Adding:" + fieldComment.getId()); |
| 121 | 330 | tag.add(fieldComment); |
| 122 | |
} |
| 123 | |
|
| 124 | |
|
| 125 | 66 | if (isFramingBit) |
| 126 | |
{ |
| 127 | 45 | if ((rawdata[pos] & 0x01) != 1) |
| 128 | |
{ |
| 129 | 1 | throw new CannotReadException(ErrorMessage.OGG_VORBIS_NO_FRAMING_BIT.getMsg((rawdata[pos] & 0x01))); |
| 130 | |
} |
| 131 | |
} |
| 132 | 65 | return tag; |
| 133 | |
} |
| 134 | |
} |
| 135 | |
|