<commit_before>/**
 * Class:    ID3v1TagCodec<br/>
 * <br/>
 * Created:  02.11.2017<br/>
 * Filename: ID3v1TagCodec.java<br/>
 * Version:  $Revision: $<br/>
 * <br/>
 * last modified on $Date:  $<br/>
 *               by $Author: $<br/>
 * <br/>
 * @author <a href="mailto:<EMAIL>"><NAME>, nacamar GmbH</a>
 * @version $Author: $ -- $Revision: $ -- $Date: $
 * <br/>
 * (c) <NAME>, nacamar GmbH 2012 - All rights reserved.
 */

package net.addradio.codec.id3.codecs;

import java.io.IOException;
import java.io.UnsupportedEncodingException;

import net.addradio.codec.id3.model.v1.Genre;
import net.addradio.codec.id3.model.v1.ID3v1Tag;
import net.addradio.codec.mpeg.audio.codecs.BitMaskFlagCodec;
import net.addradio.codec.mpeg.audio.codecs.MPEGAudioCodecException;
import net.addradio.streams.BitInputStream;

/**
 * ID3v1TagCodec
 */
public final class ID3v1TagCodec {

    /**
     * decodeID3v1Tag.
     * @param bis {@link BitInputStream}
     * @return {@link ID3v1Tag}
     * @throws IOException due to IO problems.
     * @throws UnsupportedEncodingException while byte to string conversion.
     * @throws MPEGAudioCodecException if {@link Genre} could not be decoded.
     */
    public static final ID3v1Tag decodeID3v1Tag(final BitInputStream bis)
            throws IOException, UnsupportedEncodingException, MPEGAudioCodecException {
        final ID3v1Tag tag = new ID3v1Tag();
        tag.setTitle(ID3CodecTools.readStringFromStream(bis, 30));
        tag.setArtist(ID3CodecTools.readStringFromStream(bis, 30));
        tag.setAlbum(ID3CodecTools.readStringFromStream(bis, 30));
        tag.setTitle(ID3CodecTools.readStringFromStream(bis, 30));
        tag.setYear(Integer.parseInt(ID3CodecTools.readStringFromStream(bis, 4)));
        tag.setComment(ID3CodecTools.readStringFromStream(bis, 30));
        tag.setGenre((Genre) BitMaskFlagCodec.decode(bis.read(), Genre.class));
        return tag;
    }

    /**
     * ID3v1TagCodec constructor.
     */
    private ID3v1TagCodec() {<commit_msg>fixed int parsing<commit_after>/**
 * Class:    ID3v1TagCodec<br/>
 * <br/>
 * Created:  02.11.2017<br/>
 * Filename: ID3v1TagCodec.java<br/>
 * Version:  $Revision: $<br/>
 * <br/>
 * last modified on $Date:  $<br/>
 *               by $Author: $<br/>
 * <br/>
 * @author <a href="mailto:<EMAIL>"><NAME>, nacamar GmbH</a>
 * @version $Author: $ -- $Revision: $ -- $Date: $
 * <br/>
 * (c) <NAME>, nacamar GmbH 2012 - All rights reserved.
 */

package net.addradio.codec.id3.codecs;

import java.io.IOException;
import java.io.UnsupportedEncodingException;

import net.addradio.codec.id3.model.v1.Genre;
import net.addradio.codec.id3.model.v1.ID3v1Tag;
import net.addradio.codec.mpeg.audio.codecs.BitMaskFlagCodec;
import net.addradio.codec.mpeg.audio.codecs.MPEGAudioCodecException;
import net.addradio.streams.BitInputStream;

/**
 * ID3v1TagCodec
 */
public final class ID3v1TagCodec {

    /**
     * decodeID3v1Tag.
     * @param bis {@link BitInputStream}
     * @return {@link ID3v1Tag}
     * @throws IOException due to IO problems.
     * @throws UnsupportedEncodingException while byte to string conversion.
     * @throws MPEGAudioCodecException if {@link Genre} could not be decoded.
     */
    public static final ID3v1Tag decodeID3v1Tag(final BitInputStream bis)
            throws IOException, UnsupportedEncodingException, MPEGAudioCodecException {
        final ID3v1Tag tag = new ID3v1Tag();
        tag.setTitle(ID3CodecTools.readStringFromStream(bis, 30));
        tag.setArtist(ID3CodecTools.readStringFromStream(bis, 30));
        tag.setAlbum(ID3CodecTools.readStringFromStream(bis, 30));
        tag.setTitle(ID3CodecTools.readStringFromStream(bis, 30));
        final String readStringFromStream = ID3CodecTools.readStringFromStream(bis, 4);
        tag.setYear(saveParseInt(readStringFromStream));
        tag.setComment(ID3CodecTools.readStringFromStream(bis, 30));
        tag.setGenre((Genre) BitMaskFlagCodec.decode(bis.read(), Genre.class));
        return tag;
    }

    /**
     * saveParseInt.
     * @param readStringFromStream {@link String}
     * @return {@code int}
     */
    private static int saveParseInt(final String readStringFromStream) {
        // SEBASTIAN maybe throw ID3 encoding exception

        if (readStringFromStream == null || readStringFromStream.trim().isEmpty()) {
            return 0;
        }
        try {
            return Integer.parseInt(readStringFromStream);
        } catch (NumberFormatException nfe) {
            return 0;
        }
    }

    /**
     * ID3v1TagCodec constructor.
     */
    private ID3v1TagCodec() {
{'fraction_non_alphanumeric': 0.12703230002167787, 'fraction_numerical': 0.026663776284413614, 'mean_word_length': 3.3000931966449207, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6540081', 'n_tokens_mistral': 1560, 'n_tokens_neox': 1533, 'n_words': 294}