Esempio n. 1
0
 @Override
 public Map<String, ?> getAttributes(URI uri, Map<?, ?> options) {
   Map<String, Object> result = new HashMap<String, Object>();
   String filePath = uri.toFileString();
   File file = new File(filePath);
   if (file.exists()) {
     Set<String> requestedAttributes = getRequestedAttributes(options);
     if (requestedAttributes == null
         || requestedAttributes.contains(IURIConverter.ATTRIBUTE_TIME_STAMP)) {
       result.put(IURIConverter.ATTRIBUTE_TIME_STAMP, file.lastModified());
     }
     if (requestedAttributes == null
         || requestedAttributes.contains(IURIConverter.ATTRIBUTE_LENGTH)) {
       result.put(IURIConverter.ATTRIBUTE_LENGTH, file.length());
     }
     if (requestedAttributes == null
         || requestedAttributes.contains(IURIConverter.ATTRIBUTE_READ_ONLY)) {
       result.put(IURIConverter.ATTRIBUTE_READ_ONLY, !file.canWrite());
     }
     if (requestedAttributes == null
         || requestedAttributes.contains(IURIConverter.ATTRIBUTE_HIDDEN)) {
       result.put(IURIConverter.ATTRIBUTE_HIDDEN, file.isHidden());
     }
     if (requestedAttributes == null
         || requestedAttributes.contains(IURIConverter.ATTRIBUTE_DIRECTORY)) {
       result.put(IURIConverter.ATTRIBUTE_DIRECTORY, file.isDirectory());
     }
   }
   return result;
 }
Esempio n. 2
0
 /**
  * Creates an input stream for the file path and returns it.
  *
  * <p>This implementation allocates a {@link FileInputStream}.
  *
  * @return an open input stream.
  * @exception IOException if there is a problem obtaining an open input stream.
  */
 @Override
 public InputStream createInputStream(URI uri, Map<?, ?> options) throws IOException {
   String filePath = uri.toFileString();
   File file = new File(filePath);
   InputStream inputStream = new FileInputStream(file);
   Map<Object, Object> response = getResponse(options);
   if (response != null) {
     response.put(IURIConverter.RESPONSE_TIME_STAMP_PROPERTY, file.lastModified());
   }
   return inputStream;
 }
Esempio n. 3
0
 @Override
 public void setAttributes(URI uri, Map<String, ?> attributes, Map<?, ?> options)
     throws IOException {
   String filePath = uri.toFileString();
   File file = new File(filePath);
   if (file.exists()) {
     Long timeStamp = (Long) attributes.get(IURIConverter.ATTRIBUTE_TIME_STAMP);
     if (timeStamp != null && !file.setLastModified(timeStamp)) {
       throw new IOException("Could not set the timestamp for the file '" + file + "'");
     }
     Boolean isReadOnly = (Boolean) attributes.get(IURIConverter.ATTRIBUTE_READ_ONLY);
     if (Boolean.TRUE.equals(isReadOnly) && !file.setReadOnly()) {
       throw new IOException("Could not set the file '" + file + "' to be read only");
     }
   } else {
     throw new FileNotFoundException("The file '" + file + "' does not exist");
   }
 }
Esempio n. 4
0
 /**
  * Creates an output stream for the file path and returns it.
  *
  * <p>This implementation allocates a {@link FileOutputStream} and creates subdirectories as
  * necessary.
  *
  * @return an open output stream.
  * @exception IOException if there is a problem obtaining an open output stream.
  */
 @Override
 public OutputStream createOutputStream(URI uri, Map<?, ?> options) throws IOException {
   String filePath = uri.toFileString();
   final File file = new File(filePath);
   String parent = file.getParent();
   if (parent != null) {
     new File(parent).mkdirs();
   }
   final Map<Object, Object> response = getResponse(options);
   OutputStream outputStream =
       new FileOutputStream(file) {
         @Override
         public void close() throws IOException {
           try {
             super.close();
           } finally {
             if (response != null) {
               response.put(IURIConverter.RESPONSE_TIME_STAMP_PROPERTY, file.lastModified());
             }
           }
         }
       };
   return outputStream;
 }
Esempio n. 5
0
 @Override
 public boolean exists(URI uri, Map<?, ?> options) {
   String filePath = uri.toFileString();
   File file = new File(filePath);
   return file.exists();
 }
Esempio n. 6
0
 @Override
 public void delete(URI uri, Map<?, ?> options) throws IOException {
   String filePath = uri.toFileString();
   File file = new File(filePath);
   file.delete();
 }