コード例 #1
0
  @Override
  public synchronized boolean delete(SyndicateFSPath path)
      throws FileNotFoundException, IOException {
    if (path == null) {
      LOG.error("path is null");
      throw new IllegalArgumentException("path is null");
    }

    SyndicateFSPath absPath = getAbsolutePath(path);
    SyndicateFSFileStatus status = getFileStatus(absPath);
    if (status == null) {
      LOG.error("file not exist");
      throw new FileNotFoundException("file not exist : " + path.getPath());
    }

    if (status.isFile()) {
      Future<ClientResponse> unlinkFuture = this.client.unlink(absPath.getPath());
      if (unlinkFuture != null) {
        try {
          this.client.processUnlink(unlinkFuture);
        } catch (RestfulException ex) {
          LOG.error("exception occurred", ex);
          throw new IOException(ex);
        }
      } else {
        throw new IOException("Can not create a REST client");
      }
    } else if (status.isDirectory()) {
      Future<ClientResponse> removeDirFuture = this.client.removeDir(absPath.getPath());
      if (removeDirFuture != null) {
        try {
          this.client.processRemoveDir(removeDirFuture);
        } catch (RestfulException ex) {
          LOG.error("exception occurred", ex);
          throw new IOException(ex);
        }
      } else {
        throw new IOException("Can not create a REST client");
      }
    } else {
      LOG.error("Can not delete from unknown status");
      throw new IOException("Can not delete from unknown status");
    }

    this.filestatusCache.remove(absPath);
    return true;
  }
コード例 #2
0
  @Override
  public synchronized boolean isFile(SyndicateFSPath path) {
    if (path == null) {
      LOG.error("path is null");
      throw new IllegalArgumentException("path is null");
    }

    SyndicateFSPath absPath = getAbsolutePath(path);
    SyndicateFSFileStatus status = null;
    try {
      status = getFileStatus(absPath);
    } catch (IOException ex) {
      LOG.error("exception occurred", ex);
    }

    if (status != null) {
      return status.isFile();
    }
    return false;
  }
コード例 #3
0
  @Override
  public SyndicateFSOutputStream getFileOutputStream(SyndicateFSPath path) throws IOException {
    if (path == null) {
      LOG.error("path is null");
      throw new IllegalArgumentException("path is null");
    }

    SyndicateFSPath absPath = getAbsolutePath(path);
    SyndicateFSFileStatus status = getFileStatus(absPath);

    if (status != null) {
      if (!status.isFile()) {
        LOG.error("Can not open the file to write (is directory) : " + absPath.getPath());
        throw new IOException(
            "Can not open the file to write (is directory) : " + absPath.getPath());
      }

      SyndicateFSFileHandle handle = getFileHandle(status, false);
      if (handle == null) {
        LOG.error("Can not open the file to write : " + absPath.getPath());
        throw new IOException("Can not open the file to write : " + absPath.getPath());
      }

      SyndicateFSOutputStream os = new SyndicateFSOutputStream(handle);
      this.openOutputStream.add(os);
      return os;
    } else {
      // create new file
      SyndicateFSFileHandle handle = createNewFile(absPath);
      if (handle == null) {
        LOG.error("Can not create a file to write : " + absPath.getPath());
        throw new IOException("Can not create a file to write : " + absPath.getPath());
      }

      SyndicateFSOutputStream os = new SyndicateFSOutputStream(handle);
      this.openOutputStream.add(os);
      return os;
    }
  }