-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
It's a little too much work to have the necessary server support on our own to do mime/multipart decoding, so instead, just compress one part, on our own.
- Loading branch information
Showing
2 changed files
with
57 additions
and
6 deletions.
There are no files selected for viewing
51 changes: 51 additions & 0 deletions
51
src/main/java/io/jenkins/plugins/launchable/GzipFileMimePart.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,51 @@ | ||
package io.jenkins.plugins.launchable; | ||
|
||
import org.apache.commons.io.output.CloseShieldOutputStream; | ||
import org.apache.http.entity.ContentType; | ||
import org.apache.http.entity.mime.MIME; | ||
import org.apache.http.entity.mime.content.AbstractContentBody; | ||
|
||
import java.io.File; | ||
import java.io.FileInputStream; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.io.OutputStream; | ||
import java.util.zip.GZIPOutputStream; | ||
|
||
final class GzipFileMimePart extends AbstractContentBody { | ||
private final File file; | ||
private final String filename; | ||
|
||
public GzipFileMimePart(File file, ContentType contentType, String filename) { | ||
super(contentType); | ||
this.file = file; | ||
this.filename = filename == null ? file.getName() : filename; | ||
} | ||
|
||
@Override | ||
public void writeTo(OutputStream out) throws IOException { | ||
try (OutputStream o = new GZIPOutputStream(new CloseShieldOutputStream(out)); | ||
InputStream in = new FileInputStream(this.file)) { | ||
final byte[] tmp = new byte[4096]; | ||
int l; | ||
while ((l = in.read(tmp)) != -1) { | ||
o.write(tmp, 0, l); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public String getTransferEncoding() { | ||
return MIME.ENC_BINARY; | ||
} | ||
|
||
@Override | ||
public long getContentLength() { | ||
return this.file.length(); | ||
} | ||
|
||
@Override | ||
public String getFilename() { | ||
return filename; | ||
} | ||
} |
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