Advertisement
wsx22

Untitled

Jun 25th, 2019
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.35 KB | None | 0 0
  1.     @Override
  2.     public Publisher<PutResult> put(Path filePath, OutputStream outputStream) {
  3.  
  4.         Optional<File> optionalFile = find(filePath);
  5.  
  6.         if (optionalFile.isPresent()) {
  7.  
  8.             updateFile(optionalFile.get());
  9.             log.info(FILE_OVERWRITTEN);
  10.             return Mono.just(PutResult.OVERWRITTEN);
  11.         }
  12.  
  13.         File folderMetaData = new File();
  14.  
  15.         folderMetaData.setName(filePath.toAbsolutePath().toString());
  16.         folderMetaData.setMimeType(FILE_MIME_TYPE);
  17.  
  18.         Optional<byte[]> data = Optional.empty();
  19.  
  20.         try {
  21.             data = Optional.of(Files.readAllBytes(filePath));
  22.         } catch (IOException e) {
  23.             e.printStackTrace();
  24.         }
  25.  
  26.         InputStreamContent fileContent = null;
  27.         if (data.isPresent()) {
  28.             fileContent = new InputStreamContent(StringUtils.EMPTY, new ByteArrayInputStream(data.get()));
  29.         }
  30.  
  31.         log.info(String.format(UPLOAD_START, filePath.toAbsolutePath().toString()));
  32.  
  33.         try {
  34.             drive.files()
  35.                     .create(folderMetaData, fileContent)
  36.                     .execute();
  37.         } catch (IOException e) {
  38.             e.printStackTrace();
  39.         }
  40.  
  41.         log.info(String.format(UPLOAD_DONE, filePath.toAbsolutePath().toString()));
  42.  
  43.         return Mono.just(PutResult.SUCCESS);
  44.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement