~ubuntu-branches/ubuntu/utopic/libjaudiotagger-java/utopic

« back to all changes in this revision

Viewing changes to src/org/jaudiotagger/audio/asf/io/LanguageListReader.java

  • Committer: Bazaar Package Importer
  • Author(s): Damien Raude-Morvan
  • Date: 2011-04-28 23:52:43 UTC
  • mfrom: (3.1.4 sid)
  • Revision ID: james.westby@ubuntu.com-20110428235243-pzalvw6lncis3ukf
Tags: 2.0.3-1
* d/control: Drop Depends on default-jre per Debian Java Policy as its
  a library package.
* d/watch: Fix to directly monitor SVN tags.
* Switch to 3.0 (quilt) format.
* Bump Standards-Version to 3.9.2 (no changes needed).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
package org.jaudiotagger.audio.asf.io;
2
 
 
3
 
import org.jaudiotagger.audio.asf.data.Chunk;
4
 
import org.jaudiotagger.audio.asf.data.GUID;
5
 
import org.jaudiotagger.audio.asf.data.LanguageList;
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
 
 * Reads and interprets the &quot;Language List Object&quot; of ASF files.<br>
14
 
 * 
15
 
 * @author Christian Laireiter
16
 
 */
17
 
public class LanguageListReader implements ChunkReader {
18
 
 
19
 
    /**
20
 
     * The GUID this reader {@linkplain #getApplyingIds() applies to}
21
 
     */
22
 
    private final static GUID[] APPLYING = { GUID.GUID_LANGUAGE_LIST };
23
 
 
24
 
    /**
25
 
     * {@inheritDoc}
26
 
     */
27
 
    public boolean canFail() {
28
 
        return false;
29
 
    }
30
 
 
31
 
    /**
32
 
     * {@inheritDoc}
33
 
     */
34
 
    public GUID[] getApplyingIds() {
35
 
        return APPLYING.clone();
36
 
    }
37
 
 
38
 
    /**
39
 
     * {@inheritDoc}
40
 
     */
41
 
    public Chunk read(final GUID guid, final InputStream stream,
42
 
            final long streamPosition) throws IOException {
43
 
        assert GUID.GUID_LANGUAGE_LIST.equals(guid);
44
 
        final BigInteger chunkLen = Utils.readBig64(stream);
45
 
 
46
 
        final int readUINT16 = Utils.readUINT16(stream);
47
 
 
48
 
        final LanguageList result = new LanguageList(streamPosition, chunkLen);
49
 
        for (int i = 0; i < readUINT16; i++) {
50
 
            final int langIdLen = (stream.read() & 0xFF);
51
 
            final String langId = Utils
52
 
                    .readFixedSizeUTF16Str(stream, langIdLen);
53
 
            // langIdLen = 2 bytes for each char and optionally one zero
54
 
            // termination character
55
 
            assert langId.length() == langIdLen / 2 - 1
56
 
                    || langId.length() == langIdLen / 2;
57
 
            result.addLanguage(langId);
58
 
        }
59
 
 
60
 
        return result;
61
 
    }
62
 
 
63
 
}
 
1
package org.jaudiotagger.audio.asf.io;
 
2
 
 
3
import org.jaudiotagger.audio.asf.data.Chunk;
 
4
import org.jaudiotagger.audio.asf.data.GUID;
 
5
import org.jaudiotagger.audio.asf.data.LanguageList;
 
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
 * Reads and interprets the &quot;Language List Object&quot; of ASF files.<br>
 
14
 * 
 
15
 * @author Christian Laireiter
 
16
 */
 
17
public class LanguageListReader implements ChunkReader {
 
18
 
 
19
    /**
 
20
     * The GUID this reader {@linkplain #getApplyingIds() applies to}
 
21
     */
 
22
    private final static GUID[] APPLYING = { GUID.GUID_LANGUAGE_LIST };
 
23
 
 
24
    /**
 
25
     * {@inheritDoc}
 
26
     */
 
27
    public boolean canFail() {
 
28
        return false;
 
29
    }
 
30
 
 
31
    /**
 
32
     * {@inheritDoc}
 
33
     */
 
34
    public GUID[] getApplyingIds() {
 
35
        return APPLYING.clone();
 
36
    }
 
37
 
 
38
    /**
 
39
     * {@inheritDoc}
 
40
     */
 
41
    public Chunk read(final GUID guid, final InputStream stream,
 
42
            final long streamPosition) throws IOException {
 
43
        assert GUID.GUID_LANGUAGE_LIST.equals(guid);
 
44
        final BigInteger chunkLen = Utils.readBig64(stream);
 
45
 
 
46
        final int readUINT16 = Utils.readUINT16(stream);
 
47
 
 
48
        final LanguageList result = new LanguageList(streamPosition, chunkLen);
 
49
        for (int i = 0; i < readUINT16; i++) {
 
50
            final int langIdLen = (stream.read() & 0xFF);
 
51
            final String langId = Utils
 
52
                    .readFixedSizeUTF16Str(stream, langIdLen);
 
53
            // langIdLen = 2 bytes for each char and optionally one zero
 
54
            // termination character
 
55
            assert langId.length() == langIdLen / 2 - 1
 
56
                    || langId.length() == langIdLen / 2;
 
57
            result.addLanguage(langId);
 
58
        }
 
59
 
 
60
        return result;
 
61
    }
 
62
 
 
63
}