使用pentaho用户定义的Java类连接到amazone s3时出错

时间:2019-02-21 08:31:35

标签: java amazon-s3 pentaho

无法将类型从“ java.lang.Object”转换为“ com.amazonaws.services.s3.AmazonS3”。尝试使用pentaho用户定义的java类连接到amazone s3时,将出现此错误。

import java.io.*;
import java.util.zip.*;
import java.util.Arrays;
import java.io.BufferedReader;
import org.apache.commons.io.IOUtils;

import com.amazonaws.AmazonClientException;
import com.amazonaws.AmazonServiceException;
import com.amazonaws.auth.AWSCredentials;
import com.amazonaws.auth.AWSStaticCredentialsProvider;
import com.amazonaws.auth.profile.ProfileCredentialsProvider;
import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.AmazonS3ClientBuilder;
import com.amazonaws.services.s3.model.ObjectMetadata;

public boolean processRow(StepMetaInterface smi, StepDataInterface sdi) throws KettleException {
  if (first) {
    first = false;
  }

  Object[] r = getRow();
  if (r == null) {
    setOutputDone();
    return false;
  }
  AWSCredentials credentials = null;
  Object[] outputRow = createOutputRow(r, data.outputRowMeta.size());
  try {
	credentials = new ProfileCredentialsProvider("default").getCredentials();
	AmazonS3 s3 = AmazonS3ClientBuilder.standard().withCredentials(new AWSStaticCredentialsProvider(credentials))
				.withRegion("us-west-1").build();

	String bucketName = "";
	String key = "";

	byte[] compressed = get(Fields.In, "Message").getBinary(r);
	
	ByteArrayInputStream bis = new ByteArrayInputStream(compressed);
	
	ObjectMetadata metaData = new ObjectMetadata();
	metaData.setContentLength(b.length);
	metaData.setContentType("application/octet-stream");
	metaData.setContentEncoding("UTF-8");
			
	s3.putObject(bucketName, key, bis, metaData);
	
	get(Fields.Out, "Message").setValue(outputRow, compressed);
	putRow(data.outputRowMeta, outputRow);
  } catch (Exception e) {
	throw (Exception) e;  
  }
  return true;
}

感谢您的支持

0 个答案:

没有答案