aboutsummaryrefslogtreecommitdiff
path: root/tools/tradefed-host/src/com/android/afwtest/tradefed/utils/StreamDiscarder.java
diff options
context:
space:
mode:
authorkuantung <kuantung@google.com>2017-09-07 12:57:39 -0700
committerkuantung <kuantung@google.com>2017-09-07 12:57:39 -0700
commit5da3c14f79d42c132c3663775254cb0b2d111319 (patch)
tree646d291bb7cf65b95219d1037cc1ae2a084e9e2d /tools/tradefed-host/src/com/android/afwtest/tradefed/utils/StreamDiscarder.java
parent307c18ff4aa64197526f06cb1db3d756c389065b (diff)
parent2f6763757c432159b9e8668669b8b3cb14cff03d (diff)
downloadAfwTestHarness-oreo-dev.tar.gz
import history from sso://googleplex-android/platform/test/AfwTestHarness oc-dev b/65199386oreo-dev
Diffstat (limited to 'tools/tradefed-host/src/com/android/afwtest/tradefed/utils/StreamDiscarder.java')
-rw-r--r--tools/tradefed-host/src/com/android/afwtest/tradefed/utils/StreamDiscarder.java56
1 files changed, 56 insertions, 0 deletions
diff --git a/tools/tradefed-host/src/com/android/afwtest/tradefed/utils/StreamDiscarder.java b/tools/tradefed-host/src/com/android/afwtest/tradefed/utils/StreamDiscarder.java
new file mode 100644
index 0000000..dd4191c
--- /dev/null
+++ b/tools/tradefed-host/src/com/android/afwtest/tradefed/utils/StreamDiscarder.java
@@ -0,0 +1,56 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.afwtest.tradefed.utils;
+
+import com.android.tradefed.log.LogUtil.CLog;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+/**
+ * {@link Runnable} that reads and discards data from specified stream.
+ */
+public final class StreamDiscarder implements Runnable {
+
+ private static final int BATCH_SIZE = 1024;
+
+ private final InputStream mStream;
+ private final byte[] buffer;
+
+ /**
+ * Constructs {@link StreamDiscarder} instance.
+ *
+ * @param is {@link InputStream} to read and discard data from.
+ */
+ public StreamDiscarder(InputStream is) {
+ mStream = is;
+ buffer = new byte[BATCH_SIZE];
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ @SuppressWarnings("StatementWithEmptyBody")
+ public void run() {
+ try {
+ while (!Thread.interrupted() && mStream.read(buffer) > 0) {}
+ } catch (IOException e) {
+ CLog.e(e);
+ }
+ }
+}