-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into wonjeong#44-improve-image-deletion
- Loading branch information
Showing
11 changed files
with
71 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
src/main/java/server/inuappcenter/kr/data/redis/domain/ImageRedis.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package server.inuappcenter.kr.data.redis.domain; | ||
|
||
import lombok.Getter; | ||
import org.springframework.data.annotation.Id; | ||
import org.springframework.data.redis.core.RedisHash; | ||
|
||
|
||
@Getter | ||
@RedisHash(value = "image") | ||
public class ImageRedis { | ||
@Id | ||
private Long id; | ||
private final byte[] imageData; | ||
|
||
public ImageRedis(Long id, byte[] imageData) { | ||
this.id = id; | ||
this.imageData = imageData; | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...y/redis/BoardResponseRedisRepository.java → ...ository/BoardResponseRedisRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
src/main/java/server/inuappcenter/kr/data/redis/repository/ImageRedisRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package server.inuappcenter.kr.data.redis.repository; | ||
|
||
import org.springframework.data.repository.CrudRepository; | ||
import server.inuappcenter.kr.data.redis.domain.ImageRedis; | ||
|
||
public interface ImageRedisRepository extends CrudRepository<ImageRedis, Long> { | ||
} |
45 changes: 9 additions & 36 deletions
45
src/main/java/server/inuappcenter/kr/data/utils/ImageUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,21 @@ | ||
package server.inuappcenter.kr.data.utils; | ||
|
||
import java.io.ByteArrayOutputStream; | ||
import java.util.zip.Deflater; | ||
import java.util.zip.Inflater; | ||
import org.xerial.snappy.Snappy; | ||
import java.io.IOException; | ||
|
||
public class ImageUtils { | ||
|
||
public static byte[] compressImage(byte[] data) { | ||
Deflater deflater = new Deflater(); | ||
deflater.setLevel(Deflater.BEST_COMPRESSION); | ||
deflater.setInput(data); | ||
deflater.finish(); | ||
|
||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream(data.length); | ||
byte[] tmp = new byte[4*1024]; | ||
|
||
while (!deflater.finished()) { | ||
int size = deflater.deflate(tmp); | ||
outputStream.write(tmp, 0, size); | ||
} | ||
|
||
try { | ||
outputStream.close(); | ||
} catch (Exception ignored) { | ||
|
||
} | ||
public class ImageUtils { | ||
|
||
return outputStream.toByteArray(); | ||
public static byte[] compressImage(byte[] data) throws IOException { | ||
return Snappy.compress(data); | ||
} | ||
|
||
public static byte[] decompressImage(byte[] data) { | ||
Inflater inflater = new Inflater(); | ||
inflater.setInput(data); | ||
ByteArrayOutputStream outputSteam = new ByteArrayOutputStream(data.length); | ||
byte[] tmp = new byte[4*1024]; | ||
|
||
try { | ||
while (!inflater.finished()) { | ||
int count = inflater.inflate(tmp); | ||
outputSteam.write(tmp, 0, count); | ||
} | ||
outputSteam.close(); | ||
} catch (Exception ignored) { | ||
return Snappy.uncompress(data); | ||
} catch(Exception e) { | ||
throw new RuntimeException(e.getMessage()); | ||
} | ||
return outputSteam.toByteArray(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters