大家一起读Java美文

作为一个程序员,我们的休息时间在哪里?当你感到疲惫的时候,不妨静下心来,看一看别人写的代码,或者优秀程序员的杰作,可以说是另一种好的放松方式.
虽然Java没有文学那么优美,用文字来表达情感,但Java却用另一种方式,A-Z等字符诉说着另一种情感,让我们大家一起来读Java,来发现美.
今天比较清闲,就在网上找了一下源码,想到ibatis,也用了很久,而今天再想起的时候,发现已不是曾经的她了,而变成了mybatis,先了解了一下之后,从SVN上把源代码检索下来,
http://mybatis.googlecode.com/svn/trunk/,从IO包看了一下,当看到这个类的时候,产生了这个想法,如何让你的代码写的漂亮,写的全面,功能强大,扩展性强?如何让别人喜欢上你的代码?
以下代码,整体来说,只是提供了3个方法,但每一个方法却又分成3块,而这些都很类似,看上去,就像一个,对于编程3年的我来说,这样的代码,无非就是最漂亮的,没有多余的代码,每一行,每一块,都有真实的意义.如果说,还要继续优化的,我想还是可以找出问题,不过,有些心里晓得就行了,不必争论.
请仔细看一下吧,也许你看完之后,会有另类感觉.但有人也许会认为很不值得一提,毕竟优秀的代码太多了,而我在这里只是想要表达,我们也可以把Java代码当作一种美文读,不要感觉乏味,枯燥.
请大家一起读Java美文,让我们一起从这里寻找快乐.



package org.apache.ibatis.io;

import java.io.InputStream;
import java.net.URL;

/**
* A class to wrap access to multiple class loaders making them work as one
*/
public class ClassLoaderWrapper {

ClassLoader defaultClassLoader;

ClassLoaderWrapper() {
}

/**
* Get a resource as a URL using the current class path
*
* @param resource - the resource to locate
* @return the resource or null
*/
public URL getResourceAsURL(String resource) {
return getResourceAsURL(resource, new ClassLoader[]{
defaultClassLoader,
Thread.currentThread().getContextClassLoader(),
getClass().getClassLoader(),
ClassLoader.getSystemClassLoader()
});
}

/**
* Get a resource from the classpath, starting with a specific class loader
*
* @param resource - the resource to find
* @param classLoader - the first classloader to try
* @return the stream or null
*/
public URL getResourceAsURL(String resource, ClassLoader classLoader) {
return getResourceAsURL(resource, new ClassLoader[]{
classLoader,
defaultClassLoader,
Thread.currentThread().getContextClassLoader(),
getClass().getClassLoader(),
ClassLoader.getSystemClassLoader()
});
}

/**
* Get a resource from the classpath
*
* @param resource - the resource to find
* @return the stream or null
*/
public InputStream getResourceAsStream(String resource) {
return getResourceAsStream(resource, new ClassLoader[]{
defaultClassLoader,
Thread.currentThread().getContextClassLoader(),
getClass().getClassLoader(),
ClassLoader.getSystemClassLoader()
});
}

/**
* Get a resource from the classpath, starting with a specific class loader
*
* @param resource - the resource to find
* @param classLoader - the first class loader to try
* @return the stream or null
*/
public InputStream getResourceAsStream(String resource, ClassLoader classLoader) {
return getResourceAsStream(resource, new ClassLoader[]{
classLoader,
defaultClassLoader,
Thread.currentThread().getContextClassLoader(),
getClass().getClassLoader(),
ClassLoader.getSystemClassLoader()
});
}

/**
* Find a class on the classpath (or die trying)
*
* @param name - the class to look for
* @return - the class
* @throws ClassNotFoundException Duh.
*/
public Class> classForName(String name) throws ClassNotFoundException {
return classForName(name, new ClassLoader[]{
defaultClassLoader,
Thread.currentThread().getContextClassLoader(),
getClass().getClassLoader(),
ClassLoader.getSystemClassLoader()
});
}

/**
* Find a class on the classpath, starting with a specific classloader (or die trying)
*
* @param name - the class to look for
* @param classLoader - the first classloader to try
* @return - the class
* @throws ClassNotFoundException Duh.
*/
public Class> classForName(String name, ClassLoader classLoader) throws ClassNotFoundException {
return classForName(name, new ClassLoader[]{
classLoader,
defaultClassLoader,
Thread.currentThread().getContextClassLoader(),
getClass().getClassLoader(),
ClassLoader.getSystemClassLoader()
});
}

/**
* Try to get a resource from a group of classloaders
*
* @param resource - the resource to get
* @param classLoader - the classloaders to examine
* @return the resource or null
*/
InputStream getResourceAsStream(String resource, ClassLoader[] classLoader) {
for (ClassLoader cl : classLoader) {
if (null != cl) {

// try to find the resource as passed
InputStream returnValue = cl.getResourceAsStream(resource);

// now, some class loaders want this leading "/", so we'll add it and try again if we didn't find the resource
if (null == returnValue) returnValue = cl.getResourceAsStream("/" + resource);

if (null != returnValue) return returnValue;
}
}
return null;
}

/**
* Get a resource as a URL using the current class path
*
* @param resource - the resource to locate
* @param classLoader - the class loaders to examine
* @return the resource or null
*/
URL getResourceAsURL(String resource, ClassLoader[] classLoader) {

URL url;

for (ClassLoader cl : classLoader) {

if (null != cl) {

// look for the resource as passed in...
url = cl.getResource(resource);

// ...but some class loaders want this leading "/", so we'll add it
// and try again if we didn't find the resource
if (null == url) url = cl.getResource("/" + resource);

// "It's always in the last place I look for it!"
// ... because only an idiot would keep looking for it after finding it, so stop looking already.
if (null != url) return url;

}

}

// didn't find it anywhere.
return null;

}

/**
* Attempt to load a class from a group of classloaders
*
* @param name - the class to load
* @param classLoader - the group of classloaders to examine
* @return the class
* @throws ClassNotFoundException - Remember the wisdom of Judge Smails: Well, the world needs ditch diggers, too.
*/
Class> classForName(String name, ClassLoader[] classLoader) throws ClassNotFoundException {

for (ClassLoader cl : classLoader) {

if (null != cl) {

try {

Class> c = Class.forName(name, true, cl);

if (null != c) return c;

} catch (ClassNotFoundException e) {
// we'll ignore this until all classloaders fail to locate the class
}

}

}

throw new ClassNotFoundException("Cannot find class: " + name);

}

}

要制作一个心灵小屋美文网页,需要考虑以下几个步骤: 1. 网站规划:确定网站的整体结构和布局。考虑要展示的内容,比如美文、心灵鸡汤、启示语等。设计一个清晰的导航栏,方便用户浏览和查找。 2. 美术设计:选择一个适合心灵小屋主题的视觉设计,包括网站的颜色、字体、图片等元素。利用温暖、柔和的色调和简洁的排版,营造出温馨舒适的氛围。 3. 内容创作:找到高质量的心灵美文,可以是经典的名言警句、励志的故事、情感的表达等。同时也可以用文字配合图片来呈现更具感染力的作品。 4. 页面设计:用HTML和CSS编写网页结构和样式。利用HTML实现网页的基本框架,包括标题、段落和图像等。使用CSS设置网页的样式和布局,使其美观、舒适。 5. 多媒体元素:在网页中添加多媒体元素,比如音频、视频等。可以将一些感人的音乐、视频等嵌入到网页中,增加阅情感共鸣。 6. 交互设计:利用JavaScript和jQuery等技术,增加一些交互性功能。例如,可以在网页上设置留言板或评论区,让用户能够分享自己的心灵感悟。 7. 响应式设计:确保网站可以在不同的设备上自适应地显示和交互。根据设备的屏幕大小和分辨率,调整网页布局和样式,保证用户体验的一致性。 8. 测试和优化:在发布网站之前,进行功能测试和用户体验测试。确保网站在各种浏览器和操作系统上都能正常运行,并寻找任何可能的改进和优化。 通过以上步骤,就可以制作一个美观、舒适、富有灵感的心灵小屋美文网页。提供高质量的内容,并确保用户可以方便地浏览和参与互动,是打造一个成功的网页的关键要素。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值