Example usage for com.amazonaws.services.s3 AmazonS3Client AmazonS3Client

List of usage examples for com.amazonaws.services.s3 AmazonS3Client AmazonS3Client

Introduction

In this page you can find the example usage for com.amazonaws.services.s3 AmazonS3Client AmazonS3Client.

Prototype

@SdkInternalApi
AmazonS3Client(AmazonS3ClientParams s3ClientParams) 

Source Link

Document

Constructs a new client to invoke service methods on S3 using the specified parameters.

Usage

From source file:datameer.awstasks.aws.emr.EmrCluster.java

License:Apache License

private String uploadingJobJar(File jobJar, String s3JobJarName) {
    if (_s3Service == null) {
        _s3Service = new AmazonS3Client(new BasicAWSCredentials(getSettings().getAccessKey(), _accessSecret));
    }/*from   ww  w .  j  a  va2s.c  o m*/
    synchronized (jobJar.getAbsolutePath().intern()) {
        String s3JobJarPath = new File(getSettings().getS3JobJarBasePath(), s3JobJarName).getPath();
        String s3Bucket = getSettings().getS3Bucket();
        if (!_s3Service.doesBucketExist(s3Bucket)) {
            throw new IllegalStateException("s3 bucket '" + s3Bucket + "' does not exists");
        }
        if (!S3Util.existsFile(_s3Service, s3Bucket, s3JobJarPath)) {
            LOG.info("uploading " + jobJar + " to " + s3JobJarPath);
            S3Util.uploadFile(_s3Service, s3Bucket, jobJar, s3JobJarPath);
        } else {
            LOG.info("using cached job-jar: " + s3JobJarPath);
        }
        return "s3n://" + getSettings().getAccessKey() + "@" + s3Bucket + s3JobJarPath;
    }
}

From source file:datameer.awstasks.util.Ec2Configuration.java

License:Apache License

public AmazonS3 createS3Service() {
    return new AmazonS3Client(new BasicAWSCredentials(_accessKeyId, _accessKeySecret));
}

From source file:de.fischer.thotti.s3.clients.S3InternalClient.java

License:Apache License

protected S3InternalClient(AWSAccessCredentials credentials, LoggingSupport logger) {
    if (null == credentials) {
        throw new NullPointerException();
    }/*  w  ww .  j a  v a2 s  .co m*/

    MyAWSCredentials myCredentials = new MyAWSCredentials();

    myCredentials.setAccessKeyId(credentials.getAccessKeyId());
    myCredentials.setSecretKey(credentials.getSecretKey());

    amazonS3Client = new AmazonS3Client(myCredentials);

    if (null == logger) {
        loggingSupport = new SLF4JLogger(S3ClientConstants.S3_LOGGER_DOMAIN);
    } else {
        loggingSupport = logger;
    }
}

From source file:de.fischer.thotti.s3.S3BucketCreatorIT.java

License:Apache License

@AfterMethod
public void removeBucket() {

    AmazonS3Client client = new AmazonS3Client(
            new MyAWSCredentials(s3Credentials.getAccessKeyId(), s3Credentials.getSecretKey()));

    try {//  ww  w.  j a va  2 s  .co  m
        client.deleteBucket(bucketName);
    } catch (AmazonServiceException ase) {
        // @todo improve error handing

    } catch (AmazonClientException e) {
        // @todo Improve logging
    }

}

From source file:edu.harvard.hms.dbmi.bd2k.irct.aws.event.result.S3AfterGetResult.java

License:Mozilla Public License

@Override
public void init(Map<String, String> parameters) {
    log = LogFactory.getLog("AWS S3 Monitoring");
    bucketName = parameters.get("Bucket Name");
    irctSaveLocation = parameters.get("resultDataFolder");
    s3Folder = parameters.get("s3Folder");

    s3client = new AmazonS3Client(new InstanceProfileCredentialsProvider());

}

From source file:edu.harvard.hms.dbmi.bd2k.irct.aws.event.result.S3AfterSaveResult.java

License:Mozilla Public License

@Override
public void init(Map<String, String> parameters) {
    log = LogFactory.getLog("AWS S3 Monitoring");
    bucketName = parameters.get("Bucket Name");
    s3Folder = parameters.get("s3Folder");

    s3client = new AmazonS3Client(new InstanceProfileCredentialsProvider());
}

From source file:edu.iu.finch.core.NexRad.java

License:Apache License

private void init(AWSCredentials credentials) {
    s3Client = new AmazonS3Client(credentials);
    Region region = Region.getRegion(Regions.US_EAST_1);
    s3Client.setRegion(region);/*from  w  w  w . j  a  va 2s. c om*/
}

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.  j  a 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  . j  a va  2s .com*/

    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.umass.cs.aws.support.examples.AWSStatusCheck.java

License:Apache License

private static void init() throws Exception {
    AWSCredentials credentials = new PropertiesCredentials(new File(CREDENTIALSFILE));

    ec2 = new AmazonEC2Client(credentials);
    s3 = new AmazonS3Client(credentials);
    sdb = new AmazonSimpleDBClient(credentials);
}