private Properties loadProperties(FsFile propertiesFile) throws IOException { final Properties properties = new Properties(); InputStream stream = propertiesFile.getInputStream(); properties.load(stream); stream.close(); return properties; }
private static Properties getProperties(FsFile propertiesFile) { Properties properties = new Properties(); // return an empty Properties object if the propertiesFile does not exist if (!propertiesFile.exists()) return properties; InputStream stream; try { stream = propertiesFile.getInputStream(); } catch (IOException e) { throw new RuntimeException(e); } try { try { properties.load(stream); } finally { stream.close(); } } catch (IOException e) { throw new RuntimeException(e); } return properties; }
private synchronized static Document parse(FsFile 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 = xmlFile.getInputStream(); return documentBuilder.parse(inputStream); } catch (ParserConfigurationException | IOException | SAXException e) { throw new RuntimeException(e); } finally { if (inputStream != null) try { inputStream.close(); } catch (IOException e) { throw new RuntimeException(e); } } }
private synchronized static Document parse(FsFile 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 = xmlFile.getInputStream(); return documentBuilder.parse(inputStream); } catch (ParserConfigurationException | IOException | SAXException e) { throw new RuntimeException(e); } finally { if (inputStream != null) try { inputStream.close(); } catch (IOException e) { // ignore } } }
public InputStream getRawValue(ResName resName, String qualifiers) { FileTypedResource typedResource = (FileTypedResource) resources.get(resName, qualifiers); FsFile file = typedResource == null ? null : typedResource.getFsFile(); try { return file == null ? null : file.getInputStream(); } catch (IOException e) { throw new RuntimeException(e); } }
@Override public InputStream getRawValue(ResName resName, ResTable_config config) { FileTypedResource fileTypedResource = getFileResource(resName, config); if (fileTypedResource == null) { return null; } else { FsFile file = fileTypedResource.getFsFile(); try { return file == null ? null : file.getInputStream(); } catch (IOException e) { throw new RuntimeException(e); } } }
@Override protected void loadResourceXmlFile(XmlContext xmlContext) { FsFile xmlFile = xmlContext.getXmlFile(); XMLStreamReader xmlStreamReader = null; try { xmlStreamReader = factory.createXMLStreamReader(xmlFile.getInputStream()); 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); } } }
@Override protected void loadResourceXmlFile(XmlContext xmlContext) { FsFile xmlFile = xmlContext.getXmlFile(); XMLStreamReader xmlStreamReader; try { xmlStreamReader = factory.createXMLStreamReader(xmlFile.getInputStream()); 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); } } }
@Implementation protected final InputStream open(String fileName) throws IOException { return findAssetFile(fileName).getInputStream(); }
@Implementation protected final InputStream open(String fileName, int accessMode) throws IOException { return findAssetFile(fileName).getInputStream(); }
@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()); } }
@HiddenApi @Implementation public final InputStream openNonAsset(int cookie, String fileName, int accessMode) throws IOException { final ResName resName = qualifyFromNonAssetFileName(fileName); final FileTypedResource typedResource = (FileTypedResource) resourceLoader.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()); } }
@Implementation public final InputStream open(String fileName, int accessMode) throws IOException { return ShadowApplication.getInstance().getAppManifest().getAssetsDirectory().join(fileName).getInputStream(); }
@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()); } }
@Implementation public final InputStream open(String fileName) throws IOException { return ShadowApplication.getInstance().getAppManifest().getAssetsDirectory().join(fileName).getInputStream(); }
@Implementation public final InputStream open(String fileName) throws IOException { return ShadowApplication.getInstance().getAppManifest().getAssetsDirectory().join(fileName).getInputStream(); }
@Implementation public final InputStream open(String fileName, int accessMode) throws IOException { return ShadowApplication.getInstance().getAppManifest().getAssetsDirectory().join(fileName).getInputStream(); }
@Implementation public final InputStream open(String fileName) throws IOException { return ShadowApplication.getInstance().getAppManifest().getAssetsDirectory().join(fileName).getInputStream(); }
@Implementation public final InputStream open(String fileName, int accessMode) throws IOException { return ShadowApplication.getInstance().getAppManifest().getAssetsDirectory().join(fileName).getInputStream(); }
@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 = typedResource.getFsFile().getInputStream(); } else { stream = new ByteArrayInputStream(typedResource.getFsFile().getBytes()); } 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; }