Exemplo n.º 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)));
     }
   }
 }
Exemplo n.º 2
0
  @PrePersist
  protected void onCreate() {
    this.timestamp = new Date();

    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(timestamp.getTime());
    calendar.add(Calendar.DATE, 30);
    this.expiry = calendar.getTime();
    this.accessCode = Math.round(Math.random() * (double) Long.MAX_VALUE);
    this.accessPassword =
        Util.generateRandomString(
            Integer.parseInt(GlobalProps.getProperty(GlobalProps.PROP_DROPBOX_PASSWORDLENGTH)));
  }
Exemplo n.º 3
0
 /**
  * getItemByName
  *
  * <p>Gets the fedora object given the pid
  *
  * <pre>
  * Version	Date		Developer				Description
  * 0.1		26/04/2012	Genevieve Turner (GT)	Initial
  * 0.2		02/05/2012	Genevieve Turner (GT)	Updated to fix issue with url encoded pid
  * 0.3		08/05/2012	Genevieve Turner (GT)	Updated to use newly created util decode function
  * </pre>
  *
  * @param id The fedora object pid
  * @return Returns the FedoraObject of the given pid
  */
 @Override
 public FedoraObject getItemByPid(String pid) {
   String decodedPid = null;
   decodedPid = Util.decodeUrlEncoded(pid);
   if (decodedPid == null) {
     return null;
   }
   FedoraObjectDAOImpl object = new FedoraObjectDAOImpl();
   FedoraObject item = object.getSingleByName(decodedPid);
   if (item != null) {
     LOGGER.trace("Retrieved item {}", item.getObject_id());
   }
   return item;
 }
Exemplo n.º 4
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;
 }