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

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

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

Fs.getInputStream介绍

暂无

代码示例

代码示例来源: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

public static byte[] getBytes(Path path) throws IOException {
 return Util.readBytes(getInputStream(path));
}

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

private static Properties getProperties(Path propertiesFile) {
 Properties properties = new Properties();
 // return an empty Properties object if the propertiesFile does not exist
 if (!Files.exists(propertiesFile)) return properties;
 InputStream stream;
 try {
  stream = Fs.getInputStream(propertiesFile);
 } catch (IOException e) {
  throw new RuntimeException(e);
 }
 try {
  try {
   properties.load(stream);
  } finally {
   stream.close();
  }
 } catch (IOException e) {
  throw new RuntimeException(e);
 }
 return properties;
}

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

private static synchronized Document parse(Path xmlFile) {
 InputStream inputStream = null;
 try {
  if (documentBuilder == null) {
   DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
   documentBuilderFactory.setNamespaceAware(true);
   documentBuilderFactory.setIgnoringComments(true);
   documentBuilderFactory.setIgnoringElementContentWhitespace(true);
   documentBuilder = documentBuilderFactory.newDocumentBuilder();
  }
  inputStream = Fs.getInputStream(xmlFile);
  return documentBuilder.parse(inputStream);
 } catch (ParserConfigurationException | IOException | SAXException e) {
  throw new RuntimeException(e);
 } finally {
  if (inputStream != null) try {
   inputStream.close();
  } catch (IOException e) {
   // ignore
  }
 }
}

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

@Override public InputStream getRawValue(ResName resName, ResTable_config config) {
 FileTypedResource fileTypedResource = getFileResource(resName, config);
 if (fileTypedResource == null) {
  return null;
 } else {
  Path file = fileTypedResource.getPath();
  try {
   return file == null ? null : Fs.getInputStream(file);
  } catch (IOException e) {
   throw new RuntimeException(e);
  }
 }
}

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

@Override
protected void loadResourceXmlFile(XmlContext xmlContext) {
 Path xmlFile = xmlContext.getXmlFile();
 XMLStreamReader xmlStreamReader;
 try {
  xmlStreamReader = factory.createXMLStreamReader(Fs.getInputStream(xmlFile));
  doParse(xmlStreamReader, xmlContext);
 } catch (Exception e) {
  throw new RuntimeException("error parsing " + xmlFile, e);
 }
 if (xmlStreamReader != null) {
  try {
   xmlStreamReader.close();
  } catch (XMLStreamException e) {
   throw new RuntimeException(e);
  }
 }
}

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

/**
 * Extract an asset from a zipped up assets provided by the build system, this is required because
 * there is no way to get a FileDescriptor from a zip entry. This is a temporary measure for Bazel
 * which can be removed once binary resources are supported.
 */
private static Path getFileFromZip(Path path) {
 byte[] buffer = new byte[1024];
 try {
  Path outputDir = new TempDirectory("robolectric_assets").create("fromzip");
  try (InputStream zis = Fs.getInputStream(path)) {
   Path fileFromZip = outputDir.resolve(path.getFileName().toString());
   try (OutputStream fos = Files.newOutputStream(fileFromZip)) {
    int len;
    while ((len = zis.read(buffer)) > 0) {
     fos.write(buffer, 0, len);
    }
   }
   return fileFromZip;
  }
 } catch (IOException e) {
  throw new RuntimeException(e);
 }
}

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

@Implementation
protected final InputStream open(String fileName, int accessMode) throws IOException {
 return Fs.getInputStream(findAssetFile(fileName));
}

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

@Implementation
protected final InputStream open(String fileName) throws IOException {
 return Fs.getInputStream(findAssetFile(fileName));
}

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

InputStream inputStream = Fs.getInputStream(androidManifestFile);
Document manifestDocument = db.parse(inputStream);
inputStream.close();

代码示例来源: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;
}

相关文章