mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-11-14 06:18:12 +00:00
Bug 4391: Added DataMiningQuerySerializer which (de-)serializes a
StatisticQueryDefinitionDTO to a base64 string
This commit is contained in:
1 parent
d47028bea4
commit
7b42dad4de
1 file changed
+47
+47
@@ -0,0 +1,47 @@
|
||||
package com.sap.sse.datamining.shared;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.util.Base64;
|
||||
|
||||
import com.sap.sse.datamining.shared.dto.StatisticQueryDefinitionDTO;
|
||||
|
||||
public final class DataMiningQuerySerializer {
|
||||
|
||||
private DataMiningQuerySerializer() {
|
||||
}
|
||||
|
||||
public static String toBase64String(StatisticQueryDefinitionDTO dto) {
|
||||
ByteArrayOutputStream stream = new ByteArrayOutputStream();
|
||||
try {
|
||||
ObjectOutputStream out = new ObjectOutputStream(stream);
|
||||
out.writeObject(dto);
|
||||
out.close();
|
||||
stream.close();
|
||||
byte[] bytes = stream.toByteArray();
|
||||
return new String(Base64.getEncoder().encode(bytes), "UTF-8");
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
public static StatisticQueryDefinitionDTO fromBase64String(String string) {
|
||||
try {
|
||||
byte[] bytes = Base64.getDecoder().decode(string);
|
||||
ByteArrayInputStream stream = new ByteArrayInputStream(bytes);
|
||||
ObjectInputStream in;
|
||||
in = new ObjectInputStream(stream);
|
||||
Object o = in.readObject();
|
||||
if (o instanceof StatisticQueryDefinitionDTO) {
|
||||
return (StatisticQueryDefinitionDTO) o;
|
||||
}
|
||||
} catch (IOException | ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user