Example usage for java.lang Error Error

List of usage examples for java.lang Error Error

Introduction

In this page you can find the example usage for java.lang Error Error.

Prototype

public Error(Throwable cause) 

Source Link

Document

Constructs a new error with the specified cause and a detail message of (cause==null ?

Usage

From source file:edu.cornell.mannlib.vitro.webapp.edit.n3editing.processEdit.RdfLiteralHash.java

/**
 * Make a hash based on individual, property, literal and (lang or datatype).
 * /*  w w w  .  j a v  a 2  s . c o m*/
 * @param stmt
 * @return a value between MIN_INTEGER and MAX_INTEGER 
 */
public static int makeRdfLiteralHash(DataPropertyStatement stmt) {
    if ((stmt.getLanguage() != null && stmt.getLanguage().trim().length() > 0)
            && (stmt.getDatatypeURI() != null && stmt.getDatatypeURI().trim().length() > 0))
        throw new Error("DataPropertyStatement should not have both a language " + "and a datatype; lang: '"
                + stmt.getLanguage() + "' datatype: '" + stmt.getDatatypeURI() + "'");

    if (stmt.getIndividualURI() == null || stmt.getIndividualURI().trim().length() == 0)
        throw new Error("Cannot make a hash for a statement with no subject URI");

    if (stmt.getDatapropURI() == null || stmt.getDatapropURI().trim().length() == 0)
        throw new Error("Cannot make a hash for a statement with no predicate URI");

    String langOrDatatype = "9876NONE";
    if (stmt.getLanguage() != null && stmt.getLanguage().trim().length() > 0) {
        langOrDatatype = stmt.getLanguage();
    } else {
        if (stmt.getDatatypeURI() != null && stmt.getDatatypeURI().trim().length() > 0) {
            langOrDatatype = stmt.getDatatypeURI();
        }
    }

    String hashMe = langOrDatatype + "_" + stmt.getIndividualURI() + "_" + stmt.getDatapropURI() + "_"
            + stmt.getData();
    if (log.isDebugEnabled())
        log.debug("got hash " + hashMe.hashCode() + " for String '" + hashMe + "'");
    return hashMe.hashCode();
}

From source file:hudson.util.Protector.java

public static String protect(String secret) {
    try {/* ww  w.  j  av  a2  s .  c  o  m*/
        Cipher cipher = Secret.getCipher(ALGORITHM);
        cipher.init(Cipher.ENCRYPT_MODE, DES_KEY);
        return new String(Base64.encodeBase64(cipher.doFinal((secret + MAGIC).getBytes("UTF-8"))));
    } catch (GeneralSecurityException e) {
        throw new Error(e); // impossible
    } catch (UnsupportedEncodingException e) {
        throw new Error(e); // impossible
    }
}

From source file:Main.java

public static void xmlToStreamE(Node n, OutputStream os) {
    try {//w w  w. ja  v  a  2  s.  c o  m
        Source source = new DOMSource(n);

        //  PrintWriter pr = new PrintWriter(new OutputStreamWriter(os,StandardCharsets.UTF_8),true);
        Result result = new StreamResult(os);//pr);
        Transformer transformer = TransformerFactory.newInstance().newTransformer();
        transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
        transformer.transform(source, result);
    } catch (IllegalArgumentException | TransformerException e) {
        throw new Error(e);
    }
}

From source file:Main.java

/**
 * Compute the HMAC with SHA-256 of data, as defined in
 * http://tools.ietf.org/html/rfc2104#section-2 .
 * @param key The key byte array.//from   w w w .  j  av  a  2s. c  o  m
 * @param data The input byte buffer. This does not change the position.
 * @return The HMAC result.
 */
public static byte[] computeHmacWithSha256(byte[] key, ByteBuffer data) {
    final String algorithm = "HmacSHA256";
    Mac mac;
    try {
        mac = Mac.getInstance(algorithm);
    } catch (NoSuchAlgorithmException ex) {
        // Don't expect this to happen.
        throw new Error("computeHmac: " + algorithm + " is not supported: " + ex.getMessage());
    }

    try {
        mac.init(new SecretKeySpec(key, algorithm));
    } catch (InvalidKeyException ex) {
        // Don't expect this to happen.
        throw new Error("computeHmac: Can't init " + algorithm + " with key: " + ex.getMessage());
    }
    int savePosition = data.position();
    mac.update(data);
    data.position(savePosition);
    return mac.doFinal();
}

From source file:com.eviware.soapui.plugins.PluginProxies.java

private static Method getObjectEqualsMethod() {
    try {/*from ww w  . ja  v a2  s . c  o m*/
        return Object.class.getMethod("equals", Object.class);
    } catch (NoSuchMethodException e) {
        // shouldn't happen. Really.
        throw new Error("Object.equals() not found!");
    }
}

From source file:Main.java

public static String toStringE(Node element) {
    try {//  w w  w  .j  ava 2  s.c  o  m
        if (element == null) {
            return "null";
        }
        Source source = new DOMSource(element);

        StringWriter stringWriter = new StringWriter();
        try (PrintWriter printWriter = new PrintWriter(stringWriter)) {
            Result result = new StreamResult(printWriter);

            Transformer transformer = TransformerFactory.newInstance().newTransformer();
            transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
            transformer.transform(source, result);
        }
        return stringWriter.toString();
    } catch (IllegalArgumentException | TransformerException ex) {
        throw new Error(ex);
    }
}

From source file:com.aerospike.delivery.db.base.Database.java

public static Database makeInMemoryDatabase() {
    if (sharedInstance == null) {
        return sharedInstance = new InMemoryDatabase();
    } else if (!(sharedInstance instanceof InMemoryDatabase)) {
        throw new Error("There is already a shared instance for another kind of database.");
    } else {/*from w w  w.  j av a 2 s . c  om*/
        return sharedInstance;
    }
}

From source file:edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.SparqlEvaluateVTwo.java

public SparqlEvaluateVTwo(Model model) {
    if (model == null)
        throw new Error("SparqlEvaluate must be passed a Model");
    this.model = model;
}

From source file:edu.cornell.mannlib.vitro.webapp.edit.n3editing.processEdit.SparqlEvaluate.java

public SparqlEvaluate(Model model) {
    if (model == null)
        throw new Error("SparqlEvaluate must be passed a Model");
    this.model = model;
}

From source file:dk.dma.ais.reader.AisReaders.java

/**
 * Equivalent to {@link #parseSource(String)} except that it will parse an array of sources. Returning a map making
 * sure there all source names are unique
 *//*from w w  w . j a v  a 2  s  .  com*/
public static AisReaderGroup createGroup(String name, List<String> sources) {
    Map<String, AisTcpReader> readers = new HashMap<>();
    for (String s : sources) {
        AisTcpReader r = parseSource(s);
        if (readers.put(r.getSourceId(), r) != null) {
            // Make sure its unique
            throw new Error("More than one reader specified with the same source id (id =" + r.getSourceId()
                    + "), source string = " + sources);
        }
    }
    AisReaderGroup g = new AisReaderGroup(name);
    for (AisTcpReader r : readers.values()) {
        g.add(r);
    }
    return g;
}