org.robolectric.res.Fs.fromUrl()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(4.8k)|赞(0)|评价(0)|浏览(107)

本文整理了Java中org.robolectric.res.Fs.fromUrl()方法的一些代码示例,展示了Fs.fromUrl()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Fs.fromUrl()方法的具体详情如下:
包路径:org.robolectric.res.Fs
类名称:Fs
方法名:fromUrl

Fs.fromUrl介绍

[英]Isn't this what Paths#get(URI) should do?
[中]

代码示例

代码示例来源:origin: robolectric/robolectric

/** @deprecated Use {@link #fromUrl(String)} instead. */
@Deprecated
public static Path fileFromPath(String path) {
 return Fs.fromUrl(path);
}

代码示例来源:origin: robolectric/robolectric

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;
}

代码示例来源:origin: robolectric/robolectric

private Path getFileFromProperty(String propertyName) {
  String path = properties.getProperty(propertyName);
  if (path == null || path.isEmpty()) {
   return null;
  }

  return Fs.fromUrl(path);
 }
}

代码示例来源:origin: robolectric/robolectric

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);
 }
}

代码示例来源:origin: robolectric/robolectric

/**
 * 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);
 }
}

代码示例来源:origin: robolectric/robolectric

@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;
 }
}

代码示例来源:origin: robolectric/robolectric

@HiddenApi @Implementation
public int addAssetPath(String path) {
 assetDirs.add(Fs.fromUrl(path));
 return 1;
}

代码示例来源:origin: robolectric/robolectric

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;
  }
 }
}

代码示例来源:origin: robolectric/robolectric

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;
}

代码示例来源:origin: robolectric/robolectric

@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);
}

代码示例来源:origin: robolectric/robolectric

@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());
}

代码示例来源:origin: robolectric/robolectric

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"));

相关文章