Commit 161901cd authored by Andrew Grieve's avatar Andrew Grieve Committed by Commit Bot

Revert "Android: Add FileUtils.copyStream() and FileUtils.readStream()"

This reverts MinidumpUploadCallable.java in 398ed50f.

Reason for revert: Breaking crash uploads

Original change's description:
> Android: Add FileUtils.copyStream() and FileUtils.readStream()
>
> And also make use of existing FileUtils functions in a couple
> spots. This is mostly a no-behavior-change clean-up.
>
> Behavior changes:
> * Also removes a useless Trace event from ResourceExtractor.
> * FileUtils.recursivelyDeleteFile() now succeeds if the file
>   didn't exist to start with and has a return value.
> * MinidumpUploadCallable now makes an extra copy of the response
>   data (choosing code simplicity of performance for crash logic).
>
> Change-Id: I367d385e397f48d40ff0a7f9a01e2d661a7def64
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1604187
> Commit-Queue: Andrew Grieve <agrieve@chromium.org>
> Reviewed-by: Ted Choc <tedchoc@chromium.org>
> Reviewed-by: Richard Coles <torne@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#659827}

TBR=torne@chromium.org,tedchoc@chromium.org,agrieve@chromium.org
Bug: 964334

Change-Id: I73a23d193f093d6afaef1c8abed4b8904e2b5b52
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1617549
Commit-Queue: Andrew Grieve <agrieve@chromium.org>
Reviewed-by: default avatarAndrew Grieve <agrieve@chromium.org>
Cr-Commit-Position: refs/heads/master@{#660861}
parent 7966dd42
......@@ -8,7 +8,6 @@ import android.content.SharedPreferences;
import android.support.annotation.IntDef;
import org.chromium.base.ContextUtils;
import org.chromium.base.FileUtils;
import org.chromium.base.Log;
import org.chromium.base.StreamUtil;
import org.chromium.base.VisibleForTesting;
......@@ -17,11 +16,14 @@ import org.chromium.components.minidump_uploader.util.HttpURLConnectionFactory;
import org.chromium.components.minidump_uploader.util.HttpURLConnectionFactoryImpl;
import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.net.HttpURLConnection;
......@@ -117,8 +119,7 @@ public class MinidumpUploadCallable implements Callable<Integer> {
return MinidumpUploadStatus.FAILURE;
}
minidumpInputStream = new FileInputStream(mFileToUpload);
FileUtils.copyStream(
minidumpInputStream, new GZIPOutputStream(connection.getOutputStream()));
streamCopy(minidumpInputStream, new GZIPOutputStream(connection.getOutputStream()));
boolean success = handleExecutionResponse(connection);
return success ? MinidumpUploadStatus.SUCCESS : MinidumpUploadStatus.FAILURE;
......@@ -126,11 +127,14 @@ public class MinidumpUploadCallable implements Callable<Integer> {
// ArrayIndexOutOfBoundsException due to bad GZIPOutputStream implementation on some
// old sony devices.
// For now just log the stack trace.
Log.w(TAG, "Error while uploading %s", mFileToUpload.getName(), e);
Log.w(TAG, "Error while uploading " + mFileToUpload.getName(), e);
return MinidumpUploadStatus.FAILURE;
} finally {
connection.disconnect();
StreamUtil.closeQuietly(minidumpInputStream);
if (minidumpInputStream != null) {
StreamUtil.closeQuietly(minidumpInputStream);
}
}
}
......@@ -170,9 +174,9 @@ public class MinidumpUploadCallable implements Callable<Integer> {
if (isSuccessful(responseCode)) {
String responseContent = getResponseContentAsString(connection);
// The crash server returns the crash ID.
String uploadId = responseContent.isEmpty() ? "unknown" : responseContent;
String uploadId = responseContent != null ? responseContent : "unknown";
String crashFileName = mFileToUpload.getName();
Log.i(TAG, "Minidump %s uploaded successfully, id: %s", crashFileName, uploadId);
Log.i(TAG, "Minidump " + crashFileName + " uploaded successfully, id: " + uploadId);
// TODO(acleung): MinidumpUploadService is in charge of renaming while this class is
// in charge of deleting. We should move all the file system operations into
......@@ -280,8 +284,33 @@ public class MinidumpUploadCallable implements Callable<Integer> {
*/
private static String getResponseContentAsString(HttpURLConnection connection)
throws IOException {
byte[] bytes = FileUtils.readStream(connection.getInputStream());
return new String(bytes);
String responseContent = null;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
streamCopy(connection.getInputStream(), baos);
if (baos.size() > 0) {
responseContent = baos.toString();
}
return responseContent;
}
/**
* Copies all available data from |inStream| to |outStream|. Closes both
* streams when done.
*
* @param inStream the stream to read
* @param outStream the stream to write to
* @throws IOException
*/
private static void streamCopy(InputStream inStream, OutputStream outStream)
throws IOException {
byte[] temp = new byte[4096];
int bytesRead = inStream.read(temp);
while (bytesRead >= 0) {
outStream.write(temp, 0, bytesRead);
bytesRead = inStream.read(temp);
}
inStream.close();
outStream.close();
}
// TODO(gayane): Remove this function and unused prefs in M51. crbug.com/555022
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment