<p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px; font-family:Arial; font-size:14px; line-height:26px"> 近段时间,对apache commons io的源码做了深入的了解,在此把一些见解与大家分享。</p>
<p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px; font-family:Arial; font-size:14px; line-height:26px"> 首先我选择了大部分框架还依赖的2.2版本而不是最新的2.4版本(2.5发行版还没有发布)进行源码的研读,今天就简介一下commons io的output部分。</p>
<p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px; font-family:Arial; font-size:14px; line-height:26px"> <img alt="" src="https://beijingoptbbs.oss-cn-beijing.aliyuncs.com/cs/5606289-23e968af4c45d29d07a8d735d1e691dd"><br> </p>
<p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px; font-family:Arial; font-size:14px; line-height:26px"> <span style="font-family:Arial; font-size:14px; line-height:26px">Output部分并不复杂,只是功能较多,主要由以下十二部分组成:通用部分、异常输出流标记、计数器相关功能、关闭输出流相关功能、三通相关功能、XML相关功能、流间对接相关功能、测试流相关功能、线程绑定部分、阀值输出部分、文件锁相关功能、字符集相关功能。</span><br> </p>
<p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px; font-family:Arial; font-size:14px; line-height:26px"> <span style="font-family:Arial; font-size:14px; line-height:26px"><span style="font-family:Arial; font-size:14px; line-height:26px">但我们应该先来了解一下ouyput所依赖的以下commons-io类:</span><br> </span></p>
<p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px; font-family:Arial; font-size:14px; line-height:26px"> <span style="font-family:Arial; font-size:14px; line-height:26px"><span style="font-family:Arial; font-size:14px; line-height:26px"></span></span></p>
<p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px; font-family:Arial; font-size:14px; line-height:26px"> <span style="color:rgb(51,51,51)">o</span><span style="color:rgb(51,51,51)">rg.apache.</span><span style="color:rgb(51,51,51)">commons.io.FileUtils</span></p>
<p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px; font-family:Arial; font-size:14px; line-height:26px"> <span style="color:rgb(51,51,51)">文件工具类,该类只使用了它的判断文件新旧功能。</span></p>
<p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px; font-family:Arial; font-size:14px; line-height:26px"> <span style="color:rgb(51,51,51)">有写文件、读文件、创建文件夹、复制文件/<span style="font-family:宋体">文件夹、删除文件</span>/<span style="font-family:宋体">文件夹、从</span>URL<span style="font-family:宋体">中获取文件、遍历后显示文件集结果、比较文件内容、修改文件最后修改时间、检查文件正确性,这些功能。</span></span></p>
<br>
<p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px; font-family:Arial; font-size:14px; line-height:26px"> <span style="font-family:Arial; font-size:14px; line-height:26px"><span style="font-family:Arial; font-size:14px; line-height:26px"></span></span></p>
<p><span style="color:rgb(51,51,51)">org.apache.commons.io.IOUtils</span></p>
<p><span style="color:rgb(51,51,51)">通用输入输出流的便捷操作工具类,有许多静态的工具方法,主要有关闭流、读取流、写入流、两流间复制、两流内容是否相等。</span></p>
<p><span style="color:rgb(51,51,51)">字节转字符和字符转</span><span style="color:rgb(51,51,51)">字节</span><span style="color:rgb(51,51,51)">的方法,鼓励使用给定字符集编码的方法进行操作,这样对环境迁移如开发环境到运行环境能获得更好的支持。</span></p>
<p><span style="color:rgb(51,51,51)">该类中的方法都不会对流进行清洗或关闭,这样就不会影响调用处的使用。</span></p>
<br>
<p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px; font-family:Arial; font-size:14px; line-height:26px"> <span style="font-family:Arial; font-size:14px; line-height:26px"><span style="font-family:Arial; font-size:14px; line-height:26px"></span></span></p>
<p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px; font-family:Arial; font-size:14px; line-height:26px"> <span style="color:rgb(51,51,51)">org.apache.commons.io.</span><span style="color:rgb(51,51,51)">TaggedIOException</span></p>
<p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px; font-family:Arial; font-size:14px; line-height:26px"> <span style="color:rgb(51,51,51)">可添加标记的IO<span style="font-family:宋体">异常。可以通过标记来</span></span><span style="color:rgb(51,51,51)">确认是哪一个输入输出流引起的。</span></p>
<br>
<p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px; font-family:Arial; font-size:14px; line-height:26px"> <span style="font-family:Arial; font-size:14px; line-height:26px"><span style="font-family:Arial; font-size:1 |
|