Advertisement
Guest User

Untitled

a guest
Feb 25th, 2020
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.21 KB | None | 0 0
  1. package com.rk.morozov.controller;
  2.  
  3. import com.rk.morozov.entity.ContentType;
  4. import org.springframework.beans.factory.annotation.Value;
  5. import org.springframework.http.ResponseEntity;
  6. import org.springframework.web.bind.annotation.GetMapping;
  7. import org.springframework.web.bind.annotation.RestController;
  8.  
  9. import java.io.FileInputStream;
  10. import java.io.ObjectInputStream;
  11.  
  12. @RestController
  13. public class ApiController {
  14.  
  15.     @Value("${MorozovApplication.filepath.video}")
  16.     private String videoFilePath;
  17.     @Value("${MorozovApplication.filepath.text}")
  18.     private String textFilePath;
  19.  
  20.     @Value("${MorozovApplication.content.type}")
  21.     private ContentType contentType;
  22.  
  23.     @GetMapping("/content")
  24.     public ResponseEntity<Object> getContent() throws Exception{
  25.         Object content = contentType.equals(ContentType.TEXT) ? getContentFromPath(textFilePath) : getContentFromPath(videoFilePath);
  26.         return ResponseEntity.ok(content);
  27.     }
  28.  
  29.     private Object getContentFromPath(String path) throws Exception {
  30.         FileInputStream fileIn = new FileInputStream(path);
  31.         ObjectInputStream objectIn = new ObjectInputStream(fileIn);
  32.  
  33.         return objectIn.readObject();
  34.     }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement