Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1233)

Unified Diff: android_webview/java/src/org/chromium/android_webview/InputStreamUtil.java

Issue 430443003: Use unchecked InputStream methods in the android_webview. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: remove old InputStream jni Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | android_webview/javatests/src/org/chromium/android_webview/test/AwContentsClientShouldInterceptRequestTest.java » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: android_webview/java/src/org/chromium/android_webview/InputStreamUtil.java
diff --git a/android_webview/java/src/org/chromium/android_webview/InputStreamUtil.java b/android_webview/java/src/org/chromium/android_webview/InputStreamUtil.java
new file mode 100644
index 0000000000000000000000000000000000000000..d4fb7493d1f726fddbbc5559d58d626a3ed0ca60
--- /dev/null
+++ b/android_webview/java/src/org/chromium/android_webview/InputStreamUtil.java
@@ -0,0 +1,70 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package org.chromium.android_webview;
+
+import android.util.Log;
+
+import org.chromium.base.CalledByNative;
+import org.chromium.base.JNINamespace;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+/**
+ * Utility methods for calling InputStream methods. These take care of exception handling.
+ */
+@JNINamespace("android_webview")
+class InputStreamUtil {
+ private static final String LOGTAG = "AwAssets";
+ // The InputStream APIs return -1 in some cases. In order to convey the extra information that
+ // the call had failed due to an exception being thrown we simply map all negative return values
+ // from the original calls to -1 and make -2 mean that an exception has been thrown.
+ private static final int CALL_FAILED_STATUS = -1;
+ private static final int EXCEPTION_THROWN_STATUS = -2;
+
+ private static String logMessage(String method) {
+ return "Got exception when calling " + method + "() on an InputStream returned from " +
+ "shouldInterceptRequest. This will cause the related request to fail.";
+ }
+
+ @CalledByNative
+ public static void close(InputStream stream) {
+ try {
+ stream.close();
+ } catch (IOException e) {
+ Log.e(LOGTAG, logMessage("close"), e);
+ }
+ }
+
+ @CalledByNative
+ public static int available(InputStream stream) {
+ try {
+ return Math.max(CALL_FAILED_STATUS, stream.available());
+ } catch (IOException e) {
+ Log.e(LOGTAG, logMessage("available"), e);
+ return EXCEPTION_THROWN_STATUS;
+ }
+ }
+
+ @CalledByNative
+ public static int read(InputStream stream, byte[] b, int off, int len) {
+ try {
+ return Math.max(CALL_FAILED_STATUS, stream.read(b, off, len));
+ } catch (IOException e) {
+ Log.e(LOGTAG, logMessage("read"), e);
+ return EXCEPTION_THROWN_STATUS;
+ }
+ }
+
+ @CalledByNative
+ public static long skip(InputStream stream, long n) {
+ try {
+ return Math.max(CALL_FAILED_STATUS, stream.skip(n));
+ } catch (IOException e) {
+ Log.e(LOGTAG, logMessage("skip"), e);
+ return EXCEPTION_THROWN_STATUS;
+ }
+ }
+}
« no previous file with comments | « no previous file | android_webview/javatests/src/org/chromium/android_webview/test/AwContentsClientShouldInterceptRequestTest.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698