当前位置: 首页>>代码示例>>Java>>正文


Java JKException类代码示例

本文整理汇总了Java中com.jk.exceptions.JKException的典型用法代码示例。如果您正苦于以下问题:Java JKException类的具体用法?Java JKException怎么用?Java JKException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


JKException类属于com.jk.exceptions包,在下文中一共展示了JKException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getDefaultDataSource

import com.jk.exceptions.JKException; //导入依赖的package包/类
/**
 * Gets the default data source.
 *
 * @return the default data source
 */
public static JKDataSource getDefaultDataSource() {
	try {
		JKDataSourceFactory.logger.debug("get default datasource");
		if (JKDataSourceFactory.defaultResourceManager == null) {
			JKDataSourceFactory.logger.debug("trying to load config file");
			JKDataSourceFactory.tryLoadConfig();
			if (JKDataSourceFactory.defaultResourceManager == null) {
				JKDataSourceFactory.logger.debug("no configuration file is provided , defaults will be used");
				JKDataSourceFactory.defaultResourceManager = JKDataSourceFactory.createInstance(new Properties());
			}
		}
		return JKDataSourceFactory.defaultResourceManager;
	} catch (final IOException e) {
		throw new JKException(e);
	}
}
 
开发者ID:kiswanij,项目名称:jk-db,代码行数:22,代码来源:JKDataSourceFactory.java

示例2: getResourceUrl

import com.jk.exceptions.JKException; //导入依赖的package包/类
@Override
public URL getResourceUrl(String fileName) {
	if(fileName==null){
		return null;
	}
	URL resource = getClass().getResource(fileName);
	if (resource == null) {
		resource = Thread.currentThread().getContextClassLoader().getResource(fileName);
		if (resource == null) {
			resource = ClassLoader.getSystemResource(fileName);
			if (resource == null) {
				File file = new File(fileName);
				if (file.exists()) {
					try {
						resource = file.toURI().toURL();
					} catch (MalformedURLException e) {
						throw new JKException(e);
					}
				}
			}
		}
	}
	return resource;
}
 
开发者ID:kiswanij,项目名称:jk-util,代码行数:25,代码来源:JKDefaultResourceLoader.java

示例3: convertToString

import com.jk.exceptions.JKException; //导入依赖的package包/类
/**
 * Convert to string.
 *
 * @param input
 *            the input
 * @return the string
 * @throws IOException
 *             Signals that an I/O exception has occurred.
 */
public static String convertToString(InputStream input) throws IOException {
	try {
		if (input == null) {
			throw new IOException("Input Stream Cannot be NULL");
		}
		StringBuilder sb1 = new StringBuilder();
		String line;
		try {
			BufferedReader r1 = new BufferedReader(new InputStreamReader(input, "UTF-8"));
			while ((line = r1.readLine()) != null) {
				sb1.append(line);
			}
		} finally {
			input.close();
		}
		return sb1.toString();
	} catch (IOException e) {
		throw new JKException(e);
	}
}
 
开发者ID:kiswanij,项目名称:jk-util,代码行数:30,代码来源:JKIOUtil.java

示例4: isPeriodActive

import com.jk.exceptions.JKException; //导入依赖的package包/类
/**
 * Checks if is period active.
 *
 * @param startDate
 *            the start date
 * @param endDate
 *            the end date
 * @return true, if is period active
 */
public static boolean isPeriodActive(final Date startDate, final Date endDate)  {
	if (startDate == null && endDate == null) {
		return true;
	}
	if (startDate == null) {
		throw new JKException("START_DATE_CAN_NOT_BE_NULL");
	}
	if (endDate == null) {
		throw new JKException("END_DATE_CAN_NOT_BE_NULL");
	}
	if (compareTwoDates(startDate, endDate).equals(CompareDates.DATE1_GREATER_THAN_DATE2)) {
		throw new JKException("START_DATE_MUST_BE_BEFORE_END_DATE");
	}
	final boolean startLessThanCurrent = compareTwoDates(startDate, getSystemDate()).equals(CompareDates.DATE1_LESS_THAN_DATE2);
	final boolean endGreaterThanCurrent = compareTwoDates(endDate, getSystemDate()).equals(CompareDates.DATE1_GREATER_THAN_DATE2);
	return startLessThanCurrent && endGreaterThanCurrent;
}
 
开发者ID:kiswanij,项目名称:jk-util,代码行数:27,代码来源:JKDateTimeUtil.java

示例5: loadDriverClass

import com.jk.exceptions.JKException; //导入依赖的package包/类
/**
 * Load driver class.
 */
private void loadDriverClass() {
	logger.debug("loadDriverClass");
	try {
		Class.forName(getDriverName());
	} catch (final ClassNotFoundException e) {
		throw new JKException(e);
	}
}
 
开发者ID:kiswanij,项目名称:jk-db,代码行数:12,代码来源:JKAbstractDataSource.java

示例6: getResourceAsStream

import com.jk.exceptions.JKException; //导入依赖的package包/类
@Override
public InputStream getResourceAsStream(String resourceName) {
	URL url = getResourceUrl(resourceName);
	if (url != null) {
		try {
			return url.openStream();
		} catch (IOException e) {
			throw new JKException(e);
		}
	}
	return null;
}
 
开发者ID:kiswanij,项目名称:jk-util,代码行数:13,代码来源:JKDefaultResourceLoader.java

示例7: parse

import com.jk.exceptions.JKException; //导入依赖的package包/类
/**
 * Parses the.
 *
 * @param <T>
 *            the generic type
 * @param in
 *            the in
 * @param clas
 *            the clas
 * @return the t
 */
/*
 * 
 */
public <T> T parse(InputStream in, Class<?>... clas) {
	try {
		JAXBContext jaxbContext = JAXBContext.newInstance(clas);
		Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
		T t = (T) jaxbUnmarshaller.unmarshal(in);
		return t;
	} catch (JAXBException e) {
		throw new JKException(e);
	}
}
 
开发者ID:kiswanij,项目名称:jk-util,代码行数:25,代码来源:JKXmlHandler.java

示例8: toXml

import com.jk.exceptions.JKException; //导入依赖的package包/类
/**
 * To xml.
 *
 * @param object
 *            the object
 * @param out
 *            the out
 * @param clas
 *            the clas
 */
public void toXml(Object object, OutputStream out, Class<?>... clas) {
	try {
		JAXBContext jaxbContext = JAXBContext.newInstance(clas);
		Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
		// output pretty printed
		jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
		jaxbMarshaller.marshal(object, out);
	} catch (JAXBException e) {
		throw new JKException(e);
	}
}
 
开发者ID:kiswanij,项目名称:jk-util,代码行数:22,代码来源:JKXmlHandler.java

示例9: readStream

import com.jk.exceptions.JKException; //导入依赖的package包/类
/**
 * Read stream.
 *
 * @param inStream
 *            the in stream
 * @return the byte[]
 */
public static byte[] readStream(final InputStream inStream) {
	try {
		return IOUtils.toByteArray(inStream);
	} catch (IOException e) {
		throw new JKException(e);
	}
	//
	// try {
	// DataInputStream in = null;
	// try {
	// in = new DataInputStream(inStream);
	// int ch;
	//
	// List<Byte> bytes=new ArrayList<>();
	// while((ch=in.read())!=-1){
	// bytes.add(ch);
	// }
	// return arr;
	// } finally {
	// if (in != null) {
	// in.close();
	// }
	// }
	// } catch (final IOException e) {
	// throw new RuntimeException(e);
	// }
}
 
开发者ID:kiswanij,项目名称:jk-util,代码行数:35,代码来源:JKIOUtil.java

示例10: getUrlInputStream

import com.jk.exceptions.JKException; //导入依赖的package包/类
public static InputStream getUrlInputStream(String urlString) {
	URL url;
	try {
		url = new URL(urlString);
		HttpURLConnection con = (HttpURLConnection) url.openConnection();
		con.connect();
		return con.getInputStream();
	} catch (Exception e) {
		throw new JKException(e);
	}

}
 
开发者ID:kiswanij,项目名称:jk-util,代码行数:13,代码来源:HttpUtil.java

示例11: callStaticMethod

import com.jk.exceptions.JKException; //导入依赖的package包/类
/**
 * Call static method.
 *
 * @param clas
 *            the clas
 * @param methodName
 *            the method name
 * @param params
 *            the params
 * @return the object
 */
///////////////////////////////////////////////////////////////////
public static Object callStaticMethod(Class clas, String methodName, Object... params) {
	try {
		Class[] paramsTypes = new Class[params.length];
		for (int i = 0; i < params.length; i++) {
			paramsTypes[i] = Object.class;
		}
		Method method = clas.getMethod(methodName, paramsTypes);
		Object o = method.invoke(null, params);
		return o;
	} catch (Exception e) {
		throw new JKException(e);
	}
}
 
开发者ID:kiswanij,项目名称:jk-util,代码行数:26,代码来源:JKObjectUtil.java

示例12: copy

import com.jk.exceptions.JKException; //导入依赖的package包/类
/**
 * Copy.
 *
 * @param source
 *            the source
 * @return the object
 */
// /////////////////////////////////////////////////////////////////
public static Object copy(Object source) {
	try {
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		ObjectOutputStream oos = new ObjectOutputStream(baos);
		oos.writeObject(source);
		ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
		ObjectInputStream ois = new ObjectInputStream(bais);
		Object deepCopy = ois.readObject();
		return deepCopy;
	} catch (Exception e) {
		throw new JKException(e);
	}
}
 
开发者ID:kiswanij,项目名称:jk-util,代码行数:22,代码来源:JKObjectUtil.java

示例13: getMacAddress

import com.jk.exceptions.JKException; //导入依赖的package包/类
/**
 * Gets the physical active mac address.
 *
 * @return the mac address
 * @throws Exception
 *             the exception
 */

public static String getMacAddress() {
	try {
		List<String> macAddress = new ArrayList<String>();

		Enumeration<NetworkInterface> enumNetWorkInterface = NetworkInterface.getNetworkInterfaces();
		while (enumNetWorkInterface.hasMoreElements()) {
			NetworkInterface netWorkInterface = enumNetWorkInterface.nextElement();
			byte[] hardwareAddress = netWorkInterface.getHardwareAddress();
			if (hardwareAddress != null && netWorkInterface.isUp() && !netWorkInterface.isVirtual()) {
				String displayName = netWorkInterface.getDisplayName().toLowerCase();
				if (!displayName.contains("virtual") && !displayName.contains("tunnel")) {
					String strMac = "";
					for (int i = 0; i < hardwareAddress.length; i++) {
						strMac += String.format("%02X%s", hardwareAddress[i], (i < hardwareAddress.length - 1) ? "-" : "");
					}
					if (strMac.trim().length() > 0) {
						macAddress.add(strMac);
					}
				}
			}
		}
		return macAddress.toString().replace(",", ";").replace("[", "").replace("]", "");
	} catch (Exception e) {
		throw new JKException(e);
	}
}
 
开发者ID:kiswanij,项目名称:jk-util,代码行数:35,代码来源:MachineInfo.java

示例14: handleException

import com.jk.exceptions.JKException; //导入依赖的package包/类
protected void handleException(Exception e) {
	if (e instanceof RuntimeException) {
		throw (RuntimeException) e;
	}
	throw new JKException(e);
}
 
开发者ID:kiswanij,项目名称:jk-faces,代码行数:7,代码来源:JKManagedBean.java

示例15: getFieldValue

import com.jk.exceptions.JKException; //导入依赖的package包/类
/**
 * Gets the field value.
 *
 * @param <T>
 *            the generic type
 * @param clas
 *            the clas
 * @param instance
 *            the instance
 * @param fieldName
 *            the field name
 * @return the field value
 */
public static <T> T getFieldValue(Class<?> clas, Object instance, String fieldName) {
	try {
		Field declaredField = clas.getDeclaredField(fieldName);
		declaredField.setAccessible(true);
		return (T) declaredField.get(instance);
	} catch (NoSuchFieldException | IllegalArgumentException | IllegalAccessException e) {
		throw new JKException(e);
	}
}
 
开发者ID:kiswanij,项目名称:jk-util,代码行数:23,代码来源:JKObjectUtil.java


注:本文中的com.jk.exceptions.JKException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。