List of usage examples for android.content.res AssetManager ACCESS_STREAMING
int ACCESS_STREAMING
To view the source code for android.content.res AssetManager ACCESS_STREAMING.
Click Source Link
From source file:Main.java
public static String readFromAsstes(Context context, String fileName) { AssetManager assetManager = context.getAssets(); ByteArrayOutputStream bos = null; InputStream inputStream = null; String result = null;//from ww w . j a v a2s. c o m try { inputStream = assetManager.open(fileName, AssetManager.ACCESS_STREAMING); bos = new ByteArrayOutputStream(); byte[] data = new byte[1024]; int length; while ((length = inputStream.read(data)) != -1) { bos.write(data, 0, length); } result = bos.toString().replaceAll("\\s*", ""); } catch (IOException ioe) { ioe.printStackTrace(); } finally { try { if (bos != null) bos.close(); if (inputStream != null) inputStream.close(); } catch (IOException ignored) { } } return result; }
From source file:ca.uqac.florentinth.speakerauthentication.Utils.JSONUtils.java
public static String parseJSONFile(Context ctx, String file) { String json = null;/*from w w w.j a va 2 s . co m*/ try { InputStream inputStream = ctx.getAssets().open(file, AssetManager.ACCESS_STREAMING); int size = inputStream.available(); byte[] buffer = new byte[size]; inputStream.read(buffer); inputStream.close(); json = new String(buffer, "UTF-8"); } catch (IOException e) { e.printStackTrace(); } return json; }
From source file:Main.java
public static void copyAssetFile(AssetManager am, String assetName, File destBaseDir, boolean overwrite) throws IOException { File destFile = new File(destBaseDir.getAbsolutePath().concat(File.separator).concat(assetName)); if (destFile.exists() && !overwrite) return;/*from w w w.j a v a 2 s . c o m*/ if (overwrite) { destFile.delete(); } destFile.getParentFile().mkdirs(); InputStream is = null; OutputStream os = null; try { byte[] buff = new byte[4096]; is = am.open(assetName, AssetManager.ACCESS_STREAMING); os = new FileOutputStream(destFile); while (true) { int nread = is.read(buff); if (nread <= 0) break; os.write(buff, 0, nread); } } finally { closeQuietly(is); closeQuietly(os); } }
From source file:at.bitfire.ical4android.EventTest.java
public void testCalendarProperties() throws IOException, InvalidCalendarException { @Cleanup//from w w w. j a va2 s . c o m InputStream is = assetMgr.open("events/multiple.ics", AssetManager.ACCESS_STREAMING); Map<String, String> properties = new HashMap<>(); Event[] events = Event.fromStream(is, null, properties); assertEquals(1, properties.size()); assertEquals("Test-Kalender", properties.get(Event.CALENDAR_NAME)); }
From source file:com.granita.icloudcalsync.resource.ContactTest.java
public void testReferenceVCard() throws IOException, InvalidResourceException { Contact c = parseVCF("reference.vcf"); assertEquals("Gump", c.getFamilyName()); assertEquals("Forrest", c.getGivenName()); assertEquals("Forrest Gump", c.getDisplayName()); assertEquals("Bubba Gump Shrimp Co.", c.getOrganization().getValues().get(0)); assertEquals("Shrimp Man", c.getJobTitle()); Telephone phone1 = c.getPhoneNumbers().get(0); assertEquals("(111) 555-1212", phone1.getText()); assertEquals("WORK", phone1.getParameters("TYPE").get(0)); assertEquals("VOICE", phone1.getParameters("TYPE").get(1)); Telephone phone2 = c.getPhoneNumbers().get(1); assertEquals("(404) 555-1212", phone2.getText()); assertEquals("HOME", phone2.getParameters("TYPE").get(0)); assertEquals("VOICE", phone2.getParameters("TYPE").get(1)); Email email = c.getEmails().get(0);/*from ww w .ja v a 2 s . co m*/ assertEquals("forrestgump@example.com", email.getValue()); assertEquals("PREF", email.getParameters("TYPE").get(0)); assertEquals("INTERNET", email.getParameters("TYPE").get(1)); @Cleanup InputStream photoStream = assetMgr.open("davdroid-logo-192.png", AssetManager.ACCESS_STREAMING); byte[] expectedPhoto = IOUtils.toByteArray(photoStream); assertTrue(Arrays.equals(c.getPhoto(), expectedPhoto)); }
From source file:at.bitfire.davdroid.resource.ContactTest.java
public void testReferenceVCard3() throws IOException, InvalidResourceException { Contact c = parseVCF("reference-vcard3.vcf", Charset.forName(CharEncoding.UTF_8)); assertEquals("Gmp", c.familyName); assertEquals("Frrest", c.givenName); assertEquals("Frrest Gmp", c.displayName); assertEquals("Bubba Gump Shrimp Co.", c.organization.getValues().get(0)); assertEquals("Shrimp Man", c.jobTitle); Telephone phone1 = c.getPhoneNumbers().get(0); assertEquals("(111) 555-1212", phone1.getText()); assertEquals("WORK", phone1.getParameters("TYPE").get(0)); assertEquals("VOICE", phone1.getParameters("TYPE").get(1)); Telephone phone2 = c.getPhoneNumbers().get(1); assertEquals("(404) 555-1212", phone2.getText()); assertEquals("HOME", phone2.getParameters("TYPE").get(0)); assertEquals("VOICE", phone2.getParameters("TYPE").get(1)); Email email = c.getEmails().get(0);//w ww . j av a2 s. c om assertEquals("forrestgump@example.com", email.getValue()); assertEquals("PREF", email.getParameters("TYPE").get(0)); assertEquals("INTERNET", email.getParameters("TYPE").get(1)); @Cleanup InputStream photoStream = assetMgr.open("davdroid-logo-192.png", AssetManager.ACCESS_STREAMING); byte[] expectedPhoto = IOUtils.toByteArray(photoStream); assertTrue(Arrays.equals(c.photo, expectedPhoto)); }
From source file:com.limitfan.gojuuon.utils.ScreenSlidePageFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout containing a title and body text. ViewGroup rootView = (ViewGroup) inflater.inflate(com.limitfan.gojuuon.R.layout.detail_slide_page, container, false);/* w w w .java 2 s . c om*/ ImageView stroke = (ImageView) (rootView.findViewById(com.limitfan.gojuuon.R.id.stroke)); String romaji = Common.roma[getPageNumber()]; try { String img = ""; if (ActKana.isHira) img = "kanagraph/hiragana_" + romaji + ".jpg"; else img = "kanagraph/katakana_" + romaji + ".jpg"; InputStream is = getContext().getAssets().open(img, AssetManager.ACCESS_STREAMING); Bitmap bm = BitmapFactory.decodeStream(is); stroke.setImageBitmap(bm); } catch (Exception e) { } ViewGroup listView = (ViewGroup) rootView.findViewById(com.limitfan.gojuuon.R.id.list); ViewGroup demo_speak = (ViewGroup) inflater.inflate(com.limitfan.gojuuon.R.layout.demo_list_item, null); ((TextView) demo_speak.findViewById(com.limitfan.gojuuon.R.id.text)) .setText(com.limitfan.gojuuon.R.string.demo); ((ImageView) demo_speak.findViewById(com.limitfan.gojuuon.R.id.icon)) .setImageResource(com.limitfan.gojuuon.R.drawable.speak_off); listView.addView(demo_speak); TextView sample = (TextView) (rootView.findViewById(com.limitfan.gojuuon.R.id.sample)); setSample(sample); demo_speak.setOnClickListener(new SpeakListener()); //stroke.setImageResource(); // Set the title view to show the page number. //EditText main = ((EditText) rootView.findViewById(R.id.Description)); // main.setText(getString(R.string.title_template_step, mPageNumber + 1)); //main.setEnabled(false); // main.setBackgroundColor(Color.TRANSPARENT); // main.setText(getFromAssets("details/"+(mPageNumber+1)+".txt")); return rootView; }
From source file:at.bitfire.ical4android.EventTest.java
public void testGrouping() throws IOException, InvalidCalendarException { @Cleanup// w w w. j ava 2 s . c o m InputStream is = assetMgr.open("events/multiple.ics", AssetManager.ACCESS_STREAMING); Event[] events = Event.fromStream(is, null); assertEquals(3, events.length); Event e = findEvent(events, "multiple-0@ical4android.EventTest"); assertEquals("Event 0", e.summary); assertEquals(0, e.getExceptions().size()); e = findEvent(events, "multiple-1@ical4android.EventTest"); assertEquals("Event 1", e.summary); assertEquals(1, e.getExceptions().size()); assertEquals("Event 1 Exception", e.getExceptions().get(0).summary); e = findEvent(events, "multiple-2@ical4android.EventTest"); assertEquals("Event 2", e.summary); assertEquals(2, e.getExceptions().size()); assertTrue("Event 2 Updated Exception 1".equals(e.getExceptions().get(0).summary) || "Event 2 Updated Exception 1".equals(e.getExceptions().get(1).summary)); assertTrue("Event 2 Exception 2".equals(e.getExceptions().get(0).summary) || "Event 2 Exception 2".equals(e.getExceptions().get(1).summary)); }
From source file:com.granita.icloudcalsync.resource.ContactTest.java
protected Contact parseVCF(String fname) throws IOException, InvalidResourceException { @Cleanup//w ww . jav a2s.c om InputStream in = assetMgr.open(fname, AssetManager.ACCESS_STREAMING); Contact c = new Contact(fname, null); c.parseEntity(in, new Resource.AssetDownloader() { @Override public byte[] download(URI uri) throws URISyntaxException, IOException, HttpException, DavException { return IOUtils.toByteArray(uri); } }); return c; }
From source file:at.bitfire.davdroid.resource.ContactTest.java
protected Contact parseVCF(String fname, Charset charset) throws IOException { @Cleanup/*from www .j a v a 2 s . c o m*/ InputStream in = assetMgr.open(fname, AssetManager.ACCESS_STREAMING); Contact c = new Contact(fname, null); c.parseEntity(in, charset, new Resource.AssetDownloader() { @Override public byte[] download(URI uri) throws URISyntaxException, IOException, HttpException, DavException { return IOUtils.toByteArray(uri); } }); return c; }