|
|
|
|
@ -33,8 +33,9 @@ public class ZIP extends AbstractComponent {
|
|
|
|
|
* @return 압축한 zip 파일
|
|
|
|
|
*/
|
|
|
|
|
public File compress(String zipPath, List<String> targets) {
|
|
|
|
|
File zip = zipFile(zipPath);
|
|
|
|
|
try (
|
|
|
|
|
FileOutputStream fout = new FileOutputStream(zipPath);
|
|
|
|
|
FileOutputStream fout = new FileOutputStream(zip);
|
|
|
|
|
ZipOutputStream zout = new ZipOutputStream(fout);
|
|
|
|
|
) {
|
|
|
|
|
for (String path: targets) {
|
|
|
|
|
@ -42,12 +43,20 @@ public class ZIP extends AbstractComponent {
|
|
|
|
|
compress(zout, file, file.getName());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return new File(zipPath);
|
|
|
|
|
return zip;
|
|
|
|
|
} catch(Exception e) {
|
|
|
|
|
throw runtimeException(e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private File zipFile(String zipPath) {
|
|
|
|
|
File zip = new File(zipPath);
|
|
|
|
|
File dir = zip.getParentFile();
|
|
|
|
|
if (dir != null && !dir.exists())
|
|
|
|
|
dir.mkdirs();
|
|
|
|
|
return zip;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**지정한 파일들을 지정한 경로의 zip 파일로 압축한다.
|
|
|
|
|
* @param zipPath zip 파일 경로
|
|
|
|
|
* @param inputs 압축할 파일의 InputStream 맵
|
|
|
|
|
@ -56,7 +65,7 @@ public class ZIP extends AbstractComponent {
|
|
|
|
|
* </ul>
|
|
|
|
|
*/
|
|
|
|
|
public File compress(String zipPath, Map<String, InputStream> inputs) {
|
|
|
|
|
File zip = new File(zipPath);
|
|
|
|
|
File zip = zipFile(zipPath);
|
|
|
|
|
try (
|
|
|
|
|
FileOutputStream fout = new FileOutputStream(zip);
|
|
|
|
|
ZipOutputStream zout = new ZipOutputStream(fout );
|
|
|
|
|
@ -88,16 +97,6 @@ public class ZIP extends AbstractComponent {
|
|
|
|
|
}
|
|
|
|
|
} else
|
|
|
|
|
compress(zout, filename, new FileInputStream(file));
|
|
|
|
|
/*
|
|
|
|
|
try (InputStream 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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
*/
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void compress(ZipOutputStream zout, String filename, InputStream input) throws Exception {
|
|
|
|
|
|