45 lines
1.4 KiB
Java
45 lines
1.4 KiB
Java
package eu.mikroskeem.uurimustoo.algoritmidetest.algoritmid;
|
|
|
|
import java.io.IOException;
|
|
import java.io.InputStream;
|
|
import java.io.OutputStream;
|
|
import java.util.zip.ZipEntry;
|
|
import java.util.zip.ZipInputStream;
|
|
import java.util.zip.ZipOutputStream;
|
|
|
|
/**
|
|
* @author Mark Vainomaa
|
|
*/
|
|
public class Zip extends AbstractAlgorithm {
|
|
@Override public String getName() { return "ZIP"; }
|
|
|
|
@Override
|
|
public void compress(InputStream inputStream, OutputStream outputStream) throws IOException {
|
|
try(ZipOutputStream out = new ZipOutputStream(outputStream)) {
|
|
ZipEntry ze = new ZipEntry("Test.class");
|
|
out.putNextEntry(ze);
|
|
byte[] buf = new byte[8192];
|
|
int s;
|
|
while((s = inputStream.read(buf)) != -1){
|
|
out.write(buf, 0, s);
|
|
}
|
|
out.closeEntry();
|
|
out.finish();
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void decompress(InputStream inputStream, OutputStream outputStream) throws IOException {
|
|
try(ZipInputStream in = new ZipInputStream(inputStream)) {
|
|
ZipEntry ze = in.getNextEntry();
|
|
assert ze.getName().equals("Test.class");
|
|
byte[] buf = new byte[8192];
|
|
int s;
|
|
while((s = in.read(buf)) != -1){
|
|
outputStream.write(buf, 0, s);
|
|
}
|
|
outputStream.flush();
|
|
}
|
|
}
|
|
}
|