UCharacterNameReader.java 3.96 KB
/*
 * Decompiled with CFR 0_118.
 */
package com.adobe.agl.impl;

import com.adobe.agl.impl.ICUBinary;
import com.adobe.agl.impl.UCharacterName;

import java.io.DataInputStream;
import java.io.IOException;
import java.io.InputStream;

final class UCharacterNameReader
implements ICUBinary.Authenticate {
    private DataInputStream m_dataInputStream_;
    private int m_tokenstringindex_;
    private int m_groupindex_;
    private int m_groupstringindex_;
    private int m_algnamesindex_;
    private static final byte[] DATA_FORMAT_VERSION_ = new byte[]{1, 0, 0, 0};
    private static final byte[] DATA_FORMAT_ID_ = new byte[]{117, 110, 97, 109};

    public boolean isDataVersionAcceptable(byte[] version) {
        return version[0] == DATA_FORMAT_VERSION_[0];
    }

    protected UCharacterNameReader(InputStream inputStream) throws IOException {
        ICUBinary.readHeader(inputStream, DATA_FORMAT_ID_, this);
        this.m_dataInputStream_ = new DataInputStream(inputStream);
    }

    protected void read(UCharacterName data) throws IOException {
        this.m_tokenstringindex_ = this.m_dataInputStream_.readInt();
        this.m_groupindex_ = this.m_dataInputStream_.readInt();
        this.m_groupstringindex_ = this.m_dataInputStream_.readInt();
        this.m_algnamesindex_ = this.m_dataInputStream_.readInt();
        int count = this.m_dataInputStream_.readChar();
        char[] token = new char[count];
        for (int i = 0; i < count; i = (char)(i + '\u0001')) {
            token[i] = this.m_dataInputStream_.readChar();
        }
        int size = this.m_groupindex_ - this.m_tokenstringindex_;
        byte[] tokenstr = new byte[size];
        this.m_dataInputStream_.readFully(tokenstr);
        data.setToken(token, tokenstr);
        count = this.m_dataInputStream_.readChar();
        data.setGroupCountSize(count, 3);
        char[] group = new char[count *= 3];
        for (int i2 = 0; i2 < count; ++i2) {
            group[i2] = this.m_dataInputStream_.readChar();
        }
        size = this.m_algnamesindex_ - this.m_groupstringindex_;
        byte[] groupstring = new byte[size];
        this.m_dataInputStream_.readFully(groupstring);
        data.setGroup(group, groupstring);
        count = this.m_dataInputStream_.readInt();
        UCharacterName.AlgorithmName[] alg = new UCharacterName.AlgorithmName[count];
        for (int i3 = 0; i3 < count; ++i3) {
            UCharacterName.AlgorithmName an = this.readAlg();
            if (an == null) {
                throw new IOException("unames.icu read error: Algorithmic names creation error");
            }
            alg[i3] = an;
        }
        data.setAlgorithm(alg);
    }

    private UCharacterName.AlgorithmName readAlg() throws IOException {
        int rangeend;
        byte type;
        int variant;
        UCharacterName.AlgorithmName result = new UCharacterName.AlgorithmName();
        int rangestart = this.m_dataInputStream_.readInt();
        if (!result.setInfo(rangestart, rangeend = this.m_dataInputStream_.readInt(), type = this.m_dataInputStream_.readByte(), (byte)(variant = this.m_dataInputStream_.readByte()))) {
            return null;
        }
        int size = this.m_dataInputStream_.readChar();
        if (type == 1) {
            char[] factor = new char[variant];
            for (int j = 0; j < variant; ++j) {
                factor[j] = this.m_dataInputStream_.readChar();
            }
            result.setFactor(factor);
            size -= variant << 1;
        }
        StringBuffer prefix = new StringBuffer();
        char c = (char)(this.m_dataInputStream_.readByte() & 255);
        while (c != '\u0000') {
            prefix.append(c);
            c = (char)(this.m_dataInputStream_.readByte() & 255);
        }
        result.setPrefix(prefix.toString());
        if ((size -= 12 + prefix.length() + 1) > 0) {
            byte[] string = new byte[size];
            this.m_dataInputStream_.readFully(string);
            result.setFactorString(string);
        }
        return result;
    }
}