Skip to content

Commit

Permalink
#11 Fix UT/Sonar
Browse files Browse the repository at this point in the history
  • Loading branch information
TannerCai committed Feb 18, 2019
1 parent 0a44324 commit cb9d1a7
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 65 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,37 +59,47 @@ private static boolean deleteDir(File dir) {
return dir.delete();
}

public static void unzip(File zip, File directory) throws ZipException, IOException {
ZipFile zipFile = new ZipFile(zip);
try {
Enumeration<? extends ZipEntry> entries = zipFile.entries();
while (entries.hasMoreElements()) {
ZipEntry zipEntry = entries.nextElement();
if (zipEntry.isDirectory()) {
File temp = new File(directory + File.separator + zipEntry.getName());
temp.mkdirs();
continue;
}
BufferedInputStream bis = new BufferedInputStream(zipFile.getInputStream(zipEntry));
File f = new File(directory + File.separator + zipEntry.getName());
File f_p = f.getParentFile();
if (f_p != null && !f_p.exists()) {
f_p.mkdirs();
}
BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(f));
int len = -1;
byte[] bs = new byte[2048];
while ((len = bis.read(bs, 0, 2048)) != -1) {
bos.write(bs, 0, len);
}
bos.flush();
bos.close();
bis.close();
}
} finally {
zipFile.close();
public static void unzip(File zip, File directory) throws ZipException, IOException {
try (ZipFile zipFile = new ZipFile(zip)){
Enumeration<? extends ZipEntry> entries = zipFile.entries();
while (entries.hasMoreElements()) {
ZipEntry zipEntry = entries.nextElement();
if (zipEntry.isDirectory()) {
File temp = new File(directory + File.separator + zipEntry.getName());
temp.mkdirs();
continue;
}
unzip(directory,zipFile, zipEntry);
}
}
}
}

private static void unzip(File directory, ZipFile zipFile, ZipEntry zipEntry) throws ZipException, IOException {
BufferedInputStream bis = null;
BufferedOutputStream bos = null;
try {
bis = new BufferedInputStream(zipFile.getInputStream(zipEntry));
File f = new File(directory + File.separator + zipEntry.getName());
File f_p = f.getParentFile();
if (f_p != null && !f_p.exists()) {
f_p.mkdirs();
}
bos = new BufferedOutputStream(new FileOutputStream(f));
int len = -1;
byte[] bs = new byte[2048];
while ((len = bis.read(bs, 0, 2048)) != -1) {
bos.write(bs, 0, len);
}
} finally {
if (bos != null) {
bos.flush();
bos.close();
}
if (bis != null) {
bis.close();
}
}
}

public static void launch() throws PallasException, IOException {
InputStream is = CerebroEmbed.class.getClassLoader().getResourceAsStream("cerebro.zip");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -650,7 +650,14 @@ protected static CharSequence encodeUriQuery(CharSequence in) {
if (outBuf == null) {
outBuf = new StringBuilder(in.length() + 5*3);
outBuf.append(in,0,i);
formatter = new Formatter(outBuf);
try {
formatter = new Formatter(outBuf);
} finally {
if (formatter != null) {
formatter.flush();
formatter.close();
}
}
}
//leading %, 0 padded, width 2, capital hex
formatter.format("%%%02X",(int)c);//TODO
Expand Down
34 changes: 0 additions & 34 deletions pallas-core/src/main/java/com/vip/pallas/bean/EsAliases.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,52 +17,18 @@

package com.vip.pallas.bean;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.vip.pallas.utils.JsonUtil;

public class EsAliases {

private List<Map<String, Map<String, String>>> actions;

/*
public static void main(String[] args) throws Exception {
EsAliases esAliases = new EsAliases();
List<Map<String, Map<String, String>>> actions = new ArrayList<Map<String, Map<String, String>>>(2);
Map<String, Map<String, String>> removeMap0 = new HashMap<String, Map<String, String>>();
Map<String, Map<String, String>> addMap0 = new HashMap<String, Map<String, String>>();
Map<String, String> removeMap = new HashMap<String, String>();
Map<String, String> addMap = new HashMap<String, String>();
removeMap.put("index", "vsearch11");
removeMap.put("alias", "msearch");
addMap.put("index", "vsearch12");
addMap.put("alias", "msearch");
removeMap0.put("remove", removeMap);
addMap0.put("add", addMap);
actions.add(removeMap0);
actions.add(addMap0);
esAliases.setActions(actions);
System.out.println(JsonUtil.toJson(esAliases));
}*/



public List<Map<String, Map<String, String>>> getActions() {
return actions;
}



public void setActions(List<Map<String, Map<String, String>>> actions) {
this.actions = actions;
}
Expand Down

0 comments on commit cb9d1a7

Please sign in to comment.