Skip to content

Commit

Permalink
Merge pull request #99 from licheng-xd/master
Browse files Browse the repository at this point in the history
db中取出的数据从unicode转回utf8再返回client
  • Loading branch information
knightliao committed May 26, 2016
2 parents f9e9a0b + afd184e commit e016eb3
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.baidu.disconf.web.service.config.service.impl;

import com.baidu.disconf.web.utils.CodeUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down Expand Up @@ -32,6 +33,9 @@ public Config getConfByParameter(Long appId, Long envId, String env, String key,
DisConfigTypeEnum disConfigTypeEnum) {

Config config = configDao.getByParameter(appId, envId, env, key, disConfigTypeEnum);
if (config != null) {
config.setValue(CodeUtils.unicodeToUtf8(config.getValue()));
}
return config;
}

Expand All @@ -44,7 +48,7 @@ public ValueVo getConfItemByParameter(Long appId, Long envId, String version, St
if (config == null) {
return ConfigUtils.getErrorVo("cannot find this config");
}

config.setValue(CodeUtils.unicodeToUtf8(config.getValue()));
ValueVo valueVo = new ValueVo();
valueVo.setValue(config.getValue());
valueVo.setStatus(Constants.OK);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public List<File> getDisconfFileList(ConfListForm confListForm) {

File file = new File(curTime, config.getName());
try {
FileUtils.writeByteArrayToFile(file, config.getValue().getBytes());
FileUtils.writeByteArrayToFile(file, CodeUtils.unicodeToUtf8(config.getValue()).getBytes());
} catch (IOException e) {
LOG.warn(e.toString());
}
Expand Down Expand Up @@ -496,7 +496,7 @@ public void notifyZookeeper(Long configId) {
*/
@Override
public String getValue(Long configId) {
return configDao.getValue(configId);
return CodeUtils.unicodeToUtf8(configDao.getValue(configId));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ public static String utf8ToUnicode(String inStr) {
* 2007-3-15
*/
public static String unicodeToUtf8(String theString) {
if (theString == null)
return null;
char aChar;
int len = theString.length();
StringBuffer outBuffer = new StringBuffer(len);
Expand Down

0 comments on commit e016eb3

Please sign in to comment.