List of usage examples for java.lang Error Error
public Error(Throwable cause)
From source file:Main.java
/***********************************************************************/ public static String locateFile(String fileLocation, String backupPaths[]) throws Exception { String[] newArray = new String[backupPaths.length + 1]; System.arraycopy(backupPaths, 0, newArray, 1, backupPaths.length); newArray[0] = "."; backupPaths = newArray;/* ww w . ja v a2 s . co m*/ for (int i = 0; i < backupPaths.length; i++) { String tfileLocation = backupPaths[i] + File.separator + fileLocation; File file = new File(tfileLocation); if (file.exists()) { return file.getAbsolutePath(); } } throw new Error(String.format("Couldn't find '%s' from locations %s with current directory '%s'", fileLocation, Arrays.asList(backupPaths), new File(".").getAbsolutePath())); }
From source file:Main.java
public final static Document newDocumentE() { try {/*from www .ja v a 2 s .c o m*/ DocumentBuilder bldr = getDocumentBuilder(); return bldr.newDocument(); } catch (ParserConfigurationException ex) { throw new Error(ex); } }
From source file:Main.java
/** * Should always be able convert to/from UTF-8, so encoding exceptions are converted to an Error to avoid adding * throws declarations in lots of methods. * @param str String//from w w w . j ava2s. c o m * @return utf8 bytes * @see String#getBytes() */ public static byte[] getBytes(String str) { try { return str.getBytes("UTF8"); } catch (java.io.UnsupportedEncodingException e) { throw new Error("String to UTF-8 conversion failed: " + e.getMessage()); } }
From source file:Main.java
public static void await(CountDownLatch latch) { try {/*from ww w . j a v a 2s.c o m*/ latch.await(); } catch (InterruptedException e) { throw new Error(e); } }
From source file:Main.java
static Document getLoadingDoc(InputStream in) throws SAXException, IOException { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setIgnoringElementContentWhitespace(true); dbf.setValidating(false);// w w w . jav a 2 s. c o m dbf.setCoalescing(true); dbf.setIgnoringComments(true); try { DocumentBuilder db = dbf.newDocumentBuilder(); InputSource is = new InputSource(in); return db.parse(is); } catch (ParserConfigurationException x) { throw new Error(x); } }
From source file:com.igormaznitsa.zxpoly.utils.Utils.java
public static Image loadIcon(final String name) { final InputStream resource = findResourceOrError("com/igormaznitsa/zxpoly/icons/" + name); try {/*from w w w . j a v a2 s . c o m*/ return ImageIO.read(resource); } catch (IOException ex) { throw new Error("Can't read resource icon [" + name + ']'); } finally { IOUtils.closeQuietly(resource); } }
From source file:Main.java
public static void await(CyclicBarrier barrier) { try {/* www .ja v a2s .com*/ barrier.await(); } catch (Exception e) { throw new Error(e); } }
From source file:hudson.util.Scrambler.java
public static String scramble(String secret) { if (secret == null) { return null; }//from w w w. j av a 2s .c o m try { return new String(Base64.encodeBase64(secret.getBytes("UTF-8"))); } catch (UnsupportedEncodingException e) { throw new Error(e); // impossible } }
From source file:Main.java
/** * Should always be able convert to/from UTF-8, so encoding exceptions are converted to an Error to avoid adding * throws declarations in lots of methods. * @param bytes byte array//from w w w . ja v a 2 s.c o m * @param offset starting offset in byte array * @param length length in byte array starting from offset * @return same as <code>new String(bytes, offset, length, "UTF8")</code> */ public static String getString(byte[] bytes, int offset, int length) { try { return new String(bytes, offset, length, "UTF8"); } catch (java.io.UnsupportedEncodingException e) { throw new Error("UTF-8 to string conversion failed: " + e.getMessage()); } }
From source file:Main.java
/** * Compute the sha-256 digest of data.//from www . jav a 2 s . c o m * @param data The input byte buffer. This does not change the position. * @return The digest. */ public static byte[] digestSha256(ByteBuffer data) { MessageDigest sha256; try { sha256 = MessageDigest.getInstance("SHA-256"); } catch (NoSuchAlgorithmException exception) { // Don't expect this to happen. throw new Error("MessageDigest: SHA-256 is not supported: " + exception.getMessage()); } int savePosition = data.position(); sha256.update(data); data.position(savePosition); return sha256.digest(); }