forked from Cookies_Github_mirror/AquaDX
[O] Reduce duplicate code
This commit is contained in:
@@ -2,9 +2,7 @@ package icu.samnyan.aqua.sega.billing;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
import icu.samnyan.aqua.sega.billing.model.response.BillingResponse;
|
||||
import icu.samnyan.aqua.sega.billing.util.Decoder;
|
||||
|
||||
import icu.samnyan.aqua.sega.util.Decoder;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.core.io.Resource;
|
||||
@@ -44,7 +42,7 @@ public class BillingController {
|
||||
RSAPrivateKey key = loadBillingKey();
|
||||
|
||||
byte[] bytes = dataStream.readAllBytes();
|
||||
Map<String, String> reqMap = Decoder.decode(bytes);
|
||||
Map<String, String> reqMap = Decoder.decodeBilling(bytes);
|
||||
|
||||
logger.info("Request: Billing, " + mapper.writeValueAsString(reqMap));
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package icu.samnyan.aqua.sega.billing.model.response;
|
||||
package icu.samnyan.aqua.sega.billing;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
@@ -1,28 +0,0 @@
|
||||
package icu.samnyan.aqua.sega.billing.util;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author samnyan (privateamusement@protonmail.com)
|
||||
*/
|
||||
public class Decoder {
|
||||
|
||||
public static Map<String, String> decode(byte[] src) {
|
||||
//byte[] bytes = Base64.getMimeDecoder().decode(src);
|
||||
|
||||
byte[] output = RawCompression.decompress(src);
|
||||
|
||||
String outputString = new String(output, StandardCharsets.UTF_8).trim();
|
||||
String[] split = outputString.split("&");
|
||||
Map<String, String> resultMap = new HashMap<>();
|
||||
for (String s :
|
||||
split) {
|
||||
String[] kv = s.split("=");
|
||||
resultMap.put(kv[0], kv[1]);
|
||||
}
|
||||
|
||||
return resultMap;
|
||||
}
|
||||
}
|
||||
@@ -1,40 +0,0 @@
|
||||
package icu.samnyan.aqua.sega.billing.util;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.Unpooled;
|
||||
|
||||
import java.util.zip.DataFormatException;
|
||||
import java.util.zip.Inflater;
|
||||
|
||||
import icu.samnyan.aqua.sega.util.ByteBufUtil;
|
||||
|
||||
/**
|
||||
* @author samnyan (privateamusement@protonmail.com)
|
||||
*/
|
||||
public class RawCompression {
|
||||
|
||||
public static byte[] decompress(byte[] src) {
|
||||
ByteBuf result = Unpooled.buffer();
|
||||
byte[] buffer = new byte[100];
|
||||
Inflater decompressor = new Inflater(true); // Enable no wrap option
|
||||
decompressor.setInput(src);
|
||||
|
||||
try {
|
||||
while (!decompressor.finished()) {
|
||||
int count = decompressor.inflate(buffer);
|
||||
if (count == 0) {
|
||||
break;
|
||||
}
|
||||
result.writeBytes(buffer, result.readerIndex(), count);
|
||||
}
|
||||
decompressor.end();
|
||||
|
||||
return ByteBufUtil.toBytes(result);
|
||||
} catch (DataFormatException e) {
|
||||
e.printStackTrace();
|
||||
return new byte[0];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user