summaryrefslogtreecommitdiff
path: root/common/testutils/devicetests/com/android/testutils/async/ReadableDataAnswer.java
diff options
context:
space:
mode:
Diffstat (limited to 'common/testutils/devicetests/com/android/testutils/async/ReadableDataAnswer.java')
-rw-r--r--common/testutils/devicetests/com/android/testutils/async/ReadableDataAnswer.java76
1 files changed, 0 insertions, 76 deletions
diff --git a/common/testutils/devicetests/com/android/testutils/async/ReadableDataAnswer.java b/common/testutils/devicetests/com/android/testutils/async/ReadableDataAnswer.java
deleted file mode 100644
index 4bf55270..00000000
--- a/common/testutils/devicetests/com/android/testutils/async/ReadableDataAnswer.java
+++ /dev/null
@@ -1,76 +0,0 @@
-/*
- * Copyright (C) 2023 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.testutils.async;
-
-import org.mockito.invocation.InvocationOnMock;
-import org.mockito.stubbing.Answer;
-
-import java.util.ArrayList;
-
-public class ReadableDataAnswer implements Answer {
- private final ArrayList<byte[]> mBuffers = new ArrayList<>();
- private int mBufferPos;
-
- public ReadableDataAnswer(byte[] ... buffers) {
- for (byte[] buffer : buffers) {
- addBuffer(buffer);
- }
- }
-
- public void addBuffer(byte[] buffer) {
- if (buffer.length != 0) {
- mBuffers.add(buffer);
- }
- }
-
- public int getRemainingSize() {
- int totalSize = 0;
- for (byte[] buffer : mBuffers) {
- totalSize += buffer.length;
- }
- return totalSize - mBufferPos;
- }
-
- private void cleanupBuffers() {
- if (!mBuffers.isEmpty() && mBufferPos == mBuffers.get(0).length) {
- mBuffers.remove(0);
- mBufferPos = 0;
- }
- }
-
- @Override
- public Object answer(InvocationOnMock invocation) throws Throwable {
- cleanupBuffers();
-
- if (mBuffers.isEmpty()) {
- return Integer.valueOf(0);
- }
-
- byte[] src = mBuffers.get(0);
-
- byte[] dst = invocation.<byte[]>getArgument(0);
- int dstPos = invocation.<Integer>getArgument(1);
- int dstLen = invocation.<Integer>getArgument(2);
-
- int copyLen = Math.min(dstLen, src.length - mBufferPos);
- System.arraycopy(src, mBufferPos, dst, dstPos, copyLen);
- mBufferPos += copyLen;
-
- cleanupBuffers();
- return Integer.valueOf(copyLen);
- }
-}