use of java.util.Scanner in project platform_frameworks_base by android.
the class FontFamily_Delegate method setFontLocation.
public static synchronized void setFontLocation(String fontLocation) {
sFontLocation = fontLocation;
// init list of bundled fonts.
File allFonts = new File(fontLocation, FN_ALL_FONTS_LIST);
// Current number of fonts is 103. Use the next round number to leave scope for more fonts
// in the future.
Set<String> allFontsList = new HashSet<String>(128);
Scanner scanner = null;
try {
scanner = new Scanner(allFonts);
while (scanner.hasNext()) {
String name = scanner.next();
// Skip font configuration files.
if (!name.endsWith(".xml")) {
allFontsList.add(name);
}
}
} catch (FileNotFoundException e) {
Bridge.getLog().error(LayoutLog.TAG_BROKEN, "Unable to load the list of fonts. Try re-installing the SDK Platform from the SDK Manager.", e, null);
} finally {
if (scanner != null) {
scanner.close();
}
}
SDK_FONTS = Collections.unmodifiableSet(allFontsList);
for (FontFamily_Delegate fontFamily : sPostInitDelegate) {
fontFamily.init();
}
sPostInitDelegate.clear();
}
use of java.util.Scanner in project platform_frameworks_base by android.
the class MediaPlayer method addSubtitleSource.
/** @hide */
public void addSubtitleSource(InputStream is, MediaFormat format) throws IllegalStateException {
final InputStream fIs = is;
final MediaFormat fFormat = format;
if (is != null) {
// way to implement timeouts in the future.
synchronized (mOpenSubtitleSources) {
mOpenSubtitleSources.add(is);
}
} else {
Log.w(TAG, "addSubtitleSource called with null InputStream");
}
getMediaTimeProvider();
// process each subtitle in its own thread
final HandlerThread thread = new HandlerThread("SubtitleReadThread", Process.THREAD_PRIORITY_BACKGROUND + Process.THREAD_PRIORITY_MORE_FAVORABLE);
thread.start();
Handler handler = new Handler(thread.getLooper());
handler.post(new Runnable() {
private int addTrack() {
if (fIs == null || mSubtitleController == null) {
return MEDIA_INFO_UNSUPPORTED_SUBTITLE;
}
SubtitleTrack track = mSubtitleController.addTrack(fFormat);
if (track == null) {
return MEDIA_INFO_UNSUPPORTED_SUBTITLE;
}
// TODO: do the conversion in the subtitle track
Scanner scanner = new Scanner(fIs, "UTF-8");
String contents = scanner.useDelimiter("\\A").next();
synchronized (mOpenSubtitleSources) {
mOpenSubtitleSources.remove(fIs);
}
scanner.close();
synchronized (mIndexTrackPairs) {
mIndexTrackPairs.add(Pair.<Integer, SubtitleTrack>create(null, track));
}
Handler h = mTimeProvider.mEventHandler;
int what = TimeProvider.NOTIFY;
int arg1 = TimeProvider.NOTIFY_TRACK_DATA;
Pair<SubtitleTrack, byte[]> trackData = Pair.create(track, contents.getBytes());
Message m = h.obtainMessage(what, arg1, 0, trackData);
h.sendMessage(m);
return MEDIA_INFO_EXTERNAL_METADATA_UPDATE;
}
public void run() {
int res = addTrack();
if (mEventHandler != null) {
Message m = mEventHandler.obtainMessage(MEDIA_INFO, res, 0, null);
mEventHandler.sendMessage(m);
}
thread.getLooper().quitSafely();
}
});
}
use of java.util.Scanner in project android-maps-utils by googlemaps.
the class MyItemReader method read.
public List<MyItem> read(InputStream inputStream) throws JSONException {
List<MyItem> items = new ArrayList<MyItem>();
String json = new Scanner(inputStream).useDelimiter(REGEX_INPUT_BOUNDARY_BEGINNING).next();
JSONArray array = new JSONArray(json);
for (int i = 0; i < array.length(); i++) {
String title = null;
String snippet = null;
JSONObject object = array.getJSONObject(i);
double lat = object.getDouble("lat");
double lng = object.getDouble("lng");
if (!object.isNull("title")) {
title = object.getString("title");
}
if (!object.isNull("snippet")) {
snippet = object.getString("snippet");
}
items.add(new MyItem(lat, lng, title, snippet));
}
return items;
}
use of java.util.Scanner in project android-maps-utils by googlemaps.
the class HeatmapsDemoActivity method readItems.
// Datasets from http://data.gov.au
private ArrayList<LatLng> readItems(int resource) throws JSONException {
ArrayList<LatLng> list = new ArrayList<LatLng>();
InputStream inputStream = getResources().openRawResource(resource);
String json = new Scanner(inputStream).useDelimiter("\\A").next();
JSONArray array = new JSONArray(json);
for (int i = 0; i < array.length(); i++) {
JSONObject object = array.getJSONObject(i);
double lat = object.getDouble("lat");
double lng = object.getDouble("lng");
list.add(new LatLng(lat, lng));
}
return list;
}
use of java.util.Scanner in project languagetool by languagetool-org.
the class SynthesizerTools method loadWords.
public static List<String> loadWords(InputStream stream) {
List<String> result = new ArrayList<>();
try (Scanner scanner = new Scanner(stream, "UTF-8")) {
while (scanner.hasNextLine()) {
String line = scanner.nextLine().trim();
if (line.isEmpty() || line.charAt(0) == '#') {
// ignore empty lines and comments
continue;
}
result.add(line);
}
}
return result;
}
Aggregations