-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
+ Created the first version of gift images
- Loading branch information
1 parent
6c20cb6
commit 63ade5d
Showing
6 changed files
with
128 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,5 @@ | |
.gradle/ | ||
out/ | ||
build/ | ||
gifts/ | ||
*.iml |
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
54 changes: 54 additions & 0 deletions
54
src/main/java/com/capstone/potlatch/util/GiftImageFileManager.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,54 @@ | ||
package com.capstone.potlatch.util; | ||
|
||
import com.capstone.potlatch.models.Gift; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
import java.nio.file.StandardCopyOption; | ||
|
||
public class GiftImageFileManager { | ||
|
||
public static GiftImageFileManager get() throws IOException { | ||
return new GiftImageFileManager(); | ||
} | ||
|
||
private Path targetDir = Paths.get("gifts"); | ||
|
||
private GiftImageFileManager() throws IOException{ | ||
if(!Files.exists(targetDir)){ | ||
Files.createDirectories(targetDir); | ||
} | ||
} | ||
|
||
// Private helper method for resolving video file paths | ||
public Path getImagePath(Gift gift, String size) throws IOException { | ||
assert(gift != null); | ||
|
||
String dirPathString = "id_" + gift.getId(); | ||
Path dirPath = targetDir.resolve(dirPathString); | ||
if(!Files.exists(dirPath)){ | ||
Files.createDirectories(dirPath); | ||
} | ||
|
||
return dirPath.resolve("image_" + size + ".jpg"); | ||
} | ||
|
||
// public void copyData(Gift gift, String size, OutputStream out) throws IOException { | ||
// Path source = getImagePath(gift, size); | ||
// if(!Files.exists(source)){ | ||
// throw new FileNotFoundException("Unable to find the referenced image file for gift id:"+gift.getId()); | ||
// } | ||
// Files.copy(source, out); | ||
// } | ||
|
||
public void saveImage(Gift gift, String size, InputStream giftImage) throws IOException{ | ||
assert(giftImage != null); | ||
|
||
Path target = getImagePath(gift, size); | ||
Files.copy(giftImage, target, StandardCopyOption.REPLACE_EXISTING); | ||
} | ||
|
||
} |