/** @deprecated Use {@link #fromUrl(String)} instead. */ @Deprecated public static Path fileFromPath(String path) { return Fs.fromUrl(path); }
public XmlResourceParserImpl( Document document, Path fileName, String packageName, String applicationPackageName, ResourceTable resourceTable) { this.document = document; this.fileName = fileName; this.packageName = packageName; this.resourceTable = resourceTable; this.applicationNamespace = ANDROID_RES_NS_PREFIX + applicationPackageName; }
private Path getFileFromProperty(String propertyName) { String path = properties.getProperty(propertyName); if (path == null || path.isEmpty()) { return null; } return Fs.fromUrl(path); } }
private Path getResource(String pathStr) { URL manifestUrl = getClass().getClassLoader().getResource(pathStr); if (manifestUrl == null) { throw new IllegalArgumentException("couldn't find '" + pathStr + "'"); } else { return Fs.fromUrl(manifestUrl); } }
/** * Use this method instead of {@link Paths#get(String, String...)} or {@link Paths#get(URI)}. * * <p>Supports "file:path", "jar:file:jarfile.jar!/path", and plain old paths. * * <p>For JAR files, automatically open and cache filesystems. */ public static Path fromUrl(String urlString) { if (urlString.startsWith("file:") || urlString.startsWith("jar:")) { URL url; try { url = new URL(urlString); } catch (MalformedURLException e) { throw new RuntimeException("Failed to resolve path from " + urlString, e); } return fromUrl(url); } else { return Paths.get(urlString); } }
@Nonnull private List<Path> getDirectoriesFromProperty(String property) { if (property == null) { return Collections.emptyList(); } List<String> dirs; if (property.startsWith("@")) { String filename = property.substring(1); try { dirs = Arrays.asList( new String(Util.readBytes(new FileInputStream(filename)), UTF_8).split("\\n")); } catch (IOException e) { throw new RuntimeException("Cannot read file " + filename); } } else { dirs = Arrays.asList(property.split(File.pathSeparator)); } List<Path> files = new ArrayList<>(); for (String dir : dirs) { files.add(Fs.fromUrl(dir)); } return files; } }
@HiddenApi @Implementation public int addAssetPath(String path) { assetDirs.add(Fs.fromUrl(path)); return 1; }
public List<AssetPath> getAssetPaths() { synchronized (mLock) { ArrayList<AssetPath> assetPaths = new ArrayList<>(mAssetPaths.size()); for (asset_path asset_path : mAssetPaths) { Path path; switch (asset_path.type) { case kFileTypeDirectory: path = Fs.fromUrl(asset_path.path.string()); break; case kFileTypeRegular: path = Fs.fromUrl(asset_path.path.string()); break; default: throw new IllegalStateException("Unsupported type " + asset_path.type + " for + " + asset_path.path.string()); } assetPaths.add(new AssetPath(path, asset_path.isSystemAsset)); } return assetPaths; } } }
public List<AssetPath> getAssetPaths() { ArrayList<AssetPath> assetPaths = new ArrayList<>(apk_assets_.size()); for (CppApkAssets apkAssets : apk_assets_) { Path path = Fs.fromUrl(apkAssets.GetPath()); assetPaths.add(new AssetPath(path, apkAssets.GetLoadedArsc().IsSystem())); } return assetPaths; }
@HiddenApi @Implementation(minSdk = P) public void setApkAssets(Object apkAssetsObject, Object invalidateCachesObject) { ApkAssets[] apkAssets = (ApkAssets[]) apkAssetsObject; boolean invalidateCaches = (boolean) invalidateCachesObject; for (ApkAssets apkAsset : apkAssets) { assetDirs.add(Fs.fromUrl(apkAsset.getAssetPath())); } directlyOn(realObject, AssetManager.class).setApkAssets(apkAssets, invalidateCaches); }
@Implementation protected final XmlResourceParser openXmlResourceParser(int cookie, String fileName) throws IOException { XmlBlock xmlBlock = XmlBlock.create(Fs.fromUrl(fileName), resourceTable.getPackageName()); if (xmlBlock == null) { throw new Resources.NotFoundException(fileName); } return getXmlResourceParser(resourceTable, xmlBlock, resourceTable.getPackageName()); }
ManifestIdentifier manifestIdentifier = manifestFactory.identify(config); URL expectedUrl = getClass().getClassLoader().getResource("TestAndroidManifest.xml"); assertThat(manifestIdentifier.getManifestFile()).isEqualTo(Fs.fromUrl(expectedUrl)); assertThat(manifestIdentifier.getResDir()).isEqualTo(Paths.get("/path/to/merged-resources")); assertThat(manifestIdentifier.getAssetDir()).isEqualTo(Paths.get("/path/to/merged-assets"));