List of usage examples for java.lang IllegalStateException IllegalStateException
public IllegalStateException(Throwable cause)
From source file:edu.harvard.med.screensaver.analysis.ZScoreFunction.java
public Double compute(Double valueController) { if (!_initialized) { throw new IllegalStateException("uninitialized"); }//from w w w. ja va 2 s . c o m return (valueController - _mean) / _stdDev; }
From source file:lumbermill.internal.elasticsearch.ElasticSearchBulkResponse.java
public static ElasticSearchBulkResponse parse(RequestSigner.SignableRequest request, Response response) { try {/*from w w w. java 2 s . co m*/ return new ElasticSearchBulkResponse( Json.OBJECT_MAPPER.readValue(response.body().source().readByteString().utf8(), JsonNode.class), request); } catch (IOException e) { throw new IllegalStateException(e); } }
From source file:com.amazonaws.util.Md5Utils.java
/** * Computes the MD5 hash of the data in the given input stream and returns * it as an array of bytes./* www .jav a 2 s. c o m*/ * Note this method closes the given input stream upon completion. */ public static byte[] computeMD5Hash(InputStream is) throws IOException { BufferedInputStream bis = new BufferedInputStream(is); try { MessageDigest messageDigest = MessageDigest.getInstance("MD5"); byte[] buffer = new byte[SIXTEEN_K]; int bytesRead; while ((bytesRead = bis.read(buffer, 0, buffer.length)) != -1) { messageDigest.update(buffer, 0, bytesRead); } return messageDigest.digest(); } catch (NoSuchAlgorithmException e) { // should never get here throw new IllegalStateException(e); } finally { try { bis.close(); } catch (Exception e) { LogFactory.getLog(Md5Utils.class).debug("Unable to close input stream of hash candidate: " + e); } } }
From source file:org.seedstack.spring.batch.sample.mapper.ContactFieldSetMapper.java
@Override public Contact mapFieldSet(final FieldSet fieldSet) throws BindException { if (fieldSet == null) { throw new IllegalStateException("Exception in Field Set Mapper. Field Set Mapper must not be null..."); }/*from ww w .j a v a 2s .c o m*/ final Contact contact = new Contact(); contact.setFirstName(fieldSet.readString(FIRST_NAME)); contact.setLastName(fieldSet.readString(LAST_NAME)); contact.setEmail(fieldSet.readString(EMAIL)); return contact; }
From source file:com.fluidops.iwb.api.helper.RDFUtils.java
public static List<Statement> readStatements(File rdfXmlFile) { FileReader rdfXmlReader = null; try {/*from w w w . j a v a2 s . c om*/ rdfXmlReader = new FileReader(rdfXmlFile); return readStatements(rdfXmlReader); } catch (FileNotFoundException e) { throw new IllegalStateException(e); } finally { IOUtils.closeQuietly(rdfXmlReader); } }
From source file:com.brienwheeler.svc.monitor.telemetry.impl.TelemetryServiceBaseTestUtils.java
@SuppressWarnings("unchecked") public static <T> T findProcessor(TelemetryServiceBase telemetryServiceBase, Class<T> clazz) { List<ITelemetryInfoProcessor> processors = (List<ITelemetryInfoProcessor>) ReflectionTestUtils .getField(telemetryServiceBase, "processors"); if (processors != null) { for (ITelemetryInfoProcessor proc : processors) if (clazz.isAssignableFrom(proc.getClass())) return clazz.cast(proc); }//from ww w . j ava 2s . c om throw new IllegalStateException("no " + clazz.getSimpleName() + " found in test context!"); }
From source file:flpitu88.web.backend.psicoweb.config.Jwt.java
/** * Static method to decode a JSON Web Token * * @param token Token to decode/* ww w .j av a 2s.co m*/ * @param key Key used for the signature * @param verify True if you want to verify the signature * * @return payload * * @throws IllegalStateException * @throws IllegalArgumentException * @throws VerifyException * @throws NoSuchAlgorithmException * @throws UnsupportedEncodingException * @throws InvalidKeyException * @throws AlgorithmException */ public static Map<String, Object> decode(String token, String key, Boolean verify) throws IllegalStateException, VerifyException, IllegalArgumentException, NoSuchAlgorithmException, UnsupportedEncodingException, InvalidKeyException, AlgorithmException { if (token == null || token.length() == 0) { throw new IllegalStateException("Token not set"); } // Check key if (key == null || key.length() == 0) { throw new IllegalArgumentException("Key cannot be null or empty"); } String[] segments = StringUtils.split(token, "."); if (segments.length != 3) { throw new IllegalStateException("Bad number of segments: " + segments.length); } // All segment should be base64 String headerSeg = segments[0]; String payloadSeg = segments[1]; String signatureSeg = segments[2]; Type stringObjectMap = new TypeToken<HashMap<String, Object>>() { }.getType(); Gson gson = new Gson(); HashMap<String, Object> header = gson.fromJson(base64Decode(headerSeg), stringObjectMap); HashMap<String, Object> payload = gson.fromJson(base64Decode(payloadSeg), stringObjectMap); if (verify) { Algorithm algorithm = getAlgorithm(header.get("alg").toString()); // Verify signature. `sign` will return base64 String String signinInput = StringUtils.join(new String[] { headerSeg, payloadSeg }, "."); if (!verify(signinInput, key, algorithm.getValue(), signatureSeg)) { throw new VerifyException("Bad signature"); } } return payload; }
From source file:de.tudarmstadt.ukp.dkpro.core.api.lexmorph.TagsetMappingFactory.java
/** * Get the UIMA type name for the given tag in the given language. * * @param aModel a model//from w w w . j ava 2 s . c o m * @param aTag a tag. * @return UIMA type name */ public static final Type getTagType(Map<String, String> aMapping, String aTag, TypeSystem aTS) { String type = aMapping.get(aTag); if (type == null) { type = aMapping.get("*"); } if (type == null) { throw new IllegalStateException("No fallback (*) mapping defined!"); } Type uimaType = aTS.getType(type); if (uimaType == null) { throw new IllegalStateException( "Type [" + type + "] mapped to tag [" + aTag + "] is not defined in type system"); } return uimaType; }
From source file:jp.eisbahn.oauth2.server.utils.Util.java
/** * Decode the BASE64 encoded string./*from ww w. j av a 2s.co m*/ * @param source The BASE64 string. * @return The decoded original string. */ public static String decodeBase64(String source) { try { return new String(Base64.decodeBase64(source), "UTF-8"); } catch (UnsupportedEncodingException e) { throw new IllegalStateException(e); } }
From source file:com.tactfactory.harmony.utils.TactFileUtils.java
/** * Create a new file if doesn't exist (and path). * * @param filename Full path of file//w w w . j ava 2s . c o m * @return File instance */ public static File makeFile(final String filename) { final File file = new File(filename); final File parent = file.getParentFile(); if (!parent.exists() && !parent.mkdirs()) { final IllegalStateException exception = new IllegalStateException("Couldn't create dir: " + parent); ConsoleUtils.displayError(exception); throw exception; } try { file.createNewFile(); } catch (final IOException e) { // TODO Auto-generated catch block ConsoleUtils.displayError(e); } return file; }