Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.commons.compress.archivers.zip;

/**
* Configuration for BZIP2 compression in ZIP archives.
*
* @since 1.29.0
*/
public class BZip2CompressorConfig implements CompressorConfig {

private final int blockSize;

/**
* Creates a default BZIP2 configuration (blockSize 9).
*/
public BZip2CompressorConfig() {
this(9);
}

/**
* Creates a BZIP2 configuration with the specified block size.
*
* @param blockSize the block size (1-9)
*/
public BZip2CompressorConfig(final int blockSize) {
this.blockSize = blockSize;
}

/**
* Gets the block size.
*
* @return the block size
*/
public int getBlockSize() {
return blockSize;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.commons.compress.archivers.zip;

import java.io.IOException;
import java.io.OutputStream;

import org.apache.commons.compress.compressors.CompressorOutputStream;
import org.apache.commons.compress.compressors.bzip2.BZip2CompressorOutputStream;

/**
* Factory for creating BZIP2 compressor output streams in ZIP archives.
*
* @since 1.29.0
*/
public class BZip2ZipCompressorStreamFactory implements ZipCompressorStreamFactory {

@Override
public CompressorOutputStream<?> createCompressorOutputStream(final OutputStream out, final CompressorConfig config) throws IOException {
final BZip2CompressorConfig bzip2Config = (BZip2CompressorConfig) config;
return new BZip2CompressorOutputStream(out, bzip2Config.getBlockSize());
}

@Override
public CompressorConfig defaultConfig() {
return new BZip2CompressorConfig();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.commons.compress.archivers.zip;

/**
* Marker interface for compressor-specific configuration.
* Implementations carry parameters for a specific compression method
* (e.g., compression level, block size).
*
* @since 1.29.0
*/
public interface CompressorConfig {
}
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,30 @@ void reset() {
writtenToOutputStreamForLastEntry = 0;
}

/**
* Updates the CRC checksum without writing data.
*
* @param b the byte array
* @param offset start offset
* @param length number of bytes
*
* @since 1.29.0
*/
void updateCrc(final byte[] b, final int offset, final int length) {
crc.update(b, offset, length);
}

/**
* Updates the source payload length counter.
*
* @param length number of uncompressed bytes
*
* @since 1.29.0
*/
void updateSourcePayloadLength(final int length) {
sourcePayloadLength += length;
}

/**
* Writes bytes to ZIP entry.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.commons.compress.archivers.zip;

/**
* Configuration for XZ compression in ZIP archives.
*
* @since 1.29.0
*/
public class XZCompressorConfig implements CompressorConfig {

private final int preset;

/**
* Creates a default XZ configuration (preset 6).
*/
public XZCompressorConfig() {
this(6);
}

/**
* Creates an XZ configuration with the specified preset.
*
* @param preset the LZMA2 preset level (0-9)
*/
public XZCompressorConfig(final int preset) {
this.preset = preset;
}

/**
* Gets the preset level.
*
* @return the preset level
*/
public int getPreset() {
return preset;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.commons.compress.archivers.zip;

import java.io.IOException;
import java.io.OutputStream;

import org.apache.commons.compress.compressors.CompressorOutputStream;
import org.apache.commons.compress.compressors.xz.XZCompressorOutputStream;

/**
* Factory for creating XZ compressor output streams in ZIP archives.
*
* @since 1.29.0
*/
public class XZZipCompressorStreamFactory implements ZipCompressorStreamFactory {

@Override
public CompressorOutputStream<?> createCompressorOutputStream(final OutputStream out, final CompressorConfig config) throws IOException {
final XZCompressorConfig xzConfig = (XZCompressorConfig) config;
return new XZCompressorOutputStream(out, xzConfig.getPreset());
}

@Override
public CompressorConfig defaultConfig() {
return new XZCompressorConfig();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,8 @@ private static String toEntryName(final Path inputPath, final String entryName,

private long time = -1;

private CompressorConfig compressorConfig;

/**
* Constructs a new instance with an empty name.
*/
Expand Down Expand Up @@ -854,6 +856,16 @@ public int getMethod() {
return method;
}

/**
* Gets the compressor configuration for this entry.
*
* @return the compressor config, or {@code null} if not set
* @since 1.29.0
*/
public CompressorConfig getCompressorConfig() {
return compressorConfig;
}

/**
* Gets the name of the entry.
*
Expand Down Expand Up @@ -1397,6 +1409,18 @@ public void setMethod(final int method) {
this.method = method;
}

/**
* Sets the compressor configuration for this entry.
* When used with {@link ZipArchiveOutputStream} in auto-compress mode,
* this configuration overrides the factory's default.
*
* @param compressorConfig the compressor config, or {@code null} to use the factory default
* @since 1.29.0
*/
public void setCompressorConfig(final CompressorConfig compressorConfig) {
this.compressorConfig = compressorConfig;
}

/**
* Sets the name of the entry.
*
Expand Down
Loading