Skip to content

Commit f522c8c

Browse files
author
Amir Tocker
committed
Merge branch 'master' into fix/upload-large-url
2 parents 349a27f + 920cfbb commit f522c8c

File tree

8 files changed

+100
-16
lines changed

8 files changed

+100
-16
lines changed

cloudinary-android/src/main/java/com/cloudinary/android/UploaderStrategy.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,10 @@ public void totalBytesLoaded(long bytes) {
115115
String responseData = readFully(responseStream);
116116
connection.disconnect();
117117

118+
try {
119+
responseStream.close();
120+
} catch (Exception e) {}
121+
118122
if (code != 200 && code != 400 && code != 404 && code != 500) {
119123
throw new RuntimeException("Server returned unexpected status code - " + code + " - " + responseData);
120124
}

cloudinary-core/src/main/java/com/cloudinary/AuthToken.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
import javax.crypto.Mac;
77
import javax.crypto.spec.SecretKeySpec;
8-
import javax.xml.bind.DatatypeConverter;
98
import java.io.UnsupportedEncodingException;
109
import java.net.URLEncoder;
1110
import java.security.InvalidKeyException;
@@ -230,13 +229,13 @@ public AuthToken merge(AuthToken other) {
230229
}
231230

232231
private String digest(String message) {
233-
byte[] binKey = DatatypeConverter.parseHexBinary(key);
232+
byte[] binKey = StringUtils.hexStringToByteArray(key);
234233
try {
235234
Mac hmac = Mac.getInstance("HmacSHA256");
236235
SecretKeySpec secret = new SecretKeySpec(binKey, "HmacSHA256");
237236
hmac.init(secret);
238237
final byte[] bytes = message.getBytes();
239-
return DatatypeConverter.printHexBinary(hmac.doFinal(bytes)).toLowerCase();
238+
return StringUtils.encodeHexString(hmac.doFinal(bytes)).toLowerCase();
240239
} catch (NoSuchAlgorithmException e) {
241240
throw new RuntimeException("Cannot create authorization token.", e);
242241
} catch (InvalidKeyException e) {

cloudinary-core/src/main/java/com/cloudinary/utils/StringUtils.java

Lines changed: 83 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@
99
public class StringUtils {
1010
public static final String EMPTY = "";
1111

12+
/**
13+
* Join a list of Strings
14+
* @param list strings to join
15+
* @param separator the separator to insert between the strings
16+
* @return a string made of the strings in list separated by separator
17+
*/
1218
public static String join(List<String> list, String separator) {
1319
if (list == null) {
1420
return null;
@@ -17,21 +23,40 @@ public static String join(List<String> list, String separator) {
1723
return join(list.toArray(), separator, 0, list.size());
1824
}
1925

26+
/**
27+
* Join a array of Strings
28+
* @param array strings to join
29+
* @param separator the separator to insert between the strings
30+
* @return a string made of the strings in array separated by separator
31+
*/
2032
public static String join(Object[] array, String separator) {
2133
if (array == null) {
2234
return null;
2335
}
2436
return join(array, separator, 0, array.length);
2537
}
2638

39+
/**
40+
* Join a collection of Strings
41+
* @param collection strings to join
42+
* @param separator the separator to insert between the strings
43+
* @return a string made of the strings in collection separated by separator
44+
*/
2745
public static String join(Collection<String> collection, String separator) {
2846
if (collection == null) {
2947
return null;
3048
}
31-
3249
return join(collection.toArray(new String[collection.size()]), separator, 0, collection.size());
3350
}
3451

52+
/**
53+
* Join a array of Strings from startIndex to endIndex
54+
* @param array strings to join
55+
* @param separator the separator to insert between the strings
56+
* @param startIndex the string to start from
57+
* @param endIndex the last string to join
58+
* @return a string made of the strings in array separated by separator
59+
*/
3560
public static String join(final Object[] array, String separator, final int startIndex, final int endIndex) {
3661
if (array == null) {
3762
return null;
@@ -60,6 +85,11 @@ public static String join(final Object[] array, String separator, final int star
6085

6186
final protected static char[] hexArray = "0123456789abcdef".toCharArray();
6287

88+
/**
89+
* Convert an array of bytes to a string of hex values
90+
* @param bytes bytes to convert
91+
* @return a string of hex values.
92+
*/
6393
public static String encodeHexString(byte[] bytes) {
6494
char[] hexChars = new char[bytes.length * 2];
6595
for (int j = 0; j < bytes.length; j++) {
@@ -70,39 +100,86 @@ public static String encodeHexString(byte[] bytes) {
70100
return new String(hexChars);
71101
}
72102

103+
/**
104+
* Convert a string of hex values to an array of bytes
105+
* @param s a string of two digit Hex numbers. The length of string to parse must be even.
106+
* @return bytes representation of the string
107+
*/
108+
public static byte[] hexStringToByteArray(String s) {
109+
int len = s.length();
110+
byte[] data = new byte[len / 2];
111+
112+
if (len % 2 != 0) {
113+
throw new IllegalArgumentException("Length of string to parse must be even.");
114+
}
115+
116+
for (int i = 0; i < len; i += 2) {
117+
data[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) << 4) + Character.digit(s.charAt(i + 1), 16));
118+
}
119+
120+
return data;
121+
}
122+
123+
/**
124+
* {@see HtmlEscape.escapeHtml}
125+
*/
73126
public static String escapeHtml(String input) {
74127
return HtmlEscape.escapeTextArea(input);
75128
}
76129

130+
/**
131+
* Verify that the input has non whitespace characters in it
132+
* @param input a String-like object
133+
* @return true if input has non whitespace characters in it
134+
*/
77135
public static boolean isNotBlank(Object input) {
78136
if (input == null) return false;
79137
return !isBlank(input.toString());
80138
}
81139

140+
/**
141+
* Verify that the input has non whitespace characters in it
142+
* @param input a String
143+
* @return true if input has non whitespace characters in it
144+
*/
82145
public static boolean isNotBlank(String input) {
83146
return !isBlank(input);
84147
}
85148

149+
/**
150+
* Verify that the input has no characters
151+
* @param input a string
152+
* @return true if input is null or has no characters
153+
*/
86154
public static boolean isEmpty(String input) {
87-
if (input == null || input.length() == 0) {
88-
return true;
89-
}
90-
return false;
155+
return input == null || input.length() == 0;
91156
}
92157

158+
/**
159+
* Verify that the input is an empty string or contains only whitespace characters.<br>
160+
* {@see Character.isWhitespace}
161+
* @param input a string
162+
* @return true if input is an empty string or contains only whitespace characters
163+
*/
93164
public static boolean isBlank(String input) {
94165
int strLen;
95166
if (input == null || (strLen = input.length()) == 0) {
96167
return true;
97168
}
98169
for (int i = 0; i < strLen; i++) {
99-
if (Character.isWhitespace(input.charAt(i)) == false) {
170+
if (!Character.isWhitespace(input.charAt(i))) {
100171
return false;
101172
}
102173
}
103174
return true;
104175
}
105176

177+
/**
178+
* Read the entire input stream in 1KB chunks
179+
* @param in input stream to read from
180+
* @return a String generated from the input stream
181+
* @throws IOException thrown by the input stream
182+
*/
106183
public static String read(InputStream in) throws IOException {
107184
ByteArrayOutputStream baos = new ByteArrayOutputStream();
108185
byte[] buffer = new byte[1024];

gradle/wrapper/gradle-wrapper.jar

504 Bytes
Binary file not shown.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#Mon Jun 12 09:17:06 IDT 2017
1+
#Tue Jul 18 12:33:44 IDT 2017
22
distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-3.4-all.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-4.0.1-all.zip

gradlew

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ DEFAULT_JVM_OPTS=""
3333
# Use the maximum available, or set MAX_FD != -1 to use that value.
3434
MAX_FD="maximum"
3535

36-
warn ( ) {
36+
warn () {
3737
echo "$*"
3838
}
3939

40-
die ( ) {
40+
die () {
4141
echo
4242
echo "$*"
4343
echo
@@ -155,7 +155,7 @@ if $cygwin ; then
155155
fi
156156

157157
# Escape application args
158-
save ( ) {
158+
save () {
159159
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
160160
echo " "
161161
}

java_shared.gradle

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ tasks.withType(JavaCompile) {
66
options.encoding = 'UTF-8'
77
}
88

9+
javadoc {
10+
options.encoding = 'UTF-8'
11+
}
12+
913
test {
1014
testLogging.showStandardStreams = true
1115
testLogging.exceptionFormat = 'full'

samples/photo_album/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@
2323
<dependency>
2424
<groupId>com.cloudinary</groupId>
2525
<artifactId>cloudinary-taglib</artifactId>
26-
<version>1.2.2-SNAPSHOT</version>
26+
<version>1.13.0</version>
2727
</dependency>
2828
<dependency>
2929
<groupId>com.cloudinary</groupId>
3030
<artifactId>cloudinary-http44</artifactId>
31-
<version>1.2.2-SNAPSHOT</version>
31+
<version>1.13.0</version>
3232
</dependency>
3333
<dependency>
3434
<groupId>org.springframework</groupId>

0 commit comments

Comments
 (0)