Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix down sdk zip err
Browse files Browse the repository at this point in the history
ansjsun committed Jul 4, 2016
1 parent 04f0d9e commit 7491cc3
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions src/main/java/org/nlpcn/jcoder/controller/JarAction.java
Original file line number Diff line number Diff line change
@@ -14,6 +14,7 @@
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -140,7 +141,11 @@ public void downDevSDK(HttpServletResponse response, @Param("resource") boolean
jars.addAll(JarService.findSystemJars());
jars.addAll(JarService.findJars());

Collection<Task> taskList = StaticValue.systemDao.search(Task.class, Cnd.where("status", "=", 1)) ;
for (File file : new File("/Users/sunjian/Documents/workspace/jcoder_sdk/lib").listFiles()) {
jars.add(file);
}

Collection<Task> taskList = StaticValue.systemDao.search(Task.class, Cnd.where("status", "=", 1));

byte[] buffer = new byte[10240];

@@ -151,11 +156,17 @@ public void downDevSDK(HttpServletResponse response, @Param("resource") boolean

try (ZipOutputStream out = new ZipOutputStream(response.getOutputStream())) {

Set<String> sets = new HashSet<>();
// 写jar包
for (File jar : jars) {
if (jar.isDirectory() || !jar.canRead() || !jar.getName().toLowerCase().endsWith(".jar")) {
continue;
}
String name = "jcoder_sdk/lib/" + jar.getName();
if (sets.contains(name)) {
continue;
}
sets.add(name);
out.putNextEntry(new ZipEntry("jcoder_sdk/lib/" + jar.getName()));
try (FileInputStream fis = new FileInputStream(jar)) {
while ((len = fis.read(buffer)) > 0) {
@@ -171,7 +182,7 @@ public void downDevSDK(HttpServletResponse response, @Param("resource") boolean
String code = task.getCode();
String path = JavaSourceUtil.findPackage(code);
String className = JavaSourceUtil.findClassName(code);

out.putNextEntry(new ZipEntry("jcoder_sdk/src/" + path.replace(".", "/") + "/" + className + ".java"));
out.write(code.getBytes("utf-8"));
} catch (RuntimeException e) {
@@ -191,14 +202,14 @@ public FileVisitResult visitFile(Path tempFile, BasicFileAttributes attrs) throw
if (f.isDirectory() || !f.canRead() || f.isHidden()) {
return FileVisitResult.CONTINUE;
}

String filePath = ("jcoder_sdk/" + f.getAbsolutePath().replace(basePath, "")).replace("\\", "/").replace("//", "/");

out.putNextEntry(new ZipEntry(filePath));

int len = 0;
byte[] buffer = new byte[10240];

try (FileInputStream fis = new FileInputStream(f)) {
while ((len = fis.read(buffer)) > 0) {
out.write(buffer, 0, len);
@@ -298,5 +309,5 @@ public String uploadJar(@Param("file") TempFile[] file) throws IOException {
return StaticValue.okMessage("upload " + fileNum + " file ok!");
}
}

}

0 comments on commit 7491cc3

Please sign in to comment.