-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8656ee0
commit 5ba0d19
Showing
14 changed files
with
707 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
src/main/java/org/codehaus/plexus/archiver/tar/PlexusIoTarZstdFileResourceCollection.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Copyright 2022 The Apache Software Foundation | ||
* | ||
* Licensed 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 | ||
* | ||
* http://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.codehaus.plexus.archiver.tar; | ||
|
||
import javax.inject.Named; | ||
import java.io.File; | ||
|
||
/** | ||
* Alias for {@link PlexusIoTarFileResourceCollection} | ||
*/ | ||
@Named( "tar.zst" ) | ||
public class PlexusIoTarZstdFileResourceCollection extends PlexusIoTarFileResourceCollection | ||
{ | ||
|
||
public PlexusIoTarZstdFileResourceCollection() | ||
{ | ||
} | ||
|
||
@Override | ||
protected TarFile newTarFile( File file ) | ||
{ | ||
return new ZstdTarFile( file ); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
src/main/java/org/codehaus/plexus/archiver/tar/TarZstdUnArchiver.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* Copyright 2022 The Apache Software Foundation | ||
* | ||
* Licensed 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 | ||
* | ||
* http://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.codehaus.plexus.archiver.tar; | ||
|
||
import javax.inject.Named; | ||
import java.io.File; | ||
|
||
/** | ||
* Extract files in tar with zstd compression | ||
*/ | ||
@Named( "tar.zst" ) | ||
public class TarZstdUnArchiver extends TarUnArchiver | ||
{ | ||
|
||
public TarZstdUnArchiver() | ||
{ | ||
setupCompressionMethod(); | ||
} | ||
|
||
public TarZstdUnArchiver( File sourceFile ) | ||
{ | ||
super( sourceFile ); | ||
|
||
setupCompressionMethod(); | ||
} | ||
|
||
private final void setupCompressionMethod() | ||
{ | ||
setCompression( UntarCompressionMethod.ZSTD ); | ||
} | ||
|
||
} |
41 changes: 41 additions & 0 deletions
41
src/main/java/org/codehaus/plexus/archiver/tar/ZstdTarFile.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* Copyright 2022 The Apache Software Foundation | ||
* | ||
* Licensed 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 | ||
* | ||
* http://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.codehaus.plexus.archiver.tar; | ||
|
||
import org.codehaus.plexus.archiver.zstd.ZstdUnArchiver; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
|
||
/** | ||
* Extension of {@link org.codehaus.plexus.archiver.tar.TarFile} for zst compressed files. | ||
*/ | ||
public class ZstdTarFile extends TarFile | ||
{ | ||
|
||
public ZstdTarFile( File file ) | ||
{ | ||
super( file ); | ||
} | ||
|
||
@Override | ||
protected InputStream getInputStream( File file ) throws IOException | ||
{ | ||
return ZstdUnArchiver.getZstdInputStream( super.getInputStream( file ) ); | ||
} | ||
|
||
} |
56 changes: 56 additions & 0 deletions
56
src/main/java/org/codehaus/plexus/archiver/zstd/PlexusIoZstdResourceCollection.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* Copyright 2022 The Apache Software Foundation | ||
* | ||
* Licensed 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 | ||
* | ||
* http://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.codehaus.plexus.archiver.zstd; | ||
|
||
import javax.inject.Named; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.util.HashMap; | ||
|
||
import org.codehaus.plexus.archiver.util.Streams; | ||
import org.codehaus.plexus.components.io.attributes.FileAttributes; | ||
import org.codehaus.plexus.components.io.attributes.PlexusIoResourceAttributes; | ||
import org.codehaus.plexus.components.io.resources.PlexusIoCompressedFileResourceCollection; | ||
|
||
/** | ||
* Implementation of {@link org.codehaus.plexus.components.io.resources.PlexusIoResourceCollection} for | ||
* zstd compressed files. | ||
*/ | ||
@Named( "zst" ) | ||
public class PlexusIoZstdResourceCollection extends PlexusIoCompressedFileResourceCollection | ||
{ | ||
|
||
@Override | ||
protected PlexusIoResourceAttributes getAttributes( File file ) throws IOException | ||
{ | ||
return new FileAttributes( file, new HashMap<Integer, String>(), new HashMap<Integer, String>() ); | ||
} | ||
|
||
@Override | ||
protected String getDefaultExtension() | ||
{ | ||
return ".zst"; | ||
} | ||
|
||
@Override | ||
protected InputStream getInputStream( File file ) throws IOException | ||
{ | ||
return ZstdUnArchiver.getZstdInputStream( Streams.fileInputStream( file ) ); | ||
} | ||
|
||
} |
90 changes: 90 additions & 0 deletions
90
src/main/java/org/codehaus/plexus/archiver/zstd/ZstdArchiver.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/* | ||
* Copyright 2022 The Apache Software Foundation | ||
* | ||
* Licensed 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 | ||
* | ||
* http://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.codehaus.plexus.archiver.zstd; | ||
|
||
import javax.inject.Named; | ||
|
||
import java.io.IOException; | ||
import org.codehaus.plexus.archiver.AbstractArchiver; | ||
import org.codehaus.plexus.archiver.ArchiveEntry; | ||
import org.codehaus.plexus.archiver.ArchiverException; | ||
import org.codehaus.plexus.archiver.ResourceIterator; | ||
import org.codehaus.plexus.archiver.exceptions.EmptyArchiveException; | ||
|
||
/** | ||
* Zstd archiver. | ||
*/ | ||
@Named( "zst" ) | ||
public class ZstdArchiver extends AbstractArchiver | ||
{ | ||
|
||
private final ZstdCompressor compressor = new ZstdCompressor(); | ||
|
||
public ZstdArchiver() | ||
{ | ||
} | ||
|
||
/** | ||
* Set compression level | ||
*/ | ||
public void setLevel( Integer level ) | ||
throws ArchiverException | ||
{ | ||
compressor.setLevel( level ); | ||
} | ||
|
||
@Override | ||
protected void execute() throws ArchiverException, IOException | ||
{ | ||
if ( !checkForced() ) | ||
{ | ||
return; | ||
} | ||
|
||
ResourceIterator iter = getResources(); | ||
if ( !iter.hasNext() ) | ||
{ | ||
throw new EmptyArchiveException( "archive cannot be empty" ); | ||
} | ||
ArchiveEntry entry = iter.next(); | ||
if ( iter.hasNext() ) | ||
{ | ||
throw new ArchiverException( "There is more than one file in input." ); | ||
} | ||
compressor.setSource( entry.getResource() ); | ||
compressor.setDestFile( getDestFile() ); | ||
compressor.compress(); | ||
} | ||
|
||
@Override | ||
public boolean isSupportingForced() | ||
{ | ||
return true; | ||
} | ||
|
||
@Override | ||
protected void close() throws IOException | ||
{ | ||
compressor.close(); | ||
} | ||
|
||
@Override | ||
protected String getArchiveType() | ||
{ | ||
return "zstd"; | ||
} | ||
|
||
} |
Oops, something went wrong.