List of usage examples for com.amazonaws.auth BasicAWSCredentials BasicAWSCredentials
public BasicAWSCredentials(String accessKey, String secretKey)
From source file:ecplugins.s3.S3Util.java
License:Apache License
public static int ListBuckets() throws Exception { Properties props = TestUtils.getProperties(); BasicAWSCredentials credentials = new BasicAWSCredentials(props.getProperty(StringConstants.ACCESS_ID), props.getProperty(StringConstants.SECRET_ACCESS_ID)); // Create TransferManager TransferManager tx = new TransferManager(credentials); // Get S3 Client AmazonS3 s3 = tx.getAmazonS3Client(); List<Bucket> buckets = s3.listBuckets(); return buckets.size(); }
From source file:ecplugins.s3.S3Util.java
License:Apache License
public static void UploadObject(String bucketName, String key) throws AmazonClientException, AmazonServiceException, Exception { Properties props = TestUtils.getProperties(); File file = new File(createFile()); BasicAWSCredentials credentials = new BasicAWSCredentials(props.getProperty(StringConstants.ACCESS_ID), props.getProperty(StringConstants.SECRET_ACCESS_ID)); // Create TransferManager TransferManager tx = new TransferManager(credentials); // Get S3 Client AmazonS3 s3 = tx.getAmazonS3Client(); try {//from w ww. ja v a 2 s.c o m System.out.println("Uploading a new object to S3 from a file\n"); s3.putObject(new PutObjectRequest(bucketName, key, file)); } catch (AmazonServiceException ase) { System.out.println("Caught an AmazonServiceException"); System.out.println("Error Message: " + ase.getMessage()); System.out.println("HTTP Status Code: " + ase.getStatusCode()); System.out.println("AWS Error Code: " + ase.getErrorCode()); System.out.println("Error Type: " + ase.getErrorType()); System.out.println("Request ID: " + ase.getRequestId()); } catch (AmazonClientException ace) { System.out.println( "Caught an AmazonClientException, which means the client encountered an internal error while trying to such as not being able to access the network."); System.out.println("Error Message: " + ace.getMessage()); } }
From source file:ecplugins.s3.S3Util.java
License:Apache License
public static boolean UploadFolder(String bucketName, String key) throws AmazonClientException, AmazonServiceException, Exception { Properties props = TestUtils.getProperties(); File file = new File(createFolder()); BasicAWSCredentials credentials = new BasicAWSCredentials(props.getProperty(StringConstants.ACCESS_ID), props.getProperty(StringConstants.SECRET_ACCESS_ID)); // Create TransferManager TransferManager tx = new TransferManager(credentials); // Get S3 Client AmazonS3 s3 = tx.getAmazonS3Client(); MultipleFileUpload objectUpload = tx.uploadDirectory(bucketName, key, file, true); while (!objectUpload.isDone()) { Thread.sleep(1000);//w ww . java 2 s . c o m } return true; }
From source file:ecplugins.s3.S3Util.java
License:Apache License
public static boolean isValidFile(String bucketName, String path) throws AmazonClientException, AmazonServiceException, Exception { boolean isValidFile = true; Properties props = TestUtils.getProperties(); BasicAWSCredentials credentials = new BasicAWSCredentials(props.getProperty(StringConstants.ACCESS_ID), props.getProperty(StringConstants.SECRET_ACCESS_ID)); // Create TransferManager TransferManager tx = new TransferManager(credentials); // Get S3 Client AmazonS3 s3 = tx.getAmazonS3Client(); try {/*from w ww. j a v a 2 s.c o m*/ ObjectMetadata objectMetadata = s3.getObjectMetadata(bucketName, path); } catch (AmazonS3Exception s3e) { if (s3e.getStatusCode() == 404) { // i.e. 404: NoSuchKey - The specified key does not exist isValidFile = false; } else { throw s3e; // rethrow all S3 exceptions other than 404 } } return isValidFile; }
From source file:edu.brandeis.wisedb.aws.VMCreator.java
License:Open Source License
private AmazonEC2Client getEC2() { AWSCredentials cred = new BasicAWSCredentials(config.getAWSKey(), config.getAWSKeySecret()); AmazonEC2Client ec2 = new AmazonEC2Client(cred); ec2.setEndpoint(config.getEndpoint()); return ec2;/* www .ja v a2s .c o m*/ }
From source file:edu.rutgers.winlab.crowdpp.service.SpeakerCountService.java
License:Open Source License
@Override public void onCreate() { Toast.makeText(this, "Speaker Count Service Started ", Toast.LENGTH_SHORT).show(); serviceDir = new File(Constants.servicePath); showInfo();// w w w .ja v a 2 s . c o m if (!serviceDir.exists() || !serviceDir.isDirectory()) { serviceDir.mkdir(); } mDatabase = new DataBaseHelper(getApplicationContext()); mDB = mDatabase.getWritableDatabase(); loc = new LocationTracker(getApplicationContext()); PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "No sleep"); wl.acquire(); s3Client = new AmazonS3Client(new BasicAWSCredentials(Constants.ACCESS_KEY_ID, Constants.SECRET_KEY)); s3Client.setRegion(Region.getRegion(Regions.US_WEST_2)); }
From source file:edu.rutgers.winlab.crowdpp.ui.HomeFragment.java
License:Open Source License
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { final View view = inflater.inflate(R.layout.home_fragment_layout, container, false); tb_cal = (ToggleButton) view.findViewById(R.id.tb_home_calibration); tb_service = (ToggleButton) view.findViewById(R.id.tb_home_service); tb_test = (ToggleButton) view.findViewById(R.id.tb_home_test); tv_cal_content = (TextView) view.findViewById(R.id.tv_home_calibration_content); tv_cal_text = (TextView) view.findViewById(R.id.tv_home_calibration_text); tv_debug = (TextView) view.findViewById(R.id.tv_home_test_debug); tv_record = (TextView) view.findViewById(R.id.tv_home_test_record); timer_cal = (Chronometer) view.findViewById(R.id.timer_calibration); timer_test = (Chronometer) view.findViewById(R.id.timer_test); rl_service = (RelativeLayout) view.findViewById(R.id.rl_home_service); rl_test = (RelativeLayout) view.findViewById(R.id.rl_home_test); if (isMyServiceRunning() == true) tb_service.setChecked(true);/* ww w . jav a2 s. c o m*/ if (Constants.calibration()) tv_cal_content.setText("You are all set for the calibration."); if (!Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) { Toast.makeText(getActivity(), "Can not find SD card ...", Toast.LENGTH_SHORT).show(); getActivity().finish(); } crowdppDir = new File(Constants.crowdppPath); if (!crowdppDir.exists() || !crowdppDir.isDirectory()) { crowdppDir.mkdir(); } testDir = new File(Constants.testPath); if (!testDir.exists() || !testDir.isDirectory()) { testDir.mkdir(); } calWavFile = crowdppDir + "/" + Constants.PHONE_ID + ".wav"; timer_cal.setVisibility(View.INVISIBLE); timer_test.setVisibility(View.INVISIBLE); mDatabase = new DataBaseHelper(getActivity().getApplicationContext()); mDB = mDatabase.getWritableDatabase(); gps = new LocationTracker(getActivity().getApplicationContext()); s3Client = new AmazonS3Client(new BasicAWSCredentials(Constants.ACCESS_KEY_ID, Constants.SECRET_KEY)); s3Client.setRegion(Region.getRegion(Regions.US_WEST_2)); tb_cal.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { // prevent the calibration button being pressed when either and test or service is running if (tb_service.isChecked()) { Toast.makeText(getActivity(), "Please turn off the service...", Toast.LENGTH_SHORT).show(); tb_cal.setChecked(false); } else if (tb_test.isChecked()) { Toast.makeText(getActivity(), "Please turn off the test...", Toast.LENGTH_SHORT).show(); tb_cal.setChecked(false); } // calibration else { if (isChecked) { tv_cal_text.setText(Constants.cal_text); rl_service.setVisibility(View.INVISIBLE); rl_test.setVisibility(View.INVISIBLE); timer_cal.setVisibility(View.VISIBLE); AlertDialog dialog = new AlertDialog.Builder(getActivity()).create(); dialog.setTitle("Calibration"); dialog.setMessage(Constants.cal_dialog); dialog.setButton(AlertDialog.BUTTON_POSITIVE, "OK", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { timer_cal.setBase(SystemClock.elapsedRealtime()); timer_cal.start(); tv_cal_content.setText("Recording your voice..."); Bundle mbundle = new Bundle(); mbundle.putString("audiopath", calWavFile); Log.i("HomeFragment", "start audio recording service"); // delete the existing calibration data before the recalibration FileProcess.deleteFile(calWavFile); FileProcess.deleteFile(calWavFile + ".jstk.mfcc.txt"); FileProcess.deleteFile(calWavFile + ".YIN.pitch.txt"); // start audio recording Intent recordIntent = new Intent(getActivity(), AudioRecordService.class); recordIntent.putExtras(mbundle); getActivity().startService(recordIntent); } }); dialog.show(); dialog.getButton(DialogInterface.BUTTON_POSITIVE).setTextSize(20); } else { // stop audio recording Intent recordIntent = new Intent(getActivity(), AudioRecordService.class); getActivity().stopService(recordIntent); timer_cal.stop(); tb_cal.setClickable(false); tv_cal_content.setText("Calibrating...."); // start calibration new Calibration().execute(); tb_cal.setClickable(true); tv_cal_text.setText(""); rl_service.setVisibility(View.VISIBLE); rl_test.setVisibility(View.VISIBLE); timer_cal.setVisibility(View.INVISIBLE); } } } }); tb_service.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { // prevent the service button being pressed when either and test or calibration is running if (tb_cal.isChecked()) { Toast.makeText(getActivity(), "Please turn off the calibration...", Toast.LENGTH_SHORT).show(); tb_service.setChecked(false); } else if (tb_test.isChecked()) { Toast.makeText(getActivity(), "Please turn off the test...", Toast.LENGTH_SHORT).show(); tb_service.setChecked(false); } // speaker counting service else { Intent countIntent = new Intent(getActivity(), SpeakerCountService.class); if (isChecked) { getActivity().startService(countIntent); } else { getActivity().stopService(countIntent); } } } }); tb_test.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { // prevent the test button being pressed when either and service or calibration is running if (tb_cal.isChecked()) { Toast.makeText(getActivity(), "Please turn off the calibration...", Toast.LENGTH_SHORT).show(); tb_test.setChecked(false); } else if (tb_service.isChecked()) { Toast.makeText(getActivity(), "Please turn off the service...", Toast.LENGTH_SHORT).show(); tb_test.setChecked(false); } // perform the speaker counting test else { if (isChecked) { // get location information gps.getLocation(); if (gps.canGetLocation()) { latitude = gps.getLatitude(); longitude = gps.getLongitude(); } else { latitude = -1; longitude = -1; } gps.stopUsingGPS(); timer_test.setBase(SystemClock.elapsedRealtime()); timer_test.start(); tv_debug.setText("Recording..."); testWavFile = testDir + "/" + FileProcess.newFileOnTime("wav"); // start audio recording Bundle mbundle = new Bundle(); mbundle.putString("audiopath", testWavFile); Log.i("HomeFragment", "start audio recording service"); Intent recordIntent = new Intent(getActivity(), AudioRecordService.class); recordIntent.putExtras(mbundle); date = Now.getDate(); start = Now.getTimeOfDay(); getActivity().startService(recordIntent); timer_test.setVisibility(View.VISIBLE); } else { // stop audio recording Intent recordIntent = new Intent(getActivity(), AudioRecordService.class); getActivity().stopService(recordIntent); timer_test.stop(); end = Now.getTimeOfDay(); tb_test.setClickable(false); // start speaker counting test new Test().execute(); timer_test.setVisibility(View.INVISIBLE); tb_test.setClickable(true); } } } }); return view; }
From source file:edu.si.services.beans.cameratrap.AmazonS3ClientMock.java
License:Apache License
public AmazonS3ClientMock(String accessKey, String secretKey) { super(new BasicAWSCredentials(accessKey, secretKey)); }
From source file:edu.upenn.library.fcrepo.connector.annex.S3AnnexResolverFactory.java
License:Apache License
@Override public void initialize(Properties props) { this.accessKey = props.getProperty(ACCESS_KEY_PROPNAME); this.secretKey = props.getProperty(SECRET_KEY_PROPNAME); this.bucket = props.getProperty(BUCKET_PROPNAME); AWSCredentials credentials = new BasicAWSCredentials(accessKey, secretKey); ClientConfiguration clientConfig = new ClientConfiguration(); clientConfig.setProtocol(Protocol.HTTP); S3ClientOptions clientOptions = new S3ClientOptions(); clientOptions.setPathStyleAccess(true); conn = new AmazonS3Client(credentials, clientConfig); conn.setS3ClientOptions(clientOptions); conn.setEndpoint(props.getProperty(ENDPOINT_PROPNAME)); }
From source file:elasticity.services.AmazonService.java
License:Open Source License
@Override protected void initService(Properties props) throws Exception { //Get the properties.. Properties awsProps = new Properties(); InputStream reader;//from w ww. j a va2s . com try { reader = new FileInputStream(awsPropFile); awsProps.load(reader); reader.close(); } catch (Exception e) { logger.log(Level.SEVERE, "ERROR while reading the AWS properties file:"); e.printStackTrace(System.out); throw e; } awsServiceUrl = awsProps.getProperty("aws_service_url"); awsAccessKey = awsProps.getProperty("aws_access_key"); awsSecretKey = awsProps.getProperty("aws_secret_key"); awsKeypair = awsProps.getProperty("aws_keypair"); awsInstanceType = awsProps.getProperty("aws_instance_type"); awsSecurityGroup = awsProps.getProperty("aws_security_group"); awsImageId = awsProps.getProperty("aws_image_id"); ec2 = new AmazonEC2Client(new BasicAWSCredentials(awsAccessKey, awsSecretKey)); ec2.setEndpoint(awsServiceUrl); logger.log(Level.INFO, "Initialization completed."); }