Java Code Examples for org.jets3t.service.model.S3Object#getDataInputStream()

The following examples show how to use org.jets3t.service.model.S3Object#getDataInputStream() . 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: Jets3tNativeFileSystemStore.java    From hadoop with Apache License 2.0 6 votes vote down vote up
/**
 *
 * @param key
 * The key is the object name that is being retrieved from the S3 bucket
 * @return
 * This method returns null if the key is not found
 * @throws IOException
 */

@Override
public InputStream retrieve(String key, long byteRangeStart)
        throws IOException {
  try {
    LOG.debug("Getting key: {} from bucket: {} with byteRangeStart: {}",
        key, bucket.getName(), byteRangeStart);
    S3Object object = s3Service.getObject(bucket, key, null, null, null,
                                          null, byteRangeStart, null);
    return object.getDataInputStream();
  } catch (ServiceException e) {
    handleException(e, key);
    return null;
  }
}
 
Example 2
Source File: Jets3tNativeFileSystemStore.java    From big-c with Apache License 2.0 6 votes vote down vote up
/**
 *
 * @param key
 * The key is the object name that is being retrieved from the S3 bucket
 * @return
 * This method returns null if the key is not found
 * @throws IOException
 */

@Override
public InputStream retrieve(String key, long byteRangeStart)
        throws IOException {
  try {
    LOG.debug("Getting key: {} from bucket: {} with byteRangeStart: {}",
        key, bucket.getName(), byteRangeStart);
    S3Object object = s3Service.getObject(bucket, key, null, null, null,
                                          null, byteRangeStart, null);
    return object.getDataInputStream();
  } catch (ServiceException e) {
    handleException(e, key);
    return null;
  }
}
 
Example 3
Source File: Jets3tFileSystemStore.java    From hadoop-gpu with Apache License 2.0 6 votes vote down vote up
private InputStream get(String key, boolean checkMetadata)
    throws IOException {
  
  try {
    S3Object object = s3Service.getObject(bucket, key);
    if (checkMetadata) {
      checkMetadata(object);
    }
    return object.getDataInputStream();
  } catch (S3ServiceException e) {
    if ("NoSuchKey".equals(e.getS3ErrorCode())) {
      return null;
    }
    if (e.getCause() instanceof IOException) {
      throw (IOException) e.getCause();
    }
    throw new S3Exception(e);
  }
}
 
Example 4
Source File: AmazonConnection.java    From Doradus with Apache License 2.0 6 votes vote down vote up
public byte[] get(String path) {
    try {
        S3Object obj = m_s3service.getObject(BUCKET, path);
        m_logger.trace("GetObject: {}", path);
        inc();
        if(obj == null) return null;
        int len = (int)obj.getContentLength();
        byte[] data = new byte[len];
        int start = 0;
        InputStream is = obj.getDataInputStream();
        while(start < len) {
            start += is.read(data, start, len - start);
        }
        is.close();
        return data;
    } catch (Exception e) {
        return null;
    }
}
 
Example 5
Source File: Jets3tNativeFileSystemStore.java    From hadoop-gpu with Apache License 2.0 6 votes vote down vote up
public InputStream retrieve(String key, long byteRangeStart)
  throws IOException {
  try {
    S3Object object = s3Service.getObject(bucket, key, null, null, null,
                                          null, byteRangeStart, null);
    return object.getDataInputStream();
  } catch (S3ServiceException e) {
    if ("NoSuchKey".equals(e.getS3ErrorCode())) {
      return null;
    }
    if (e.getCause() instanceof IOException) {
      throw (IOException) e.getCause();
    }
    throw new S3Exception(e);
  }
}
 
Example 6
Source File: Jets3tNativeFileSystemStore.java    From RDFS with Apache License 2.0 6 votes vote down vote up
public InputStream retrieve(String key, long byteRangeStart)
  throws IOException {
  try {
    S3Object object = s3Service.getObject(bucket, key, null, null, null,
                                          null, byteRangeStart, null);
    return object.getDataInputStream();
  } catch (S3ServiceException e) {
    if ("NoSuchKey".equals(e.getS3ErrorCode())) {
      return null;
    }
    if (e.getCause() instanceof IOException) {
      throw (IOException) e.getCause();
    }
    throw new S3Exception(e);
  }
}
 
Example 7
Source File: Jets3tFileSystemStore.java    From RDFS with Apache License 2.0 6 votes vote down vote up
private InputStream get(String key, boolean checkMetadata)
    throws IOException {
  
  try {
    S3Object object = s3Service.getObject(bucket, key);
    if (checkMetadata) {
      checkMetadata(object);
    }
    return object.getDataInputStream();
  } catch (S3ServiceException e) {
    if ("NoSuchKey".equals(e.getS3ErrorCode())) {
      return null;
    }
    if (e.getCause() instanceof IOException) {
      throw (IOException) e.getCause();
    }
    throw new S3Exception(e);
  }
}
 
Example 8
Source File: MigrationTool.java    From hadoop-gpu with Apache License 2.0 5 votes vote down vote up
private InputStream get(String key) throws IOException {
  try {
    S3Object object = s3Service.getObject(bucket, key);
    return object.getDataInputStream();
  } catch (S3ServiceException e) {
    if ("NoSuchKey".equals(e.getS3ErrorCode())) {
      return null;
    }
    if (e.getCause() instanceof IOException) {
      throw (IOException) e.getCause();
    }
    throw new S3Exception(e);
  }
}
 
Example 9
Source File: S3ReadFeature.java    From cyberduck with GNU General Public License v3.0 5 votes vote down vote up
@Override
public InputStream read(final Path file, final TransferStatus status, final ConnectionCallback callback) throws BackgroundException {
    try {
        if(file.getType().contains(Path.Type.upload)) {
            return new NullInputStream(0L);
        }
        final HttpRange range = HttpRange.withStatus(status);
        final RequestEntityRestStorageService client = session.getClient();
        final S3Object object = client.getVersionedObject(
            file.attributes().getVersionId(),
            containerService.getContainer(file).getName(),
            containerService.getKey(file),
            null, // ifModifiedSince
            null, // ifUnmodifiedSince
            null, // ifMatch
            null, // ifNoneMatch
            status.isAppend() ? range.getStart() : null,
            status.isAppend() ? (range.getEnd() == -1 ? null : range.getEnd()) : null);
        if(log.isDebugEnabled()) {
            log.debug(String.format("Reading stream with content length %d", object.getContentLength()));
        }
        return object.getDataInputStream();
    }
    catch(ServiceException e) {
        throw new S3ExceptionMappingService().map("Download {0} failed", e, file);
    }
}
 
Example 10
Source File: Jets3tFileSystemStore.java    From hadoop-gpu with Apache License 2.0 5 votes vote down vote up
private InputStream get(String key, long byteRangeStart) throws IOException {
  try {
    S3Object object = s3Service.getObject(bucket, key, null, null, null,
                                          null, byteRangeStart, null);
    return object.getDataInputStream();
  } catch (S3ServiceException e) {
    if ("NoSuchKey".equals(e.getS3ErrorCode())) {
      return null;
    }
    if (e.getCause() instanceof IOException) {
      throw (IOException) e.getCause();
    }
    throw new S3Exception(e);
  }
}
 
Example 11
Source File: Jets3tNativeFileSystemStore.java    From hadoop-gpu with Apache License 2.0 5 votes vote down vote up
public InputStream retrieve(String key) throws IOException {
  try {
    S3Object object = s3Service.getObject(bucket, key);
    return object.getDataInputStream();
  } catch (S3ServiceException e) {
    if ("NoSuchKey".equals(e.getS3ErrorCode())) {
      return null;
    }
    if (e.getCause() instanceof IOException) {
      throw (IOException) e.getCause();
    }
    throw new S3Exception(e);
  }
}
 
Example 12
Source File: MigrationTool.java    From RDFS with Apache License 2.0 5 votes vote down vote up
private InputStream get(String key) throws IOException {
  try {
    S3Object object = s3Service.getObject(bucket, key);
    return object.getDataInputStream();
  } catch (S3ServiceException e) {
    if ("NoSuchKey".equals(e.getS3ErrorCode())) {
      return null;
    }
    if (e.getCause() instanceof IOException) {
      throw (IOException) e.getCause();
    }
    throw new S3Exception(e);
  }
}
 
Example 13
Source File: Jets3tFileSystemStore.java    From RDFS with Apache License 2.0 5 votes vote down vote up
private InputStream get(String key, long byteRangeStart) throws IOException {
  try {
    S3Object object = s3Service.getObject(bucket, key, null, null, null,
                                          null, byteRangeStart, null);
    return object.getDataInputStream();
  } catch (S3ServiceException e) {
    if ("NoSuchKey".equals(e.getS3ErrorCode())) {
      return null;
    }
    if (e.getCause() instanceof IOException) {
      throw (IOException) e.getCause();
    }
    throw new S3Exception(e);
  }
}
 
Example 14
Source File: Jets3tNativeFileSystemStore.java    From RDFS with Apache License 2.0 5 votes vote down vote up
public InputStream retrieve(String key) throws IOException {
  try {
    S3Object object = s3Service.getObject(bucket, key);
    return object.getDataInputStream();
  } catch (S3ServiceException e) {
    if ("NoSuchKey".equals(e.getS3ErrorCode())) {
      return null;
    }
    if (e.getCause() instanceof IOException) {
      throw (IOException) e.getCause();
    }
    throw new S3Exception(e);
  }
}
 
Example 15
Source File: AmazonFileStorageService.java    From computoser with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public InputStream getFile(String path) throws IOException {
    try {
        path = stripLeadingSlash(path);
        S3Object object = service.getObject(bucketName, path);
        return object.getDataInputStream();
    } catch (ServiceException e) {
        throw new IOException(e);
    }
}
 
Example 16
Source File: Jets3tNativeFileSystemStore.java    From big-c with Apache License 2.0 5 votes vote down vote up
/**
 * @param key
 * The key is the object name that is being retrieved from the S3 bucket
 * @return
 * This method returns null if the key is not found
 * @throws IOException
 */

@Override
public InputStream retrieve(String key) throws IOException {
  try {
    LOG.debug("Getting key: {} from bucket: {}",
        key, bucket.getName());
    S3Object object = s3Service.getObject(bucket.getName(), key);
    return object.getDataInputStream();
  } catch (ServiceException e) {
    handleException(e, key);
    return null; //return null if key not found
  }
}
 
Example 17
Source File: Jets3tNativeFileSystemStore.java    From hadoop with Apache License 2.0 5 votes vote down vote up
/**
 * @param key
 * The key is the object name that is being retrieved from the S3 bucket
 * @return
 * This method returns null if the key is not found
 * @throws IOException
 */

@Override
public InputStream retrieve(String key) throws IOException {
  try {
    LOG.debug("Getting key: {} from bucket: {}",
        key, bucket.getName());
    S3Object object = s3Service.getObject(bucket.getName(), key);
    return object.getDataInputStream();
  } catch (ServiceException e) {
    handleException(e, key);
    return null; //return null if key not found
  }
}
 
Example 18
Source File: JetS3tLiveTest.java    From tutorials with MIT License 4 votes vote down vote up
@Test
public void givenStreamDataUploaded_StreamDataIsDownloaded() throws Exception {

    // get a bucket
    S3Bucket bucket = createBucket();
    assertNotNull(bucket);

    ArrayList<Integer> numbers = new ArrayList<>();
    numbers.add(2);
    numbers.add(3);
    numbers.add(5);
    numbers.add(7);

    // Serialize ArrayList
    ByteArrayOutputStream bytes = new ByteArrayOutputStream();
    ObjectOutputStream objectOutputStream = new ObjectOutputStream(bytes);
    objectOutputStream.writeObject(numbers);

    // Wrap bytes
    ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(bytes.toByteArray());

    // Create and populate object
    S3Object streamObject = new S3Object("stream");
    streamObject.setDataInputStream(byteArrayInputStream);
    streamObject.setContentLength(byteArrayInputStream.available());
    streamObject.setContentType("binary/octet-stream");

    // Put it
    s3Service.putObject(BucketName, streamObject);

    // Get it
    S3Object newStreamObject = s3Service.getObject(BucketName, "stream");

    // Convert back to ArrayList
    ObjectInputStream objectInputStream = new ObjectInputStream(newStreamObject.getDataInputStream());
    ArrayList<Integer> newNumbers = (ArrayList<Integer>)objectInputStream.readObject();

    assertEquals(2, (int)newNumbers.get(0));
    assertEquals(3, (int)newNumbers.get(1));
    assertEquals(5, (int)newNumbers.get(2));
    assertEquals(7, (int)newNumbers.get(3));

    // Clean up
    deleteObject("stream");
    deleteBucket();
}
 
Example 19
Source File: JetS3tLiveTest.java    From tutorials with MIT License 4 votes vote down vote up
@Test
public void givenStreamDataUploaded_StreamDataIsDownloaded() throws Exception {

    // get a bucket
    S3Bucket bucket = createBucket();
    assertNotNull(bucket);

    ArrayList<Integer> numbers = new ArrayList<>();
    numbers.add(2);
    numbers.add(3);
    numbers.add(5);
    numbers.add(7);

    // Serialize ArrayList
    ByteArrayOutputStream bytes = new ByteArrayOutputStream();
    ObjectOutputStream objectOutputStream = new ObjectOutputStream(bytes);
    objectOutputStream.writeObject(numbers);

    // Wrap bytes
    ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(bytes.toByteArray());

    // Create and populate object
    S3Object streamObject = new S3Object("stream");
    streamObject.setDataInputStream(byteArrayInputStream);
    streamObject.setContentLength(byteArrayInputStream.available());
    streamObject.setContentType("binary/octet-stream");

    // Put it
    s3Service.putObject(BucketName, streamObject);

    // Get it
    S3Object newStreamObject = s3Service.getObject(BucketName, "stream");

    // Convert back to ArrayList
    ObjectInputStream objectInputStream = new ObjectInputStream(newStreamObject.getDataInputStream());
    ArrayList<Integer> newNumbers = (ArrayList<Integer>)objectInputStream.readObject();

    assertEquals(2, (int)newNumbers.get(0));
    assertEquals(3, (int)newNumbers.get(1));
    assertEquals(5, (int)newNumbers.get(2));
    assertEquals(7, (int)newNumbers.get(3));

    // Clean up
    deleteObject("stream");
    deleteBucket();
}