mirror of https://github.com/apache/jclouds.git
Improve use of Charsets
This commit is contained in:
parent
5b213c2171
commit
9024c77405
|
@ -1,6 +1,5 @@
|
|||
package org.jclouds.cloudstack.functions;
|
||||
|
||||
import java.nio.charset.Charset;
|
||||
import java.security.KeyFactory;
|
||||
import java.security.PrivateKey;
|
||||
import java.security.spec.KeySpec;
|
||||
|
@ -14,6 +13,7 @@ import org.jclouds.domain.LoginCredentials;
|
|||
import org.jclouds.encryption.internal.Base64;
|
||||
import org.jclouds.javax.annotation.Nullable;
|
||||
|
||||
import com.google.common.base.Charsets;
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Throwables;
|
||||
import com.google.inject.Inject;
|
||||
|
@ -48,7 +48,7 @@ public class WindowsLoginCredentialsFromEncryptedData implements Function<Encryp
|
|||
cipher.init(Cipher.DECRYPT_MODE, privKey);
|
||||
byte[] cipherText = Base64.decode(dataAndKey.getEncryptedPassword());
|
||||
byte[] plainText = cipher.doFinal(cipherText);
|
||||
String password = new String(plainText, Charset.forName("ASCII"));
|
||||
String password = new String(plainText, Charsets.US_ASCII);
|
||||
|
||||
return LoginCredentials.builder()
|
||||
.user("Administrator")
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
*/
|
||||
package org.jclouds.ec2.compute.functions;
|
||||
|
||||
import java.nio.charset.Charset;
|
||||
import java.security.KeyFactory;
|
||||
import java.security.PrivateKey;
|
||||
import java.security.spec.KeySpec;
|
||||
|
@ -33,6 +32,7 @@ import org.jclouds.ec2.compute.domain.PasswordDataAndPrivateKey;
|
|||
import org.jclouds.encryption.internal.Base64;
|
||||
import org.jclouds.javax.annotation.Nullable;
|
||||
|
||||
import com.google.common.base.Charsets;
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Throwables;
|
||||
import com.google.inject.Singleton;
|
||||
|
@ -66,7 +66,7 @@ public class WindowsLoginCredentialsFromEncryptedData implements Function<Passwo
|
|||
cipher.init(Cipher.DECRYPT_MODE, privKey);
|
||||
byte[] cipherText = Base64.decode(dataAndKey.getPasswordData().getPasswordData());
|
||||
byte[] plainText = cipher.doFinal(cipherText);
|
||||
String password = new String(plainText, Charset.forName("ASCII"));
|
||||
String password = new String(plainText, Charsets.US_ASCII);
|
||||
|
||||
return LoginCredentials.builder()
|
||||
.user("Administrator")
|
||||
|
|
|
@ -49,6 +49,7 @@ import org.jclouds.openstack.swift.options.ListContainerOptions;
|
|||
import org.jclouds.util.Strings2;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.base.Charsets;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
|
@ -247,7 +248,7 @@ public abstract class CommonSwiftClientLiveTest<C extends CommonSwiftClient> ext
|
|||
}
|
||||
|
||||
// Test PUT chunked/streamed upload with data of "unknown" length
|
||||
ByteArrayInputStream bais = new ByteArrayInputStream(data.getBytes("UTF-8"));
|
||||
ByteArrayInputStream bais = new ByteArrayInputStream(data.getBytes(Charsets.UTF_8));
|
||||
SwiftObject blob = getApi().newSwiftObject();
|
||||
blob.getInfo().setName("chunked-object");
|
||||
blob.setPayload(bais);
|
||||
|
|
|
@ -18,6 +18,8 @@
|
|||
*/
|
||||
package org.jclouds.osgi;
|
||||
|
||||
import com.google.common.base.Charsets;
|
||||
|
||||
import org.jclouds.apis.ApiMetadata;
|
||||
import org.jclouds.apis.ApiRegistry;
|
||||
import org.jclouds.providers.ProviderMetadata;
|
||||
|
@ -158,7 +160,7 @@ public class MetadataBundleListener implements BundleListener {
|
|||
|
||||
try {
|
||||
is = resource.openStream();
|
||||
reader = new InputStreamReader(is, "UTF-8");
|
||||
reader = new InputStreamReader(is, Charsets.UTF_8);
|
||||
bufferedReader = new BufferedReader(reader);
|
||||
String line;
|
||||
while ((line = bufferedReader.readLine()) != null) {
|
||||
|
|
|
@ -62,6 +62,7 @@ import org.jclouds.rest.annotations.Credential;
|
|||
import org.jclouds.rest.annotations.Identity;
|
||||
import org.jclouds.rest.config.RestClientModule;
|
||||
|
||||
import com.google.common.base.Charsets;
|
||||
import com.google.common.base.Supplier;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.inject.Provides;
|
||||
|
@ -139,7 +140,7 @@ public class AzureManagementRestClientModule extends RestClientModule<AzureManag
|
|||
CertificateFactory cf = CertificateFactory.getInstance("X.509");
|
||||
@SuppressWarnings("unchecked")
|
||||
Collection<Certificate> certs = (Collection<Certificate>) cf.generateCertificates(new ByteArrayInputStream(
|
||||
pemCerts.getBytes("UTF-8")));
|
||||
pemCerts.getBytes(Charsets.UTF_8)));
|
||||
keyStore.load(null);
|
||||
keyStore.setKeyEntry("dummy", privateKey, keyStorePassword.toCharArray(),
|
||||
certs.toArray(new java.security.cert.Certificate[0]));
|
||||
|
|
|
@ -257,7 +257,7 @@ public class DataApiLiveTest extends BaseCDMIApiLiveTest {
|
|||
bytes = bos.toByteArray();
|
||||
// String.getBytes causes an exception CreateDataObjectOptions need to investigate byte
|
||||
// arrays
|
||||
// bytes = value.getBytes("UTF-8");
|
||||
// bytes = value.getBytes(Charsets.UTF_8);
|
||||
pCreateDataObjectOptions = CreateDataObjectOptions.Builder.value(bytes);
|
||||
dataObject = dataApi.create(dataObjectNameIn, pCreateDataObjectOptions);
|
||||
assertNotNull(dataObject);
|
||||
|
|
|
@ -130,7 +130,7 @@ public class DataNonCDMIContentTypeApiLiveTest extends BaseCDMIApiLiveTest {
|
|||
|
||||
// exercise create data object with none cdmi put with payload byte array.
|
||||
value = "Hello CDMI World non-cdmi byte array";
|
||||
bytes = value.getBytes("UTF-8");
|
||||
bytes = value.getBytes(Charsets.UTF_8);
|
||||
payloadIn = new ByteArrayPayload(bytes);
|
||||
payloadIn.setContentMetadata(BaseMutableContentMetadata.fromContentMetadata(payloadIn.getContentMetadata()
|
||||
.toBuilder().contentType(MediaType.PLAIN_TEXT_UTF_8.toString()).build()));
|
||||
|
|
|
@ -79,6 +79,7 @@ import org.jclouds.rest.annotations.Identity;
|
|||
import org.jclouds.rest.config.RestClientModule;
|
||||
import org.jclouds.xml.XMLParser;
|
||||
|
||||
import com.google.common.base.Charsets;
|
||||
import com.google.common.base.Supplier;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.inject.Provides;
|
||||
|
@ -348,7 +349,7 @@ public class FGCPRestClientModule extends
|
|||
@SuppressWarnings("unchecked")
|
||||
Collection<Certificate> certs = (Collection<Certificate>) cf
|
||||
.generateCertificates(new ByteArrayInputStream(pemCerts
|
||||
.getBytes("UTF-8")));
|
||||
.getBytes(Charsets.UTF_8)));
|
||||
keyStore.load(null);
|
||||
keyStore.setKeyEntry("dummy", privateKey,
|
||||
keyStorePassword.toCharArray(),
|
||||
|
|
|
@ -26,6 +26,7 @@ import java.security.KeyStoreException;
|
|||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.PrivateKey;
|
||||
import java.security.Signature;
|
||||
import java.security.SignatureException;
|
||||
import java.security.UnrecoverableKeyException;
|
||||
import java.util.Calendar;
|
||||
import java.util.Locale;
|
||||
|
@ -203,10 +204,10 @@ public class RequestAuthenticator implements HttpRequestFilter, RequestSigner {
|
|||
String signed;
|
||||
|
||||
try {
|
||||
signer.update(stringToSign.getBytes("UTF-8"));
|
||||
signer.update(stringToSign.getBytes(Charsets.UTF_8));
|
||||
signed = Base64.encodeBytes(signer.sign()).replace("\n", "\r\n");
|
||||
// signed = CryptoStreams.base64(signer.sign());
|
||||
} catch (Exception e) {
|
||||
} catch (SignatureException e) {
|
||||
throw new HttpException("error signing request", e);
|
||||
}
|
||||
// if (signatureWire.enabled())
|
||||
|
|
|
@ -49,6 +49,7 @@ import org.jclouds.util.Strings2;
|
|||
import org.jclouds.util.Throwables2;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.base.Charsets;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableMultimap;
|
||||
import com.google.common.collect.Iterables;
|
||||
|
@ -306,7 +307,7 @@ public class AzureBlobClientLiveTest extends BaseBlobStoreIntegrationTest {
|
|||
assertEquals(((HttpResponseException) e.getCause()).getResponse().getStatusCode(), 422);
|
||||
}
|
||||
|
||||
ByteArrayInputStream bais = new ByteArrayInputStream(data.getBytes("UTF-8"));
|
||||
ByteArrayInputStream bais = new ByteArrayInputStream(data.getBytes(Charsets.UTF_8));
|
||||
object = getApi().newBlob();
|
||||
object.getProperties().setName("chunked-object");
|
||||
object.setPayload(bais);
|
||||
|
|
Loading…
Reference in New Issue