Example #1
0
 /**
  * Reset the resource to an "new" status. The {@link #s3URL} is not reset, because it defines a
  * S3Resource
  */
 @Override
 protected void reset() {
   super.reset();
   this.s3Object = null;
   this.modifiedHeader = null;
 }
Example #2
0
 public void copy(Resource sourceDirectory, Resource targetDirectory, int level)
     throws ResourceException, IOException, URISyntaxException {
   // if (level > maxLevel)
   // return; // limit the crawler to a certain depth
   if (level >= countMaxLevel) countMaxLevel++; // count the deepest directory level
   System.out.println(sourceDirectory);
   // System.out.println(targetDirectory + File.separator);
   List<Resource> list =
       sourceDirectory.listResources(); // get the files of the resource directory
   if (!targetDirectory.isDirectory()) {
     if (!targetDirectory.isFile()) {
       targetDirectory = targetDirectory.createDirectoryResource();
     } else throw new IIOException("Can't create target directory: " + targetDirectory);
   } // else everything is fine
   if (list != null) {
     for (Resource source : list) {
       // create the target Resource for later use
       Resource target = targetDirectory.getChildResource(source.getName());
       if (source.isDirectory()) {
         /** Copy the Directory */
         countDir++;
         copy(source, target, level + 1);
       } else {
         /** Copy the Resource */
         if (!target.isFile()) {
           countResource++;
           countResourceTransfered++;
           System.out.println(source + " - copy");
           InputStream in = source.getInputStream();
           // if target supports metadata, write some
           if (target.supportsMetadata()) {
             target.setContentType(source.getContentType());
             target.setMetadata(source.getMetadata());
           }
           // extract the last modified timestamp from source
           long lm;
           final String key = "last-modified";
           if (source.supportsSetLastModified()) lm = source.lastModified();
           else if (source.containsKey(key)) lm = Long.valueOf(source.get(key));
           else lm = source.lastModified();
           // if target doesn't support to set last modified
           // store original timestamp in metadata
           if (target.supportsSetLastModified()) target.setLastModificationTime(lm);
           else if (target.supportsMetadata()) target.addMetadata(key, String.valueOf(lm));
           // now write the metadata
           target.write(source.length(), in);
         }
       }
     }
   }
 }