1 7 8 package org.jboss.media.format.audio.mpeg; 9 10 import java.io.IOException ; 11 import java.io.InputStream ; 12 import java.rmi.RemoteException ; 13 14 import javax.emb.MediaException; 15 16 23 class ID3Tag 24 { 25 private int size = 0; 26 private boolean unsynchronisation; 27 private boolean extendedHeader; 28 private boolean experimentalHeader; 29 private boolean footerPresent; 30 31 private byte versionMajor = 0; 32 private byte versionMinor = 0; 33 34 39 public ID3Tag(InputStream content) throws MediaException, RemoteException 40 { 41 try 42 { 43 int offset = 3; 44 45 47 content.read(new byte[6]); 48 49 byte[] tagSize = new byte[4]; 50 content.read(tagSize); 51 size = convertSynchsafeInt(tagSize); 52 53 byte[] tagData = new byte[size]; 55 56 content.read(tagData); 57 58 versionMajor = tagData[offset++]; 59 versionMinor = tagData[offset++]; 60 61 byte flags = tagData[offset++]; 62 63 unsynchronisation = (flags & 0x80) > 0; 64 extendedHeader = (flags & 0x40) > 0; 65 experimentalHeader = (flags & 0x20) > 0; 66 footerPresent = (flags & 0x10) > 0; 67 } 68 catch (IOException e) 69 { 70 throw new MediaException(e); 71 } 72 } 73 74 77 public int getSize() 78 { 79 return size; 80 } 81 82 private int convertSynchsafeInt(byte[] data) 83 { 84 if (data.length < 4) 85 { 86 throw new IllegalArgumentException ("Synchsafe integer must be 4 bytes long"); 87 } 88 89 return convertSynchsafeInt(data[0], data[1], data[2], data[3]); 90 } 91 92 private int convertSynchsafeInt(byte msb, byte b3, byte b2, byte lsb) 93 { 94 return (msb << 23) + (b3 << 15) + (b2 << 7) + lsb; 95 } 96 } | Popular Tags |