LocalFileService.java 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package com.uas.ops.diff.service;
  2. import com.uas.ops.diff.util.StringUtils;
  3. import org.springframework.beans.factory.annotation.Value;
  4. import org.springframework.stereotype.Service;
  5. import org.springframework.util.FileCopyUtils;
  6. import java.io.File;
  7. import java.io.IOException;
  8. import java.util.UUID;
  9. /**
  10. * Created by Pro1 on 2017/6/13.
  11. */
  12. //@Service
  13. @Deprecated
  14. public class LocalFileService implements FileService{
  15. @Value("${diff.home}")
  16. private String appHome;
  17. @Override
  18. public String save(byte[] data, String fileName) throws IOException{
  19. String name = StringUtils.uuid();
  20. FileCopyUtils.copy(data, new File(appHome, name));
  21. return name;
  22. }
  23. @Override
  24. public byte[] get(String path) throws IOException {
  25. File file = new File(appHome, path);
  26. if (file.exists()) {
  27. return FileCopyUtils.copyToByteArray(file);
  28. }
  29. return null;
  30. }
  31. @Override
  32. public void delete(String path) {
  33. File file = new File(appHome, path);
  34. if (file.exists()) {
  35. file.delete();
  36. }
  37. }
  38. }