Пример #1
0
 @Override
 public Upload getById(String fileId) throws IOException {
   if (config == null) {
     login();
   }
   Upload uploadRec = new Upload();
   StoredObject swiftObject = null;
   try {
     swiftObject = container.getObject(fileId);
   } catch (Exception e) {
     throw new FileNotFoundException(fileId);
   }
   Map<String, Object> metadata = swiftObject.getMetadata();
   uploadRec.setExpires(swiftObject.getDeleteAtAsDate());
   uploadRec.setFilename((String) metadata.get("filename"));
   uploadRec.setContentType((String) metadata.get("content-type"));
   uploadRec.setSize(swiftObject.getContentLength());
   Date today = new Date(System.currentTimeMillis());
   if (uploadRec.getExpires() != null) {
     if (today.after(uploadRec.getExpires())) {
       throw new FileNotFoundException(fileId);
     }
   }
   uploadRec.setContentStream(swiftObject.downloadObjectAsInputStream());
   return uploadRec;
 }
Пример #2
0
 @Test
 public void downloadAsInputStream() throws IOException {
   InputStream byteStream = object.downloadObjectAsInputStream();
   assertTrue(Arrays.equals(bytes, IOUtils.toByteArray(byteStream)));
 }