use of java.io.InvalidObjectException in project Stringlate by LonamiWebs.
the class GitHub method canPush.
// Returns both the authenticated user and whether they have right to push
public static AbstractMap.SimpleImmutableEntry<String, Boolean> canPush(String token, RepoHandler repo) {
JSONObject user = getUserInfo(token);
if (user == null)
// TODO Actually, maybe throw an NoPermissionException or something
return new AbstractMap.SimpleImmutableEntry<>(null, false);
String username = "";
try {
username = user.getString("login");
JSONArray collaborators = getCollaborators(token, repo);
if (collaborators != null) {
for (int i = 0; i < collaborators.length(); i++) {
JSONObject collaborator = collaborators.getJSONObject(i);
if (collaborator.getString("login").equals(username)) {
JSONObject permissions = collaborator.getJSONObject("permissions");
// TODO Can someone possibly not have 'pull' permissions? Then what?
return new AbstractMap.SimpleImmutableEntry<>(username, permissions.getBoolean("push"));
}
}
}
// If we're not a collaborator, then we obviously don't have permission
return new AbstractMap.SimpleImmutableEntry<>(username, false);
} catch (JSONException | InvalidObjectException e) {
e.printStackTrace();
return new AbstractMap.SimpleImmutableEntry<>(username, false);
}
}
use of java.io.InvalidObjectException in project inbloom by EverythingMe.
the class BloomFilter method load.
public static BloomFilter load(byte[] bytes) throws InvalidObjectException {
ByteBuffer bb = ByteBuffer.wrap(bytes);
bb.order(ByteOrder.BIG_ENDIAN);
short checksum = bb.getShort();
short errorRate = bb.getShort();
int cardinality = bb.getInt();
final byte[] data = Arrays.copyOfRange(bytes, bb.position(), bytes.length);
if (computeChecksum(data) != checksum)
throw new InvalidObjectException("Bad checksum");
return new BloomFilter(data, cardinality, 1.0 / errorRate);
}
use of java.io.InvalidObjectException in project AndroidAsync by koush.
the class Converter method to.
private final synchronized <T> Future<T> to(Class fromClass, Class<T> clazz, String mime) {
if (TextUtils.isEmpty(mime))
mime = MIME_ALL;
if (outputs == null) {
outputs = new Converters<>();
ConverterEntries converters = getConverters();
for (ConverterEntry entry : converters.list) {
outputs.ensure(entry.from).put(entry.to, new MultiTransformer<>(entry.typeConverter, entry.to.mime, entry.distance));
}
}
MimedType<T> target = new MimedType<>(clazz, mime);
ArrayDeque<PathInfo> bestMatch = new ArrayDeque<>();
ArrayDeque<PathInfo> currentPath = new ArrayDeque<>();
if (search(target, bestMatch, currentPath, new MimedType(fromClass, futureMime), new HashSet<MimedType>())) {
PathInfo current = bestMatch.removeFirst();
new SimpleFuture<>(new MimedData<>((Future<Object>) future, futureMime)).setCallback(current.transformer);
while (!bestMatch.isEmpty()) {
PathInfo next = bestMatch.removeFirst();
current.transformer.setCallback(next.transformer);
current = next;
}
return ((MultiTransformer<T, Object>) current.transformer).then(from -> from.data);
}
return new SimpleFuture<>(new InvalidObjectException("unable to find converter"));
}
Aggregations