-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
6 changed files
with
144 additions
and
1 deletion.
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
69 changes: 69 additions & 0 deletions
69
...n/src/main/java/io/freefair/gradle/plugins/compress/internal/CommonsCompressArchiver.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,69 @@ | ||
package io.freefair.gradle.plugins.compress.internal; | ||
|
||
import org.apache.commons.compress.compressors.CompressorInputStream; | ||
import org.apache.commons.compress.utils.IOUtils; | ||
import org.gradle.api.internal.file.archive.compression.CompressedReadableResource; | ||
import org.gradle.api.internal.file.archive.compression.URIBuilder; | ||
import org.gradle.api.resources.ResourceException; | ||
import org.gradle.internal.resource.ResourceExceptions; | ||
|
||
import java.io.*; | ||
import java.net.URI; | ||
|
||
/** | ||
* @author Lars Grefer | ||
* @see org.gradle.api.internal.file.archive.compression.AbstractArchiver | ||
*/ | ||
public abstract class CommonsCompressArchiver implements CompressedReadableResource { | ||
|
||
private final File file; | ||
private final URI uri; | ||
|
||
protected CommonsCompressArchiver(File file) { | ||
assert file != null; | ||
|
||
this.file = file; | ||
this.uri = new URIBuilder(file.toURI()).schemePrefix(this.getSchemePrefix()).build(); | ||
} | ||
|
||
@Override | ||
public File getBackingFile() { | ||
return file; | ||
} | ||
|
||
@Override | ||
public CompressorInputStream read() throws ResourceException { | ||
InputStream baseFile; | ||
try { | ||
baseFile = new BufferedInputStream(new FileInputStream(file)); | ||
} catch (FileNotFoundException e) { | ||
throw ResourceExceptions.readMissing(file, e); | ||
} | ||
|
||
try { | ||
return read(baseFile); | ||
} catch (IOException e) { | ||
IOUtils.closeQuietly(baseFile); | ||
throw ResourceExceptions.readFailed(file, e); | ||
} | ||
} | ||
|
||
protected abstract CompressorInputStream read(InputStream in) throws IOException; | ||
|
||
@Override | ||
public String getBaseName() { | ||
return file.getName(); | ||
} | ||
|
||
@Override | ||
public String getDisplayName() { | ||
return file.getPath(); | ||
} | ||
|
||
@Override | ||
public URI getURI() { | ||
return uri; | ||
} | ||
|
||
protected abstract String getSchemePrefix(); | ||
} |
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
28 changes: 28 additions & 0 deletions
28
compress-plugin/src/main/java/io/freefair/gradle/plugins/compress/internal/LzmaArchiver.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,28 @@ | ||
package io.freefair.gradle.plugins.compress.internal; | ||
|
||
import org.apache.commons.compress.compressors.lzma.LZMACompressorInputStream; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
|
||
/** | ||
* @author Lars Grefer | ||
* @see org.gradle.api.internal.file.archive.compression.GzipArchiver | ||
*/ | ||
public class LzmaArchiver extends CommonsCompressArchiver { | ||
|
||
public LzmaArchiver(File xzFile) { | ||
super(xzFile); | ||
} | ||
|
||
@Override | ||
protected LZMACompressorInputStream read(InputStream in) throws IOException { | ||
return new LZMACompressorInputStream(in); | ||
} | ||
|
||
@Override | ||
protected String getSchemePrefix() { | ||
return "lzma:"; | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
compress-plugin/src/main/java/io/freefair/gradle/plugins/compress/internal/XzArchiver.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,28 @@ | ||
package io.freefair.gradle.plugins.compress.internal; | ||
|
||
import org.apache.commons.compress.compressors.xz.XZCompressorInputStream; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
|
||
/** | ||
* @author Lars Grefer | ||
* @see org.gradle.api.internal.file.archive.compression.GzipArchiver | ||
*/ | ||
public class XzArchiver extends CommonsCompressArchiver { | ||
|
||
public XzArchiver(File xzFile) { | ||
super(xzFile); | ||
} | ||
|
||
@Override | ||
protected XZCompressorInputStream read(InputStream in) throws IOException { | ||
return new XZCompressorInputStream(in, true); | ||
} | ||
|
||
@Override | ||
protected String getSchemePrefix() { | ||
return "xz:"; | ||
} | ||
} |
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