forked from see-realview/see-realview-backend
-
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.
feat: implement web database downloader
- 웹 데이터베이스 다운로드를 위한 컴포넌트 구현
- Loading branch information
Showing
2 changed files
with
50 additions
and
0 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
41 changes: 41 additions & 0 deletions
41
see-realview/src/main/java/com/see/realview/_core/utils/WebDatabaseReader.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,41 @@ | ||
package com.see.realview._core.utils; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.beans.factory.annotation.Qualifier; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.web.reactive.function.client.WebClient; | ||
import reactor.core.publisher.Mono; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
@Component | ||
@Slf4j | ||
public class WebDatabaseReader { | ||
|
||
private final WebClient databaseWebClient; | ||
|
||
public WebDatabaseReader(@Autowired @Qualifier("databaseWebClient") WebClient databaseWebClient) { | ||
this.databaseWebClient = databaseWebClient; | ||
} | ||
|
||
public List<String> read(String url, String identifier) { | ||
log.debug("웹 데이터베이스 다운로드 시작 | " + url); | ||
Mono<byte[]> readBytes = databaseWebClient | ||
.get() | ||
.uri(url) | ||
.retrieve() | ||
.bodyToMono(byte[].class); | ||
|
||
byte[] dataBytes = readBytes.block(); | ||
if (dataBytes == null) { | ||
log.debug("웹 데이터베이스 다운로드 실패 | " + url); | ||
return List.of(); | ||
} | ||
|
||
log.debug("웹 데이터베이스 다운로드 완료 | " + url); | ||
String data = Arrays.toString(dataBytes); | ||
return List.of(data.split(identifier)); | ||
} | ||
} |