| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| AsfHeader |
|
| 0.0;0 |
| 1 | /* | |
| 2 | * Entagged Audio Tag library | |
| 3 | * Copyright (c) 2004-2005 Christian Laireiter <liree@web.de> | |
| 4 | * | |
| 5 | * This library is free software; you can redistribute it and/or | |
| 6 | * modify it under the terms of the GNU Lesser General Public | |
| 7 | * License as published by the Free Software Foundation; either | |
| 8 | * version 2.1 of the License, or (at your option) any later version. | |
| 9 | * | |
| 10 | * This library is distributed in the hope that it will be useful, | |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 13 | * Lesser General Public License for more details. | |
| 14 | * | |
| 15 | * You should have received a copy of the GNU Lesser General Public | |
| 16 | * License along with this library; if not, write to the Free Software | |
| 17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
| 18 | */ | |
| 19 | package org.jaudiotagger.audio.asf.data; | |
| 20 | ||
| 21 | import org.jaudiotagger.audio.asf.util.Utils; | |
| 22 | ||
| 23 | import java.math.BigInteger; | |
| 24 | import java.nio.charset.Charset; | |
| 25 | import java.util.HashSet; | |
| 26 | import java.util.List; | |
| 27 | ||
| 28 | /** | |
| 29 | * Each ASF file starts with a so called header. <br> | |
| 30 | * This header contains other chunks. Each chunk starts with a 16 byte GUID | |
| 31 | * followed by the length (in bytes) of the chunk (including GUID). The length | |
| 32 | * number takes 8 bytes and is unsigned. Finally the chunk's data appears. <br> | |
| 33 | * | |
| 34 | * @author Christian Laireiter | |
| 35 | */ | |
| 36 | public final class AsfHeader extends ChunkContainer | |
| 37 | { | |
| 38 | /** | |
| 39 | * The charset "UTF-16LE" is mandatory for ASF handling. | |
| 40 | */ | |
| 41 | 7 | public final static Charset ASF_CHARSET = Charset.forName("UTF-16LE"); //$NON-NLS-1$ |
| 42 | ||
| 43 | /** | |
| 44 | * Stores the {@link GUID} instances, which are allowed multiple times | |
| 45 | * within an ASF header. | |
| 46 | */ | |
| 47 | private final static HashSet<GUID> MULTI_CHUNKS; | |
| 48 | ||
| 49 | /** | |
| 50 | * Byte sequence representing the zero term character. | |
| 51 | */ | |
| 52 | 7 | public final static byte[] ZERO_TERM = {0, 0}; |
| 53 | ||
| 54 | static | |
| 55 | { | |
| 56 | 7 | MULTI_CHUNKS = new HashSet<GUID>(); |
| 57 | 7 | MULTI_CHUNKS.add(GUID.GUID_STREAM); |
| 58 | 7 | } |
| 59 | ||
| 60 | /** | |
| 61 | * An ASF header contains multiple chunks. <br> | |
| 62 | * The count of those is stored here. | |
| 63 | */ | |
| 64 | private final long chunkCount; | |
| 65 | ||
| 66 | /** | |
| 67 | * Creates an instance. | |
| 68 | * | |
| 69 | * @param pos | |
| 70 | * see {@link Chunk#position} | |
| 71 | * @param chunkLen | |
| 72 | * see {@link Chunk#chunkLength} | |
| 73 | * @param chunkCnt | |
| 74 | */ | |
| 75 | public AsfHeader(long pos, BigInteger chunkLen, long chunkCnt) | |
| 76 | { | |
| 77 | 80 | super(GUID.GUID_HEADER, pos, chunkLen); |
| 78 | 80 | this.chunkCount = chunkCnt; |
| 79 | 80 | } |
| 80 | ||
| 81 | /** | |
| 82 | * This method looks for an content description object in this header instance, if not found | |
| 83 | * there, it tries to get one from a contained ASF header extension object. | |
| 84 | * | |
| 85 | * @return content description if found, <code>null</code> otherwise. | |
| 86 | */ | |
| 87 | public ContentDescription findContentDescription() | |
| 88 | { | |
| 89 | 93 | ContentDescription result = getContentDescription(); |
| 90 | 93 | if (result == null && getExtendedHeader() != null) |
| 91 | { | |
| 92 | 24 | result = getExtendedHeader().getContentDescription(); |
| 93 | } | |
| 94 | 93 | return result; |
| 95 | } | |
| 96 | ||
| 97 | /** | |
| 98 | * This method looks for an extended content description object in this header instance, if not found | |
| 99 | * there, it tries to get one from a contained ASF header extension object. | |
| 100 | * | |
| 101 | * @return extended content description if found, <code>null</code> otherwise. | |
| 102 | */ | |
| 103 | public ExtendedContentDescription findExtendedContentDescription() | |
| 104 | { | |
| 105 | 88 | ExtendedContentDescription result = getExtendedContentDescription(); |
| 106 | 88 | if (result == null && getExtendedHeader() != null) |
| 107 | { | |
| 108 | 29 | result = getExtendedHeader().getExtendedContentDescription(); |
| 109 | } | |
| 110 | 88 | return result; |
| 111 | } | |
| 112 | ||
| 113 | /** | |
| 114 | * This method returns the first audio stream chunk found in the asf file or | |
| 115 | * stream. | |
| 116 | * | |
| 117 | * @return Returns the audioStreamChunk. | |
| 118 | */ | |
| 119 | public AudioStreamChunk getAudioStreamChunk() | |
| 120 | { | |
| 121 | 234 | AudioStreamChunk result = null; |
| 122 | 234 | final List<Chunk> streamChunks = assertChunkList(GUID.GUID_STREAM); |
| 123 | 468 | for (int i = 0; i < streamChunks.size() && result == null; i++) |
| 124 | { | |
| 125 | 234 | if (streamChunks.get(i) instanceof AudioStreamChunk) |
| 126 | { | |
| 127 | 234 | result = (AudioStreamChunk) streamChunks.get(i); |
| 128 | } | |
| 129 | } | |
| 130 | 234 | return result; |
| 131 | } | |
| 132 | ||
| 133 | /** | |
| 134 | * Returns the amount of chunks, when this instance was created.<br> | |
| 135 | * If chunks have been added, this won't be reflected with this call.<br> | |
| 136 | * For that use {@link #getChunks()}. | |
| 137 | * | |
| 138 | * @return Chunkcount at instance creation. | |
| 139 | */ | |
| 140 | public long getChunkCount() | |
| 141 | { | |
| 142 | 0 | return this.chunkCount; |
| 143 | } | |
| 144 | ||
| 145 | /** | |
| 146 | * @return Returns the contentDescription. | |
| 147 | */ | |
| 148 | public ContentDescription getContentDescription() | |
| 149 | { | |
| 150 | 134 | return (ContentDescription) getFirst(GUID.GUID_CONTENTDESCRIPTION, ContentDescription.class); |
| 151 | } | |
| 152 | ||
| 153 | /** | |
| 154 | * @return Returns the encodingChunk. | |
| 155 | */ | |
| 156 | public EncodingChunk getEncodingChunk() | |
| 157 | { | |
| 158 | 0 | return (EncodingChunk) getFirst(GUID.GUID_ENCODING, EncodingChunk.class); |
| 159 | } | |
| 160 | ||
| 161 | /** | |
| 162 | * @return Returns the encodingChunk. | |
| 163 | */ | |
| 164 | public EncryptionChunk getEncryptionChunk() | |
| 165 | { | |
| 166 | 0 | return (EncryptionChunk) getFirst(GUID.GUID_CONTENT_ENCRYPTION, EncryptionChunk.class); |
| 167 | } | |
| 168 | ||
| 169 | /** | |
| 170 | * @return Returns the tagHeader. | |
| 171 | */ | |
| 172 | public ExtendedContentDescription getExtendedContentDescription() | |
| 173 | { | |
| 174 | 128 | return (ExtendedContentDescription) getFirst(GUID.GUID_EXTENDED_CONTENT_DESCRIPTION, ExtendedContentDescription.class); |
| 175 | } | |
| 176 | ||
| 177 | /** | |
| 178 | * @return Returns the extended header. | |
| 179 | */ | |
| 180 | public AsfExtendedHeader getExtendedHeader() | |
| 181 | { | |
| 182 | 226 | return (AsfExtendedHeader) getFirst(GUID.GUID_HEADER_EXTENSION, AsfExtendedHeader.class); |
| 183 | } | |
| 184 | ||
| 185 | /** | |
| 186 | * @return Returns the fileHeader. | |
| 187 | */ | |
| 188 | public FileHeader getFileHeader() | |
| 189 | { | |
| 190 | 157 | return (FileHeader) getFirst(GUID.GUID_FILE, FileHeader.class); |
| 191 | } | |
| 192 | ||
| 193 | /** | |
| 194 | * @return Returns the streamBitratePropertiesChunk. | |
| 195 | */ | |
| 196 | public StreamBitratePropertiesChunk getStreamBitratePropertiesChunk() | |
| 197 | { | |
| 198 | 0 | return (StreamBitratePropertiesChunk) getFirst(GUID.GUID_STREAM_BITRATE_PROPERTIES, StreamBitratePropertiesChunk.class); |
| 199 | } | |
| 200 | ||
| 201 | /** | |
| 202 | * | |
| 203 | * {@inheritDoc} | |
| 204 | */ | |
| 205 | public String prettyPrint(final String prefix) | |
| 206 | { | |
| 207 | 0 | StringBuffer result = new StringBuffer(super |
| 208 | .prettyPrint(prefix, prefix + " | : Contains: \"" + getChunkCount() + "\" chunks" + Utils.LINE_SEPARATOR)); | |
| 209 | 0 | return result.toString(); |
| 210 | } | |
| 211 | } |