List of usage examples for java.lang Exception Exception
public Exception(Throwable cause)
From source file:io.cloudslang.content.database.services.SQLQueryLobService.java
public static boolean executeSqlQueryLob(SQLInputs sqlInputs) throws Exception { if (StringUtils.isEmpty(sqlInputs.getSqlCommand())) { throw new Exception("command input is empty."); }/*from w w w . jav a2 s .c o m*/ boolean isLOB = false; ConnectionService connectionService = new ConnectionService(); try (final Connection connection = connectionService.setUpConnection(sqlInputs)) { StringBuilder strColumns = new StringBuilder(sqlInputs.getStrColumns()); connection.setReadOnly(true); Statement statement = connection.createStatement(sqlInputs.getResultSetType(), sqlInputs.getResultSetConcurrency()); statement.setQueryTimeout(sqlInputs.getTimeout()); ResultSet results = statement.executeQuery(sqlInputs.getSqlCommand()); ResultSetMetaData mtd = results.getMetaData(); int iNumCols = mtd.getColumnCount(); for (int i = 1; i <= iNumCols; i++) { if (i > 1) strColumns.append(sqlInputs.getStrDelim()); strColumns.append(mtd.getColumnLabel(i)); } sqlInputs.setStrColumns(strColumns.toString()); int nr = -1; while (results.next()) { nr++; final StringBuilder strRowHolder = new StringBuilder(); for (int i = 1; i <= iNumCols; i++) { if (i > 1) strRowHolder.append(sqlInputs.getStrDelim()); Object columnObject = results.getObject(i); if (columnObject != null) { String value; if (columnObject instanceof java.sql.Clob) { isLOB = true; final File tmpFile = File.createTempFile("CLOB_" + mtd.getColumnLabel(i), ".txt"); copyInputStreamToFile( new ReaderInputStream(results.getCharacterStream(i), StandardCharsets.UTF_8), tmpFile); if (sqlInputs.getLRowsFiles().size() == nr) { sqlInputs.getLRowsFiles().add(nr, new ArrayList<String>()); sqlInputs.getLRowsNames().add(nr, new ArrayList<String>()); } sqlInputs.getLRowsFiles().get(nr).add(tmpFile.getAbsolutePath()); sqlInputs.getLRowsNames().get(nr).add(mtd.getColumnLabel(i)); value = "(CLOB)..."; } else { value = results.getString(i); if (sqlInputs.isNetcool()) value = SQLUtils.processNullTerminatedString(value); } strRowHolder.append(value); } else strRowHolder.append("null"); } sqlInputs.getLRows().add(strRowHolder.toString()); } } return isLOB; }
From source file:Main.java
/** * Creates a string representation of a {@link Node} instance. This method * does not introduce any character to the string representation of the * {@link Node} (eg. \n or \r characters) * * @param node A {@link Node} instance//www .j a v a 2s . c om * @return A string representation of the node instance * @throws RequestSecurityTokenException */ public static String xmlToString(Node node) throws Exception { try { Source source = new DOMSource(node); StringWriter stringWriter = new StringWriter(); Result result = new StreamResult(stringWriter); TransformerFactory factory = TransformerFactory.newInstance(); Transformer transformer = factory.newTransformer(); transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); transformer.transform(source, result); return stringWriter.getBuffer().toString(); } catch (TransformerConfigurationException e) { e.printStackTrace(); throw new Exception("Cannot build a string representation of the assertion."); } catch (TransformerException e) { e.printStackTrace(); throw new Exception("Cannot build a string representation of the assertion."); } }
From source file:SHA1Sum.java
public SHA1Sum(String hexStr) throws Exception { if (!hexStr.matches("[0-9a-fA-F]{40}")) throw new Exception("Invalid format: " + hexStr); display = hexStr.toLowerCase();/*w w w .j a va 2 s . co m*/ sha1sum = new byte[20]; for (int i = 0; i < 20; i++) { int pos = i << 1; sha1sum[i] = (byte) Integer.parseInt(hexStr.substring(pos, pos + 2), 16); } }
From source file:com.myapp.common.AES4MEncrypt.java
/** * // ww w. ja va 2 s . c om * * @param sSrc * @param sKey KEY * @return * @throws Exception * @author cdduqiang * @date 201443 */ public static String encrypt(String sSrc, String sKey) throws Exception { if (sKey == null) { log.error("Encrypt Key ??"); throw new Exception("Encrypt Key ??"); } byte[] raw = hex2byte(sKey); SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES"); Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding"); IvParameterSpec iv = new IvParameterSpec("0102030405060708".getBytes()); cipher.init(Cipher.ENCRYPT_MODE, skeySpec, iv); byte[] anslBytes = sSrc.getBytes(ENCODING);// string2AnslBytes(sSrc); byte[] encrypted = cipher.doFinal(anslBytes); return byte2hex(encrypted).toUpperCase(); }
From source file:gr.teicm.pm.smartfilemanager.corelibrary.entity.logic.drives.UnixDriveProperties.java
public UnixDriveProperties() throws Exception { if (!SystemUtils.IS_OS_LINUX) { throw new Exception("Wrong os"); }/* ww w . j a v a 2 s . c om*/ }
From source file:Util.java
public static void createHome() throws Exception { File ch = new File(System.getProperty("user.home") + File.separator + ".dataform"); if (!ch.exists()) { if (!ch.mkdir()) throw new Exception("Failed to create the dataform configuration directory"); }/*from ww w . j a v a 2s . co m*/ }
From source file:com.liferay.mobile.android.auth.SignIn.java
public static void signIn(final Session session, final JSONObjectCallback callback, final SignInMethod method) { GroupService groupService = new GroupService(session); session.setCallback(new JSONArrayCallback() { @Override// w w w . j a v a 2 s .c o m public void onSuccess(JSONArray sites) { if (sites.length() == 0) { onFailure(new Exception("User doesn't belong to any site")); } try { JSONObject site = sites.getJSONObject(0); long companyId = site.getLong("companyId"); Session userSession = new SessionImpl(session); userSession.setCallback(callback); UserService userService = new UserService(userSession); String username = getUsername(session); if (method == SignInMethod.EMAIL) { userService.getUserByEmailAddress(companyId, username); } else if (method == SignInMethod.USER_ID) { userService.getUserById(Long.parseLong(username)); } else { userService.getUserByScreenName(companyId, username); } } catch (Exception e) { onFailure(e); } } @Override public void onFailure(Exception exception) { callback.onFailure(exception); } }); try { groupService.getUserSitesGroups(); } catch (Exception e) { callback.onFailure(e); } }
From source file:com.netsteadfast.greenstep.util.ManualDataSourceFactory.java
public static DataSource getDataSource(Class<?> dataSourceClass, String url, String user, String password) throws Exception { if (!checkDataSourceClass(dataSourceClass)) { throw new Exception("DataSource Class is not implements DataSource. error!"); }//from ww w . j a va 2s . c om if (StringUtils.isBlank(url) || StringUtils.isBlank(user)) { throw new Exception("url or user is required!"); } DataSource ds = (DataSource) dataSourceClass.newInstance(); Ognl.setValue("url", ds, url); Ognl.setValue("user", ds, user); Ognl.setValue("password", ds, (null == password ? "" : password)); return ds; }
From source file:Main.java
/** Read an XML document from a file */ public static Document readXmlDocumentFromFile(File file) throws Exception { if (file.exists()) { FileInputStream stream = null; try {/* w ww . ja va2 s.com*/ stream = new FileInputStream(file); return readXmlDocumentFromStream(stream); } catch (Exception e) { throw e; } finally { if (stream != null) { try { stream.close(); } catch (Exception e) { } } } } else { throw new Exception("FileNotFound: " + file.getPath()); } }
From source file:eu.planets_project.tb.impl.model.ontology.util.OntoPropertyUtil.java
/** * Takes a OntologyProperty that's used * and converts it into the Testbed's Property model element: MeasurementImpl * @param p eu.planets_project.services.datatypes.Property * @return/*from ww w. java 2 s . c o m*/ */ public static MeasurementImpl createMeasurementFromOntologyProperty(OntologyProperty p) throws Exception { MeasurementImpl m = new MeasurementImpl(); if (p == null) throw new Exception("invalid OntologyProperty: null"); String propURI = p.getURI(); // Invent a uri if required - shouldn't be the case: if (propURI == null) { propURI = TecRegMockup.URI_ONTOLOGY_PROP_ROOT + p.getName(); } URI pURI; try { pURI = new URI(propURI); } catch (URISyntaxException e) { log.debug(e); return m; } // Copy into measurement property: m.setProperty(OntoPropertyUtil.createPropertyFromOntoProperty(pURI, p)); return m; }