Skip to content

Instantly share code, notes, and snippets.

@phl0w
Created July 8, 2012 22:25
Show Gist options
  • Select an option

  • Save phl0w/3073165 to your computer and use it in GitHub Desktop.

Select an option

Save phl0w/3073165 to your computer and use it in GitHub Desktop.
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