Пример #1
0
 /**
  * Verifies that the saved file is the size expected in bytes. If expected bytes is specified as
  * <= 0 then size verification is not performed.
  *
  * @throws IOException
  */
 protected void verifyLength() throws IOException {
   if (this.expectedLength > 0) {
     if (this.actualLength != this.expectedLength) {
       throw new IOException(
           format(
               "Saved stream''s length invalid - Expected: {0} ({1}), Actual: {2} ({3})",
               this.expectedLength,
               Util.byteCountToDisplaySize(this.expectedLength),
               this.actualLength,
               Util.byteCountToDisplaySize(this.actualLength)));
     }
   }
 }
Пример #2
0
 @Override
 public UploadedFileInfo call() throws Exception {
   UploadedFileInfo ufi;
   Path targetFile = createTempFile();
   StopWatch sw = new StopWatch();
   sw.start();
   try {
     LOGGER.debug(
         "Saving {} ({}) Expected MD5:{}...",
         targetFile.toString(),
         Util.byteCountToDisplaySize(expectedLength),
         expectedMd5);
     this.actualLength = saveStreamToFile(this.dis, targetFile);
     this.actualMd5 = Hex.encodeHexString(dis.getMessageDigest().digest());
     verifyExpecteds();
     ufi = new UploadedFileInfo(targetFile, this.actualLength, this.actualMd5);
     sw.stop();
     LOGGER.debug(
         "Saved {} ({}) Computed MD5:{}, Time: {}, Speed: {}",
         ufi.getFilepath().toString(),
         Util.byteCountToDisplaySize(ufi.getSize()),
         ufi.getMd5(),
         sw.getTimeElapsedFormatted(),
         sw.getRate(ufi.getSize()));
   } catch (Exception e) {
     LOGGER.error(
         "Error saving {} ({} bytes) Expected MD5:{} - {}",
         targetFile.toString(),
         this.expectedLength,
         this.expectedMd5,
         e.getMessage());
     throw e;
   } finally {
     IOUtils.closeQuietly(dis);
   }
   return ufi;
 }