List of usage examples for org.apache.commons.vfs FileSystemException FileSystemException
public FileSystemException(final String code, final Throwable throwable)
From source file:com.thinkberg.vfs.s3.jets3t.Jets3tFileSystem.java
public void destroyFileSystem() throws FileSystemException { try {/*from ww w . ja va 2s . c o m*/ service.deleteBucket(bucket); } catch (S3ServiceException e) { throw new FileSystemException("can't delete file system root", e); } }
From source file:com.thinkberg.vfs.s3.S3FileProvider.java
/** * Create a file system with the S3 root provided. * * @param fileName the S3 file name that defines the root (bucket) * @param fileSystemOptions file system options * @return an S3 file system//www. ja v a2 s . c o m * @throws FileSystemException if te file system cannot be created */ protected FileSystem doCreateFileSystem(FileName fileName, FileSystemOptions fileSystemOptions) throws FileSystemException { LOG.debug(String.format("creating new file system '%s'", fileName)); if (null == service) { LOG.debug("creating new S3 service"); UserAuthenticationData authenticationInfo = UserAuthenticatorUtils.authenticate(fileSystemOptions, AUTHENTICATOR_TYPES); String accessKey = UserAuthenticatorUtils.toString( UserAuthenticatorUtils.getData(authenticationInfo, UserAuthenticationData.USERNAME, null)); String secretKey = UserAuthenticatorUtils.toString( UserAuthenticatorUtils.getData(authenticationInfo, UserAuthenticationData.PASSWORD, null)); try { service = new RestS3Service(new AWSCredentials(accessKey, secretKey)); } catch (S3ServiceException e) { throw new FileSystemException("Amazon S3 service initialization failed", e); } finally { authenticationInfo.cleanup(); } } return new Jets3tFileSystem(service, (S3FileName) fileName, fileSystemOptions); }
From source file:com.newatlanta.appengine.vfs.provider.GaeFileContent.java
public long getSize() throws FileSystemException { if (!fileObject.getType().hasContent()) { throw new FileSystemException("vfs.provider/get-size-not-file.error", fileObject); }//w w w .j a v a2s . c o m return fileObject.doGetContentSize(); }
From source file:com.newatlanta.appengine.vfs.provider.GaeFileObject.java
@SuppressWarnings("unchecked") private List<Key> getChildKeys() throws FileSystemException { if (!getType().hasChildren()) { throw new FileSystemException("vfs.provider/list-children-not-folder.error", getName()); }//from w w w . ja v a2 s. c o m return (List<Key>) metadata.getProperty(CHILD_KEYS); }
From source file:com.thinkberg.vfs.s3.jets3t.Jets3tFileObject.java
protected void doRename(FileObject targetFileObject) throws Exception { String bucketId = bucket.getName(); S3Object targetObject = ((Jets3tFileObject) targetFileObject).object; LOG.debug(String.format("move object '%s' to '%s'", getS3Key(), targetObject.getKey())); // if this is a folder, then rename all children of the current folder too if (FileType.FOLDER.equals(getType())) { String path = object.getKey(); // make sure we add a '/' slash at the end to find children if (!"".equals(path)) { path = path + "/"; }//w ww. ja v a 2 s. com try { S3Object[] children = service.listObjects(bucket, path, null); String targetName = targetObject.getKey(); for (S3Object child : children) { String targetChildName = child.getKey(); targetChildName = targetName + targetChildName.substring(object.getKey().length()); service.renameObject(bucketId, child.getKey(), new S3Object(bucket, targetChildName)); } } catch (S3ServiceException e) { throw new FileSystemException(String.format("can't move children of '%s' to '%s'", object.getKey(), targetObject.getKey()), e); } } try { service.renameObject(bucket.getName(), object.getKey(), ((Jets3tFileObject) targetFileObject).object); } catch (S3ServiceException e) { throw new FileSystemException("can't rename object", e); } }
From source file:com.thinkberg.vfs.s3.jets3t.Jets3tFileObject.java
protected String[] doListChildren() throws FileSystemException { String path = object.getKey(); // make sure we add a '/' slash at the end to find children if (!"".equals(path)) { path = path + "/"; }// w w w. java 2 s . c o m try { S3Object[] children = service.listObjects(bucket, path, "/"); String[] childrenNames = new String[children.length]; for (int i = 0; i < children.length; i++) { if (!children[i].getKey().equals(path)) { // strip path from name (leave only base name) childrenNames[i] = children[i].getKey().replaceAll("[^/]*//*", ""); } } return childrenNames; } catch (S3ServiceException e) { throw new FileSystemException(String.format("can't list children of '%s'", path), e); } }
From source file:com.newatlanta.appengine.vfs.provider.GaeFileObject.java
/** * Returns the size of the file content (in bytes). *//*from w w w. j ava 2s . c o m*/ @Override public long doGetContentSize() throws FileSystemException { if (exists() && !getType().hasContent()) { throw new FileSystemException("vfs.provider/get-size-not-file.error", getName()); } Long contentSize = (Long) metadata.getProperty(CONTENT_SIZE); return (contentSize != null ? contentSize.longValue() : 0); }
From source file:com.newatlanta.appengine.vfs.provider.GaeFileObject.java
@Override protected InputStream doGetInputStream() throws IOException { if (!getType().hasContent()) { throw new FileSystemException("vfs.provider/read-not-file.error", getName()); }/* w ww. ja v a 2 s . c o m*/ return new GaeRandomAccessContent(this, RandomAccessMode.READ, false).getInputStream(); }
From source file:org.docx4all.util.AuthenticationUtil.java
public final static int getAuthorisationStatus(WebdavFileObject fo) throws FileSystemException { int status = 401; //unauthorised and retry. org.apache.webdav.lib.methods.OptionsMethod optionsMethod = null; try {//from w w w . j a va 2 s .co m String urlCharset = WebdavFileSystemConfigBuilder.getInstance() .getUrlCharset(fo.getFileSystem().getFileSystemOptions()); URLFileName urlFileName = (URLFileName) fo.getName(); optionsMethod = new org.apache.webdav.lib.methods.OptionsMethod( urlFileName.getPathQueryEncoded(urlCharset)); optionsMethod.setMethodRetryHandler(WebdavMethodRetryHandler.getInstance()); optionsMethod.setFollowRedirects(true); char[] username = null; if (urlFileName.getUserName() != null) { username = urlFileName.getUserName().toCharArray(); } char[] password = null; if (urlFileName.getPassword() != null) { password = urlFileName.getPassword().toCharArray(); } WebdavClientFactory factory = new WebdavClientFactory(); HttpClient client = factory.createConnection(urlFileName.getHostName(), urlFileName.getPort(), username, password, fo.getFileSystem().getFileSystemOptions()); status = client.executeMethod(optionsMethod); } catch (Exception exc) { throw new FileSystemException("Cannot get authorisation status", exc); } finally { if (optionsMethod != null) { optionsMethod.releaseConnection(); } } return status; }
From source file:org.efaps.webdav4vfs.test.ramvfs.RamFileObject.java
@Override() protected InputStream doGetInputStream() throws Exception { // VFS-210: ram allows to gather an input stream even from a directory. So we need to check the type anyway. if (!getType().hasContent()) { throw new FileSystemException("vfs.provider/read-not-file.error", getName()); }/*from w w w . j av a 2s .c o m*/ return new ByteArrayInputStream(this.data.getBuffer()); }