| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| ChunkHeaderReader |
|
| 1.0;1 |
| 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.io; | |
| 20 | ||
| 21 | import org.jaudiotagger.audio.asf.data.Chunk; | |
| 22 | import org.jaudiotagger.audio.asf.data.GUID; | |
| 23 | import org.jaudiotagger.audio.asf.util.Utils; | |
| 24 | ||
| 25 | import java.io.IOException; | |
| 26 | import java.io.InputStream; | |
| 27 | import java.math.BigInteger; | |
| 28 | ||
| 29 | /** | |
| 30 | * Default reader, Reads GUID and size out of an input stream and creates a | |
| 31 | * {@link org.jaudiotagger.audio.asf.data.Chunk}object, finally skips the | |
| 32 | * remaining chunk bytes. | |
| 33 | * | |
| 34 | * @author Christian Laireiter | |
| 35 | */ | |
| 36 | final class ChunkHeaderReader implements ChunkReader { | |
| 37 | ||
| 38 | /** | |
| 39 | * The GUID this reader {@linkplain #getApplyingIds() applies to} | |
| 40 | */ | |
| 41 | 4 | private final static GUID[] APPLYING = { GUID.GUID_UNSPECIFIED }; |
| 42 | ||
| 43 | /** | |
| 44 | * Default instance. | |
| 45 | */ | |
| 46 | 4 | private static final ChunkHeaderReader INSTANCE = new ChunkHeaderReader(); |
| 47 | ||
| 48 | /** | |
| 49 | * Returns an instance of the reader. | |
| 50 | * | |
| 51 | * @return instance. | |
| 52 | */ | |
| 53 | public static ChunkHeaderReader getInstance() { | |
| 54 | 2572 | return INSTANCE; |
| 55 | } | |
| 56 | ||
| 57 | /** | |
| 58 | * Hidden Utility class constructor. | |
| 59 | */ | |
| 60 | 4 | private ChunkHeaderReader() { |
| 61 | // Hidden | |
| 62 | 4 | } |
| 63 | ||
| 64 | /** | |
| 65 | * {@inheritDoc} | |
| 66 | */ | |
| 67 | public boolean canFail() { | |
| 68 | 0 | return false; |
| 69 | } | |
| 70 | ||
| 71 | /** | |
| 72 | * {@inheritDoc} | |
| 73 | */ | |
| 74 | public GUID[] getApplyingIds() { | |
| 75 | 0 | return APPLYING.clone(); |
| 76 | } | |
| 77 | ||
| 78 | /** | |
| 79 | * {@inheritDoc} | |
| 80 | */ | |
| 81 | public Chunk read(final GUID guid, final InputStream stream, | |
| 82 | final long chunkStart) throws IOException { | |
| 83 | 2572 | final BigInteger chunkLen = Utils.readBig64(stream); |
| 84 | 2572 | stream.skip(chunkLen.longValue() - 24); |
| 85 | 2572 | return new Chunk(guid, chunkStart, chunkLen); |
| 86 | } | |
| 87 | ||
| 88 | } |