Skip to content

Commit

Permalink
Fixed lint about toUpperCase, and backported Arrays.copyOfRange(byte[…
Browse files Browse the repository at this point in the history
…],int,int) for API < 9
  • Loading branch information
smarek committed Dec 24, 2013
1 parent 835b5f5 commit 1292fef
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@

import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;

public abstract class DataAsyncHttpResponseHandler extends AsyncHttpResponseHandler {
private static final String LOG_TAG = "DataAsyncHttpResponseHandler";
Expand All @@ -42,8 +41,6 @@ public DataAsyncHttpResponseHandler() {

/**
* Fired when the request progress, override to handle in your own code
*
* @param responseBody
*/
public void onProgressData(byte[] responseBody) {
}
Expand All @@ -64,7 +61,7 @@ protected void handleMessage(Message message) {
response = (Object[]) message.obj;
if (response != null && response.length >= 1) {
try {
onProgressData((byte[])response[0]);
onProgressData((byte[]) response[0]);
} catch (Throwable t) {
Log.e(LOG_TAG, "custom onProgressData contains an error", t);
}
Expand Down Expand Up @@ -100,12 +97,11 @@ byte[] getResponseData(HttpEntity entity) throws IOException {
ByteArrayBuffer buffer = new ByteArrayBuffer((int) contentLength);
try {
byte[] tmp = new byte[BUFFER_SIZE];
int l, count = 0;
int l;
// do not send messages if request has been cancelled
while ((l = instream.read(tmp)) != -1 && !Thread.currentThread().isInterrupted()) {
count += l;
buffer.append(tmp, 0, l);
sendProgressDataMessage(Arrays.copyOfRange(tmp, 0, l));
sendProgressDataMessage(copyOfRange(tmp, 0, l));
}
} finally {
instream.close();
Expand All @@ -119,5 +115,35 @@ byte[] getResponseData(HttpEntity entity) throws IOException {
}
return responseBody;
}

/**
* Copies elements from {@code original} into a new array, from indexes start (inclusive) to end
* (exclusive). The original order of elements is preserved. If {@code end} is greater than
* {@code original.length}, the result is padded with the value {@code (byte) 0}.
*
* @param original the original array
* @param start the start index, inclusive
* @param end the end index, exclusive
* @return the new array
* @throws ArrayIndexOutOfBoundsException if {@code start < 0 || start > original.length}
* @throws IllegalArgumentException if {@code start > end}
* @throws NullPointerException if {@code original == null}
* @see java.util.Arrays
* @since 1.6
*/
public static byte[] copyOfRange(byte[] original, int start, int end) throws ArrayIndexOutOfBoundsException, IllegalArgumentException, NullPointerException {
if (start > end) {
throw new IllegalArgumentException();
}
int originalLength = original.length;
if (start < 0 || start > originalLength) {
throw new ArrayIndexOutOfBoundsException();
}
int resultLength = end - start;
int copyLength = Math.min(resultLength, originalLength - start);
byte[] result = new byte[resultLength];
System.arraycopy(original, start, result, 0, copyLength);
return result;
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import java.io.InputStream;
import java.io.OutputStream;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.zip.GZIPOutputStream;
Expand Down Expand Up @@ -297,7 +298,7 @@ static byte[] escape(String string) {
for (int zero = 0; zero < intLength; zero++) {
BUILDER.append('0');
}
BUILDER.append(intString.toUpperCase());
BUILDER.append(intString.toUpperCase(Locale.US));
} else {
BUILDER.append(ch);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Locale;
import java.util.concurrent.ConcurrentHashMap;

/**
Expand Down Expand Up @@ -201,7 +202,7 @@ protected String byteArrayToHexString(byte[] bytes) {
}
sb.append(Integer.toHexString(v));
}
return sb.toString().toUpperCase();
return sb.toString().toUpperCase(Locale.US);
}

/**
Expand Down

0 comments on commit 1292fef

Please sign in to comment.