use of org.robolectric.res.FileTypedResource in project robolectric by robolectric.
the class ShadowAssetManager method openNonAsset.
@HiddenApi
@Implementation
public final InputStream openNonAsset(int cookie, String fileName, int accessMode) throws IOException {
final ResName resName = qualifyFromNonAssetFileName(fileName);
final FileTypedResource typedResource = (FileTypedResource) resourceTable.getValue(resName, RuntimeEnvironment.getQualifiers());
if (typedResource == null) {
throw new IOException("Unable to find resource for " + fileName);
}
if (accessMode == AssetManager.ACCESS_STREAMING) {
return typedResource.getFsFile().getInputStream();
} else {
return new ByteArrayInputStream(typedResource.getFsFile().getBytes());
}
}
use of org.robolectric.res.FileTypedResource in project robolectric by robolectric.
the class ShadowLegacyAssetManager method openNonAsset.
@HiddenApi
@Implementation
public final InputStream openNonAsset(int cookie, String fileName, int accessMode) throws IOException {
final ResName resName = qualifyFromNonAssetFileName(fileName);
final FileTypedResource typedResource = (FileTypedResource) getResourceTable().getValue(resName, config);
if (typedResource == null) {
throw new IOException("Unable to find resource for " + fileName);
}
InputStream stream;
if (accessMode == AssetManager.ACCESS_STREAMING) {
stream = Fs.getInputStream(typedResource.getPath());
} else {
stream = new ByteArrayInputStream(Fs.getBytes(typedResource.getPath()));
}
if (RuntimeEnvironment.getApiLevel() >= P) {
Asset asset = Asset.newFileAsset(typedResource);
long assetPtr = Registries.NATIVE_ASSET_REGISTRY.register(asset);
// Camouflage the InputStream as an AssetInputStream so subsequent instanceof checks pass.
stream = ShadowAssetInputStream.createAssetInputStream(stream, assetPtr, realObject);
}
return stream;
}
Aggregations