Search in sources :

Example 36 with Scanner

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();
}
Also used : Scanner(java.util.Scanner) FileNotFoundException(java.io.FileNotFoundException) File(java.io.File) HashSet(java.util.HashSet)

Example 37 with Scanner

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();
        }
    });
}
Also used : MediaFormat(android.media.MediaFormat) Scanner(java.util.Scanner) HandlerThread(android.os.HandlerThread) Message(android.os.Message) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) Runnable(java.lang.Runnable) Handler(android.os.Handler) Pair(android.util.Pair)

Example 38 with Scanner

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;
}
Also used : Scanner(java.util.Scanner) JSONObject(org.json.JSONObject) ArrayList(java.util.ArrayList) JSONArray(org.json.JSONArray) MyItem(com.google.maps.android.utils.demo.model.MyItem)

Example 39 with Scanner

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;
}
Also used : Scanner(java.util.Scanner) JSONObject(org.json.JSONObject) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) JSONArray(org.json.JSONArray) LatLng(com.google.android.gms.maps.model.LatLng)

Example 40 with Scanner

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;
}
Also used : Scanner(java.util.Scanner) ArrayList(java.util.ArrayList)

Aggregations

Scanner (java.util.Scanner)862 File (java.io.File)135 ArrayList (java.util.ArrayList)77 IOException (java.io.IOException)72 Test (org.junit.Test)70 NoSuchElementException (java.util.NoSuchElementException)59 InputStream (java.io.InputStream)54 ServiceBuilder (com.github.scribejava.core.builder.ServiceBuilder)49 OAuthRequest (com.github.scribejava.core.model.OAuthRequest)49 Response (com.github.scribejava.core.model.Response)49 FileNotFoundException (java.io.FileNotFoundException)47 InputMismatchException (java.util.InputMismatchException)47 HashMap (java.util.HashMap)35 FileInputStream (java.io.FileInputStream)33 OAuth20Service (com.github.scribejava.core.oauth.OAuth20Service)31 OAuth2AccessToken (com.github.scribejava.core.model.OAuth2AccessToken)29 Locale (java.util.Locale)24 BigInteger (java.math.BigInteger)23 List (java.util.List)22 OAuth1AccessToken (com.github.scribejava.core.model.OAuth1AccessToken)18