|
@@ -1,6 +1,5 @@
|
|
package com.qmth.boot.tools.io;
|
|
package com.qmth.boot.tools.io;
|
|
|
|
|
|
-import com.sun.istack.internal.NotNull;
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
|
import java.io.*;
|
|
import java.io.*;
|
|
@@ -44,6 +43,9 @@ public class ZipWriter {
|
|
}
|
|
}
|
|
|
|
|
|
private ZipWriter(OutputStream outputStream) {
|
|
private ZipWriter(OutputStream outputStream) {
|
|
|
|
+ if (outputStream == null) {
|
|
|
|
+ throw new IllegalArgumentException("OutputStream should not be null");
|
|
|
|
+ }
|
|
this.ous = new ZipOutputStream(outputStream);
|
|
this.ous = new ZipOutputStream(outputStream);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -54,9 +56,12 @@ public class ZipWriter {
|
|
* @param path
|
|
* @param path
|
|
* @throws IOException
|
|
* @throws IOException
|
|
*/
|
|
*/
|
|
- public void write(@NotNull InputStream inputStream, @NotNull String... path) throws IOException {
|
|
|
|
|
|
+ public void write(InputStream inputStream, String... path) throws IOException {
|
|
|
|
+ if (inputStream == null) {
|
|
|
|
+ throw new IllegalArgumentException("InputStream should not be null");
|
|
|
|
+ }
|
|
if (path == null || path.length == 0) {
|
|
if (path == null || path.length == 0) {
|
|
- throw new RuntimeException("path should not be empty");
|
|
|
|
|
|
+ throw new IllegalArgumentException("path should not be empty");
|
|
}
|
|
}
|
|
ous.putNextEntry(new ZipEntry(StringUtils.join(path, File.separator)));
|
|
ous.putNextEntry(new ZipEntry(StringUtils.join(path, File.separator)));
|
|
IOUtils.copy(inputStream, ous);
|
|
IOUtils.copy(inputStream, ous);
|
|
@@ -70,7 +75,7 @@ public class ZipWriter {
|
|
* @param path
|
|
* @param path
|
|
* @throws IOException
|
|
* @throws IOException
|
|
*/
|
|
*/
|
|
- public void write(@NotNull File file, @NotNull String... path) throws IOException {
|
|
|
|
|
|
+ public void write(File file, String... path) throws IOException {
|
|
write(new FileInputStream(file), path);
|
|
write(new FileInputStream(file), path);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -81,7 +86,7 @@ public class ZipWriter {
|
|
* @param path
|
|
* @param path
|
|
* @throws IOException
|
|
* @throws IOException
|
|
*/
|
|
*/
|
|
- public void write(@NotNull byte[] data, @NotNull String... path) throws IOException {
|
|
|
|
|
|
+ public void write(byte[] data, String... path) throws IOException {
|
|
write(new ByteArrayInputStream(data), path);
|
|
write(new ByteArrayInputStream(data), path);
|
|
}
|
|
}
|
|
|
|
|