1 /* 2 * Copyright (C) 2024 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package android.aconfig.storage.test; 18 19 import java.io.FileInputStream; 20 import java.io.InputStream; 21 import java.nio.ByteBuffer; 22 23 public final class TestDataUtils { 24 private static final String TEST_PACKAGE_MAP_PATH = "mock.v%d.package.map"; 25 private static final String TEST_FLAG_MAP_PATH = "mock.v%d.flag.map"; 26 private static final String TEST_FLAG_VAL_PATH = "mock.v%d.val"; 27 private static final String TEST_FLAG_INFO_PATH = "mock.v%d.info"; 28 29 public static final String TESTDATA_PATH = "/data/local/tmp/aconfig_storage_file_test_java/testdata/"; 30 getTestPackageMapByteBuffer(int version)31 public static ByteBuffer getTestPackageMapByteBuffer(int version) throws Exception { 32 return readFile(TESTDATA_PATH + String.format(TEST_PACKAGE_MAP_PATH, version)); 33 } 34 getTestFlagMapByteBuffer(int version)35 public static ByteBuffer getTestFlagMapByteBuffer(int version) throws Exception { 36 return readFile(TESTDATA_PATH + String.format(TEST_FLAG_MAP_PATH, version)); 37 } 38 getTestFlagValByteBuffer(int version)39 public static ByteBuffer getTestFlagValByteBuffer(int version) throws Exception { 40 return readFile(TESTDATA_PATH + String.format(TEST_FLAG_VAL_PATH, version)); 41 } 42 getTestFlagInfoByteBuffer(int version)43 public static ByteBuffer getTestFlagInfoByteBuffer(int version) throws Exception { 44 return readFile(TESTDATA_PATH + String.format(TEST_FLAG_INFO_PATH, version)); 45 } 46 readFile(String fileName)47 private static ByteBuffer readFile(String fileName) throws Exception { 48 InputStream input = new FileInputStream(fileName); 49 return ByteBuffer.wrap(input.readAllBytes()); 50 } 51 } 52