File: PreLh3Decoder.java

package info (click to toggle)
libjlha-java 0.0.20050504-9
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 1,448 kB
  • ctags: 1,411
  • sloc: java: 10,791; xml: 156; makefile: 11
file content (725 lines) | stat: -rw-r--r-- 26,416 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
//start of PreLh3Decoder.java
//TEXT_STYLE:CODE=Shift_JIS(Japanese):RET_CODE=CRLF

/**
 * PreLh3Decoder.java
 * 
 * Copyright (C) 2002  Michel Ishizuka  All rights reserved.
 * 
 * ȉ̏ɓӂȂ΃\[XƃoCi`̍ĔzzƎgp
 * ύX̗Lɂ炸‚B
 * 
 * PD\[XR[h̍ĔzzɂĒ쌠\ ̏̃Xg
 *     щL̐ێȂĂ͂ȂȂB
 * 
 * QDoCi`̍ĔzzɂĒ쌠\ ̏̃Xg
 *     щL̐gp ̑̔zz
 *     ܂ގɋLqȂ΂ȂȂB
 * 
 * ̃\tgEFA͐Β˔ڂɂĖۏ؂Œ񋟂A̖
 * IBłƂۏ؁AilLƂۏ؂ɂƂǂ܂炸A
 * Ȃ閾IшÎIȕۏ؂ȂB
 * Β˔ڂ ̃\tgEFA̎gpɂ钼ړIAԐړIA
 * IAȁAT^IȁA邢͕KRIȑQ(gpɂf[^
 * AƖ̒f〈܂Ăv̈⎸A֐i
 * T[rX̓l邪AĂꂾɌ肳Ȃ
 * Q)ɑ΂āAȂ鎖Ԃ̌ƂȂƂĂA_̐
 * C△ߎӔC܂ ȂӔC낤ƂAƂꂪs
 * ŝׂ߂łƂĂA܂͂̂悤ȑQ̉”\
 * ĂƂĂ؂̐ӔC𕉂Ȃ̂ƂB
 */

package jp.gr.java_conf.dangan.util.lha;

//import classes and interfaces
import java.io.InputStream;
import java.lang.Math;
import jp.gr.java_conf.dangan.io.BitInputStream;
import jp.gr.java_conf.dangan.util.lha.StaticHuffman;
import jp.gr.java_conf.dangan.util.lha.PreLzssDecoder;

//import exceptions
import java.io.IOException;
import java.io.EOFException;
import java.lang.NullPointerException;
import java.lang.IllegalArgumentException;
import jp.gr.java_conf.dangan.io.BitDataBrokenException;
import jp.gr.java_conf.dangan.io.NotEnoughBitsException;
import jp.gr.java_conf.dangan.util.lha.BadHuffmanTableException;

/**
 * -lh3- 𓀗p PreLzssDecoderB
 * 
 * <pre>
 * -- revision history --
 * $Log: PreLh3Decoder.java,v $
 * Revision 1.1  2002/12/01 00:00:00  dangan
 * [maintenance]
 *     \[X
 *
 * Revision 1.0  2002/08/05 00:00:00  dangan
 * add to version control
 * [bug fix]
 *     available ̌vZÂ̂CB
 * [maintenance]
 *     \[X
 *     ^up~
 *     CZX̏C
 *
 * </pre>
 * 
 * @author  $Author: dangan $
 * @version $Revision: 1.1 $
 */
public class PreLh3Decoder implements PreLzssDecoder {


    //------------------------------------------------------------------
    //  class field
    //------------------------------------------------------------------
    //  LZSS parameter
    //------------------------------------------------------------------
    //  private static final int DictionarySize
    //  private static final int MaxMatch
    //  private static final int Threshold
    //------------------------------------------------------------------
    /** TCY */
    private static final int DictionarySize = 8192;

    /** őv */
    private static final int MaxMatch       = 256;

    /** ŏv */
    private static final int Threshold      = 3;


    //------------------------------------------------------------------
    //  class field
    //------------------------------------------------------------------
    //  private static final int CodeSize
    //------------------------------------------------------------------
    /**
     * codẽnt}؂̃TCY 
     * codeȏ̒lꍇ͗]vȃrbgo͂ĕ₤B
     */
    private static final int CodeSize = 286;


    //------------------------------------------------------------------
    //  instance field
    //------------------------------------------------------------------
    //  source
    //------------------------------------------------------------------
    //  private BitInputStream in
    //------------------------------------------------------------------
    /**
     * -lh3- ̈kf[^ BitInputStream
     */
     private BitInputStream in;


    //------------------------------------------------------------------
    //  instance field
    //------------------------------------------------------------------
    //  huffman decoder
    //------------------------------------------------------------------
    //  private int blockSize
    //  private int[] codeLen
    //  private short[] codeTable
    //  private int codeTableBits
    //  private short[][] codeTree
    //  private int[] offHiLen
    //  private short[] offHiTable
    //  private int offHiTableBits
    //  private short[][] offHiTree
    //------------------------------------------------------------------
    /**
     * ݏ̃ubN̎cTCYB
     */
    private int blockSize;

    /**
     * code ̃nt}̕\
     */
    private int[] codeLen;

    /**
     * code p̃e[u
     * ̏ꍇ codeTree indexB
     * ̏ꍇ code Srbg]́B 
     */
    private short[] codeTable;

    /**
     * codeTable ߂ɕKvbitB
     */
    private int codeTableBits;

    /**
     * codeTable Ɏ܂肫Ȃf[^̕p̖
     * ̏ꍇ codeTree indexB
     * ̏ꍇ code Srbg]́B 
     */
    private short[][] codeTree;

    /**
     * offHi ̃nt}̕\
     */
    private int[] offHiLen;

    /**
     * offHi p̃e[u
     * ̏ꍇ offHi indexB
     * ̏ꍇ code Srbg]́B 
     */
    private short[] offHiTable;

    /**
     * offHiTable ߂ɕKvbitB
     */
    private int offHiTableBits;

    /**
     * offHiTable Ɏ܂肫Ȃf[^̕p̖
     * ̏ꍇ offHi indexB
     * ̏ꍇ code Srbg]́B 
     */
    private short[][] offHiTree;


    //------------------------------------------------------------------
    //  instance field
    //------------------------------------------------------------------
    //  backup for mark/reset
    //------------------------------------------------------------------
    //  private int markBlockSize
    //  private int[] markCodeLen
    //  private short[] markCodeTable
    //  private short[][] markCodeTree
    //  private int[] markOffHiLen
    //  private short[] markOffHiTable
    //  private short[][] markOffHiTree
    //------------------------------------------------------------------
    /** blockSizẽobNAbvp */
    private int markBlockSize;
    /** codeLen ̃obNAbvp */
    private int[] markCodeLen;
    /** codeTable ̃obNAbvp */
    private short[] markCodeTable;
    /** codeTree ̃obNAbvp */
    private short[][] markCodeTree;
    /** offHiLen ̃obNAbvp */
    private int[] markOffHiLen;
    /** offHiTable ̃obNAbvp */
    private short[] markOffHiTable;
    /** offHiTree ̃obNAbvp */
    private short[][] markOffHiTree;


    //------------------------------------------------------------------
    //  constructer
    //------------------------------------------------------------------
    //  private PreLh3Decoder()
    //  public PreLh3Decoder( InputStream in )
    //  public PreLh3Decoder( InputStream in, 
    //                        int CodeTableBits, int OffHiTableBits )
    //------------------------------------------------------------------
    /**
     * ftHgRXgN^B
     * gpsB
     */
    private PreLh3Decoder(){    }

    /**
     * -lh3- 𓀗p PreLzssDecoder \zB<br>
     * e[uTCYɂ ftHglgpB
     * 
     * @param in kf[^̓Xg[
     */
    public PreLh3Decoder( InputStream in ){
        this( in, 12, 8 );
    }

    /**
     * -lh3- 𓀗p PreLzssDecoder \zB<br>
     * 
     * @param in             kf[^̓Xg[
     * @param CodeTableBits  code 𕜍邽߂Ɏgp
     *                       e[ũTCYrbgŎw肷B 
     *                       12 w肷 4096 ̃bNAbve[u𐶐B 
     * @param OffHiTableBits offHi 𕜍邽߂Ɏgp
     *                       e[ũTCYrbgŎw肷B
     *                       8 w肷 256 ̃bNAbve[u𐶐B 
     * 
     * @exception IllegalArgumentException
     *                       CodeTableBits, OffHiTableBits  0ȉ̏ꍇ
     */
    public PreLh3Decoder( InputStream in, 
                          int         CodeTableBits,
                          int         OffHiTableBits ){
        if( in != null
         && 0 < CodeTableBits
         && 0 < OffHiTableBits ){
            if( in instanceof BitInputStream ){
                this.in = (BitInputStream)in;
            }else{
                this.in = new BitInputStream( in );
            }
            this.blockSize      = 0;
            this.codeTableBits  = CodeTableBits;
            this.offHiTableBits = OffHiTableBits;
        }else if( in == null ){
            throw new NullPointerException( "in" );
        }else if( CodeTableBits <= 0 ){
            throw new IllegalArgumentException( "CodeTableBits too small. CodeTableBits must be larger than 1." );
        }else{
            throw new IllegalArgumentException( "OffHiTableBits too small. OffHiTableBits must be larger than 1." );
        }
    }


    //------------------------------------------------------------------
    //  method of jp.gr.java_conf.dangan.util.lha.PreLzssDecoder
    //------------------------------------------------------------------
    //  read
    //------------------------------------------------------------------
    //  public int readCode()
    //  public int readOffset()
    //------------------------------------------------------------------
    /**
     * -lh3- ňkꂽ
     * 1byte LZSSk̃f[^A
     * ͈kR[ĥvǂݍށB<br>
     * 
     * @return 1byte  k̃f[^́A
     *         kꂽkR[ĥv
     * 
     * @exception IOException  o̓G[ꍇ
     * @exception EOFException EndOfStreamɒBꍇ
     * @exception BadHuffmanTableException
     *                         nt}؂\邽߂
     *                         nt}̕\sȂ߁A
     *                         nt}킪łȂꍇ
     */
    public int readCode() throws IOException {
        if( this.blockSize <= 0 ){
            this.readBlockHead();
        }
        this.blockSize--;

        int code;
        try{
            int node = this.codeTable[ this.in.peekBits( this.codeTableBits ) ];
            if( node < 0 ){
                code = ~node;
                this.in.skipBits( this.codeLen[ code ] );
            }else{
                this.in.skipBits( this.codeTableBits );
                do{
                    node = this.codeTree[ this.in.readBit() ][ node ];
                }while( 0 <= node );
                code = ~node;
            }
        }catch( NotEnoughBitsException exception ){
            int avail = exception.getAvailableBits();
            int bits = this.in.peekBits( avail );
            bits = bits << ( this.codeTableBits - avail );
            int node = this.codeTable[ bits ];

            if( node < 0 ){
                code = ~node; 
                if( this.in.skipBits( this.codeLen[code] ) < this.codeLen[code] ){
                    throw new EOFException();
                }
            }else{
                this.in.skipBits( avail );
                throw new EOFException();
            }
        }catch( ArrayIndexOutOfBoundsException exception ){
            throw new EOFException();
        }

        final int CodeMax = PreLh3Decoder.CodeSize - 1;
        if( code == CodeMax ){
            code += this.in.readBits( 8 );
        }
        return code;
    }

    /**
     * -lh3- ňkꂽ
     * LZSSkR[ĥvʒuǂݍށB<br>
     * 
     * @return -lh3- ňkꂽkR[ĥvʒu
     * 
     * @exception IOException o̓G[ꍇ
     */
    public int readOffset() throws IOException {
        int offHi;
        try{
            int node = this.offHiTable[ this.in.peekBits( this.offHiTableBits ) ];
            if( node < 0 ){
                offHi = ~node;
                this.in.skipBits( this.offHiLen[ offHi ] );
            }else{
                this.in.skipBits( this.offHiTableBits );
                do{
                    node = this.offHiTree[ this.in.readBit() ][ node ];
                }while( 0 <= node );
                offHi = ~node;
            }
        }catch( NotEnoughBitsException exception ){
            int avail = exception.getAvailableBits();
            int bits = this.in.peekBits( avail );
            bits = bits << ( this.offHiTableBits - avail );
            int node = this.offHiTable[ bits ];

            if( node < 0 ){
                offHi = ~node; 
                if( this.offHiLen[offHi] <= avail ){
                    this.in.skipBits( this.offHiLen[offHi] );
                }else{
                    this.in.skipBits( avail );
                    throw new EOFException();
                }
            }else{
                this.in.skipBits( avail );
                throw new EOFException();
            }
        }catch( ArrayIndexOutOfBoundsException exception ){
            throw new EOFException();
        }
        
        return ( offHi << 6 ) | this.in.readBits( 6 );
    }


    //------------------------------------------------------------------
    //  method of jp.gr.java_conf.dangan.util.lha.PreLzssDecoder
    //------------------------------------------------------------------
    //  mark / reset
    //------------------------------------------------------------------
    //  public void mark( int readLimit )
    //  public void reset()
    //  public boolean markSupported()
    //------------------------------------------------------------------
    /**
     * ڑꂽ̓Xg[݈̌ʒuɃ}[Nݒ肵A
     * reset() \bhŃ}[N_ ǂݍ݈ʒu
     * ߂悤ɂB<br>
     * InputStream  mark() ƈႢAreadLimit Őݒ肵
     * EoCgOɃ}[NʒuɂȂ”\
     * 鎖ɒӂ邱ƁB<br>
     * 
     * @param readLimit }[Nʒuɖ߂ẼoCgB
     *                  ̃oCg𒴂ăf[^ǂ
     *                  񂾏ꍇ reset()łȂȂ
     *                  \B<br>
     * 
     * @see PreLzssDecoder#mark(int)
     */
    public void mark( int readLimit ){
        readLimit = readLimit * StaticHuffman.LimitLen / 8;
        if( this.blockSize < readLimit ){
            readLimit += 245;
        }
        this.in.mark( readLimit );

        this.markBlockSize  = this.blockSize;
        this.markCodeLen    = this.codeLen;
        this.markCodeTable  = this.codeTable;
        this.markCodeTree   = this.codeTree;
        this.markOffHiLen   = this.offHiLen;
        this.markOffHiTable = this.offHiTable;
        this.markOffHiTree  = this.offHiTree;
    }

    /**
     * ڑꂽ̓Xg[̓ǂݍ݈ʒuŌ
     * mark() \bhĂяoꂽƂ̈ʒuɐݒ肷B<br>
     * 
     * @exception IOException o̓G[ꍇ
     */
    public void reset() throws IOException {
        //mark()Ȃ reset() 悤ƂꍇA
        //readLimit 𒴂 reset() 悤ƂꍇA
        //ڑꂽ InputStream  markSupported()  false Ԃꍇ
        //BitInputStream  IOException 𓊂B
        this.in.reset();                                                        //throws IOException

        this.blockSize  = this.markBlockSize;
        this.codeLen    = this.markCodeLen;
        this.codeTable  = this.markCodeTable;
        this.codeTree   = this.markCodeTree;
        this.offHiLen   = this.markOffHiLen;
        this.offHiTable = this.markOffHiTable;
        this.offHiTree  = this.markOffHiTree;
    }

    /**
     * ڑꂽ̓Xg[ mark()  reset() 
     * T|[g邩𓾂B<br>
     * 
     * @return Xg[ mark()  reset() 
     *         T|[gꍇ trueB<br>
     *         T|[gȂꍇ falseB<br>
     */
    public boolean markSupported(){
        return this.in.markSupported();
    }

    //------------------------------------------------------------------
    //  method of jp.gr.java_conf.dangan.util.lha.PreLzssDecoder
    //------------------------------------------------------------------
    //  other
    //------------------------------------------------------------------
    //  public int available()
    //  public void close()
    //------------------------------------------------------------------
    /**
     * ubNɓǂݏoƂ̏oŒoCg𓾂B<br>
     * InputStream  available() ƈႢA
     * ̍ŒoCg͕KۏႳĂȂɒӂ邱ƁB<br>
     * 
     * @return ubNȂœǂݏoŒoCgB<br>
     * 
     * @exception IOException o̓G[ꍇ
     * 
     * @see PreLzssDecoder#available()
     */
    public int available() throws IOException {
        int avail = this.in.available() * 8 / StaticHuffman.LimitLen;
        if( this.blockSize < avail ){
            avail -= 245;
        }
        return Math.max( avail, 0 );
    }

    /**
     * ̃Xg[‚AgpĂSĂ̎B
     * 
     * @exception IOException o̓G[ꍇ
     */
    public void close() throws IOException {
        this.in.close();
        this.in             = null;

        this.blockSize      = 0;
        this.codeLen        = null;
        this.codeTable      = null;
        this.codeTree       = null;
        this.offHiLen       = null;
        this.offHiTable     = null;
        this.offHiTree      = null;

        this.markBlockSize  = 0;
        this.markCodeLen    = null;
        this.markCodeTable  = null;
        this.markCodeTree   = null;
        this.markOffHiLen   = null;
        this.markOffHiTable = null;
        this.markOffHiTree  = null;
    }


    //------------------------------------------------------------------
    //  method of jp.gr.java_conf.dangan.util.lha.PostLzssEncoder
    //------------------------------------------------------------------
    //  get LZSS parameter
    //------------------------------------------------------------------
    //  public int getDictionarySize()
    //  public int getMaxMatch()
    //  public int getThreshold()
    //------------------------------------------------------------------
    /**
     * -lh3-` LZSS̃TCY𓾂B
     * 
     * @return -lh3-` LZSS̃TCY
     */
    public int getDictionarySize(){
        return PreLh3Decoder.DictionarySize;
    }

    /**
     * -lh3-` LZSS̍őv𓾂B
     * 
     * @return -lh3-` LZSS̍őv
     */
    public int getMaxMatch(){
        return PreLh3Decoder.MaxMatch;
    }

    /**
     * -lh3-` LZSS̈kA񈳏k臒l𓾂B
     * 
     * @return -lh3-` LZSS̈kA񈳏k臒l
     */
    public int getThreshold(){
        return PreLh3Decoder.Threshold;
    }


    //------------------------------------------------------------------
    //  local method
    //------------------------------------------------------------------
    //  read block head
    //------------------------------------------------------------------
    //  private void readBlockHead()
    //  private int[] readCodeLen()
    //  private int[] readOffHiLen()
    //------------------------------------------------------------------
    /**
     * nt}ubN̐擪ɂ
     * ubNTCYnt}̃XgǂݍށB
     * 
     * @exception IOException  o̓G[ꍇ
     * @exception EOFException EndOfStreamɒBꍇ
     * @exception BadHuffmanTableException
     *                         nt}؂\邽߂
     *                         nt}̕\sȂ߁A
     *                         nt}킪łȂꍇ
     * @exception BitDataBrokenException
     *                         \ʌŃf[^ǂ݂݂
     *                         fꂽߗvꂽrbg
     *                         ̃f[^Ȃꍇ
     */
    private void readBlockHead() throws IOException {
        //ubNTCYǂݍ
        //ȃf[^̏ꍇA̕ EndOfStream ɓBB
        try{
            this.blockSize = this.in.readBits( 16 );                            //throws BitDataBrokenException, EOFException, IOException
        }catch( BitDataBrokenException exception ){
            if( exception.getCause() instanceof EOFException ){
                throw (EOFException)exception.getCause();
            }else{
                throw exception;
            }
        }

        //code ̏
        this.codeLen = this.readCodeLen();
        if( 1 < this.codeLen.length ){
            short[][] tableAndTree = 
                StaticHuffman.createTableAndTree( this.codeLen, this.codeTableBits );
            this.codeTable = tableAndTree[0];
            this.codeTree  = new short[][]{ tableAndTree[1], tableAndTree[2] };
        }else{
            int code = this.codeLen[0];
            this.codeLen   = new int[ PreLh3Decoder.CodeSize ];
            this.codeTable = new short[ 1 << this.codeTableBits ];
            for( int i = 0 ; i < this.codeTable.length ; i++ ){
                this.codeTable[i] = ((short)~code);
            }
            this.codeTree = new short[][]{ new short[0], new short[0] };
        }

        //offHi ̏
        this.offHiLen = this.readOffHiLen();
        if( 1 < this.offHiLen.length ){
            short[][] tableAndTree = 
                StaticHuffman.createTableAndTree( this.offHiLen, this.offHiTableBits );
            this.offHiTable = tableAndTree[0];
            this.offHiTree  = new short[][]{ tableAndTree[1], tableAndTree[2] };
        }else{
            int offHi = this.offHiLen[0];
            this.offHiLen   = new int[ PreLh3Decoder.DictionarySize >> 6 ];
            this.offHiTable = new short[ 1 << this.offHiTableBits ];
            for( int i = 0 ; i < this.offHiTable.length ; i++ ){
                this.offHiTable[i] = ((short)~offHi);
            }
            this.offHiTree = new short[][]{ new short[0], new short[0] };
        }
    }

    /**
     * code ̃nt}̃Xgǂ݂ށB
     * 
     * @return nt}̃XgB
     *           1 ̗B̃R[h
     * 
     * @exception IOException  o̓G[ꍇ
     * @exception EOFException EndOfStreamɒBꍇ
     * @exception BitDataBrokenException
     *                         \ʌŃf[^ǂ݂݂
     *                         fꂽߗvꂽrbg
     *                         ̃f[^Ȃꍇ
     */
    private int[] readCodeLen() throws IOException {
        int[] codeLen = new int[ PreLh3Decoder.CodeSize ];

        for( int i = 0 ; i < codeLen.length ; i++ ){
            if( this.in.readBoolean() )
                codeLen[i] = this.in.readBits( 4 ) + 1;

            if( i == 2 && codeLen[0] == 1 && codeLen[1] == 1 && codeLen[2] == 1 ){
                return new int[]{ this.in.readBits( 9 ) };
            }
        }
        return codeLen;
    }

    /**
     * offHĩnt}̃Xgǂ݂
     * 
     * @return nt}̃XgB
     *           1 ̗B̃R[h
     * 
     * @exception IOException  o̓G[ꍇ
     * @exception EOFException EndOfStreamɒBꍇ
     * @exception BitDataBrokenException
     *                         \ʌŃf[^ǂ݂݂
     *                         fꂽߗvꂽrbg
     *                         ̃f[^Ȃꍇ
     */
    private int[] readOffHiLen() throws IOException {
        if( this.in.readBoolean() ){
            int[] offHiLen = new int[ PreLh3Decoder.DictionarySize >> 6 ];

            for( int i = 0 ; i < offHiLen.length ; i++ ){
                offHiLen[i] = this.in.readBits( 4 );

                if( i == 2 && offHiLen[0] == 1 && offHiLen[1] == 1 && offHiLen[2] == 1 ){
                    return new int[]{ this.in.readBits( 7 ) };
                }
            }
            return offHiLen;
        }else{
            return PreLh3Decoder.createConstOffHiLen();
        }
    }


    //------------------------------------------------------------------
    //  local method
    //------------------------------------------------------------------
    //  constant huffman tree
    //------------------------------------------------------------------
    //  private static int[] createConstOffHiLen()
    //------------------------------------------------------------------
    /**
     * -lh3-  offsetfR[hpStaticHuffman
     * nt}Xg𐶐B
     * 
     * @return -lh3-  offsetfR[hpStaticHuffman
     *         nt}Xg
     */
    private static int[] createConstOffHiLen(){
        final int length = PreLh3Decoder.DictionarySize >> 6;
        final int[] list = { 2, 0x01, 0x01, 0x03, 0x06, 0x0D, 0x1F, 0x4E, 0 };

        int[] LenList = new int[ length ];
        int index = 0;
        int len = list[ index++ ];

        for( int i = 0 ; i < length ; i++ ){
            while( list[index] == i ){
                len++;
                index++;
            }
            LenList[i] = len;
        }
        return LenList;
    }

}
//end of PreLh3Decoder.java