protected S3Root(FileURL url, S3Service service) { super(url, service); atts = new SimpleFileAttributes(); atts.setPath("/"); atts.setExists(true); atts.setDate(0); atts.setSize(0); atts.setDirectory(true); atts.setPermissions(DEFAULT_PERMISSIONS); atts.setOwner(null); atts.setGroup(null); }
@Override public long getDate() { checkResolveFile(); return attributes.getDate(); }
@Override public FilePermissions getPermissions() { return attributes.getPermissions(); }
private static SimpleFileAttributes getDefaultAttributes() { SimpleFileAttributes attributes = new SimpleFileAttributes(); attributes.setDate(System.currentTimeMillis()); attributes.setSize(-1); // Unknown attributes.setPermissions(PERMISSIONS); // exist = false // isDirectory = false // path = null (unused) return attributes; }
/** * Creates a SimpleFileAttributes instance with the no-arg constructor and ensures that the default values returned * by SimpleFileAttributes' getters are as specified by {@link FileAttributes}. */ @Test public void testDefaultValues() { SimpleFileAttributes attrs = new SimpleFileAttributes(); assert attrs.getPath() == null; assert !attrs.exists(); assert 0 == attrs.getDate(); assert 0 == attrs.getSize(); assert !attrs.isDirectory(); assert attrs.getPermissions() == null; assert attrs.getOwner() == null; assert attrs.getGroup() == null; } }
date = System.currentTimeMillis(); attributes.setDate(date); attributes.setSize(conn.getContentLength()); attributes.setDirectory(true); attributes.setExists(true);
@Override public boolean exists() { if(!fileResolved) { // Note: file will only be resolved once, even if the request failed try { resolveFile(); } catch(IOException e) {} } return attributes.exists(); }
/** * Overridden to trigger attributes update if the expiration date has been reached. */ @Override public long getSize() { checkForExpiration(false); return super.getSize(); }
@Override public boolean isDirectory() { checkResolveFile(); return attributes.isDirectory(); }
/** * Overridden to trigger attributes update if the expiration date has been reached. */ @Override public String getOwner() { checkForExpiration(false); return super.getOwner(); }
/** * Overridden to trigger attributes update if the expiration date has been reached. */ @Override public String getPath() { checkForExpiration(false); return super.getPath(); }
/** * Overridden to trigger attributes update if the expiration date has been reached. */ @Override public String getGroup() { checkForExpiration(false); return super.getGroup(); }
/** * Creates a SimpleFileAttributes instance from an AbstractFile and ensures that the values returned by * SimpleFileAttributes' getters match those of AbstractFile. * * @throws IOException should not happen */ @Test public void testAccessors() throws IOException { LocalFileTest lft = new LocalFileTest(); // File doesn't exist AbstractFile tempFile = lft.getTemporaryFile(); assertAttributesMatch(tempFile, new SimpleFileAttributes(tempFile)); // File exists as a regular file tempFile.mkfile(); assertAttributesMatch(tempFile, new SimpleFileAttributes(tempFile)); // File exists as a directory tempFile.delete(); tempFile.mkdir(); assertAttributesMatch(tempFile, new SimpleFileAttributes(tempFile)); }
/** * Asserts that the attributes of the given AbstractFile and SimpleFileAttributes match. */ private void assertAttributesMatch(AbstractFile file, SimpleFileAttributes attrs) { assert file.getAbsolutePath().equals(attrs.getPath()); assert file.exists() == attrs.exists(); assert file.getDate() == attrs.getDate(); assert file.getSize() == attrs.getSize(); assert file.isDirectory() == attrs.isDirectory(); assert file.getPermissions() == attrs.getPermissions(); assert file.getOwner() == null ? attrs.getOwner() == null : file.getOwner().equals(attrs.getOwner()); assert file.getGroup() == null ? attrs.getGroup() == null : file.getGroup().equals(attrs.getGroup()); }
/** * Overridden to trigger attributes update if the expiration date has been reached. */ @Override public boolean exists() { checkForExpiration(false); return super.exists(); }
@Override public long getSize() { checkResolveFile(); return attributes.getSize(); // Size == -1 if not known }
/** * Overridden to trigger attributes update if the expiration date has been reached. */ @Override public boolean isDirectory() { checkForExpiration(false); return super.isDirectory(); }
/** * Creates a new SimpleFileAttributes instance whose attributes are set to those of the given AbstractFile. * Note that the path attribute is set to the file's {@link com.mucommander.commons.file.AbstractFile#getAbsolutePath() absolute path}. * * @param file the file from which to fetch the attribute values */ public SimpleFileAttributes(AbstractFile file) { setPath(file.getAbsolutePath()); setExists(file.exists()); setDate(file.getDate()); setSize(file.getSize()); setDirectory(file.isDirectory()); setPermissions(file.getPermissions()); setOwner(file.getOwner()); setGroup(file.getGroup()); }
/** * Overridden to trigger attributes update if the expiration date has been reached. */ @Override public FilePermissions getPermissions() { checkForExpiration(false); return super.getPermissions(); }
/** * Overridden to trigger attributes update if the expiration date has been reached. */ @Override public long getDate() { checkForExpiration(false); return super.getDate(); }