List of usage examples for com.amazonaws.auth AWSCredentials AWSCredentials
AWSCredentials
From source file:ru.iris.common.voice.IvonaSynthesiser.java
License:Apache License
public InputStream getMP3Data(String synthText) throws IOException { AWSCredentials credentials = new AWSCredentials() { @Override/*from w w w .java2 s .co m*/ public String getAWSAccessKeyId() { return cfg.get("ivonaAccessKey"); } @Override public String getAWSSecretKey() { return cfg.get("ivonaSecretKey"); } }; IvonaSpeechCloudClient speechCloud = new IvonaSpeechCloudClient(credentials); speechCloud.setEndpoint("https://tts.eu-west-1.ivonacloud.com"); CreateSpeechRequest createSpeechRequest = new CreateSpeechRequest(); Input input = new Input(); Voice voice = new Voice(); voice.setName(cfg.get("ivonaVoice")); input.setData(synthText); createSpeechRequest.setInput(input); createSpeechRequest.setVoice(voice); InputStream in = null; try { CreateSpeechResult createSpeechResult = speechCloud.createSpeech(createSpeechRequest); LOGGER.debug("Success sending request:"); LOGGER.debug(" content type:\t" + createSpeechResult.getContentType()); LOGGER.debug(" request id:\t" + createSpeechResult.getTtsRequestId()); LOGGER.debug(" request chars:\t" + createSpeechResult.getTtsRequestCharacters()); LOGGER.debug(" request units:\t" + createSpeechResult.getTtsRequestUnits()); System.out.println("\nStarting to retrieve audio stream:"); in = createSpeechResult.getBody(); return in; } finally { if (in != null) { in.close(); } } }
From source file:ubicrypt.core.provider.s3.S3Provider.java
License:Open Source License
@Override public Observable<ProviderStatus> init(long userId) { return Observable.<ProviderStatus>create(subscriber -> { if (conf == null) { subscriber.onError(new RuntimeException("conf not specified")); return; }//from www .j a va 2s . c o m try { AmazonS3ClientBuilder clientb = AmazonS3ClientBuilder.standard() .withCredentials(new AWSCredentialsProvider() { @Override public AWSCredentials getCredentials() { return new AWSCredentials() { @Override public String getAWSAccessKeyId() { return conf.getAccessKeyId(); } @Override public String getAWSSecretKey() { return conf.getSecrectKey(); } }; } @Override public void refresh() { } }); if (conf.getRegion() != null) { clientb.withRegion(conf.getRegion()); } client = clientb.build(); prefix = Long.toString(userId, MAX_RADIX) + "/"; try { client.headBucket(new HeadBucketRequest(conf.getBucket())); } catch (AmazonS3Exception e) { switch (e.getErrorCode()) { case "404 Not Found": client.createBucket(conf.getBucket()); break; default: subscriber.onError(e); return; } } maxKey.set(client.listObjects(conf.getBucket(), prefix).getObjectSummaries().stream().map(obj -> { try { return Long.valueOf(substringAfter(obj.getKey(), prefix), MAX_RADIX); } catch (Exception e) { return 0L; } }).max(Long::compareTo).orElse(0L)); initialized.set(true); subscriber.onNext(ProviderStatus.initialized); subscriber.onCompleted(); } catch (Exception e) { subscriber.onError(e); } }).subscribeOn(Schedulers.io()); }
From source file:ubicrypt.ui.ctrl.S3ProviderController.java
License:Open Source License
public void listBuckets() { AmazonS3Client client = new AmazonS3Client(new AWSCredentials() { @Override//from w ww .jav a 2 s. c o m public String getAWSAccessKeyId() { return accessKey.getText(); } @Override public String getAWSSecretKey() { return secret.getText(); } }); try { client.listBuckets().forEach(bucket -> buckets.getItems().add(bucket.getName())); error.setVisible(false); error.setText(""); buckets.requestFocus(); } catch (SdkClientException e) { log.info("error accessing s3:{}", e.getMessage()); error.setVisible(true); error.setText(e.getMessage()); } buckets.setDisable(false); finish.setDisable(false); finish.setOnMouseClicked(addEvent -> { S3Provider provider = new S3Provider(); S3Conf conf = new S3Conf(); conf.setAccessKeyId(accessKey.getText()); conf.setSecrectKey(secret.getText()); conf.setRegion(Regions.fromName((String) regions.getSelectionModel().getSelectedItem())); conf.setBucket((String) buckets.getSelectionModel().getSelectedItem()); provider.setConf(conf); providerCommander.register(provider).subscribe(result -> { log.info("provider s3:{} registered:{}", conf.getBucket(), result); clearInputs(); navigator.popHome(); }, err -> { log.error("error on adding s3 provider", err); Platform.runLater(() -> { error.setVisible(true); error.setText("Error: " + err.getMessage()); }); }); }); }