📄 buffers.java
字号:
map.put("value", "");
}
else if (fieldlinestr[1].equalsIgnoreCase("int")) {
map.put("value", "0");
}
this.saasBuffer.add(map);
}
}
fieldline = fieldbuff.readLine();
}
fieldbuff.close();
ffield.close();
}
catch (IOException e) {
throw new RuntimeException("[init]缓存域初始化失败!");
}
}
public void addField(String name, Buffer inbuffer, Buffer outBuffer) {
for (Iterator it = inbuffer.iterator(); it.hasNext();) {
HashMap map = (HashMap) it.next();
if (map.get("name") != null) {
if (map.get("name").toString().equalsIgnoreCase(name)) {
if (checkContainsKey(map.get("name").toString(), outBuffer) >= 0)
outBuffer.add(map);
break;
}
}
}
}
public void addFieldSting(String name, String type, Buffer inbuffer) {
for (Iterator it = inbuffer.iterator(); it.hasNext();) {
HashMap map = (HashMap) it.next();
if (map.get("name") != null) {
if (!map.get("name").toString().equalsIgnoreCase(name)) {
if (!it.hasNext()) {
HashMap newMap = new HashMap();
newMap.put("name", name.toUpperCase());
newMap.put("type", type);
if (type.equalsIgnoreCase("string")) {
newMap.put("value", "");
}
else if (type.equalsIgnoreCase("int")) {
newMap.put("value", "0");
}
inbuffer.add(newMap);
}
}
}
}
}
public int checkContainsKey(String key, Buffer inBuffer) {
for (Iterator it = inBuffer.iterator(); it.hasNext();) {
HashMap map = (HashMap) it.next();
if (map.get("name") != null) {
if (map.get("name").toString().equalsIgnoreCase(key)) {
return -1;
}
}
}
return 0;
}
public void list() {
if (this.httpBuffer.isEmpty()) {
throw new RuntimeException("缓存还没有初始化,操作失败!");
}
for (Iterator it = this.httpBuffer.iterator(); it.hasNext();) {
HashMap map = (HashMap) it.next();
if (map.get("name") != null) {
if (map.get("value") != null) {
log.LOG_INFO(map.get("name") + ":" + convetStrToDb(map.get("value").toString()));
}
else {
log.LOG_INFO(map.get("name") + ":" + map.get("value"));
}
}
}
}
public String convetStrToDb(String instr) {
String outstr = "";
if (instr == null || instr == "") {
outstr = "";
}
else {
try {
outstr = new String(instr.getBytes("ISO8859_1"), "GBK");
}
catch (Exception e) {
throw new RuntimeException(e);
}
}
if (instr == null || instr == "") {
outstr = "";
}
return outstr;
}
public String convetStrToWeb(String str) {
String outstr = "";
if (str == null || str == "") {
outstr = "";
}
else {
try {
outstr = new String(str.getBytes("GBK"), "ISO8859_1");
}
catch (Exception e) {
throw new RuntimeException(e);
}
}
if (str == null || str == "") {
outstr = "";
}
return outstr;
}
public void setSessionField(String sessionField) {
String value = "SESSION";
if (sessionField == "")
return;
if (this.getString("SESSION_STR") != "") {
value = this.getString("SESSION_STR") + "," + sessionField;
}
else {
value = value + "," + sessionField;
}
this.setString("SESSION_STR", value);
}
public int removeSessionField(String sessionField) {
return 0;
}
public ArrayList getSessionList() {
ArrayList sessionList = new ArrayList();
String sessionFields = this.getString("SESSION_STR");
String[] sessionField = sessionFields.split(",");
for (int i = 0; i < sessionField.length; i++) {
if (!sessionField[i].equalsIgnoreCase("SESSION_STR")) {
HashMap map = new HashMap();
map.put("name", sessionField[i]);
sessionList.add(map);
}
}
return sessionList;
}
public String getSessionField(String sessionField) {
String field = "";
String sessionFields = this.getString("SESSION_STR");
if (sessionFields.indexOf(sessionField) > 0) {
field = sessionField;
}
return field;
}
public void setCommenFields(Buffer inbuffer, Buffer outBuffer) {
this.addField("SUCCEED_FWD", inbuffer, outBuffer);
this.addField("ERROR_FWD", inbuffer, outBuffer);
this.addField("SESSION_STR", inbuffer, outBuffer);
this.addField("RESULT_CODE", inbuffer, outBuffer);
this.addField("RESULT_INFO", inbuffer, outBuffer);
this.addField("OUT_QUERY", inbuffer, outBuffer);
this.addField("OUT_BUFFER", inbuffer, outBuffer);
this.addField("SESSION", inbuffer, outBuffer);
this.addField("REALPATH", inbuffer, outBuffer);
}
public String saveUploadFile(FormFile file, HttpServletRequest request, HttpSession session, String gen_id) {
String basepath = request.getRealPath("");
String fileName = file.getFileName();
String contentType = file.getContentType();
String size = (file.getFileSize() + " bytes");
config configFile= new config();
configFile.init();
String rootpath = configFile.getString("mysqlbase.projpath");
String cust_id = String.valueOf(session.getAttribute("SESSION_CUST_ID"));
String filePath = rootpath+"/upload/" + cust_id + "/" + gen_id + fileName;
try {
//判断文件夹是否存在
File floder = new File(rootpath+"/upload/" + cust_id );
if (!floder.exists()) {
try {
floder.mkdirs();
}
catch (Exception e) {
log.LOG_INFO("创建文件夹失败!");
}
}
ByteArrayOutputStream baos = new ByteArrayOutputStream();
InputStream stream = file.getInputStream();
OutputStream bos = new FileOutputStream(filePath);
int bytesRead = 0;
byte[] buffer = new byte[8192];
while ((bytesRead = stream.read(buffer, 0, 8192)) != -1) {
bos.write(buffer, 0, bytesRead);
}
bos.close();
stream.close();
}
catch (IOException e) {
throw new RuntimeException(e);
}
return filePath;
}
public ArrayList BuffersToBuffer(Buffers buffer) {
ArrayList toBuffer = new Buffer();
for (Iterator it = httpBuffer.iterator(); it.hasNext();) {
HashMap map = (HashMap) it.next();
if (map.get("name") != null) {
HashMap outmap = new HashMap();
outmap.put(map.get("name").toString(), map.get("value"));
toBuffer.add(outmap);
}
}
return toBuffer;
}
public ArrayList BuffersToArrayList(Buffers buffer) {
ArrayList toBuffer = new Buffer();
for (Iterator it = httpBuffer.iterator(); it.hasNext();) {
HashMap map = (HashMap) it.next();
if (map.get("name") != null) {
HashMap outmap = new HashMap();
outmap.put("type", map.get("type").toString());
outmap.put("name", map.get("name").toString());
outmap.put("value", map.get("value"));
toBuffer.add(outmap);
}
}
return toBuffer;
}
public boolean isFieldExist(String fields) {
if (getString(fields) == null) {
return false;
}
else {
return true;
}
}
public void convertInterfceData(HttpServletRequest req) {
this.init(req);
InterfaceMgr interfMgr = new InterfaceMgr();
String basepath = req.getRealPath("");
Buffer saasBuffer = new Buffer();
String fieldspath = basepath + "/WEB-INF/interface.flds";
ArrayList interfData = new ArrayList();
try {
interfData = interfMgr.getInterfaceData(req);
}
catch (Exception e) {
throw new RuntimeException(e);
}
try {
FileReader ffield = new FileReader(fieldspath);
BufferedReader fieldbuff = new BufferedReader(ffield);
String fieldline = fieldbuff.readLine();
while (fieldline != null) {
if (!fieldline.trim().equalsIgnoreCase("")) {
if (!fieldline.substring(0, 1).equalsIgnoreCase("#")) {
String[] fieldlinestr = fieldline.split(",");
for (Iterator it = interfData.iterator(); it.hasNext();) {
HashMap datamap = (HashMap) it.next();
if (datamap.get(fieldlinestr[0].toLowerCase()) != null) {
this.addField(fieldlinestr[1], this.httpBuffer, this.httpBuffer);
this.setString(fieldlinestr[1], convetStrToWeb(datamap.get(fieldlinestr[0].toLowerCase()).toString()));
break;
}
}
}
}
fieldline = fieldbuff.readLine();
}
fieldbuff.close();
ffield.close();
}
catch (IOException e) {
throw new RuntimeException("[init]缓存域初始化失败!");
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -