Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.rk.morozov.controller;
- import com.rk.morozov.entity.ContentType;
- import org.springframework.beans.factory.annotation.Value;
- import org.springframework.http.ResponseEntity;
- import org.springframework.web.bind.annotation.GetMapping;
- import org.springframework.web.bind.annotation.RestController;
- import java.io.FileInputStream;
- import java.io.ObjectInputStream;
- @RestController
- public class ApiController {
- @Value("${MorozovApplication.filepath.video}")
- private String videoFilePath;
- @Value("${MorozovApplication.filepath.text}")
- private String textFilePath;
- @Value("${MorozovApplication.content.type}")
- private ContentType contentType;
- @GetMapping("/content")
- public ResponseEntity<Object> getContent() throws Exception{
- Object content = contentType.equals(ContentType.TEXT) ? getContentFromPath(textFilePath) : getContentFromPath(videoFilePath);
- return ResponseEntity.ok(content);
- }
- private Object getContentFromPath(String path) throws Exception {
- FileInputStream fileIn = new FileInputStream(path);
- ObjectInputStream objectIn = new ObjectInputStream(fileIn);
- return objectIn.readObject();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement