jdk/src/java.base/share/classes/sun/misc/UCDecoder.java
author martin
Tue, 15 Sep 2015 21:56:04 -0700
changeset 32649 2ee9017c7597
parent 25859 3317bb8137f4
permissions -rw-r--r--
8136583: Core libraries should use blessed modifier order Summary: Run blessed-modifier-order script (see bug) Reviewed-by: psandoz, chegar, alanb, plevart
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 1995, 2000, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
package sun.misc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
import java.io.OutputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.io.ByteArrayOutputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.io.PushbackInputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.io.PrintStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * This class implements a robust character decoder. The decoder will
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * converted encoded text into binary data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * The basic encoding unit is a 3 character atom. It encodes two bytes
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * of data. Bytes are encoded into a 64 character set, the characters
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * were chosen specifically because they appear in all codesets.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * We don't care what their numerical equivalent is because
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * we use a character array to map them. This is like UUencoding
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * with the dependency on ASCII removed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * The three chars that make up an atom are encoded as follows:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 *      00xxxyyy 00axxxxx 00byyyyy
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 *      00 = leading zeros, all values are 0 - 63
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 *      xxxyyy - Top 3 bits of X, Top 3 bits of Y
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 *      axxxxx - a = X parity bit, xxxxx lower 5 bits of X
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 *      byyyyy - b = Y parity bit, yyyyy lower 5 bits of Y
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * The atoms are arranged into lines suitable for inclusion into an
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * email message or text file. The number of bytes that are encoded
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * per line is 48 which keeps the total line length  under 80 chars)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * Each line has the form(
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 *  *(LLSS)(DDDD)(DDDD)(DDDD)...(CRC)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 *  Where each (xxx) represents a three character atom.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 *  (LLSS) - 8 bit length (high byte), and sequence number
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 *           modulo 256;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 *  (DDDD) - Data byte atoms, if length is odd, last data
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 *           atom has (DD00) (high byte data, low byte 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 *  (CRC)  - 16 bit CRC for the line, includes length,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 *           sequence, and all data bytes. If there is a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 *           zero pad byte (odd length) it is _NOT_
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 *           included in the CRC.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 * If an error is encountered during decoding this class throws a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 * CEFormatException. The specific detail messages are:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 *    "UCDecoder: High byte parity error."
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 *    "UCDecoder: Low byte parity error."
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 *    "UCDecoder: Out of sequence line."
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 *    "UCDecoder: CRC check failed."
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 * @author      Chuck McManis
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 * @see         CharacterEncoder
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 * @see         UCEncoder
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
public class UCDecoder extends CharacterDecoder {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    /** This class encodes two bytes per atom. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    protected int bytesPerAtom() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        return (2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    /** this class encodes 48 bytes per line */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    protected int bytesPerLine() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        return (48);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    /* this is the UCE mapping of 0-63 to characters .. */
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 25859
diff changeset
    98
    private static final byte map_array[] = {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        //     0         1         2         3         4         5         6         7
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        (byte)'0',(byte)'1',(byte)'2',(byte)'3',(byte)'4',(byte)'5',(byte)'6',(byte)'7', // 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        (byte)'8',(byte)'9',(byte)'A',(byte)'B',(byte)'C',(byte)'D',(byte)'E',(byte)'F', // 1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        (byte)'G',(byte)'H',(byte)'I',(byte)'J',(byte)'K',(byte)'L',(byte)'M',(byte)'N', // 2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        (byte)'O',(byte)'P',(byte)'Q',(byte)'R',(byte)'S',(byte)'T',(byte)'U',(byte)'V', // 3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        (byte)'W',(byte)'X',(byte)'Y',(byte)'Z',(byte)'a',(byte)'b',(byte)'c',(byte)'d', // 4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        (byte)'e',(byte)'f',(byte)'g',(byte)'h',(byte)'i',(byte)'j',(byte)'k',(byte)'l', // 5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        (byte)'m',(byte)'n',(byte)'o',(byte)'p',(byte)'q',(byte)'r',(byte)'s',(byte)'t', // 6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        (byte)'u',(byte)'v',(byte)'w',(byte)'x',(byte)'y',(byte)'z',(byte)'(',(byte)')'  // 7
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    private int sequence;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    private byte tmp[] = new byte[2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    private CRC16 crc = new CRC16();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     * Decode one atom - reads the characters from the input stream, decodes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     * them, and checks for valid parity.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    protected void decodeAtom(PushbackInputStream inStream, OutputStream outStream, int l) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        int i, p1, p2, np1, np2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        byte a = -1, b = -1, c = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        byte high_byte, low_byte;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        byte tmp[] = new byte[3];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        i = inStream.read(tmp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        if (i != 3) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
                throw new CEStreamExhausted();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        for (i = 0; (i < 64) && ((a == -1) || (b == -1) || (c == -1)); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
            if (tmp[0] == map_array[i]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
                a = (byte) i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
            if (tmp[1] == map_array[i]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
                b = (byte) i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
            if (tmp[2] == map_array[i]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
                c = (byte) i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        high_byte = (byte) (((a & 0x38) << 2) + (b & 0x1f));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        low_byte = (byte) (((a & 0x7) << 5) + (c & 0x1f));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        p1 = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        p2 = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        for (i = 1; i < 256; i = i * 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
            if ((high_byte & i) != 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
                p1++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
            if ((low_byte & i) != 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
                p2++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        np1 = (b & 32) / 32;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        np2 = (c & 32) / 32;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        if ((p1 & 1) != np1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
            throw new CEFormatException("UCDecoder: High byte parity error.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        if ((p2 & 1) != np2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
            throw new CEFormatException("UCDecoder: Low byte parity error.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        outStream.write(high_byte);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        crc.update(high_byte);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        if (l == 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
            outStream.write(low_byte);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
            crc.update(low_byte);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    private ByteArrayOutputStream lineAndSeq = new ByteArrayOutputStream(2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     * decodeBufferPrefix initializes the sequence number to zero.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    protected void decodeBufferPrefix(PushbackInputStream inStream, OutputStream outStream) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        sequence = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     * decodeLinePrefix reads the sequence number and the number of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     * encoded bytes from the line. If the sequence number is not the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     * previous sequence number + 1 then an exception is thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     * UCE lines are line terminator immune, they all start with *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     * so the other thing this method does is scan for the next line
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     * by looking for the * character.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     * @exception CEFormatException out of sequence lines detected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    protected int decodeLinePrefix(PushbackInputStream inStream, OutputStream outStream)  throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        int     i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        int     nLen, nSeq;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        byte    xtmp[];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        int     c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        crc.value = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        while (true) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
            c = inStream.read(tmp, 0, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
            if (c == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
                throw new CEStreamExhausted();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
            if (tmp[0] == '*') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        lineAndSeq.reset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        decodeAtom(inStream, lineAndSeq, 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        xtmp = lineAndSeq.toByteArray();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        nLen = xtmp[0] & 0xff;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        nSeq = xtmp[1] & 0xff;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        if (nSeq != sequence) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
            throw new CEFormatException("UCDecoder: Out of sequence line.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        sequence = (sequence + 1) & 0xff;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        return (nLen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     * this method reads the CRC that is at the end of every line and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     * verifies that it matches the computed CRC.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     * @exception CEFormatException if CRC check fails.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
    protected void decodeLineSuffix(PushbackInputStream inStream, OutputStream outStream) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        int lineCRC = crc.value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        int readCRC;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        byte tmp[];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        lineAndSeq.reset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        decodeAtom(inStream, lineAndSeq, 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        tmp = lineAndSeq.toByteArray();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        readCRC = ((tmp[0] << 8) & 0xFF00) + (tmp[1] & 0xff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        if (readCRC != lineCRC) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
            throw new CEFormatException("UCDecoder: CRC check failed.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
}