org.apache.commons.vfs2.FileNotFoundException Java Examples

The following examples show how to use org.apache.commons.vfs2.FileNotFoundException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Http5FileObject.java    From commons-vfs with Apache License 2.0 6 votes vote down vote up
@Override
protected InputStream doGetInputStream(final int bufferSize) throws Exception {
    final HttpGet getRequest = new HttpGet(getInternalURI());
    final ClassicHttpResponse httpResponse = executeHttpUriRequest(getRequest);
    final int status = httpResponse.getCode();

    if (status == HttpStatus.SC_NOT_FOUND) {
        throw new FileNotFoundException(getName());
    }

    if (status != HttpStatus.SC_OK) {
        throw new FileSystemException("vfs.provider.http/get.error", getName(), Integer.valueOf(status));
    }

    return new MonitoredHttpResponseContentInputStream(httpResponse, bufferSize);
}
 
Example #2
Source File: Http4FileObject.java    From commons-vfs with Apache License 2.0 6 votes vote down vote up
@Override
protected InputStream doGetInputStream(final int bufferSize) throws Exception {
    final HttpGet getRequest = new HttpGet(getInternalURI());
    final HttpResponse httpResponse = executeHttpUriRequest(getRequest);
    final int status = httpResponse.getStatusLine().getStatusCode();

    if (status == HttpStatus.SC_NOT_FOUND) {
        throw new FileNotFoundException(getName());
    }

    if (status != HttpStatus.SC_OK) {
        throw new FileSystemException("vfs.provider.http/get.error", getName(), Integer.valueOf(status));
    }

    return new MonitoredHttpResponseContentInputStream(httpResponse, bufferSize);
}
 
Example #3
Source File: FTPRemoteFile.java    From datacollector with Apache License 2.0 5 votes vote down vote up
@Override
public boolean isReadable() throws IOException {
  try (InputStream ignored = createInputStream()){
    LOG.trace("File is readable");
    return true;
  } catch (IOException e) {
    LOG.error("Error reading file", e);
    if (e instanceof FileNotFoundException) {
      // File is not found because its either deleted or don't have permissions
      return false;
    }
   throw e;
  }
}
 
Example #4
Source File: WebdavFileObject.java    From commons-vfs with Apache License 2.0 5 votes vote down vote up
private boolean isDirectory(final URLFileName name) throws IOException {
    try {
        final DavProperty property = getProperty(name, DavConstants.PROPERTY_RESOURCETYPE);
        Node node;
        if (property != null && (node = (Node) property.getValue()) != null) {
            return node.getLocalName().equals(DavConstants.XML_COLLECTION);
        }
        return false;
    } catch (final FileNotFoundException fse) {
        throw new FileNotFolderException(name);
    }
}
 
Example #5
Source File: HttpFileObject.java    From commons-vfs with Apache License 2.0 5 votes vote down vote up
/**
 * Creates an input stream to read the file content from. Is only called if {@link #doGetType} returns
 * {@link FileType#FILE}.
 * <p>
 * It is guaranteed that there are no open output streams for this file when this method is called.
 * </p>
 * <p>
 * The returned stream does not have to be buffered.
 * </p>
 */
@Override
protected InputStream doGetInputStream(final int bufferSize) throws Exception {
    final GetMethod getMethod = new GetMethod();
    setupMethod(getMethod);
    final int status = getAbstractFileSystem().getClient().executeMethod(getMethod);
    if (status == HttpURLConnection.HTTP_NOT_FOUND) {
        throw new FileNotFoundException(getName());
    }
    if (status != HttpURLConnection.HTTP_OK) {
        throw new FileSystemException("vfs.provider.http/get.error", getName(), Integer.valueOf(status));
    }

    return new HttpInputStream(getMethod, bufferSize);
}
 
Example #6
Source File: Webdav4FileObject.java    From commons-vfs with Apache License 2.0 5 votes vote down vote up
private boolean isDirectory(final GenericURLFileName name) throws IOException {
    try {
        final DavProperty property = getProperty(name, DavConstants.PROPERTY_RESOURCETYPE);
        Node node;
        if (property != null && (node = (Node) property.getValue()) != null) {
            return node.getLocalName().equals(DavConstants.XML_COLLECTION);
        }
        return false;
    } catch (final FileNotFoundException fse) {
        throw new FileNotFolderException(name);
    }
}
 
Example #7
Source File: SftpFileObject.java    From commons-vfs with Apache License 2.0 4 votes vote down vote up
/**
 * Creates an input stream to read the file content from.
 */
@SuppressWarnings("resource")
@Override
protected InputStream doGetInputStream(final int bufferSize) throws Exception {
    // VFS-113: avoid npe
    synchronized (getAbstractFileSystem()) {
        final ChannelSftp channel = getAbstractFileSystem().getChannel();
        try {
            // return channel.get(getName().getPath());
            // hmmm - using the in memory method is soooo much faster ...

            // TODO - Don't read the entire file into memory. Use the
            // stream-based methods on ChannelSftp once they work properly

            /*
             * final ByteArrayOutputStream outstr = new ByteArrayOutputStream(); channel.get(relPath, outstr);
             * outstr.close(); return new ByteArrayInputStream(outstr.toByteArray());
             */

            InputStream inputStream;
            try {
                // VFS-210: sftp allows to gather an input stream even from a directory and will
                // fail on first read. So we need to check the type anyway
                if (!getType().hasContent()) {
                    throw new FileSystemException("vfs.provider/read-not-file.error", getName());
                }

                inputStream = channel.get(relPath);
            } catch (final SftpException e) {
                if (e.id == ChannelSftp.SSH_FX_NO_SUCH_FILE) {
                    throw new FileNotFoundException(getName());
                }

                throw new FileSystemException(e);
            }

            return new SftpInputStream(channel, inputStream, bufferSize);

        } finally {
            // getAbstractFileSystem().putChannel(channel);
        }
    }
}