diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml
new file mode 100644
index 0000000..a55e7a1
--- /dev/null
+++ b/.idea/codeStyles/codeStyleConfig.xml
@@ -0,0 +1,5 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index 42d5c9e..7b69941 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1,56 +1,56 @@
- 4.0.0
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ 4.0.0
- net.irext.decoder
- irext-decode-service
- 0.0.1-SNAPSHOT
- jar
+ net.irext.decoder
+ irext-decode-service
+ 0.0.1-SNAPSHOT
+ jar
- IRext Decode Service
- Decoding IR binaries online
+ IRext Decode Service
+ Decoding IR binaries online
-
+
org.springframework.boot
spring-boot-starter-parent
2.1.1.RELEASE
-
-
+
+
-
- UTF-8
- UTF-8
- 1.8
-
+
+ UTF-8
+ UTF-8
+ 1.8
+
-
+
org.mybatis.spring.boot
mybatis-spring-boot-starter
1.3.2
-
- org.springframework.boot
- spring-boot-starter-web
+
+ org.springframework.boot
+ spring-boot-starter-web
2.1.1.RELEASE
-
-
- org.springframework.boot
- spring-boot-starter-logging
-
-
-
-
- org.springframework.boot
- spring-boot-starter-data-redis
+
+
+ org.springframework.boot
+ spring-boot-starter-logging
+
+
+
+
+ org.springframework.boot
+ spring-boot-starter-data-redis
2.1.1.RELEASE
-
-
- mysql
- mysql-connector-java
+
+
+ mysql
+ mysql-connector-java
8.0.13
-
+
commons-io
commons-io
@@ -61,30 +61,30 @@
aliyun-sdk-oss
3.4.0
-
- org.springframework.boot
- spring-boot-autoconfigure
- 2.1.1.RELEASE
-
-
- redis.clients
- jedis
-
-
- org.springframework.boot
- spring-boot-starter-log4j2
- 2.1.1.RELEASE
-
-
+
+ org.springframework.boot
+ spring-boot-autoconfigure
+ 2.1.1.RELEASE
+
+
+ redis.clients
+ jedis
+
+
+ org.springframework.boot
+ spring-boot-starter-log4j2
+ 2.1.1.RELEASE
+
+
-
-
-
- org.springframework.boot
- spring-boot-maven-plugin
-
-
-
+
+
+
+ org.springframework.boot
+ spring-boot-maven-plugin
+
+
+
diff --git a/src/main/java/net/irext/decoder/IRDecoderApplication.java b/src/main/java/net/irext/decoder/IRDecoderApplication.java
index 8967ec3..bd9ec28 100644
--- a/src/main/java/net/irext/decoder/IRDecoderApplication.java
+++ b/src/main/java/net/irext/decoder/IRDecoderApplication.java
@@ -22,8 +22,8 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class IRDecoderApplication {
- public static void main(String[] args) {
- SpringApplication.run(IRDecoderApplication.class, args);
- }
+ public static void main(String[] args) {
+ SpringApplication.run(IRDecoderApplication.class, args);
+ }
}
diff --git a/src/main/java/net/irext/decoder/businesslogic/DecodeLogic.java b/src/main/java/net/irext/decoder/businesslogic/DecodeLogic.java
index 5e3f2de..a3436e7 100644
--- a/src/main/java/net/irext/decoder/businesslogic/DecodeLogic.java
+++ b/src/main/java/net/irext/decoder/businesslogic/DecodeLogic.java
@@ -2,9 +2,8 @@ package net.irext.decoder.businesslogic;
import net.irext.decoder.alioss.OSSHelper;
import net.irext.decoder.cache.IDecodeSessionRepository;
-import net.irext.decoder.model.IRBinary;
-import net.irext.decoder.model.RemoteIndex;
import net.irext.decoder.cache.IIRBinaryRepository;
+import net.irext.decoder.model.RemoteIndex;
import net.irext.decoder.utils.FileUtil;
import net.irext.decoder.utils.LoggerUtil;
import net.irext.decoder.utils.MD5Util;
@@ -44,7 +43,7 @@ public class DecodeLogic {
return decodeLogic;
}
- public byte[] openIRBinary(ServletContext context, IIRBinaryRepository irBinaryRepository,
+ public RemoteIndex openIRBinary(ServletContext context, IIRBinaryRepository irBinaryRepository,
RemoteIndex remoteIndex) {
if (null == remoteIndex) {
return null;
@@ -56,15 +55,16 @@ public class DecodeLogic {
LoggerUtil.getInstance().trace(TAG, "checksum for remoteIndex " +
remoteIndex.getId() + " = " + checksum);
- byte[] binaries = irBinaryRepository.find(remoteIndex.getId());
- if (null != binaries) {
- LoggerUtil.getInstance().trace(TAG, "binary content fetched from redis : " + binaries.length);
+ RemoteIndex cachedRemoteIndex = irBinaryRepository.find(remoteIndex.getId());
+ if (null != cachedRemoteIndex) {
+ LoggerUtil.getInstance().trace(TAG, "binary content fetched from redis : " +
+ cachedRemoteIndex.getRemoteMap());
// validate binary content
String cachedChecksum =
MD5Util.byteArrayToHexString(MessageDigest.getInstance("MD5")
- .digest(binaries)).toUpperCase();
+ .digest(cachedRemoteIndex.getBinaries())).toUpperCase();
if (cachedChecksum.equals(checksum)) {
- return binaries;
+ return cachedRemoteIndex;
}
}
@@ -79,9 +79,9 @@ public class DecodeLogic {
if (null != fin) {
byte[] newBinaries = IOUtils.toByteArray(fin);
LoggerUtil.getInstance().trace(TAG, "binary content get, save it to redis");
-
- irBinaryRepository.add(remoteIndex.getId(), newBinaries);
- return binaries;
+ remoteIndex.setBinaries(newBinaries);
+ irBinaryRepository.add(remoteIndex.getId(), remoteIndex);
+ return remoteIndex;
}
} else {
LoggerUtil.getInstance().trace(TAG, "servlet context is null");
@@ -94,20 +94,24 @@ public class DecodeLogic {
}
public int[] decode(IIRBinaryRepository irBinaryRepository, IDecodeSessionRepository decodeSessionRepository,
- String sessionId, int remoteIndexId, ACStatus acStatus, int keyCode, int changeWindDirection) {
+ String sessionId, int remoteIndexId, ACStatus acStatus, int keyCode, int changeWindDirection) {
// since the binary is already opened and probably cached to redis, we just need to load it
Integer cachedRemoteIndexId = decodeSessionRepository.find(sessionId);
- int []decoded = null;
+ int[] decoded = null;
if (null != cachedRemoteIndexId) {
- byte[] remoteBinary = irBinaryRepository.find(cachedRemoteIndexId);
- IRDecode irDecode = IRDecode.getInstance();
- int ret = 0;
- // int ret = irDecode.openBinary(categoryId, subCate, binaryContent, binaryContent.length);
- if (0 == ret) {
- decoded = irDecode.decodeBinary(keyCode, acStatus, changeWindDirection);
+ RemoteIndex cachedRemoteIndex = irBinaryRepository.find(cachedRemoteIndexId);
+ if (null != cachedRemoteIndex) {
+ int categoryId = cachedRemoteIndex.getCategoryId();
+ int subCate = cachedRemoteIndex.getSubCate();
+ byte[] binaryContent = cachedRemoteIndex.getBinaries();
+ IRDecode irDecode = IRDecode.getInstance();
+ int ret = irDecode.openBinary(categoryId, subCate, binaryContent, binaryContent.length);
+ if (0 == ret) {
+ decoded = irDecode.decodeBinary(keyCode, acStatus, changeWindDirection);
+ }
+ irDecode.closeBinary();
+ return decoded;
}
- irDecode.closeBinary();
- return decoded;
} else {
LoggerUtil.getInstance().trace(TAG, "session cache missed, need to re-open binary");
}
@@ -124,7 +128,7 @@ public class DecodeLogic {
if (binFile.exists()) {
FileInputStream fileInputStream = new FileInputStream(binFile);
// validate binary content
- byte []binaries = IOUtils.toByteArray(fileInputStream);
+ byte[] binaries = IOUtils.toByteArray(fileInputStream);
String fileChecksum =
MD5Util.byteArrayToHexString(MessageDigest.getInstance("MD5").digest(binaries)).toUpperCase();
@@ -135,7 +139,7 @@ public class DecodeLogic {
OSSHelper ossHelper = new OSSHelper();
InputStream inputStream = ossHelper.getOSS2InputStream(OSSHelper.BUCKET_NAME, "", fileName);
// validate binary content
- byte []binaries = IOUtils.toByteArray(inputStream);
+ byte[] binaries = IOUtils.toByteArray(inputStream);
String ossChecksum =
MD5Util.byteArrayToHexString(MessageDigest.getInstance("MD5").digest(binaries)).toUpperCase();
if (ossChecksum.equals(checksum)) {
diff --git a/src/main/java/net/irext/decoder/cache/IDecodeSessionRepository.java b/src/main/java/net/irext/decoder/cache/IDecodeSessionRepository.java
index 5a6c6c2..5820541 100644
--- a/src/main/java/net/irext/decoder/cache/IDecodeSessionRepository.java
+++ b/src/main/java/net/irext/decoder/cache/IDecodeSessionRepository.java
@@ -1,7 +1,5 @@
package net.irext.decoder.cache;
-import net.irext.decoder.model.DecodeSession;
-
import java.util.Map;
/**
diff --git a/src/main/java/net/irext/decoder/cache/IIRBinaryRepository.java b/src/main/java/net/irext/decoder/cache/IIRBinaryRepository.java
index 2e1d5d9..abffd0b 100644
--- a/src/main/java/net/irext/decoder/cache/IIRBinaryRepository.java
+++ b/src/main/java/net/irext/decoder/cache/IIRBinaryRepository.java
@@ -1,6 +1,6 @@
package net.irext.decoder.cache;
-import net.irext.decoder.model.IRBinary;
+import net.irext.decoder.model.RemoteIndex;
import java.util.Map;
@@ -16,11 +16,11 @@ import java.util.Map;
*/
public interface IIRBinaryRepository {
- Map