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

The following examples show how to use org.jets3t.service.model.S3Object#setContentLength() . 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
public void storeLargeFile(String key, File file, byte[] md5Hash)
    throws IOException {
  S3Object object = new S3Object(key);
  object.setDataInputFile(file);
  object.setContentType("binary/octet-stream");
  object.setContentLength(file.length());
  object.setServerSideEncryptionAlgorithm(serverSideEncryptionAlgorithm);
  if (md5Hash != null) {
    object.setMd5Hash(md5Hash);
  }

  List<StorageObject> objectsToUploadAsMultipart =
      new ArrayList<StorageObject>();
  objectsToUploadAsMultipart.add(object);
  MultipartUtils mpUtils = new MultipartUtils(multipartBlockSize);

  try {
    mpUtils.uploadObjects(bucket.getName(), s3Service,
                          objectsToUploadAsMultipart, null);
  } catch (Exception e) {
    handleException(e, key);
  }
}
 
Example 2
Source File: Jets3tFileSystemStore.java    From hadoop with Apache License 2.0 6 votes vote down vote up
private void put(String key, InputStream in, long length, boolean storeMetadata)
    throws IOException {
  
  try {
    S3Object object = new S3Object(key);
    object.setDataInputStream(in);
    object.setContentType("binary/octet-stream");
    object.setContentLength(length);
    if (storeMetadata) {
      object.addAllMetadata(METADATA);
    }
    s3Service.putObject(bucket, object);
  } catch (S3ServiceException e) {
    if (e.getCause() instanceof IOException) {
      throw (IOException) e.getCause();
    }
    throw new S3Exception(e);
  }
}
 
Example 3
Source File: Jets3tNativeFileSystemStore.java    From big-c with Apache License 2.0 6 votes vote down vote up
public void storeLargeFile(String key, File file, byte[] md5Hash)
    throws IOException {
  S3Object object = new S3Object(key);
  object.setDataInputFile(file);
  object.setContentType("binary/octet-stream");
  object.setContentLength(file.length());
  object.setServerSideEncryptionAlgorithm(serverSideEncryptionAlgorithm);
  if (md5Hash != null) {
    object.setMd5Hash(md5Hash);
  }

  List<StorageObject> objectsToUploadAsMultipart =
      new ArrayList<StorageObject>();
  objectsToUploadAsMultipart.add(object);
  MultipartUtils mpUtils = new MultipartUtils(multipartBlockSize);

  try {
    mpUtils.uploadObjects(bucket.getName(), s3Service,
                          objectsToUploadAsMultipart, null);
  } catch (Exception e) {
    handleException(e, key);
  }
}
 
Example 4
Source File: Jets3tFileSystemStore.java    From big-c with Apache License 2.0 6 votes vote down vote up
private void put(String key, InputStream in, long length, boolean storeMetadata)
    throws IOException {
  
  try {
    S3Object object = new S3Object(key);
    object.setDataInputStream(in);
    object.setContentType("binary/octet-stream");
    object.setContentLength(length);
    if (storeMetadata) {
      object.addAllMetadata(METADATA);
    }
    s3Service.putObject(bucket, object);
  } catch (S3ServiceException e) {
    if (e.getCause() instanceof IOException) {
      throw (IOException) e.getCause();
    }
    throw new S3Exception(e);
  }
}
 
Example 5
Source File: Jets3tFileSystemStore.java    From RDFS with Apache License 2.0 6 votes vote down vote up
private void put(String key, InputStream in, long length, boolean storeMetadata)
    throws IOException {
  
  try {
    S3Object object = new S3Object(key);
    object.setDataInputStream(in);
    object.setContentType("binary/octet-stream");
    object.setContentLength(length);
    if (storeMetadata) {
      object.addAllMetadata(METADATA);
    }
    s3Service.putObject(bucket, object);
  } catch (S3ServiceException e) {
    if (e.getCause() instanceof IOException) {
      throw (IOException) e.getCause();
    }
    throw new S3Exception(e);
  }
}
 
Example 6
Source File: Jets3tFileSystemStore.java    From hadoop-gpu with Apache License 2.0 6 votes vote down vote up
private void put(String key, InputStream in, long length, boolean storeMetadata)
    throws IOException {
  
  try {
    S3Object object = new S3Object(key);
    object.setDataInputStream(in);
    object.setContentType("binary/octet-stream");
    object.setContentLength(length);
    if (storeMetadata) {
      object.addAllMetadata(METADATA);
    }
    s3Service.putObject(bucket, object);
  } catch (S3ServiceException e) {
    if (e.getCause() instanceof IOException) {
      throw (IOException) e.getCause();
    }
    throw new S3Exception(e);
  }
}
 
Example 7
Source File: Jets3tNativeFileSystemStore.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Override
public void storeEmptyFile(String key) throws IOException {
  try {
    S3Object object = new S3Object(key);
    object.setDataInputStream(new ByteArrayInputStream(new byte[0]));
    object.setContentType("binary/octet-stream");
    object.setContentLength(0);
    object.setServerSideEncryptionAlgorithm(serverSideEncryptionAlgorithm);
    s3Service.putObject(bucket, object);
  } catch (ServiceException e) {
    handleException(e, key);
  }
}
 
Example 8
Source File: Jets3tNativeFileSystemStore.java    From big-c with Apache License 2.0 5 votes vote down vote up
@Override
public void storeEmptyFile(String key) throws IOException {
  try {
    S3Object object = new S3Object(key);
    object.setDataInputStream(new ByteArrayInputStream(new byte[0]));
    object.setContentType("binary/octet-stream");
    object.setContentLength(0);
    object.setServerSideEncryptionAlgorithm(serverSideEncryptionAlgorithm);
    s3Service.putObject(bucket, object);
  } catch (ServiceException e) {
    handleException(e, key);
  }
}
 
Example 9
Source File: AmazonFileStorageService.java    From computoser with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public void storeFile(String path, InputStream is, long size) throws IOException {
    path = stripLeadingSlash(path);
    S3Object fileObject = new S3Object(path);
    fileObject.setDataInputStream(is);
    if (size != -1) {
        fileObject.setContentLength(size);
    }
    try {
        service.putObject(bucketName, fileObject);
    } catch (S3ServiceException e) {
        throw new IOException(e);
    }
}
 
Example 10
Source File: Jets3tNativeFileSystemStore.java    From RDFS with Apache License 2.0 5 votes vote down vote up
public void storeEmptyFile(String key) throws IOException {
  try {
    S3Object object = new S3Object(key);
    object.setDataInputStream(new ByteArrayInputStream(new byte[0]));
    object.setContentType("binary/octet-stream");
    object.setContentLength(0);
    s3Service.putObject(bucket, object);
  } catch (S3ServiceException e) {
    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 void storeEmptyFile(String key) throws IOException {
  try {
    S3Object object = new S3Object(key);
    object.setDataInputStream(new ByteArrayInputStream(new byte[0]));
    object.setContentType("binary/octet-stream");
    object.setContentLength(0);
    s3Service.putObject(bucket, object);
  } catch (S3ServiceException e) {
    if (e.getCause() instanceof IOException) {
      throw (IOException) e.getCause();
    }
    throw new S3Exception(e);
  }
}
 
Example 12
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 13
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();
}