1/*
2 * Copyright (C) 2017 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
17package com.android.layoutlib.bridge.intensive.util;
18
19import com.android.ide.common.rendering.api.AssetRepository;
20
21import java.io.File;
22import java.io.FileInputStream;
23import java.io.FileNotFoundException;
24import java.io.IOException;
25import java.io.InputStream;
26
27/**
28 * {@link AssetRepository} used for render tests.
29 */
30public class TestAssetRepository extends AssetRepository {
31    private static InputStream open(String path) throws FileNotFoundException {
32        File asset = new File(path);
33        if (asset.isFile()) {
34            return new FileInputStream(asset);
35        }
36
37        return null;
38    }
39
40    @Override
41    public boolean isSupported() {
42        return true;
43    }
44
45    @Override
46    public InputStream openAsset(String path, int mode) throws IOException {
47        return open(path);
48    }
49
50    @Override
51    public InputStream openNonAsset(int cookie, String path, int mode) throws IOException {
52        return open(path);
53    }
54}
55