Skip to content

Commit

Permalink
[#77] 이미지 압축 에러 버그 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
occidere committed Jul 29, 2018
1 parent 7b957da commit 854db50
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/util/ImageCompress.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public static void compress(String targetDirectory) throws Exception {
public static void compress(String saveFileFullName, String targetDirectory) throws Exception {
saveFileFullName = removeLastSeparator(saveFileFullName) + ".zip";
targetDirectory = removeLastSeparator(targetDirectory);
// System.out.printf("saveFileFullName: %s\ntargetDirectory: %s\n", saveFileFullName, targetDirectory);

System.out.printf("이미지 압축중 ... ");

Expand All @@ -43,6 +44,7 @@ public static void compress(String saveFileFullName, String targetDirectory) thr

for(File image : fileList) {
String canonicalPath = StringUtils.substringAfter(image.getAbsolutePath(), getLastDirectory(targetDirectory));
// System.out.printf("image.getAbsolutePath(): %s\ncanonicalPath: %s\n", image.getAbsolutePath(), canonicalPath);

zipOutputStream.putNextEntry(new ZipEntry(canonicalPath));
zipOutputStream.write(FileUtils.readFileToByteArray(image));
Expand All @@ -60,7 +62,8 @@ public static void compress(String saveFileFullName, String targetDirectory) thr
* @return 마지막 디렉토리 명
*/
private static String getLastDirectory(String absolutePath) {
return StringUtils.substringAfterLast(removeLastSeparator(absolutePath), File.separator);
String replaced = removeLastSeparator(absolutePath).replace("\\", "/");
return StringUtils.substringAfterLast(replaced, "/");
}

/**
Expand All @@ -69,7 +72,10 @@ private static String getLastDirectory(String absolutePath) {
* @return 마지막에 경로 구분자가 있었다면 제거된 값
*/
private static String removeLastSeparator(String path) {
String separator = File.separator;
return StringUtils.containsOnly(path, separator) ? path : StringUtils.stripEnd(path, separator);
String replaced = path.replace("\\", "/");
if(replaced.endsWith("/") && replaced.length() > 1) {
replaced = path.substring(0, replaced.length()-1);
}
return replaced;
}
}

0 comments on commit 854db50

Please sign in to comment.