Fix code style
This commit is contained in:
parent
6c79bf8514
commit
984aec2342
@ -11,7 +11,7 @@ public class Main {
|
|||||||
byte[] classFile = ByteArrays.fromInputStream(Main.class.getResourceAsStream("/Test.class"));
|
byte[] classFile = ByteArrays.fromInputStream(Main.class.getResourceAsStream("/Test.class"));
|
||||||
Utils.generateReport(classFile);
|
Utils.generateReport(classFile);
|
||||||
|
|
||||||
System.out.println("=== Suure class faili pakkimise test (100x)");
|
System.out.println("==== Suure class faili pakkimise test (100x)");
|
||||||
byte[] classFile2 = ByteArrays.fromInputStream(Main.class.getResourceAsStream("/TestBig.class"));
|
byte[] classFile2 = ByteArrays.fromInputStream(Main.class.getResourceAsStream("/TestBig.class"));
|
||||||
Utils.generateReport(classFile2);
|
Utils.generateReport(classFile2);
|
||||||
}
|
}
|
||||||
|
@ -21,14 +21,13 @@ import static eu.mikroskeem.uurimustoo.algoritmidetest.Utils.DummyCompressor.of;
|
|||||||
* @author Mark Vainomaa
|
* @author Mark Vainomaa
|
||||||
*/
|
*/
|
||||||
public class Utils {
|
public class Utils {
|
||||||
public static List<AbstractAlgorithm> getAllCompressors(){
|
public static List<AbstractAlgorithm> getAllCompressors() {
|
||||||
return new FastClasspathScanner(AbstractAlgorithm.class.getPackage().getName())
|
return new FastClasspathScanner(AbstractAlgorithm.class.getPackage().getName())
|
||||||
.scan().getNamesOfSubclassesOf(AbstractAlgorithm.class)
|
.scan().getNamesOfSubclassesOf(AbstractAlgorithm.class)
|
||||||
.stream()
|
.stream()
|
||||||
.map(className -> {
|
.map(className -> {
|
||||||
try {
|
try {
|
||||||
return (AbstractAlgorithm)Reflect.getClass(className)
|
return (AbstractAlgorithm) Reflect.getClass(className).get().construct().getClassInstance();
|
||||||
.get().construct().getClassInstance();
|
|
||||||
} catch (Exception e){
|
} catch (Exception e){
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -38,7 +37,7 @@ public class Utils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static CompressorResult executeCompressor(byte[] input, AbstractAlgorithm compressor){
|
public static CompressorResult executeCompressor(byte[] input, AbstractAlgorithm compressor) {
|
||||||
String compressorName = compressor.getName();
|
String compressorName = compressor.getName();
|
||||||
boolean decompressFailed = false;
|
boolean decompressFailed = false;
|
||||||
|
|
||||||
@ -56,17 +55,17 @@ public class Utils {
|
|||||||
end2 = Instant.now();
|
end2 = Instant.now();
|
||||||
Validate.checkGeneratedClass(decompressed);
|
Validate.checkGeneratedClass(decompressed);
|
||||||
assert decompressed.length == input.length;
|
assert decompressed.length == input.length;
|
||||||
} catch (Throwable e){
|
} catch (Throwable e) {
|
||||||
System.out.println(String.format("Tekkis viga %s algoritmi lahtipakkimisel! %s", compressorName, e.toString()));
|
System.out.println(String.format("Tekkis viga %s algoritmi lahtipakkimisel! %s", compressorName, e.toString()));
|
||||||
decompressFailed = true;
|
decompressFailed = true;
|
||||||
}
|
}
|
||||||
float sizeDiff = (float)input.length / (float)compressed.length;
|
float sizeDiff = (float)input.length / (float)compressed.length;
|
||||||
int compressTime = Duration.between(start, end).getNano();
|
int compressTime = Duration.between(start, end).getNano();
|
||||||
int decompressTime = start2!=null&&end2!=null?Duration.between(start2, end2).getNano():-1;
|
int decompressTime = (start2 != null && end2 != null) ? Duration.between(start2, end2).getNano() : -1;
|
||||||
return new CompressorResult(compressor, decompressFailed, compressed.length, sizeDiff, compressTime, decompressTime);
|
return new CompressorResult(compressor, decompressFailed, compressed.length, sizeDiff, compressTime, decompressTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<CompressorResult> executeAllNTimes(byte[] input, int n){
|
public static List<CompressorResult> executeAllNTimes(byte[] input, int n) {
|
||||||
int i = 0;
|
int i = 0;
|
||||||
List<CompressorResult> lastExecuted = executeAll(input, getAllCompressors());
|
List<CompressorResult> lastExecuted = executeAll(input, getAllCompressors());
|
||||||
while(i < n-1){
|
while(i < n-1){
|
||||||
@ -82,11 +81,11 @@ public class Utils {
|
|||||||
return lastExecuted;
|
return lastExecuted;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<CompressorResult> executeAll(byte[] input, List<AbstractAlgorithm> compressors){
|
public static List<CompressorResult> executeAll(byte[] input, List<AbstractAlgorithm> compressors) {
|
||||||
return compressors.stream().map(c -> executeCompressor(input, c)).collect(Collectors.toList());
|
return compressors.stream().map(c -> executeCompressor(input, c)).collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void generateReport(byte[] input){
|
public static void generateReport(byte[] input) {
|
||||||
|
|
||||||
System.out.println("----------------------------------------------------------------------------");
|
System.out.println("----------------------------------------------------------------------------");
|
||||||
System.out.println("| Algoritm | Suurus | Väiksem | Aeg (kokku) | Aeg (lahti) |");
|
System.out.println("| Algoritm | Suurus | Väiksem | Aeg (kokku) | Aeg (lahti) |");
|
||||||
@ -97,8 +96,8 @@ public class Utils {
|
|||||||
compressorResult.getCompressor().getName(),
|
compressorResult.getCompressor().getName(),
|
||||||
compressorResult.getSize(),
|
compressorResult.getSize(),
|
||||||
compressorResult.getDifference(),
|
compressorResult.getDifference(),
|
||||||
(compressorResult.getTimeInNS() / 1000000)+"ms",
|
(compressorResult.getTimeInNS() / 1000000) + "ms",
|
||||||
(compressorResult.getDecompressTimeInNS() / 1000000)+"ms"
|
(compressorResult.getDecompressTimeInNS() / 1000000) + "ms"
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
System.out.println("|--------------------------------------------------------------------------|");
|
System.out.println("|--------------------------------------------------------------------------|");
|
||||||
@ -116,7 +115,7 @@ public class Utils {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int compareTo(@NotNull Utils.CompressorResult o) {
|
public int compareTo(@NotNull Utils.CompressorResult o) {
|
||||||
return new Integer(size).compareTo(o.getSize());
|
return Integer.compare(size, o.getSize());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,7 +2,11 @@ package eu.mikroskeem.uurimustoo.algoritmidetest.algoritmid;
|
|||||||
|
|
||||||
import eu.mikroskeem.shuriken.common.SneakyThrow;
|
import eu.mikroskeem.shuriken.common.SneakyThrow;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.ByteArrayInputStream;
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.OutputStream;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Mark Vainomaa
|
* @author Mark Vainomaa
|
||||||
@ -10,25 +14,25 @@ import java.io.*;
|
|||||||
public abstract class AbstractAlgorithm {
|
public abstract class AbstractAlgorithm {
|
||||||
public abstract String getName();
|
public abstract String getName();
|
||||||
|
|
||||||
public byte[] compress(byte[] input){
|
public byte[] compress(byte[] input) {
|
||||||
try {
|
try {
|
||||||
ByteArrayInputStream bais = new ByteArrayInputStream(input);
|
ByteArrayInputStream bais = new ByteArrayInputStream(input);
|
||||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||||
compress(bais, baos);
|
compress(bais, baos);
|
||||||
return baos.toByteArray();
|
return baos.toByteArray();
|
||||||
} catch (IOException e){
|
} catch (IOException e) {
|
||||||
SneakyThrow.throwException(e);
|
SneakyThrow.throwException(e);
|
||||||
}
|
}
|
||||||
return new byte[0]; // Never reaches here anyway
|
return new byte[0]; // Never reaches here anyway
|
||||||
}
|
}
|
||||||
|
|
||||||
public byte[] decompress(byte[] input){
|
public byte[] decompress(byte[] input) {
|
||||||
try {
|
try {
|
||||||
ByteArrayInputStream bais = new ByteArrayInputStream(input);
|
ByteArrayInputStream bais = new ByteArrayInputStream(input);
|
||||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||||
decompress(bais, baos);
|
decompress(bais, baos);
|
||||||
return baos.toByteArray();
|
return baos.toByteArray();
|
||||||
} catch (IOException e){
|
} catch (IOException e) {
|
||||||
SneakyThrow.throwException(e);
|
SneakyThrow.throwException(e);
|
||||||
}
|
}
|
||||||
return new byte[0]; // Never reaches here anyway
|
return new byte[0]; // Never reaches here anyway
|
||||||
|
@ -1,7 +1,12 @@
|
|||||||
package eu.mikroskeem.uurimustoo.algoritmidetest.algoritmid;
|
package eu.mikroskeem.uurimustoo.algoritmidetest.algoritmid;
|
||||||
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import org.anarres.lzo.*;
|
import org.anarres.lzo.LzoAlgorithm;
|
||||||
|
import org.anarres.lzo.LzoCompressor;
|
||||||
|
import org.anarres.lzo.LzoDecompressor;
|
||||||
|
import org.anarres.lzo.LzoInputStream;
|
||||||
|
import org.anarres.lzo.LzoLibrary;
|
||||||
|
import org.anarres.lzo.LzoOutputStream;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
@ -17,7 +17,7 @@ public class Zip extends AbstractAlgorithm {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void compress(InputStream inputStream, OutputStream outputStream) throws IOException {
|
public void compress(InputStream inputStream, OutputStream outputStream) throws IOException {
|
||||||
try(ZipOutputStream out = new ZipOutputStream(outputStream)){
|
try(ZipOutputStream out = new ZipOutputStream(outputStream)) {
|
||||||
ZipEntry ze = new ZipEntry("Test.class");
|
ZipEntry ze = new ZipEntry("Test.class");
|
||||||
out.putNextEntry(ze);
|
out.putNextEntry(ze);
|
||||||
byte[] buf = new byte[8192];
|
byte[] buf = new byte[8192];
|
||||||
@ -32,7 +32,7 @@ public class Zip extends AbstractAlgorithm {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void decompress(InputStream inputStream, OutputStream outputStream) throws IOException {
|
public void decompress(InputStream inputStream, OutputStream outputStream) throws IOException {
|
||||||
try(ZipInputStream in = new ZipInputStream(inputStream)){
|
try(ZipInputStream in = new ZipInputStream(inputStream)) {
|
||||||
ZipEntry ze = in.getNextEntry();
|
ZipEntry ze = in.getNextEntry();
|
||||||
assert ze.getName().equals("Test.class");
|
assert ze.getName().equals("Test.class");
|
||||||
byte[] buf = new byte[8192];
|
byte[] buf = new byte[8192];
|
||||||
|
Loading…
Reference in New Issue
Block a user