52 lines
1.6 KiB
Java
52 lines
1.6 KiB
Java
package com.yutou.qqbot.utlis;
|
|
|
|
import java.io.File;
|
|
import java.io.IOException;
|
|
import java.nio.charset.Charset;
|
|
import java.util.ArrayList;
|
|
import java.util.Enumeration;
|
|
import java.util.List;
|
|
import java.util.zip.ZipEntry;
|
|
import java.util.zip.ZipFile;
|
|
|
|
public class IdeaTools {
|
|
public static String getIdea(String name) {
|
|
if(StringUtils.isEmpty(name)){
|
|
return "";
|
|
}
|
|
File file = new File("tmp" + File.separator + "idea.zip");
|
|
try {
|
|
ZipFile zipFile = new ZipFile(file, Charset.forName("gbk"));
|
|
String data = "";
|
|
if (file.exists()&&zipFile.getEntry(name)!=null) {
|
|
data = StreamTools.streamReadLine(zipFile.getInputStream(zipFile.getEntry(name)));
|
|
}
|
|
zipFile.close();
|
|
return data;
|
|
} catch (IOException e) {
|
|
e.printStackTrace();
|
|
}
|
|
return "";
|
|
}
|
|
|
|
public static List<String> getIdeaList(String url) {
|
|
File file = HttpTools.syncDownload(url, "idea.zip");
|
|
List<String> list = new ArrayList<>();
|
|
try {
|
|
ZipFile zip = new ZipFile(file, Charset.forName("gbk"));
|
|
Enumeration<? extends ZipEntry> ez = zip.entries();
|
|
while (ez.hasMoreElements()) {
|
|
ZipEntry entry = ez.nextElement();
|
|
if (entry.getName().endsWith(".txt")) {
|
|
list.add(entry.getName());
|
|
}
|
|
}
|
|
zip.close();
|
|
} catch (IOException e) {
|
|
e.printStackTrace();
|
|
}
|
|
|
|
return list;
|
|
}
|
|
}
|