|
@@ -10,8 +10,14 @@ import org.springframework.stereotype.Service;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import java.io.File;
|
|
|
+import java.io.FileInputStream;
|
|
|
+import java.io.FileOutputStream;
|
|
|
import java.util.List;
|
|
|
import java.io.IOException;
|
|
|
+import java.util.zip.ZipEntry;
|
|
|
+import java.util.zip.ZipInputStream;
|
|
|
+
|
|
|
+import static cn.hutool.core.util.ZipUtil.unzip;
|
|
|
|
|
|
@Service
|
|
|
public class MuseumPictureServiceImpl implements MuseumPictureService {
|
|
@@ -66,44 +72,45 @@ public class MuseumPictureServiceImpl implements MuseumPictureService {
|
|
|
// }
|
|
|
}
|
|
|
|
|
|
-// public void unzipAndAddToGroup(String groupId, String zipFilePath) throws IOException {
|
|
|
-// String photoGroupDir = "photos/" + groupId;
|
|
|
-// File groupDir = new File(photoGroupDir);
|
|
|
-// if (!groupDir.exists()) {
|
|
|
-// groupDir.mkdirs();
|
|
|
-// }
|
|
|
-//
|
|
|
-// unzip(zipFilePath, photoGroupDir);
|
|
|
-//}
|
|
|
-//
|
|
|
-//private void unzip(String zipFilePath, String destDir) throws IOException {
|
|
|
-// byte[] buffer = new byte[1024];
|
|
|
-// try (
|
|
|
-// FileInputStream fis = new FileInputStream(zipFilePath);
|
|
|
-// ZipInputStream zis = new ZipInputStream(fis)
|
|
|
-// ) {
|
|
|
-// ZipEntry zipEntry = zis.getNextEntry();
|
|
|
-// while (zipEntry != null) {
|
|
|
-// String filePath = destDir + File.separator + zipEntry.getName();
|
|
|
-// if (!zipEntry.isDirectory()) {
|
|
|
-// extractFile(zis, buffer, filePath);
|
|
|
-// } else {
|
|
|
-// File dir = new File(filePath);
|
|
|
-// dir.mkdir();
|
|
|
-// }
|
|
|
-// zis.closeEntry();
|
|
|
-// zipEntry = zis.getNextEntry();
|
|
|
-// }
|
|
|
-// zis.closeEntry();
|
|
|
-// }
|
|
|
-//}
|
|
|
-//
|
|
|
-//private void extractFile(ZipInputStream zis, byte[] buffer, String filePath) throws IOException {
|
|
|
-// try (FileOutputStream fos = new FileOutputStream(filePath)) {
|
|
|
-// int len;
|
|
|
-// while ((len = zis.read(buffer)) > 0) {
|
|
|
-// fos.write(buffer, 0, len);
|
|
|
-// }
|
|
|
-// }
|
|
|
-//}
|
|
|
+ @Override
|
|
|
+ public void unzipAndAddToGroup(String groupId, String zipFilePath) throws IOException {
|
|
|
+ String photoGroupDir = "photos/" + groupId;
|
|
|
+ File groupDir = new File(photoGroupDir);
|
|
|
+ if (!groupDir.exists()) {
|
|
|
+ groupDir.mkdirs();
|
|
|
+ }
|
|
|
+
|
|
|
+ unzip(zipFilePath, photoGroupDir);
|
|
|
+}
|
|
|
+
|
|
|
+ private void unzip(String zipFilePath, String destDir) throws IOException {
|
|
|
+ byte[] buffer = new byte[1024];
|
|
|
+ try (
|
|
|
+ FileInputStream fis = new FileInputStream(zipFilePath);
|
|
|
+ ZipInputStream zis = new ZipInputStream(fis)
|
|
|
+ ) {
|
|
|
+ ZipEntry zipEntry = zis.getNextEntry();
|
|
|
+ while (zipEntry != null) {
|
|
|
+ String filePath = destDir + File.separator + zipEntry.getName();
|
|
|
+ if (!zipEntry.isDirectory()) {
|
|
|
+ extractFile(zis, buffer, filePath);
|
|
|
+ } else {
|
|
|
+ File dir = new File(filePath);
|
|
|
+ dir.mkdir();
|
|
|
+ }
|
|
|
+ zis.closeEntry();
|
|
|
+ zipEntry = zis.getNextEntry();
|
|
|
+ }
|
|
|
+ zis.closeEntry();
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+private void extractFile(ZipInputStream zis, byte[] buffer, String filePath) throws IOException {
|
|
|
+ try (FileOutputStream fos = new FileOutputStream(filePath)) {
|
|
|
+ int len;
|
|
|
+ while ((len = zis.read(buffer)) > 0) {
|
|
|
+ fos.write(buffer, 0, len);
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
//}
|