Created
July 8, 2012 22:25
-
-
Save phl0w/3073165 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private final Pattern AUTHORIZATION_PATTERN = Pattern.compile("authorized\\s*=\\s*([0-9.]+)"); | |
| private boolean isAuthorized(String url) { | |
| try { | |
| int userId = Environment.getUserId(); | |
| String authorized = ""; | |
| URL site = new URL(url); | |
| BufferedReader in = new BufferedReader(new InputStreamReader(site.openStream())); | |
| String line; | |
| Matcher m; | |
| while ((line = in.readLine()) != null) { | |
| if ((m = AUTHORIZATION_PATTERN.matcher(line)).find()) { | |
| authorized = m.group(1); | |
| break; | |
| } | |
| } | |
| for (String s : authorized.split(", ")) { | |
| if (Integer.parseInt(s) == userId) { | |
| return true; | |
| } | |
| } | |
| in.close(); | |
| } catch (Exception e) { | |
| e.printStackTrace(); | |
| } | |
| return false; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment