Search in sources :

Example 86 with InvalidObjectException

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);
    }
}
Also used : AbstractMap(java.util.AbstractMap) JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) InvalidObjectException(java.io.InvalidObjectException)

Example 87 with InvalidObjectException

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);
}
Also used : InvalidObjectException(java.io.InvalidObjectException) ByteBuffer(java.nio.ByteBuffer)

Example 88 with InvalidObjectException

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"));
}
Also used : ArrayDeque(java.util.ArrayDeque) JSONObject(org.json.JSONObject) InvalidObjectException(java.io.InvalidObjectException)

Aggregations

InvalidObjectException (java.io.InvalidObjectException)88 ObjectInputStream (java.io.ObjectInputStream)18 IOException (java.io.IOException)15 ByteArrayInputStream (java.io.ByteArrayInputStream)7 SmallTest (android.test.suitebuilder.annotation.SmallTest)5 Rational (android.util.Rational)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 GwtIncompatible (com.google.common.annotations.GwtIncompatible)4 ObjectOutputStream (java.io.ObjectOutputStream)4 SimpleTimeZone (java.util.SimpleTimeZone)3 TimeZone (java.util.TimeZone)3 GwtIncompatible (com.google_voltpatches.common.annotations.GwtIncompatible)2 Point (java.awt.Point)2 File (java.io.File)2 RemoteObjectInvocationHandler (java.rmi.server.RemoteObjectInvocationHandler)2 RemoteRef (java.rmi.server.RemoteRef)2 Comparator (java.util.Comparator)2 CompositeData (javax.management.openmbean.CompositeData)2 IgniteLogger (org.apache.ignite.IgniteLogger)2 JSONObject (org.json.JSONObject)2