Search in sources :

Example 1 with BufferedFSInputStream

use of org.apache.hadoop.fs.BufferedFSInputStream in project hadoop by apache.

the class NativeAzureFileSystem method open.

@Override
public FSDataInputStream open(Path f, int bufferSize) throws FileNotFoundException, IOException {
    LOG.debug("Opening file: {}", f.toString());
    Path absolutePath = makeAbsolute(f);
    performAuthCheck(absolutePath.toString(), WasbAuthorizationOperations.READ.toString(), "read");
    String key = pathToKey(absolutePath);
    FileMetadata meta = null;
    try {
        meta = store.retrieveMetadata(key);
    } catch (Exception ex) {
        Throwable innerException = NativeAzureFileSystemHelper.checkForAzureStorageException(ex);
        if (innerException instanceof StorageException && NativeAzureFileSystemHelper.isFileNotFoundException((StorageException) innerException)) {
            throw new FileNotFoundException(String.format("%s is not found", key));
        }
        throw ex;
    }
    if (meta == null) {
        throw new FileNotFoundException(f.toString());
    }
    if (meta.isDir()) {
        throw new FileNotFoundException(f.toString() + " is a directory not a file.");
    }
    DataInputStream inputStream = null;
    try {
        inputStream = store.retrieve(key);
    } catch (Exception ex) {
        Throwable innerException = NativeAzureFileSystemHelper.checkForAzureStorageException(ex);
        if (innerException instanceof StorageException && NativeAzureFileSystemHelper.isFileNotFoundException((StorageException) innerException)) {
            throw new FileNotFoundException(String.format("%s is not found", key));
        }
        throw ex;
    }
    return new FSDataInputStream(new BufferedFSInputStream(new NativeAzureFsInputStream(inputStream, key, meta.getLength()), bufferSize));
}
Also used : Path(org.apache.hadoop.fs.Path) BufferedFSInputStream(org.apache.hadoop.fs.BufferedFSInputStream) FileNotFoundException(java.io.FileNotFoundException) FSDataInputStream(org.apache.hadoop.fs.FSDataInputStream) FSDataInputStream(org.apache.hadoop.fs.FSDataInputStream) DataInputStream(java.io.DataInputStream) StorageException(com.microsoft.azure.storage.StorageException) URISyntaxException(java.net.URISyntaxException) JsonParseException(com.fasterxml.jackson.core.JsonParseException) EOFException(java.io.EOFException) FileNotFoundException(java.io.FileNotFoundException) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) StorageException(com.microsoft.azure.storage.StorageException) FileAlreadyExistsException(org.apache.hadoop.fs.FileAlreadyExistsException) IOException(java.io.IOException)

Example 2 with BufferedFSInputStream

use of org.apache.hadoop.fs.BufferedFSInputStream in project hadoop by apache.

the class NativeS3FileSystem method open.

@Override
public FSDataInputStream open(Path f, int bufferSize) throws IOException {
    // will throw if the file doesn't exist
    FileStatus fs = getFileStatus(f);
    if (fs.isDirectory()) {
        throw new FileNotFoundException("'" + f + "' is a directory");
    }
    LOG.info("Opening '" + f + "' for reading");
    Path absolutePath = makeAbsolute(f);
    String key = pathToKey(absolutePath);
    return new FSDataInputStream(new BufferedFSInputStream(new NativeS3FsInputStream(store, statistics, store.retrieve(key), key), bufferSize));
}
Also used : Path(org.apache.hadoop.fs.Path) BufferedFSInputStream(org.apache.hadoop.fs.BufferedFSInputStream) FileStatus(org.apache.hadoop.fs.FileStatus) FileNotFoundException(java.io.FileNotFoundException) FSDataInputStream(org.apache.hadoop.fs.FSDataInputStream)

Aggregations

FileNotFoundException (java.io.FileNotFoundException)2 BufferedFSInputStream (org.apache.hadoop.fs.BufferedFSInputStream)2 FSDataInputStream (org.apache.hadoop.fs.FSDataInputStream)2 Path (org.apache.hadoop.fs.Path)2 JsonParseException (com.fasterxml.jackson.core.JsonParseException)1 JsonMappingException (com.fasterxml.jackson.databind.JsonMappingException)1 StorageException (com.microsoft.azure.storage.StorageException)1 DataInputStream (java.io.DataInputStream)1 EOFException (java.io.EOFException)1 IOException (java.io.IOException)1 URISyntaxException (java.net.URISyntaxException)1 FileAlreadyExistsException (org.apache.hadoop.fs.FileAlreadyExistsException)1 FileStatus (org.apache.hadoop.fs.FileStatus)1