Skip to content

Commit

Permalink
#103 Avoid array when ECD
Browse files Browse the repository at this point in the history
  • Loading branch information
oleg-cherednik committed Nov 23, 2024
1 parent 64d62f1 commit 4115078
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 234 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import ru.olegcherednik.zip4jvm.exception.CompressionNotSupportedException;
import ru.olegcherednik.zip4jvm.io.in.data.BaseDataInput;
import ru.olegcherednik.zip4jvm.io.in.data.DataInput;
import ru.olegcherednik.zip4jvm.io.in.data.ecd.Bzip2DataInput;
import ru.olegcherednik.zip4jvm.io.in.data.ecd.EnhancedDeflateDataInput;
import ru.olegcherednik.zip4jvm.io.in.data.ecd.InflateDataInput;
import ru.olegcherednik.zip4jvm.io.in.data.ecd.StoreDataInput;
Expand Down Expand Up @@ -53,7 +54,7 @@ public static DataInput create(ZipEntry zipEntry,
if (compressionMethod == CompressionMethod.ENHANCED_DEFLATE)
return new EnhancedDeflateDataInput(in);
if (compressionMethod == CompressionMethod.BZIP2)
return new Bzip2EntryDataInput(in);
return new Bzip2DataInput(in);
if (compressionMethod == CompressionMethod.LZMA)
return new LzmaEntryDataInput(zipEntry, in);
if (compressionMethod == CompressionMethod.ZSTD)
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@
* @author Oleg Cherednik
* @since 12.04.2020
*/
final class Bzip2DataInput extends CompressedDataInput {
public final class Bzip2DataInput extends CompressedDataInput {

private final Bzip2InputStream bzip;

Bzip2DataInput(DataInput in) {
public Bzip2DataInput(DataInput in) {
super(in);
bzip = new Bzip2InputStream(in);
}
Expand Down
42 changes: 35 additions & 7 deletions src/main/java/ru/olegcherednik/zip4jvm/model/Compression.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,30 +19,58 @@
package ru.olegcherednik.zip4jvm.model;

import ru.olegcherednik.zip4jvm.exception.CompressionNotSupportedException;
import ru.olegcherednik.zip4jvm.io.in.data.DataInput;

import lombok.Getter;
import lombok.RequiredArgsConstructor;

import java.util.Optional;
import java.util.function.Function;

/**
* This matches with {@link CompressionMethod}, but here we have only supported methods.
*
* @author Oleg Cherednik
* @since 03.08.2019
*/
@Getter
@RequiredArgsConstructor
public enum Compression {

STORE(CompressionMethod.STORE, "store"),
DEFLATE(CompressionMethod.DEFLATE, "deflate"),
ENHANCED_DEFLATE(CompressionMethod.ENHANCED_DEFLATE, "enhanced-deflate"),
BZIP2(CompressionMethod.BZIP2, "bzip2"),
LZMA(CompressionMethod.LZMA, "lzma"),
ZSTD(CompressionMethod.ZSTD, "zstd");
STORE(CompressionMethod.STORE, null, "store"),
DEFLATE(CompressionMethod.DEFLATE, null, "deflate"),
ENHANCED_DEFLATE(CompressionMethod.ENHANCED_DEFLATE, null, "enhanced-deflate"),
BZIP2(CompressionMethod.BZIP2, null, "bzip2"),
LZMA(CompressionMethod.LZMA, null, "lzma"),
ZSTD(CompressionMethod.ZSTD, null, "zstd");

@Getter
private final CompressionMethod method;
private final Function<DataInput, DataInput> decoratorDataInput;
@Getter
private final String title;

public DataInput addCompressionDecorator(DataInput in) {
return Optional.ofNullable(decoratorDataInput)
.orElseThrow(() -> new CompressionNotSupportedException(this))
.apply(in);
}

// public static DataInput create(Zip64.ExtensibleDataSector extensibleDataSector, DataInput in) {
// CompressionMethod compressionMethod = extensibleDataSector.getCompressionMethod();
//
// if (compressionMethod == CompressionMethod.STORE)
// return new StoreDataInput(in);
// if (compressionMethod == CompressionMethod.DEFLATE)
// return new InflateDataInput(in);
// if (compressionMethod == CompressionMethod.ENHANCED_DEFLATE)
// return new EnhancedDeflateDataInput(in);
// if (compressionMethod == CompressionMethod.BZIP2)
// return new Bzip2DataInput(in);
//
// throw new CompressionNotSupportedException(compressionMethod);
// }


public static Compression parseCompressionMethod(CompressionMethod compressionMethod) {
for (Compression compression : values())
if (compression.method == compressionMethod)
Expand Down

0 comments on commit 4115078

Please sign in to comment.