Skip to content

Commit 8dd6f7e

Browse files
committed
Move brotli.dec to codec
DEVSIX-1314
1 parent 7a3250a commit 8dd6f7e

28 files changed

+343
-344
lines changed

io/src/main/java/org/brotli/dec/BitReader.java renamed to io/src/main/java/com/itextpdf/io/codec/brotli/dec/BitReader.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
55
*/
66

7-
package org.brotli.dec;
7+
package com.itextpdf.io.codec.brotli.dec;
88

99
import java.io.IOException;
1010
import java.io.InputStream;

io/src/main/java/org/brotli/dec/BrotliInputStream.java renamed to io/src/main/java/com/itextpdf/io/codec/brotli/dec/BrotliInputStream.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
55
*/
66

7-
package org.brotli.dec;
7+
package com.itextpdf.io.codec.brotli.dec;
88

99
import java.io.IOException;
1010
import java.io.InputStream;

io/src/main/java/org/brotli/dec/BrotliRuntimeException.java renamed to io/src/main/java/com/itextpdf/io/codec/brotli/dec/BrotliRuntimeException.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
55
*/
66

7-
package org.brotli.dec;
7+
package com.itextpdf.io.codec.brotli.dec;
88

99
/**
1010
* Unchecked exception used internally.

io/src/main/java/org/brotli/dec/Context.java renamed to io/src/main/java/com/itextpdf/io/codec/brotli/dec/Context.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
55
*/
66

7-
package org.brotli.dec;
7+
package com.itextpdf.io.codec.brotli.dec;
88

99
/**
1010
* Common context lookup table for all context modes.

io/src/main/java/org/brotli/dec/Decode.java renamed to io/src/main/java/com/itextpdf/io/codec/brotli/dec/Decode.java

Lines changed: 43 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,7 @@
44
See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
55
*/
66

7-
package org.brotli.dec;
8-
9-
import static org.brotli.dec.RunningState.BLOCK_START;
10-
import static org.brotli.dec.RunningState.CLOSED;
11-
import static org.brotli.dec.RunningState.COMPRESSED_BLOCK_START;
12-
import static org.brotli.dec.RunningState.COPY_LOOP;
13-
import static org.brotli.dec.RunningState.COPY_UNCOMPRESSED;
14-
import static org.brotli.dec.RunningState.COPY_WRAP_BUFFER;
15-
import static org.brotli.dec.RunningState.FINISHED;
16-
import static org.brotli.dec.RunningState.INSERT_LOOP;
17-
import static org.brotli.dec.RunningState.MAIN_LOOP;
18-
import static org.brotli.dec.RunningState.READ_METADATA;
19-
import static org.brotli.dec.RunningState.TRANSFORM;
20-
import static org.brotli.dec.RunningState.UNINITIALIZED;
21-
import static org.brotli.dec.RunningState.WRITE;
7+
package com.itextpdf.io.codec.brotli.dec;
228

239
/**
2410
* API for Brotli decompression.
@@ -436,10 +422,10 @@ private static void readMetablockInfo(State state) {
436422
final BitReader br = state.br;
437423

438424
if (state.inputEnd) {
439-
state.nextRunningState = FINISHED;
425+
state.nextRunningState = RunningState.FINISHED;
440426
state.bytesToWrite = state.pos;
441427
state.bytesWritten = 0;
442-
state.runningState = WRITE;
428+
state.runningState = RunningState.WRITE;
443429
return;
444430
}
445431
// TODO: Reset? Do we need this?
@@ -457,9 +443,9 @@ private static void readMetablockInfo(State state) {
457443
}
458444
if (state.isUncompressed || state.isMetadata) {
459445
BitReader.jumpToByteBoundary(br);
460-
state.runningState = state.isMetadata ? READ_METADATA : COPY_UNCOMPRESSED;
446+
state.runningState = state.isMetadata ? RunningState.READ_METADATA : RunningState.COPY_UNCOMPRESSED;
461447
} else {
462-
state.runningState = COMPRESSED_BLOCK_START;
448+
state.runningState = RunningState.COMPRESSED_BLOCK_START;
463449
}
464450

465451
if (state.isMetadata) {
@@ -548,7 +534,7 @@ private static void copyUncompressedData(State state) {
548534
// Could happen if block ends at ring buffer end.
549535
if (state.metaBlockLength <= 0) {
550536
BitReader.reload(br);
551-
state.runningState = BLOCK_START;
537+
state.runningState = RunningState.BLOCK_START;
552538
return;
553539
}
554540

@@ -557,15 +543,15 @@ private static void copyUncompressedData(State state) {
557543
state.metaBlockLength -= chunkLength;
558544
state.pos += chunkLength;
559545
if (state.pos == state.ringBufferSize) {
560-
state.nextRunningState = COPY_UNCOMPRESSED;
546+
state.nextRunningState = RunningState.COPY_UNCOMPRESSED;
561547
state.bytesToWrite = state.ringBufferSize;
562548
state.bytesWritten = 0;
563-
state.runningState = WRITE;
549+
state.runningState = RunningState.WRITE;
564550
return;
565551
}
566552

567553
BitReader.reload(br);
568-
state.runningState = BLOCK_START;
554+
state.runningState = RunningState.BLOCK_START;
569555
}
570556

571557
private static boolean writeRingBuffer(State state) {
@@ -594,20 +580,20 @@ static void setCustomDictionary(State state, byte[] data) {
594580
* Actual decompress implementation.
595581
*/
596582
static void decompress(State state) {
597-
if (state.runningState == UNINITIALIZED) {
583+
if (state.runningState == RunningState.UNINITIALIZED) {
598584
throw new IllegalStateException("Can't decompress until initialized");
599585
}
600-
if (state.runningState == CLOSED) {
586+
if (state.runningState == RunningState.CLOSED) {
601587
throw new IllegalStateException("Can't decompress after close");
602588
}
603589
final BitReader br = state.br;
604590
int ringBufferMask = state.ringBufferSize - 1;
605591
byte[] ringBuffer = state.ringBuffer;
606592

607-
while (state.runningState != FINISHED) {
593+
while (state.runningState != RunningState.FINISHED) {
608594
// TODO: extract cases to methods for the better readability.
609595
switch (state.runningState) {
610-
case BLOCK_START:
596+
case RunningState.BLOCK_START:
611597
if (state.metaBlockLength < 0) {
612598
throw new BrotliRuntimeException("Invalid metablock length");
613599
}
@@ -617,14 +603,14 @@ static void decompress(State state) {
617603
ringBuffer = state.ringBuffer;
618604
continue;
619605

620-
case COMPRESSED_BLOCK_START:
606+
case RunningState.COMPRESSED_BLOCK_START:
621607
readMetablockHuffmanCodesAndContextMaps(state);
622-
state.runningState = MAIN_LOOP;
608+
state.runningState = RunningState.MAIN_LOOP;
623609
// Fall through
624610

625-
case MAIN_LOOP:
611+
case RunningState.MAIN_LOOP:
626612
if (state.metaBlockLength <= 0) {
627-
state.runningState = BLOCK_START;
613+
state.runningState = RunningState.BLOCK_START;
628614
continue;
629615
}
630616
BitReader.readMoreInput(br);
@@ -648,10 +634,10 @@ static void decompress(State state) {
648634
.readBits(br, Prefix.COPY_LENGTH_N_BITS[copyCode]);
649635

650636
state.j = 0;
651-
state.runningState = INSERT_LOOP;
637+
state.runningState = RunningState.INSERT_LOOP;
652638

653639
// Fall through
654-
case INSERT_LOOP:
640+
case RunningState.INSERT_LOOP:
655641
if (state.trivialLiteralContext) {
656642
while (state.j < state.insertLength) {
657643
BitReader.readMoreInput(br);
@@ -664,10 +650,10 @@ static void decompress(State state) {
664650
(byte) readSymbol(state.hGroup0.codes, state.literalTree, br);
665651
state.j++;
666652
if (state.pos++ == ringBufferMask) {
667-
state.nextRunningState = INSERT_LOOP;
653+
state.nextRunningState = RunningState.INSERT_LOOP;
668654
state.bytesToWrite = state.ringBufferSize;
669655
state.bytesWritten = 0;
670-
state.runningState = WRITE;
656+
state.runningState = RunningState.WRITE;
671657
break;
672658
}
673659
}
@@ -690,20 +676,20 @@ static void decompress(State state) {
690676
ringBuffer[state.pos] = (byte) prevByte1;
691677
state.j++;
692678
if (state.pos++ == ringBufferMask) {
693-
state.nextRunningState = INSERT_LOOP;
679+
state.nextRunningState = RunningState.INSERT_LOOP;
694680
state.bytesToWrite = state.ringBufferSize;
695681
state.bytesWritten = 0;
696-
state.runningState = WRITE;
682+
state.runningState = RunningState.WRITE;
697683
break;
698684
}
699685
}
700686
}
701-
if (state.runningState != INSERT_LOOP) {
687+
if (state.runningState != RunningState.INSERT_LOOP) {
702688
continue;
703689
}
704690
state.metaBlockLength -= state.insertLength;
705691
if (state.metaBlockLength <= 0) {
706-
state.runningState = MAIN_LOOP;
692+
state.runningState = RunningState.MAIN_LOOP;
707693
continue;
708694
}
709695
if (state.distanceCode < 0) {
@@ -743,7 +729,7 @@ static void decompress(State state) {
743729

744730
state.copyDst = state.pos;
745731
if (state.distance > state.maxDistance) {
746-
state.runningState = TRANSFORM;
732+
state.runningState = RunningState.TRANSFORM;
747733
continue;
748734
}
749735

@@ -756,9 +742,9 @@ static void decompress(State state) {
756742
throw new BrotliRuntimeException("Invalid backward reference"); // COV_NF_LINE
757743
}
758744
state.j = 0;
759-
state.runningState = COPY_LOOP;
745+
state.runningState = RunningState.COPY_LOOP;
760746
// fall through
761-
case COPY_LOOP:
747+
case RunningState.COPY_LOOP:
762748
int src = (state.pos - state.distance) & ringBufferMask;
763749
int dst = state.pos;
764750
int copyLength = state.copyLength - state.j;
@@ -776,20 +762,20 @@ static void decompress(State state) {
776762
state.metaBlockLength--;
777763
state.j++;
778764
if (state.pos++ == ringBufferMask) {
779-
state.nextRunningState = COPY_LOOP;
765+
state.nextRunningState = RunningState.COPY_LOOP;
780766
state.bytesToWrite = state.ringBufferSize;
781767
state.bytesWritten = 0;
782-
state.runningState = WRITE;
768+
state.runningState = RunningState.WRITE;
783769
break;
784770
}
785771
}
786772
}
787-
if (state.runningState == COPY_LOOP) {
788-
state.runningState = MAIN_LOOP;
773+
if (state.runningState == RunningState.COPY_LOOP) {
774+
state.runningState = RunningState.MAIN_LOOP;
789775
}
790776
continue;
791777

792-
case TRANSFORM:
778+
case RunningState.TRANSFORM:
793779
if (state.copyLength >= Dictionary.MIN_WORD_LENGTH
794780
&& state.copyLength <= Dictionary.MAX_WORD_LENGTH) {
795781
int offset = Dictionary.OFFSETS_BY_LENGTH[state.copyLength];
@@ -807,10 +793,10 @@ static void decompress(State state) {
807793
state.pos += len;
808794
state.metaBlockLength -= len;
809795
if (state.copyDst >= state.ringBufferSize) {
810-
state.nextRunningState = COPY_WRAP_BUFFER;
796+
state.nextRunningState = RunningState.COPY_WRAP_BUFFER;
811797
state.bytesToWrite = state.ringBufferSize;
812798
state.bytesWritten = 0;
813-
state.runningState = WRITE;
799+
state.runningState = RunningState.WRITE;
814800
continue;
815801
}
816802
} else {
@@ -819,31 +805,31 @@ static void decompress(State state) {
819805
} else {
820806
throw new BrotliRuntimeException("Invalid backward reference"); // COV_NF_LINE
821807
}
822-
state.runningState = MAIN_LOOP;
808+
state.runningState = RunningState.MAIN_LOOP;
823809
continue;
824810

825-
case COPY_WRAP_BUFFER:
811+
case RunningState.COPY_WRAP_BUFFER:
826812
System.arraycopy(ringBuffer, state.ringBufferSize, ringBuffer, 0,
827813
state.copyDst - state.ringBufferSize);
828-
state.runningState = MAIN_LOOP;
814+
state.runningState = RunningState.MAIN_LOOP;
829815
continue;
830816

831-
case READ_METADATA:
817+
case RunningState.READ_METADATA:
832818
while (state.metaBlockLength > 0) {
833819
BitReader.readMoreInput(br);
834820
// Optimize
835821
BitReader.readBits(br, 8);
836822
state.metaBlockLength--;
837823
}
838-
state.runningState = BLOCK_START;
824+
state.runningState = RunningState.BLOCK_START;
839825
continue;
840826

841827

842-
case COPY_UNCOMPRESSED:
828+
case RunningState.COPY_UNCOMPRESSED:
843829
copyUncompressedData(state);
844830
continue;
845831

846-
case WRITE:
832+
case RunningState.WRITE:
847833
if (!writeRingBuffer(state)) {
848834
// Output buffer is full.
849835
return;
@@ -859,7 +845,7 @@ static void decompress(State state) {
859845
throw new BrotliRuntimeException("Unexpected state " + state.runningState);
860846
}
861847
}
862-
if (state.runningState == FINISHED) {
848+
if (state.runningState == RunningState.FINISHED) {
863849
if (state.metaBlockLength < 0) {
864850
throw new BrotliRuntimeException("Invalid metablock length");
865851
}

io/src/main/java/org/brotli/dec/Dictionary.java renamed to io/src/main/java/com/itextpdf/io/codec/brotli/dec/Dictionary.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
55
*/
66

7-
package org.brotli.dec;
7+
package com.itextpdf.io.codec.brotli.dec;
88

99
import java.nio.ByteBuffer;
1010

io/src/main/java/org/brotli/dec/DictionaryData.java renamed to io/src/main/java/com/itextpdf/io/codec/brotli/dec/DictionaryData.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
55
*/
66

7-
package org.brotli.dec;
7+
package com.itextpdf.io.codec.brotli.dec;
88

99
import java.nio.ByteBuffer;
1010

io/src/main/java/org/brotli/dec/Huffman.java renamed to io/src/main/java/com/itextpdf/io/codec/brotli/dec/Huffman.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
55
*/
66

7-
package org.brotli.dec;
7+
package com.itextpdf.io.codec.brotli.dec;
88

99
/**
1010
* Utilities for building Huffman decoding tables.

io/src/main/java/org/brotli/dec/HuffmanTreeGroup.java renamed to io/src/main/java/com/itextpdf/io/codec/brotli/dec/HuffmanTreeGroup.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
55
*/
66

7-
package org.brotli.dec;
7+
package com.itextpdf.io.codec.brotli.dec;
88

99
/**
1010
* Contains a collection of huffman trees with the same alphabet size.

io/src/main/java/org/brotli/dec/IntReader.java renamed to io/src/main/java/com/itextpdf/io/codec/brotli/dec/IntReader.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
55
*/
66

7-
package org.brotli.dec;
7+
package com.itextpdf.io.codec.brotli.dec;
88

99
/**
1010
* Byte-to-int conversion magic.

0 commit comments

Comments
 (0)