org.robolectric.res.Fs类的使用及代码示例

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

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

Fs介绍

暂无

代码示例

代码示例来源:origin: Karumi/Rosie

@Override
 protected AndroidManifest getAppManifest(Config config) {
  String manifestProperty = "../rosie/src/test/AndroidManifest.xml";
  String resProperty = "../rosie/src/main/res";
  return new AndroidManifest(Fs.fileFromPath(manifestProperty), Fs.fileFromPath(resProperty)) {
   @Override
   public int getTargetSdkVersion() {
    return MAX_SDK_SUPPORTED_BY_ROBOLECTRIC;
   }

  };
 }
}

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

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

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

FileTypedResource(Path path, ResType resType, XmlContext xmlContext) {
 super(Fs.externalize(path), resType, xmlContext);
 this.path = path;
}

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

public static FileSystem forJar(URL url) {
 return forJar(Paths.get(toUri(url)));
}

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

public static Asset newFileAsset(FileTypedResource fileTypedResource) throws IOException {
 _FileAsset fileAsset = new _FileAsset();
 Path path = fileTypedResource.getPath();
 fileAsset.mFileName = Fs.externalize(path);
 fileAsset.mLength = Files.size(path);
 fileAsset.mBuf = Fs.getBytes(path);
 return fileAsset;
}

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

private void listDrawableResources(Path dir, String type) throws IOException {
 Path[] files = Fs.listFiles(dir);
 if (files != null) {
  Qualifiers qualifiers;
    isNinePatch = true;
   } else {
    shortName = Fs.baseNameFor(f);
    isNinePatch = false;

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

private FsFile getFsFileFromProperty(String name) {
  String path = properties.getProperty(name);
  if (path == null || path.isEmpty()) {
   return null;
  }

  if (path.startsWith("jar")) {
   try {
    URL url = new URL(path);
    return Fs.fromURL(url);
   } catch (MalformedURLException e) {
    throw new RuntimeException(e);
   }
  } else {
   return Fs.fileFromPath(path);
  }
 }
}

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

public synchronized FsFile getCompileTimeSystemResourcesFile(DependencyResolver dependencyResolver) {
 if (compileTimeSystemResourcesFile == null) {
  DependencyJar compileTimeJar = new SdkConfig(27).getAndroidSdkDependency();
  compileTimeSystemResourcesFile =
    Fs.newFile(dependencyResolver.getLocalArtifactUrl(compileTimeJar).getFile());
 }
 return compileTimeSystemResourcesFile;
}

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

try {
  dependencyResolver = new PropertiesDependencyResolver(
    Fs.newFile(propPath),
    null);
 } catch (IOException e) {
Logger.info("Using Robolectric classes from %s", buildPathPropertiesUrl.getPath());
FsFile propertiesFile = Fs.fileFromPath(buildPathPropertiesUrl.getFile());
try {
 dependencyResolver = new PropertiesDependencyResolver(propertiesFile, dependencyResolver);

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

private static Path resourceFile(String... pathParts) {
 return Fs.join(resourcesBaseDir(), pathParts);
}

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

@Nonnull
private ResourcePath createRuntimeSdkResourcePath(DependencyResolver dependencyResolver) {
 try {
  Fs systemResFs = Fs.fromJar(dependencyResolver.getLocalArtifactUrl(sdkConfig.getAndroidSdkDependency()));
  Class<?> androidRClass = getRobolectricClassLoader().loadClass("android.R");
  Class<?> androidInternalRClass = getRobolectricClassLoader().loadClass("com.android.internal.R");
  // TODO: verify these can be loaded via raw-res path
  return new ResourcePath(androidRClass,
    systemResFs.join("raw-res/res"),
    systemResFs.join("raw-res/assets"),
    androidInternalRClass);
 } catch (ClassNotFoundException e) {
  throw new RuntimeException(e);
 }
}

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

private Properties loadProperties(Path propertiesFile) throws IOException {
 final Properties properties = new Properties();
 try (InputStream stream = Fs.getInputStream(propertiesFile)) {
  properties.load(stream);
 }
 return properties;
}

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

void findDrawableResources(ResourcePath resourcePath) throws IOException {
 Path[] files = Fs.listFiles(resourcePath.getResourceBase());
 if (files != null) {
  for (Path f : files) {
   if (Files.isDirectory(f) && f.getFileName().toString().startsWith("drawable")) {
    listDrawableResources(f, "drawable");
   } else if (Files.isDirectory(f) && f.getFileName().toString().startsWith("mipmap")) {
    listDrawableResources(f, "mipmap");
   }
  }
 }
}

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

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

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

@Override
Collection<Path> getAllAssetDirs() {
 ArrayList<Path> paths = new ArrayList<>();
 for (AssetPath assetPath : cppAssetManager.getAssetPaths()) {
  if (Files.isRegularFile(assetPath.file)) {
   paths.add(Fs.forJar(assetPath.file).getPath("assets"));
  } else {
   paths.add(assetPath.file);
  }
 }
 return paths;
}

代码示例来源:origin: org.robolectric/shadows-framework

@Override
Collection<FsFile> getAllAssetDirs() {
 ApkAssets[] apkAssetsArray = ReflectionHelpers.callInstanceMethod(realAssetManager, "getApkAssets");
 ArrayList<FsFile> fsFiles = new ArrayList<>();
 for (ApkAssets apkAssets : apkAssetsArray) {
  long apk_assets_native_ptr = ((ShadowArscApkAssets9) Shadow.extract(apkAssets)).getNativePtr();
  CppApkAssets cppApkAssets = Registries.NATIVE_APK_ASSETS_REGISTRY.getNativeObject(apk_assets_native_ptr);
  if (new File(cppApkAssets.GetPath()).isFile()) {
   fsFiles.add(Fs.newJarFile(new File(cppApkAssets.GetPath())).join("assets"));
  } else {
   fsFiles.add(Fs.newFile(cppApkAssets.GetPath()));
  }
 }
 return fsFiles;
}

代码示例来源:origin: org.robolectric/shadows-framework

private FsFile getFsFileFromPath(String property) {
 if (property.startsWith("jar")) {
  try {
   URL url = new URL(property);
   return Fs.fromURL(url);
  } catch (MalformedURLException e) {
   throw new RuntimeException(e);
  }
 } else {
  return Fs.fileFromPath(property);
 }
}

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

@Override
public TypedResource getValue(@Nonnull ResName resName, ResTable_config config) {
 System.out.println("getValue(" + resName + ", \"" + config + "\")");
 return new TypedResource<>(null, ResType.NULL,
   new XmlContext("", Fs.newFile("."), Qualifiers.parse("")));
}

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

private static Path resourceFile(String... pathParts) {
 return Fs.join(resourcesBaseDir(), pathParts);
}

代码示例来源:origin: org.robolectric/resources

public static FsFile fromURL(URL url) {
 switch (url.getProtocol()) {
  case "file":
   return new FileFsFile(new File(url.getPath()));
  case "jar":
   String[] parts = url.getPath().split("!", 0);
   try {
    Fs fs = fromJar(new URL(parts[0]));
    return fs.join(parts[1].substring(1));
   } catch (MalformedURLException e) {
    throw new IllegalArgumentException(e);
   }
  default:
   throw new IllegalArgumentException("unsupported fs type for '" + url + "'");
 }
}

相关文章