no message

main
이범준 1 year ago
parent 78d45235b6
commit abce3b3936

@ -55,12 +55,6 @@
</dependency>
<dependency>
<groupId>cokr.xit.base</groupId>
<artifactId>xit-file</artifactId>
<version>23.04.01-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>

@ -0,0 +1,120 @@
package cokr.xit;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.Arrays;
import java.util.List;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import java.util.zip.ZipOutputStream;
import cokr.xit.foundation.Assert;
public class ZIP {
/** zip .
* @param zipPath zip
* @param targets
* @return zip
*/
public File compress(String zipPath, String... targets) {
return compress(zipPath, Arrays.asList(targets));
}
/** zip .
* @param zipPath zip
* @param targets
* @return zip
*/
public File compress(String zipPath, List<String> targets) {
try (
FileOutputStream fout = new FileOutputStream(zipPath);
ZipOutputStream zout = new ZipOutputStream(fout);
) {
for (String path: targets) {
File file = new File(path);
compress(zout, file, file.getName());
}
return new File(zipPath);
} catch(Exception e) {
throw Assert.runtimeException(e);
}
}
private void compress(ZipOutputStream zout, File file, String filename) throws Exception {
if (file.isHidden()) return;
if (file.isDirectory()) {
zout.putNextEntry(new ZipEntry(filename.endsWith("/") ? filename : filename + "/"));
zout.closeEntry();
File[] children = file.listFiles();
for (File child: children) {
compress(zout, child, filename + "/" + child.getName());
}
} else
try (FileInputStream fis = new FileInputStream(file);) {
zout.putNextEntry(new ZipEntry(filename));
byte[] bytes = new byte[1024];
int length;
while((length = fis.read(bytes)) >= 0) {
zout.write(bytes, 0, length);
}
}
}
/** zip .
* @param zipPath zip
* @param destDir
*/
public void decompress(String zipPath, String destDir) {
try (
FileInputStream fis = new FileInputStream(zipPath);
ZipInputStream zis = new ZipInputStream(fis);
) {
decompress(zis, destDir);
} catch (Exception e) {
throw Assert.runtimeException(e);
}
}
private void decompress(ZipInputStream zis, String destDir) throws Exception {
byte[] buff = new byte[1024];
File dir = new File(destDir);
ZipEntry zipEntry = zis.getNextEntry();
while (zipEntry != null) {
File newFile = newFile(dir, zipEntry);
if (zipEntry.isDirectory()) {
if (!newFile.isDirectory() && !newFile.mkdirs())
throw new Exception("Failed to create directory " + newFile);
} else {
File parent = newFile.getParentFile();
if (!parent.isDirectory() && !parent.mkdirs())
throw new Exception("Failed to create directory " + parent);
try (
FileOutputStream fos = new FileOutputStream(newFile);
) {
int len;
while ((len = zis.read(buff)) > 0) {
fos.write(buff, 0, len);
}
}
}
zipEntry = zis.getNextEntry();
}
}
private File newFile(File destDir, ZipEntry zipEntry) throws Exception {
File destFile = new File(destDir, zipEntry.getName());
String destDirPath = destDir.getCanonicalPath();
if (!destFile.getCanonicalPath().startsWith(destDirPath + File.separator))
throw new Exception(String.format("%s is outside of the %s", zipEntry.getName(), destDirPath));
return destFile;
}
}

@ -5,7 +5,7 @@ import java.io.File;
import javax.servlet.http.HttpServletRequest;
import cokr.xit.TextFileMaker;
import cokr.xit.base.file.ZIP;
import cokr.xit.ZIP;
public class WindowsServiceBean extends Nuri2ServiceBean {

@ -6,7 +6,6 @@ import java.io.OutputStream;
import java.nio.file.Files;
import java.util.function.Consumer;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import org.springframework.stereotype.Controller;
@ -22,8 +21,6 @@ import externalsystem.nuri2.service.bean.WindowsServiceBean;
@RequestMapping(name="모바일 메시지 컨트롤러", value="/mms")
public class nuri2Controller extends AbstractController {
@Resource(name="nuri2ServiceBean")
Nuri2ServiceBean nuri2ServiceBean;
@RequestMapping(name="모듈 실행 스크립트 파일 생성", value="/createScript.do")
@ -83,7 +80,14 @@ public class nuri2Controller extends AbstractController {
public ModelAndView createConf(HttpServletRequest req) {
ModelAndView mav = new ModelAndView("downloadView");
String filePath = nuri2ServiceBean.makeConfFile(req);
Nuri2ServiceBean nuri2Service = new Nuri2ServiceBean() {
@Override
public String makeScriptFile(HttpServletRequest req) {
return null;
}
};
String filePath = nuri2Service.makeConfFile(req);
//다운로드
File file = new File(filePath);
@ -106,7 +110,7 @@ public class nuri2Controller extends AbstractController {
new Downloadable()
.setContentType("text/plain")
.setWriter(writer)
.setFilename(nuri2ServiceBean.nuri2confName)
.setFilename(nuri2Service.nuri2confName)
);
} catch (IOException e) {
e.printStackTrace();

Loading…
Cancel
Save