2021SC@SDUSC
对cocoon的core包的分析,在我们的小组分工下,初步告一段落,接下来是对其他包的分析,本次从util包开始。
目录
util.avalon:
CLLoggerWrapper:
1.总结:
实现了Logger接口,是将Commons日志记录到Avalon记录器适配器。
2.方法
void debug(String arg0)
void debug(String arg0, Throwable arg1)
void error(String arg0)
void error(String arg0, Throwable arg1)
void fatalError(String arg0)
void fatalError(String arg0, Throwable arg1)
Logger getChildLogger(String arg0)
void info(String arg0)
void info(String arg0, Throwable arg1)
boolean isDebugEnabled()
boolean isErrorEnabled()
boolean isFatalErrorEnabled()
boolean isInfoEnabled()
boolean isWarnEnabled()
void warn(String arg0)
void warn(String arg0, Throwable arg1)
所有的方法都很简单,只是简单的设置和取值,方法也见名知意,不多加以分析。
Util:
AbstractLogEnabled:
1.总结:
支持日志记录。此类将替换org.apache.avalon.framework.logger.AbstractLogEnabled。
默认情况下,此类使用为当前类配置的commons日志记录器。但是,可以通过调用setLogger(Log)来提供自定义记录器。
2.方法:
Log getLogger()
void setLogger(Log l)
BufferedOutputStream:
1.总结:
该类继承了FilterOutputsStream。这个类类似于BufferedOutputStream,但它扩展了它使用逻辑计算写入输出流的字节数。
2.方法:
void clearBuffer()
清除/重置缓冲区
void close()
关闭此缓冲输出流。
void flush()
刷新此缓冲输出流。
int getCount()
返回当前缓冲区的大小
void realFlush()
刷新此缓冲输出流。
void write(byte[] b, int off, int len)
从offset off开始将指定字节数组中的len字节写入此缓冲输出流。
void write(int b)
将指定的字节写入此缓冲输出流。
3.方法详细:
通常,write(byte[] b,int off,int len)方法将给定数组中的字节存储到此流的缓冲区中,根据需要将缓冲区刷新到底层输出流中。但是,如果请求的长度至少与此流的缓冲区一样大,则此方法将刷新缓冲区并将字节直接写入底层输出流。因此,冗余缓冲输出流不会不必要地复制数据。
ByteRange:
1.总结:
该类为一个实例,记录字节范围。
2.方法:
long getEnd()
long getStart()
ByteRange intersection(ByteRange range)
long length()
String toString()
3.方法详细:
public ByteRange intersection(ByteRange range) {
if (range.end < this.start || this.end < range.start) {
return null;
} else {
long start = (this.start > range.start) ? this.start : range.start;
long end = (this.end < range.end) ? this.end : range.end;
return new ByteRange(start, end);
}
}
首先判断参数中的range的末尾是否在该range开始之前,开始是否在该range结束之后,其中任何一条满足,两range都没有交叉,若都不满足,则取靠后的开始点,和靠前的结束点,之间的范围即使两者的交叉。
ClassUtils:
1.总结:
类管理实用程序方法的集合。
2.方法:
static ClassLoader getClassLoader()
返回上下文类加载器。
static URL getResource(String resource)
返回一个资源URL。
static Class loadClass(String className)
加载给定名称的类。
static Object newInstance(String className)
在给定类名的情况下创建一个新实例
ConfigurationUtil:
1.总结:
该类是Excalibur ConfigurationUtil类的改进版本,以支持DOMs中的名称空间。
2.方法
static Configuration toConfiguration(Element element)
将DOM元素树转换为配置树。
static Element toElement(Configuration configuration)
将配置树转换为DOM元素树。
3.方法详细:
private static Element createElement( final Document document,
final Configuration configuration )
throws ConfigurationException {
final Element element = document.createElementNS( configuration.getNamespace(), configuration.getName() );
element.setPrefix( configuration.getLocation() );
final String content = configuration.getValue( null );
if( null != content )
{
final Text child = document.createTextNode( content );
element.appendChild( child );
}
final String[] names = configuration.getAttributeNames();
for( int i = 0; i < names.length; i++ )
{
final String name = names[ i ];
final String value = configuration.getAttribute( name, null );
element.setAttribute( name, value );
}
final Configuration[] children = configuration.getChildren();
for( int i = 0; i < children.length; i++ )
{
final Element child = createElement( document, children[ i ] );
element.appendChild( child );
}
return element;
}
首先根据设置创建一个element,然后添加content中的内容。
之后依次获取configuration中的属性名和值,添加到element中。
最后将设置中的children添加到element中。