Skip to content

Fix JavaStyle violations for Storage #593

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 10, 2019
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
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public List<UploadTask> getUploadTasksUnder(@NonNull StorageReference parent) {
String parentPath = parent.toString();
for (Map.Entry<String, WeakReference<StorageTask<?>>> entry : inProgressTasks.entrySet()) {
if (entry.getKey().startsWith(parentPath)) {
StorageTask task = entry.getValue().get();
StorageTask<?> task = entry.getValue().get();
if (task instanceof UploadTask) {
inProgressList.add((UploadTask) task);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

/** Helper for mocking sleep for exponential backoff. */
public class MockSleeperHelper implements Sleeper {
private MockClockHelper clock;
private final MockClockHelper clock;

public MockSleeperHelper(MockClockHelper clock) {
this.clock = clock;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public static Task<StringBuilder> testDownloadUrl(StorageReference ref) {
executor,
task -> {
builder.append("Received Download Url.\n");
builder.append("getDownloadUrl:").append(task.getResult().toString());
builder.append("getDownloadUrl:").append(task.getResult());
builder.append("\nonComplete:Success=\n").append(task.isSuccessful());
result.setResult(builder);
});
Expand Down Expand Up @@ -180,7 +180,7 @@ public static void dumpMetadata(final StringBuilder builder, @Nullable StorageMe
builder.append("getMD5Hash:").append(metadata.getMd5Hash()).append("\n");
builder.append("getGeneration:").append(metadata.getGeneration()).append("\n");
builder.append("getMetadataGeneration:").append(metadata.getMetadataGeneration()).append("\n");
builder.append("getSizeBytes:").append(Long.toString(metadata.getSizeBytes())).append("\n");
builder.append("getSizeBytes:").append(metadata.getSizeBytes()).append("\n");
builder.append("getReference:").append(metadata.getReference().getName()).append("\n");
SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy", Locale.getDefault());
sdf.setTimeZone(TimeZone.getTimeZone("America/Los_Angeles"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
@SuppressWarnings("unused")
public class TestDownloadHelper {
private static final String TAG = "TestDownloadHelper";
private static Bitmap mIcon;
private static byte[] mBytes;
private static Bitmap icon;
private static byte[] bytes;

public static class StreamDownloadResponse {
public StringBuilder mainTask = new StringBuilder();
Expand Down Expand Up @@ -59,8 +59,8 @@ public static Task<StreamDownloadResponse> streamDownload(
response.backgroundTask.append(statusMessage);

try {
mBytes = IOUtils.toByteArray(stream);
mIcon = BitmapFactory.decodeByteArray(mBytes, 0, mBytes.length);
bytes = IOUtils.toByteArray(stream);
icon = BitmapFactory.decodeByteArray(bytes, 0, bytes.length);
} catch (OutOfMemoryError e) {
Log.w(TAG, "Can't persist download due to low memory", e);
}
Expand All @@ -71,7 +71,7 @@ public static Task<StreamDownloadResponse> streamDownload(

if (state.getTotalByteCount() != -1) {
Preconditions.checkState(totalByteCountBeginning == state.getTotalByteCount());
Preconditions.checkState(mBytes.length == state.getTotalByteCount());
Preconditions.checkState(bytes.length == state.getTotalByteCount());
}
} finally {
// Closing stream
Expand Down Expand Up @@ -106,10 +106,10 @@ public static Task<StreamDownloadResponse> streamDownload(
Log.i(TAG, statusMessage);
response.mainTask.append(statusMessage);
if (imageCallback != null) {
imageCallback.run(mIcon);
imageCallback.run(icon);
}
if (byteCallback != null) {
byteCallback.run(mBytes);
byteCallback.run(bytes);
}
})
.addOnFailureListener(
Expand Down Expand Up @@ -219,7 +219,7 @@ public static Task<StringBuilder> fileDownload(
.addOnFailureListener(
e -> {
ControllableSchedulerHelper.getInstance().verifyCallbackThread();
String statusMessage = "\nonFailure:\n" + e.toString();
String statusMessage = "\nonFailure:\n" + e;
Log.i(TAG, statusMessage);
builder.append(statusMessage);
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ public static Task<StringBuilder> streamUploadWithInterruptions() {
* indicates end of stream.
*/
class WonkyStream extends InputStream {
private ArrayList<byte[]> streamData = new ArrayList<>();
private final ArrayList<byte[]> streamData = new ArrayList<>();

private WonkyStream() {
streamData.add(new byte[] {0, 1, 2});
Expand All @@ -319,17 +319,6 @@ public int read() {
}
}

private void removeData(int removeFirst) {
if (streamData.get(0).length == removeFirst) {
streamData.remove(0);
} else {
streamData.set(
0,
Arrays.copyOfRange(
streamData.get(0), removeFirst, streamData.get(0).length - removeFirst));
}
}

@Override
public int read(byte[] b, int off, int len) {
if (streamData.isEmpty()) {
Expand All @@ -342,6 +331,17 @@ public int read(byte[] b, int off, int len) {
}
}

private void removeData(int removeFirst) {
if (streamData.get(0).length == removeFirst) {
streamData.remove(0);
} else {
streamData.set(
0,
Arrays.copyOfRange(
streamData.get(0), removeFirst, streamData.get(0).length - removeFirst));
}
}

@Override
public int available() {
if (streamData.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public int read(byte[] b, int off, int len) throws IOException {
}

int bytesRead = inputStream.read(b, off, len);
currentOffset += bytesRead > 0 ? bytesRead : 0;
currentOffset += Math.max(bytesRead, 0);
return bytesRead;
}

Expand Down