try { Resources res = getResources(); InputStream in_s = res.openRawResource(R.raw.help); byte[] b = new byte[in_s.available()]; in_s.read(b); txtHelp.setText(new String(b)); } catch (Exception e) { // e.printStackTrace(); txtHelp.setText("Error: can't show help."); }
/** * Creates a new KmlLayer object - addLayerToMap() must be called to trigger rendering onto a map. * * @param map GoogleMap object * @param resourceId Raw resource KML file * @param context Context object * @throws XmlPullParserException if file cannot be parsed */ public KmlLayer(GoogleMap map, int resourceId, Context context) throws XmlPullParserException, IOException { this(map, context.getResources().openRawResource(resourceId), context); }
@Override public InputStream getInputStream(@NonNull Context context) { return context.getResources().openRawResource(rawRes); } }
/** * Retrieves {@link InputStream} of image by URI (image is located in drawable resources of application). * * @param imageUri Image URI * @param extra Auxiliary object which was passed to {@link DisplayImageOptions.Builder#extraForDownloader(Object) * DisplayImageOptions.extraForDownloader(Object)}; can be null * @return {@link InputStream} of image */ protected InputStream getStreamFromDrawable(String imageUri, Object extra) { String drawableIdString = Scheme.DRAWABLE.crop(imageUri); int drawableId = Integer.parseInt(drawableIdString); return context.getResources().openRawResource(drawableId); }
private byte[] getCanonicalBytes() throws IOException { int resourceId = ResourceIds.raw.canonical; Resources resources = context.getResources(); InputStream is = resources.openRawResource(resourceId); return ByteStreams.toByteArray(is); } }
private byte[] loadVideoBytes() throws IOException { Resources resources = context.getResources(); InputStream is = resources.openRawResource(ResourceIds.raw.video); return ByteStreams.toByteArray(is); } }
private void copyImageToMemory(File outFile) { try { BufferedOutputStream os = new BufferedOutputStream( new FileOutputStream(outFile)); BufferedInputStream is = new BufferedInputStream(getResources() .openRawResource(R.raw.painter)); copy(is, os); } catch (FileNotFoundException e) { Log.e(TAG, "FileNotFoundException"); } }
@SuppressLint("ResourceType") @Override public InputStream getStream(String imageUri, Object extra) throws IOException { if (isDownloadingThumbnail()) { return super.getStream(imageUri, extra); } else { return resources.openRawResource(R.drawable.dummy_thumbnail_dark); } }
private byte[] getBytes(int resourceId) { ByteArrayOutputStream os = new ByteArrayOutputStream(); InputStream is = null; try { is = context.getResources().openRawResource(resourceId); byte[] buffer = new byte[1024 * 1024]; int read; while ((read = is.read(buffer)) != -1) { os.write(buffer, 0, read); } } catch (IOException e) { throw new RuntimeException(e); } finally { if (is != null) { try { is.close(); } catch (IOException e) { // Ignored; } } } return os.toByteArray(); }
/** * Parse an animation from raw/res. This is recommended over putting your animation in assets because * it uses a hard reference to R. * The resource id will be used as a cache key so future usages won't parse the json again. */ @WorkerThread public static LottieResult<LottieComposition> fromRawResSync(Context context, @RawRes int rawRes) { try { return fromJsonInputStreamSync(context.getResources().openRawResource(rawRes), rawResCacheKey(rawRes)); } catch (Resources.NotFoundException e) { return new LottieResult<>(e); } }
private static InputStream getImageInputStream() { return ApplicationProvider.getApplicationContext() .getResources() .openRawResource(R.drawable.robolectric); }
private InputStream getData() { InputStream is = null; try { is = context.getResources().openRawResource(ResourceIds.raw.canonical); byte[] buffer = new byte[1024 * 1024]; ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); int read; while ((read = is.read(buffer)) != -1) { outputStream.write(buffer, 0, read); } byte[] data = outputStream.toByteArray(); return new ByteArrayInputStream(data); } catch (IOException e) { throw new RuntimeException(e); } finally { if (is != null) { try { is.close(); } catch (IOException e) { // Ignored. } } } } }
@Implementation protected static Bitmap decodeResource(Resources res, int id, BitmapFactory.Options options) { if (id == 0) { return null; } final TypedValue value = new TypedValue(); InputStream is = res.openRawResource(id, value); Point imageSizeFromStream = getImageSizeFromStream(is); Bitmap bitmap = create("resource:" + res.getResourceName(id), options, imageSizeFromStream); ShadowBitmap shadowBitmap = Shadow.extract(bitmap); shadowBitmap.createdFromResId = id; return bitmap; }
@Test @Config(qualifiers = "fr") public void openRawResource_shouldLoadDrawableWithQualifiers() throws Exception { InputStream resourceStream = resources.openRawResource(R.drawable.an_image); Bitmap bitmap = BitmapFactory.decodeStream(resourceStream); assertThat(bitmap.getHeight()).isEqualTo(100); assertThat(bitmap.getWidth()).isEqualTo(100); }
@Test public void openRawResource_shouldLoadDrawables() throws Exception { InputStream resourceStream = resources.openRawResource(R.drawable.an_image); Bitmap bitmap = BitmapFactory.decodeStream(resourceStream); assertThat(bitmap.getHeight()).isEqualTo(53); assertThat(bitmap.getWidth()).isEqualTo(64); }
private void readItems() throws JSONException { InputStream inputStream = getResources().openRawResource(R.raw.radar_search); List<MyItem> items = new MyItemReader().read(inputStream); mClusterManager.addItems(items); } }
@Test public void openRawResource_shouldLoadRawResources() throws Exception { InputStream resourceStream = resources.openRawResource(R.raw.raw_resource); assertThat(resourceStream).isNotNull(); // assertThat(TestUtil.readString(resourceStream)).isEqualTo("raw txt file contents"); }
@Implementation protected InputStream openRawResource(int id) throws Resources.NotFoundException { if (isLegacyAssetManager()) { ShadowLegacyAssetManager shadowAssetManager = legacyShadowOf(realResources.getAssets()); ResourceTable resourceTable = shadowAssetManager.getResourceTable(); InputStream inputStream = resourceTable.getRawValue(id, shadowAssetManager.config); if (inputStream == null) { throw newNotFoundException(id); } else { return inputStream; } } else { return directlyOn(realResources, Resources.class).openRawResource(id); } }
public XmlPullParser createParser(int res) throws Exception { InputStream stream = getInstrumentation().getContext().getResources().openRawResource(res); XmlPullParserFactory factory = XmlPullParserFactory.newInstance(); factory.setNamespaceAware(true); XmlPullParser parser = factory.newPullParser(); parser.setInput(stream, null); parser.next(); return parser; }
public XmlPullParser createParser(int res) throws Exception { InputStream stream = getInstrumentation().getContext().getResources().openRawResource(res); XmlPullParserFactory factory = XmlPullParserFactory.newInstance(); factory.setNamespaceAware(true); XmlPullParser parser = factory.newPullParser(); parser.setInput(stream, null); parser.next(); return parser; }