Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import java.net.InetAddress;
import java.net.URI;
import java.net.UnknownHostException;
import java.nio.charset.Charset;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -66,6 +65,7 @@
import com.cloud.resource.ServerResource;
import com.cloud.resource.UnableDeleteHostException;
import com.cloud.storage.StorageLayer;
import com.cloud.utils.StringUtils;

/**
* Methods to discover and managem a Hyper-V agent. Prepares a
Expand Down Expand Up @@ -256,7 +256,7 @@ public final Map<? extends ServerResource, Map<String, String>> find(final long
// pool in the database
// This GUID may change.
if (cluster.getGuid() == null) {
cluster.setGuid(UUID.nameUUIDFromBytes(String.valueOf(clusterId).getBytes(Charset.forName("UTF-8"))).toString());
cluster.setGuid(UUID.nameUUIDFromBytes(String.valueOf(clusterId).getBytes(StringUtils.getPreferredCharset())).toString());
_clusterDao.update(clusterId, cluster);
}

Expand Down Expand Up @@ -322,7 +322,7 @@ public final Map<? extends ServerResource, Map<String, String>> find(final long
* @return GUID in form of a string.
*/
public static String calcServerResourceGuid(final String uuidSeed) {
String guid = UUID.nameUUIDFromBytes(uuidSeed.getBytes(Charset.forName("UTF-8"))).toString();
String guid = UUID.nameUUIDFromBytes(uuidSeed.getBytes(StringUtils.getPreferredCharset())).toString();
return guid;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.channels.SocketChannel;
import java.nio.charset.Charset;
import java.rmi.RemoteException;
import java.security.KeyManagementException;
import java.security.KeyStoreException;
Expand Down Expand Up @@ -653,7 +652,7 @@ public ExecutionResult executeInVR(String routerIP, String script, String args,
public ExecutionResult createFileInVR(String routerIp, String filePath, String fileName, String content) {
File keyFile = getSystemVMKeyFile();
try {
SshHelper.scpTo(routerIp, 3922, "root", keyFile, null, filePath, content.getBytes(Charset.forName("UTF-8")), fileName, null);
SshHelper.scpTo(routerIp, 3922, "root", keyFile, null, filePath, content.getBytes(StringUtils.getPreferredCharset()), fileName, null);
} catch (Exception e) {
s_logger.warn("Fail to create file " + filePath + fileName + " in VR " + routerIp, e);
return new ExecutionResult(false, e.getMessage());
Expand Down Expand Up @@ -1318,7 +1317,7 @@ protected Answer execute(final LoadBalancerConfigCommand cmd) {
}

try {
SshHelper.scpTo(controlIp, DEFAULT_DOMR_SSHPORT, "root", keyFile, null, "/tmp/", tmpCfgFileContents.toString().getBytes(Charset.forName("UTF-8")), routerIp.replace('.', '_') +
SshHelper.scpTo(controlIp, DEFAULT_DOMR_SSHPORT, "root", keyFile, null, "/tmp/", tmpCfgFileContents.toString().getBytes(StringUtils.getPreferredCharset()), routerIp.replace('.', '_') +
".cfg", null);

try {
Expand Down Expand Up @@ -1515,7 +1514,7 @@ protected Answer execute(VmDataCommand cmd) {
String json = new Gson().toJson(data);
s_logger.debug("VM data JSON IS:" + json);

json = Base64.encodeBase64String(json.getBytes(Charset.forName("UTF-8")));
json = Base64.encodeBase64String(json.getBytes(StringUtils.getPreferredCharset()));

String args = "-d " + json;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import java.lang.reflect.Type;
import java.net.MalformedURLException;
import java.net.URL;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
Expand All @@ -49,6 +48,7 @@
import org.apache.commons.httpclient.protocol.ProtocolSocketFactory;
import org.apache.log4j.Logger;

import com.cloud.utils.StringUtils;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

Expand Down Expand Up @@ -301,7 +301,7 @@ private void setHttpHeader(final HttpMethodBase m) {
}

String authString = username + ":" + password;
String encodedAuthString = "Basic " + Base64.encodeBase64String(authString.getBytes(Charset.forName("UTF-8")));
String encodedAuthString = "Basic " + Base64.encodeBase64String(authString.getBytes(StringUtils.getPreferredCharset()));
m.setRequestHeader("Authorization", encodedAuthString);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import java.io.StringWriter;
import java.net.MalformedURLException;
import java.net.URL;
import java.nio.charset.Charset;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
Expand Down Expand Up @@ -60,6 +59,7 @@
import com.cloud.network.schema.portprofile.VlanProfile.SwitchportBasic;
import com.cloud.network.schema.portprofile.VlanProfile.SwitchportBasic.Basic;
import com.cloud.network.schema.showvcs.Output;
import com.cloud.utils.StringUtils;

public class BrocadeVcsApi {
private static final Logger s_logger = Logger.getLogger(BrocadeVcsApi.class);
Expand Down Expand Up @@ -461,7 +461,7 @@ protected Output executeRetreiveStatus(String uri) throws BrocadeVcsApiException
throw new BrocadeVcsApiException("Failed to retreive status : " + errorMessage);
}

try (BufferedReader br = new BufferedReader(new InputStreamReader(response.getEntity().getContent(), Charset.forName("UTF-8")))) {
try (BufferedReader br = new BufferedReader(new InputStreamReader(response.getEntity().getContent(), StringUtils.getPreferredCharset()))) {
sb = new StringBuffer();

while (((readLine = br.readLine()) != null)) {
Expand Down Expand Up @@ -531,7 +531,7 @@ private String responseToErrorMessage(HttpResponse response) throws IOException

if ("text/html".equals(response.getEntity().getContentType().getValue())) {

try (BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent(), Charset.forName("UTF-8")))) {
try (BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent(), StringUtils.getPreferredCharset()))) {

StringBuffer result = new StringBuffer();
String line = "";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

package com.cloud.network.manager;

import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
Expand Down Expand Up @@ -73,6 +72,7 @@
import com.cloud.resource.ResourceManager;
import com.cloud.resource.ResourceState;
import com.cloud.resource.ServerResource;
import com.cloud.utils.StringUtils;
import com.cloud.utils.component.ManagerBase;
import com.cloud.utils.db.Transaction;
import com.cloud.utils.db.TransactionCallback;
Expand Down Expand Up @@ -159,7 +159,7 @@ public NuageVspDeviceVO addNuageVspDevice(AddNuageVspDeviceCmd cmd) {
params.put("name", "Nuage VSD - " + cmd.getHostName());
params.put("hostname", cmd.getHostName());
params.put("cmsuser", cmd.getUserName());
String cmsUserPasswordBase64 = org.apache.commons.codec.binary.StringUtils.newStringUtf8(Base64.encodeBase64(cmd.getPassword().getBytes(Charset.forName("UTF-8"))));
String cmsUserPasswordBase64 = org.apache.commons.codec.binary.StringUtils.newStringUtf8(Base64.encodeBase64(cmd.getPassword().getBytes(StringUtils.getPreferredCharset())));
params.put("cmsuserpass", cmsUserPasswordBase64);
int port = cmd.getPort();
if (0 == port) {
Expand Down Expand Up @@ -301,6 +301,7 @@ private void initNuageScheduledTasks() {

if (numOfSyncThreads != null && syncUpIntervalInMinutes != null) {
ThreadFactory threadFactory = new ThreadFactory() {
@Override
public Thread newThread(Runnable runnable) {
Thread thread = new Thread(runnable, "Nuage Vsp sync task");
if (thread.isDaemon())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
package org.apache.cloudstack.saml;

import com.cloud.utils.HttpUtils;
import com.cloud.utils.StringUtils;

import org.apache.cloudstack.api.ApiConstants;
import org.apache.cloudstack.api.response.LoginCmdResponse;
import org.apache.log4j.Logger;
Expand Down Expand Up @@ -77,7 +79,6 @@
import java.io.UnsupportedEncodingException;
import java.math.BigInteger;
import java.net.URLEncoder;
import java.nio.charset.Charset;
import java.security.InvalidKeyException;
import java.security.KeyFactory;
import java.security.KeyPair;
Expand Down Expand Up @@ -219,7 +220,7 @@ public static String encodeSAMLRequest(XMLObject authnRequest)
Deflater deflater = new Deflater(Deflater.DEFLATED, true);
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
DeflaterOutputStream deflaterOutputStream = new DeflaterOutputStream(byteArrayOutputStream, deflater);
deflaterOutputStream.write(requestMessage.getBytes(Charset.forName("UTF-8")));
deflaterOutputStream.write(requestMessage.getBytes(StringUtils.getPreferredCharset()));
deflaterOutputStream.close();
String encodedRequestMessage = Base64.encodeBytes(byteArrayOutputStream.toByteArray(), Base64.DONT_BREAK_LINES);
encodedRequestMessage = URLEncoder.encode(encodedRequestMessage, HttpUtils.UTF_8).trim();
Expand Down Expand Up @@ -263,7 +264,7 @@ public static String generateSAMLRequestSignature(final String urlEncodedString,
String url = urlEncodedString + "&SigAlg=" + URLEncoder.encode(opensamlAlgoIdSignature, HttpUtils.UTF_8);
Signature signature = Signature.getInstance(javaSignatureAlgorithmName);
signature.initSign(signingKey);
signature.update(url.getBytes(Charset.forName("UTF-8")));
signature.update(url.getBytes(StringUtils.getPreferredCharset()));
String signatureString = Base64.encodeBytes(signature.sign(), Base64.DONT_BREAK_LINES);
if (signatureString != null) {
return url + "&Signature=" + URLEncoder.encode(signatureString, HttpUtils.UTF_8);
Expand All @@ -287,7 +288,7 @@ public static String savePublicKey(PublicKey key) {
KeyFactory keyFactory = SAMLUtils.getKeyFactory();
if (keyFactory == null) return null;
X509EncodedKeySpec spec = keyFactory.getKeySpec(key, X509EncodedKeySpec.class);
return new String(org.bouncycastle.util.encoders.Base64.encode(spec.getEncoded()), Charset.forName("UTF-8"));
return new String(org.bouncycastle.util.encoders.Base64.encode(spec.getEncoded()), StringUtils.getPreferredCharset());
} catch (InvalidKeySpecException e) {
s_logger.error("Unable to create KeyFactory:" + e.getMessage());
}
Expand All @@ -300,7 +301,7 @@ public static String savePrivateKey(PrivateKey key) {
if (keyFactory == null) return null;
PKCS8EncodedKeySpec spec = keyFactory.getKeySpec(key,
PKCS8EncodedKeySpec.class);
return new String(org.bouncycastle.util.encoders.Base64.encode(spec.getEncoded()), Charset.forName("UTF-8"));
return new String(org.bouncycastle.util.encoders.Base64.encode(spec.getEncoded()), StringUtils.getPreferredCharset());
} catch (InvalidKeySpecException e) {
s_logger.error("Unable to create KeyFactory:" + e.getMessage());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public static boolean compareBytes(byte[] b1, byte[] b2) {
}

public static boolean compareStrings(String s1, String s2) {
final Charset encoding = Charset.forName("UTF-8");
final Charset encoding = StringUtils.getPreferredCharset();
return compareBytes(s1.getBytes(encoding), s2.getBytes(encoding));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@
import java.io.IOException;
import java.io.InputStream;
import java.nio.ByteBuffer;
import java.nio.charset.Charset;

import org.junit.Before;
import org.junit.Test;

import com.cloud.utils.StringUtils;

public class QCOW2UtilsTest {

InputStream inputStream;
Expand Down Expand Up @@ -67,7 +67,7 @@ public void setup() {
ByteBuffer byteBuffer = ByteBuffer.allocate(72);

// Magic
byteBuffer.put("QFI".getBytes(Charset.forName("UTF-8")));
byteBuffer.put("QFI".getBytes(StringUtils.getPreferredCharset()));
byteBuffer.put((byte)0xfb);

// Version
Expand Down