Skip to content
Merged
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
3 changes: 2 additions & 1 deletion lib/src/main/java/io/ably/lib/http/Http.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.net.MalformedURLException;
import java.net.Proxy;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
Expand Down Expand Up @@ -121,7 +122,7 @@ public static class JSONRequestBody implements RequestBody {
public JSONRequestBody(Object ob) { this(Serialisation.gson.toJson(ob)); }

@Override
public byte[] getEncoded() { return (bytes != null) ? bytes : (bytes = jsonText.getBytes()); }
public byte[] getEncoded() { return (bytes != null) ? bytes : (bytes = jsonText.getBytes(StandardCharsets.UTF_8)); }
@Override
public String getContentType() { return JSON; }

Expand Down
5 changes: 3 additions & 2 deletions lib/src/main/java/io/ably/lib/rest/Auth.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.ably.lib.rest;

import java.nio.charset.StandardCharsets;
import java.security.GeneralSecurityException;
import java.util.ArrayList;
import java.util.Arrays;
Expand Down Expand Up @@ -740,8 +741,8 @@ public void onAuthError(ErrorInfo err) {
private static final String hmac(String text, String key) {
try {
Mac mac = Mac.getInstance("HmacSHA256");
mac.init(new SecretKeySpec(key.getBytes(), "HmacSHA256"));
return new String(Base64Coder.encode(mac.doFinal(text.getBytes())));
mac.init(new SecretKeySpec(key.getBytes(StandardCharsets.UTF_8), "HmacSHA256"));
return new String(Base64Coder.encode(mac.doFinal(text.getBytes(StandardCharsets.UTF_8))));
} catch (GeneralSecurityException e) { Log.e("Auth.hmac", "Unexpected exception", e); return null; }
}

Expand Down
3 changes: 2 additions & 1 deletion lib/src/main/java/io/ably/lib/types/ProtocolSerializer.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;

import org.msgpack.core.MessagePacker;
import org.msgpack.core.MessageUnpacker;
Expand Down Expand Up @@ -51,6 +52,6 @@ public static ProtocolMessage fromJSON(String packed) throws AblyException {
****************************************/

public static byte[] writeJSON(ProtocolMessage message) throws AblyException {
return Serialisation.gson.toJson(message).getBytes();
return Serialisation.gson.toJson(message).getBytes(StandardCharsets.UTF_8);
}
}
4 changes: 3 additions & 1 deletion lib/src/main/java/io/ably/lib/util/Base64Coder.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package io.ably.lib.util;

import java.nio.charset.StandardCharsets;

//Copyright 2003-2010 Christian d'Heureuse, Inventec Informatik AG, Zurich, Switzerland
//www.source-code.biz, www.inventec.ch/chdh
//
Expand Down Expand Up @@ -52,7 +54,7 @@ public class Base64Coder {
* @return A String containing the Base64 encoded data.
*/
public static String encodeString (String s) {
return new String(encode(s.getBytes())); }
return new String(encode(s.getBytes(StandardCharsets.UTF_8))); }

/**
* Encodes a byte array into Base 64 format and breaks the output into lines of 76 characters.
Expand Down