package com.image.picservice.property;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Enumeration;
import java.util.Properties;
public class PropertyManager {
private static final int MAJOR_VERSION = 2;
/**
* The Minor version number of i.e. x.1.x.
*/
private static final int MINOR_VERSION = 0;
/**
* The revision version number of i.e. x.x.1.
*/
private static final int REVISION_VERSION = 0;
private static PropertyManager manager = null;
private static final Object managerLock = new Object();
// default property file name "config.propertie"
private static String propsName = "config.properties";
/**
*
* reset propsName value
*
*/
public static void setPropsName(final String newPropsName) {
propsName = newPropsName;
}
/**
* Returns a property.
*
* @param name
* the name of the property to return.
* @return the property value specified by name.
*/
public static String getProperty(final String name) {
if (manager == null) {
synchronized (managerLock) {
if (manager == null) {
manager = new PropertyManager(propsName);
}
}
}
return manager.getProp(name);
}
/**
* Sets a enet property. If the property doesn't already exists, a new one
* will be created.
*
* @param name
* the name of the property being set.
* @param value
* the value of the property being set.
*/
public static void setProperty(final String name, final String value) {
if (manager == null) {
synchronized (managerLock) {
if (manager == null) {
manager = new PropertyManager(propsName);
}
}
}
manager.setProp(name, value);
}
/**
* Deletes a enet property. If the property doesn't exist, the method does
* nothing.
*
* @param name
* the name of the property to delete.
*/
public static void deleteProperty(final String name) {
if (manager == null) {
synchronized (managerLock) {
if (manager == null) {
manager = new PropertyManager(propsName);
}
}
}
manager.deleteProp(name);
}
// new clear
public static void clearProperty() {
if (manager != null) {
synchronized (managerLock) {
if (manager != null) {
manager = null;
}
}
}
}
/**
* Returns the names of the enet properties.
*
* @return an Enumeration of the enet property names.
*/
public static Enumeration propertyNames() {
if (manager == null) {
synchronized (managerLock) {
if (manager == null) {
manager = new PropertyManager(propsName);
}
}
}
return manager.propNames();
}
/**
* Returns true if the properties are readable. This method is mainly
* valuable at setup time to ensure that the properties file is setup
* correctly.
*/
public static boolean propertyFileIsReadable() {
if (manager == null) {
synchronized (managerLock) {
if (manager == null) {
manager = new PropertyManager(propsName);
}
}
}
return manager.propFileIsReadable();
}
/**
* Returns true if the properties are writable. This method is mainly
* valuable at setup time to ensure that the properties file is setup
* correctly.
*/
public static boolean propertyFileIsWritable() {
if (manager == null) {
synchronized (managerLock) {
if (manager == null) {
manager = new PropertyManager(propsName);
}
}
}
return manager.propFileIsWritable();
}
/**
* Returns true if the enet.properties file exists where the path property
* purports that it does.
*/
public static boolean propertyFileExists() {
if (manager == null) {
synchronized (managerLock) {
if (manager == null) {
manager = new PropertyManager(propsName);
}
}
}
return manager.propFileExists();
}
/**
* Returns the version number of enet as a String. i.e. --
* major.minor.revision
*/
public static String getIflowVersion() {
return MAJOR_VERSION + "." + MINOR_VERSION + "." + REVISION_VERSION;
}
/**
* Returns the major version number of enet. i.e. -- 1.x.x
*/
public static int getIflowVersionMajor() {
return MAJOR_VERSION;
}
/**
* Returns the minor version number of enet. i.e. -- x.1.x
*/
public static int getIflowVersionMinor() {
return MINOR_VERSION;
}
/**
* Returns the revision version number of enet. i.e. -- x.x.1
*/
public static int getIflowVersionRevision() {
return REVISION_VERSION;
}
private Properties properties = null;
private final Object propertiesLock = new Object();
private String resourceURI;
/**
* Creates a new PropertyManager. Singleton access only.
*/
private PropertyManager(final String resourceURI) {
this.resourceURI = resourceURI;
}
/**
* Gets a enet property. enet properties are stored in enet.properties. The
* properties file should be accesible from the classpath. Additionally, it
* should have a path field that gives the full path to where the file is
* located. Getting properties is a fast operation.
*
* @param name
* the name of the property to get.
* @return the property specified by name.
*/
protected String getProp(final String name) {
// If properties aren't loaded yet. We also need to make this thread
// safe, so synchronize...
if (properties == null) {
synchronized (propertiesLock) {
// Need an additional check
if (properties == null) {
loadProps();
}
}
}
final String property = properties.getProperty(name);
if (property == null) {
return null;
} else {
return property.trim();
}
}
/**
* Sets a enet property. Because the properties must be saved to disk every
* time a property is set, property setting is relatively slow.
*/
protected void setProp(final String name, final String value) {
// Only one thread should be writing to the file system at once.
synchronized (propertiesLock) {
// Create the properties object if necessary.
if (properties == null) {
loadProps();
}
properties.setProperty(name, value);
saveProps();
}
}
protected void deleteProp(final String name) {
// Only one thread should be writing to the file system at once.
synchronized (propertiesLock) {
// Create the properties object if necessary.
if (properties == null) {
loadProps();
}
properties.remove(name);
saveProps();
}
}
protected Enumeration propNames() {
// If properties aren't loaded yet. We also need to make this thread
// safe, so synchronize...
if (properties == null) {
synchronized (propertiesLock) {
// Need an additional check
if (properties == null) {
loadProps();
}
}
}
return properties.propertyNames();
}
/**
* Loads enet properties from the disk.
*/
private void loadProps() {
properties = new Properties();
InputStream in = null;
// System.out.println(resourceURI);
try {
in = getClass().getResourceAsStream(resourceURI);
properties.load(in);
} catch (final Exception e) {
System.err
.println("Error reading properties in PropertyManager.loadProps() "
+ e);
e.printStackTrace();
} finally {
try {
in.close();
} catch (final Exception e) {
}
}
}
/**
* Saves enet properties to disk.
*/
private void saveProps() {
// Now, save the properties to disk. In order for this to work, the user
// needs to have set the path field in the properties file. Trim
// the String to make sure there are no extra spaces.
final String path = properties.getProperty("path").trim();
OutputStream out = null;
try {
out = new FileOutputStream(path);
properties.store(out, "properties -- " + (new java.
没有合适的资源?快使用搜索试试~ 我知道了~
java NIO异步框架
共259个文件
svn-base:68个
entries:36个
format:35个
5星 · 超过95%的资源 需积分: 20 32 下载量 83 浏览量
2008-11-12
10:22:51
上传
评论
收藏 827KB RAR 举报
温馨提示
Java对io重新包装,大大提高了io的处理效率和复用率。可以用nio代替多线程编程。
资源推荐
资源详情
资源评论
收起资源包目录
java NIO异步框架 (259个子文件)
all-wcprops 1KB
all-wcprops 1KB
all-wcprops 931B
all-wcprops 931B
all-wcprops 532B
all-wcprops 532B
all-wcprops 432B
all-wcprops 432B
all-wcprops 432B
all-wcprops 432B
all-wcprops 427B
all-wcprops 427B
all-wcprops 418B
all-wcprops 418B
all-wcprops 334B
all-wcprops 262B
all-wcprops 262B
all-wcprops 262B
all-wcprops 262B
all-wcprops 252B
all-wcprops 252B
all-wcprops 248B
all-wcprops 248B
all-wcprops 210B
all-wcprops 210B
all-wcprops 208B
all-wcprops 101B
all-wcprops 101B
all-wcprops 98B
all-wcprops 98B
all-wcprops 92B
all-wcprops 92B
all-wcprops 92B
all-wcprops 92B
PropertyManager.class 6KB
PropertyManager.class 6KB
MakeImage.class 6KB
DoWithData.class 6KB
Server.class 5KB
NioServerImage.class 5KB
ImageService.class 5KB
Picture.class 4KB
AsyncServer.class 4KB
NServer.class 4KB
MakeImage.class 4KB
SumServer.class 4KB
Reader.class 3KB
NioServerImage2.class 3KB
ImageHostService.class 3KB
AsyncClient.class 3KB
Myclient2.class 3KB
CreateImage.class 3KB
SumClient.class 3KB
Client.class 2KB
Notifier.class 2KB
Writer.class 2KB
BImage.class 2KB
Image.class 2KB
Request.class 2KB
Start.class 2KB
ImageHandler.class 2KB
ServerHandler.class 2KB
StringUtils.class 1KB
StringUtils.class 1KB
LogUtil.class 1KB
EventAdapter.class 1KB
Response.class 886B
ServerListener.class 477B
.classpath 300B
entries 1KB
entries 1KB
entries 1KB
entries 1KB
entries 1KB
entries 574B
entries 574B
entries 524B
entries 524B
entries 524B
entries 524B
entries 519B
entries 519B
entries 466B
entries 466B
entries 438B
entries 386B
entries 386B
entries 386B
entries 386B
entries 381B
entries 381B
entries 381B
entries 381B
entries 327B
entries 327B
entries 317B
entries 259B
entries 259B
entries 257B
entries 248B
共 259 条
- 1
- 2
- 3
资源评论
- xyaoyuan2013-07-11为编译后的文件,不是我需要的源码,具体如何不清楚
- tracyjuantong2014-04-17我需要的源码,很适用,解决了通信重要问题
dowith
- 粉丝: 1
- 资源: 3
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功