zipFile(String) 추가

master
mjkhan21 8 months ago
parent f3f3146f1c
commit 6090d28439

@ -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 {

Loading…
Cancel
Save