57 lines
1.7 KiB
Java
57 lines
1.7 KiB
Java
package eu.mikroskeem.uurimustoo.algoritmidetest.compressors;
|
|
|
|
import lombok.Getter;
|
|
|
|
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 CompressZip extends AbstractCompressor {
|
|
@Getter private final String name = "ZIP";
|
|
|
|
@Override
|
|
public void compress0(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 decompress0(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();
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public OutputStream compress(OutputStream outputStream) throws IOException {
|
|
throw new UnsupportedOperationException("See void compress0()");
|
|
}
|
|
|
|
@Override
|
|
public InputStream decompress(InputStream inputStream) throws IOException {
|
|
throw new UnsupportedOperationException("See void decompress0()");
|
|
}
|
|
}
|