Upload original JAVA语言程序设计 course files (part 31)
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- .gitattributes +134 -0
- 尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/01_课件与电子教材.zip +3 -0
- 尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/01_课件与电子教材/尚硅谷_第15章_File类与IO流/03-apache-common包/commons-io-2.5-bin.zip +3 -0
- 尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/01_课件与电子教材/尚硅谷_第15章_File类与IO流/03-apache-common包/commons-io-2.5-src.zip +3 -0
- 尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/01_课件与电子教材/尚硅谷_第15章_File类与IO流/03-apache-common包/commons-io-2.5-src/LICENSE.txt +203 -0
- 尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/01_课件与电子教材/尚硅谷_第15章_File类与IO流/03-apache-common包/commons-io-2.5-src/NOTICE.txt +5 -0
- 尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/01_课件与电子教材/尚硅谷_第15章_File类与IO流/03-apache-common包/commons-io-2.5-src/PROPOSAL.html +78 -0
- 尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/01_课件与电子教材/尚硅谷_第15章_File类与IO流/03-apache-common包/commons-io-2.5-src/RELEASE-NOTES.txt +993 -0
- 尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/01_课件与电子教材/尚硅谷_第15章_File类与IO流/03-apache-common包/commons-io-2.5-src/build.xml +355 -0
- 尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/01_课件与电子教材/尚硅谷_第15章_File类与IO流/03-apache-common包/commons-io-2.5-src/checkstyle.xml +51 -0
- 尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/01_课件与电子教材/尚硅谷_第15章_File类与IO流/03-apache-common包/commons-io-2.5-src/findbugs-exclude-filter.xml +95 -0
- 尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/01_课件与电子教材/尚硅谷_第15章_File类与IO流/03-apache-common包/commons-io-2.5-src/pom.xml +422 -0
- 尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/01_课件与电子教材/尚硅谷_第15章_File类与IO流/03-apache-common包/commons-io-2.5-src/src/assembly/bin.xml +49 -0
- 尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/01_课件与电子教材/尚硅谷_第15章_File类与IO流/03-apache-common包/commons-io-2.5-src/src/assembly/src.xml +41 -0
- 尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/01_课件与电子教材/尚硅谷_第15章_File类与IO流/03-apache-common包/commons-io-2.5-src/src/changes/changes.xml +488 -0
- 尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/01_课件与电子教材/尚硅谷_第15章_File类与IO流/03-apache-common包/commons-io-2.5-src/src/changes/release-notes.vm +1029 -0
- 尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/01_课件与电子教材/尚硅谷_第15章_File类与IO流/03-apache-common包/commons-io-2.5-src/src/main/java/org/apache/commons/io/ByteOrderMark.java +191 -0
- 尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/01_课件与电子教材/尚硅谷_第15章_File类与IO流/03-apache-common包/commons-io-2.5-src/src/main/java/org/apache/commons/io/Charsets.java +192 -0
- 尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/01_课件与电子教材/尚硅谷_第15章_File类与IO流/03-apache-common包/commons-io-2.5-src/src/main/java/org/apache/commons/io/CopyUtils.java +392 -0
- 尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/01_课件与电子教材/尚硅谷_第15章_File类与IO流/03-apache-common包/commons-io-2.5-src/src/main/java/org/apache/commons/io/DirectoryWalker.java +642 -0
- 尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/01_课件与电子教材/尚硅谷_第15章_File类与IO流/03-apache-common包/commons-io-2.5-src/src/main/java/org/apache/commons/io/EndianUtils.java +482 -0
- 尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/01_课件与电子教材/尚硅谷_第15章_File类与IO流/03-apache-common包/commons-io-2.5-src/src/main/java/org/apache/commons/io/FileCleaner.java +160 -0
- 尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/01_课件与电子教材/尚硅谷_第15章_File类与IO流/03-apache-common包/commons-io-2.5-src/src/main/java/org/apache/commons/io/FileCleaningTracker.java +288 -0
- 尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/01_课件与电子教材/尚硅谷_第15章_File类与IO流/03-apache-common包/commons-io-2.5-src/src/main/java/org/apache/commons/io/FileDeleteStrategy.java +157 -0
- 尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/01_课件与电子教材/尚硅谷_第15章_File类与IO流/03-apache-common包/commons-io-2.5-src/src/main/java/org/apache/commons/io/FileExistsException.java +60 -0
- 尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/01_课件与电子教材/尚硅谷_第15章_File类与IO流/03-apache-common包/commons-io-2.5-src/src/main/java/org/apache/commons/io/FileSystemUtils.java +541 -0
- 尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/01_课件与电子教材/尚硅谷_第15章_File类与IO流/03-apache-common包/commons-io-2.5-src/src/main/java/org/apache/commons/io/FileUtils.java +0 -0
- 尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/01_课件与电子教材/尚硅谷_第15章_File类与IO流/03-apache-common包/commons-io-2.5-src/src/main/java/org/apache/commons/io/FilenameUtils.java +1452 -0
- 尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/01_课件与电子教材/尚硅谷_第15章_File类与IO流/03-apache-common包/commons-io-2.5-src/src/main/java/org/apache/commons/io/HexDump.java +163 -0
- 尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/01_课件与电子教材/尚硅谷_第15章_File类与IO流/03-apache-common包/commons-io-2.5-src/src/main/java/org/apache/commons/io/IOCase.java +254 -0
- 尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/01_课件与电子教材/尚硅谷_第15章_File类与IO流/03-apache-common包/commons-io-2.5-src/src/main/java/org/apache/commons/io/IOExceptionWithCause.java +67 -0
- 尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/01_课件与电子教材/尚硅谷_第15章_File类与IO流/03-apache-common包/commons-io-2.5-src/src/main/java/org/apache/commons/io/IOUtils.java +0 -0
- 尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/01_课件与电子教材/尚硅谷_第15章_File类与IO流/03-apache-common包/commons-io-2.5-src/src/main/java/org/apache/commons/io/Java7Support.java +190 -0
- 尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/01_课件与电子教材/尚硅谷_第15章_File类与IO流/03-apache-common包/commons-io-2.5-src/src/main/java/org/apache/commons/io/LineIterator.java +180 -0
- 尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/01_课件与电子教材/尚硅谷_第15章_File类与IO流/03-apache-common包/commons-io-2.5-src/src/main/java/org/apache/commons/io/TaggedIOException.java +136 -0
- 尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/01_课件与电子教材/尚硅谷_第15章_File类与IO流/03-apache-common包/commons-io-2.5-src/src/main/java/org/apache/commons/io/ThreadMonitor.java +134 -0
- 尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/01_课件与电子教材/尚硅谷_第15章_File类与IO流/03-apache-common包/commons-io-2.5-src/src/main/java/org/apache/commons/io/comparator/AbstractFileComparator.java +76 -0
- 尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/01_课件与电子教材/尚硅谷_第15章_File类与IO流/03-apache-common包/commons-io-2.5-src/src/main/java/org/apache/commons/io/comparator/CompositeFileComparator.java +122 -0
- 尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/01_课件与电子教材/尚硅谷_第15章_File类与IO流/03-apache-common包/commons-io-2.5-src/src/main/java/org/apache/commons/io/comparator/DefaultFileComparator.java +68 -0
- 尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/01_课件与电子教材/尚硅谷_第15章_File类与IO流/03-apache-common包/commons-io-2.5-src/src/main/java/org/apache/commons/io/comparator/DirectoryFileComparator.java +81 -0
- 尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/01_课件与电子教材/尚硅谷_第15章_File类与IO流/03-apache-common包/commons-io-2.5-src/src/main/java/org/apache/commons/io/comparator/ExtensionFileComparator.java +123 -0
- 尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/01_课件与电子教材/尚硅谷_第15章_File类与IO流/03-apache-common包/commons-io-2.5-src/src/main/java/org/apache/commons/io/comparator/LastModifiedFileComparator.java +79 -0
- 尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/01_课件与电子教材/尚硅谷_第15章_File类与IO流/03-apache-common包/commons-io-2.5-src/src/main/java/org/apache/commons/io/comparator/NameFileComparator.java +116 -0
- 尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/01_课件与电子教材/尚硅谷_第15章_File类与IO流/03-apache-common包/commons-io-2.5-src/src/main/java/org/apache/commons/io/comparator/PathFileComparator.java +117 -0
- 尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/01_课件与电子教材/尚硅谷_第15章_File类与IO流/03-apache-common包/commons-io-2.5-src/src/main/java/org/apache/commons/io/comparator/ReverseComparator.java +69 -0
- 尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/01_课件与电子教材/尚硅谷_第15章_File类与IO流/03-apache-common包/commons-io-2.5-src/src/main/java/org/apache/commons/io/comparator/SizeFileComparator.java +142 -0
- 尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/01_课件与电子教材/尚硅谷_第15章_File类与IO流/03-apache-common包/commons-io-2.5-src/src/main/java/org/apache/commons/io/comparator/package.html +188 -0
- 尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/01_课件与电子教材/尚硅谷_第15章_File类与IO流/03-apache-common包/commons-io-2.5-src/src/main/java/org/apache/commons/io/filefilter/AbstractFileFilter.java +64 -0
- 尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/01_课件与电子教材/尚硅谷_第15章_File类与IO流/03-apache-common包/commons-io-2.5-src/src/main/java/org/apache/commons/io/filefilter/AgeFileFilter.java +159 -0
- 尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/01_课件与电子教材/尚硅谷_第15章_File类与IO流/03-apache-common包/commons-io-2.5-src/src/main/java/org/apache/commons/io/filefilter/AndFileFilter.java +170 -0
.gitattributes
CHANGED
|
@@ -1,3 +1,137 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
oid sha256:c235fd2dca9067031676c053a0a02ffe365fcb7de0107c1653c927971f927e37
|
| 3 |
size 4077721
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
oid sha256:c235fd2dca9067031676c053a0a02ffe365fcb7de0107c1653c927971f927e37
|
| 3 |
size 4077721
|
| 4 |
+
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/01_课件与电子教材/尚硅谷_第15章_File类与IO流/03-apache-common包/commons-io-2.5-bin.zip filter=lfs diff=lfs merge=lfs -text
|
| 5 |
+
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/01_课件与电子教材/尚硅谷_第15章_File类与IO流/03-apache-common包/commons-io-2.5-src.zip filter=lfs diff=lfs merge=lfs -text
|
| 6 |
+
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/01_课件与电子教材/尚硅谷_第15章_File类与IO流/03-apache-common包/commons-lang-2.6-bin.zip filter=lfs diff=lfs merge=lfs -text
|
| 7 |
+
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/01_课件与电子教材/尚硅谷_第15章_File类与IO流/03-apache-common包/commons-lang-2.6-src.zip filter=lfs diff=lfs merge=lfs -text
|
| 8 |
+
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/01_课件与电子教材/尚硅谷_第15章_File类与IO流/03-apache-common包/commons-lang3-3.6-bin.zip filter=lfs diff=lfs merge=lfs -text
|
| 9 |
+
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/01_课件与电子教材/尚硅谷_第15章_File类与IO流/03-apache-common包/commons-lang3-3.6-src.zip filter=lfs diff=lfs merge=lfs -text
|
| 10 |
+
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/01_课件与电子教材/尚硅谷_第15章_File类与IO流/03-apache-common包/common包.jpg filter=lfs diff=lfs merge=lfs -text
|
| 11 |
+
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/01_课件与电子教材/尚硅谷_第15章_File类与IO流/images/1563809289418.png filter=lfs diff=lfs merge=lfs -text
|
| 12 |
+
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/01_课件与电子教材/尚硅谷_第15章_File类与IO流/images/image-20220412215446368.png filter=lfs diff=lfs merge=lfs -text
|
| 13 |
+
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/01_课件与电子教材/尚硅谷_第15章_File类与IO流/images/image-20220412230501953.png filter=lfs diff=lfs merge=lfs -text
|
| 14 |
+
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/01_课件与电子教材/尚硅谷_第15章_File类与IO流/images/image-20220518095907714.png filter=lfs diff=lfs merge=lfs -text
|
| 15 |
+
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/01_课件与电子教材/尚硅谷_第15章_File类与IO流/images/字符集.jpg filter=lfs diff=lfs merge=lfs -text
|
| 16 |
+
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/01_课件与电子教材/尚硅谷_第15章_File类与IO流/images/第3阶段:Java高级应用-第15章.png filter=lfs diff=lfs merge=lfs -text
|
| 17 |
+
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/01_课件与电子教材/尚硅谷_第15章_File类与IO流/尚硅谷_宋红康_IO流.pptx filter=lfs diff=lfs merge=lfs -text
|
| 18 |
+
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/01_课件与电子教材/尚硅谷_第16章_网络编程/apache-tomcat-8.5.15-windows-x64.zip filter=lfs diff=lfs merge=lfs -text
|
| 19 |
+
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/01_课件与电子教材/尚硅谷_第16章_网络编程/images/20220518_101503.jpg filter=lfs diff=lfs merge=lfs -text
|
| 20 |
+
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/01_课件与电子教材/尚硅谷_第16章_网络编程/images/image-20220131125934581.png filter=lfs diff=lfs merge=lfs -text
|
| 21 |
+
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/01_课件与电子教材/尚硅谷_第16章_网络编程/images/image-20220415001614195.png filter=lfs diff=lfs merge=lfs -text
|
| 22 |
+
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/01_课件与电子教材/尚硅谷_第16章_网络编程/images/image-20220415003729013.png filter=lfs diff=lfs merge=lfs -text
|
| 23 |
+
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/01_课件与电子教材/尚硅谷_第16章_网络编程/images/image-20220415010205891.png filter=lfs diff=lfs merge=lfs -text
|
| 24 |
+
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/01_课件与电子教材/尚硅谷_第16章_网络编程/images/image-20220415011744915.png filter=lfs diff=lfs merge=lfs -text
|
| 25 |
+
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/01_课件与电子教材/尚硅谷_第16章_网络编程/images/image-20220415011844298.png filter=lfs diff=lfs merge=lfs -text
|
| 26 |
+
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/01_课件与电子教材/尚硅谷_第16章_网络编程/images/image-20220415013546074.png filter=lfs diff=lfs merge=lfs -text
|
| 27 |
+
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/01_课件与电子教材/尚硅谷_第16章_网络编程/images/image-20220503144420721.png filter=lfs diff=lfs merge=lfs -text
|
| 28 |
+
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/01_课件与电子教材/尚硅谷_第16章_网络编程/images/image-20220503144450241.png filter=lfs diff=lfs merge=lfs -text
|
| 29 |
+
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/01_课件与电子教材/尚硅谷_第16章_网络编程/images/image-20220512234904047.png filter=lfs diff=lfs merge=lfs -text
|
| 30 |
+
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/01_课件与电子教材/尚硅谷_第16章_网络编程/images/image-20220514172833216.png filter=lfs diff=lfs merge=lfs -text
|
| 31 |
+
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/01_课件与电子教材/尚硅谷_第16章_网络编程/images/image-20220514173031651.png filter=lfs diff=lfs merge=lfs -text
|
| 32 |
+
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/01_课件与电子教材/尚硅谷_第16章_网络编程/images/第3阶段:Java高级应用-第16章.png filter=lfs diff=lfs merge=lfs -text
|
| 33 |
+
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/01_课件与电子教材/尚硅谷_第16章_网络编程/尚硅谷_宋红康_Tomcat8.5快速部署.docx filter=lfs diff=lfs merge=lfs -text
|
| 34 |
+
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/01_课件与电子教材/尚硅谷_第16章_网络编程/尚硅谷_宋红康_聊天室.pptx filter=lfs diff=lfs merge=lfs -text
|
| 35 |
+
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/01_课件与电子教材/尚硅谷_第17章_反射机制/images/image-20211218091234964.png filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/01_课件与电子教材/尚硅谷_第17章_反射机制/images/image-20220417171411631.png filter=lfs diff=lfs merge=lfs -text
|
| 37 |
+
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/01_课件与电子教材/尚硅谷_第17章_反射机制/images/image-20220524101441695.png filter=lfs diff=lfs merge=lfs -text
|
| 38 |
+
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/01_课件与电子教材/尚硅谷_第17章_反射机制/images/image-20220524101448625.png filter=lfs diff=lfs merge=lfs -text
|
| 39 |
+
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/01_课件与电子教材/尚硅谷_第17章_反射机制/images/第3阶段:Java高级应用-反射机制.png filter=lfs diff=lfs merge=lfs -text
|
| 40 |
+
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/01_课件与电子教材/尚硅谷_第17章_反射机制/images/第3阶段:Java高级应用-第17章.png filter=lfs diff=lfs merge=lfs -text
|
| 41 |
+
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/01_课件与电子教材/尚硅谷_第18章_JDK8-17新特性/images/01-交通方式.png filter=lfs diff=lfs merge=lfs -text
|
| 42 |
+
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/01_课件与电子教材/尚硅谷_第18章_JDK8-17新特性/images/1568796248165.png filter=lfs diff=lfs merge=lfs -text
|
| 43 |
+
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/01_课件与电子教材/尚硅谷_第18章_JDK8-17新特性/images/4428b288361296048.png filter=lfs diff=lfs merge=lfs -text
|
| 44 |
+
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/01_课件与电子教材/尚硅谷_第18章_JDK8-17新特性/images/image-20220525200441935.png filter=lfs diff=lfs merge=lfs -text
|
| 45 |
+
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/01_课件与电子教材/尚硅谷_第18章_JDK8-17新特性/images/image-20220527101814203.png filter=lfs diff=lfs merge=lfs -text
|
| 46 |
+
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/01_课件与电子教材/尚硅谷_第18章_JDK8-17新特性/images/image-20220527111442115.png filter=lfs diff=lfs merge=lfs -text
|
| 47 |
+
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/01_课件与电子教材/尚硅谷_第18章_JDK8-17新特性/images/image-20220528212048244.png filter=lfs diff=lfs merge=lfs -text
|
| 48 |
+
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/01_课件与电子教材/尚硅谷_第18章_JDK8-17新特性/images/image-20220528212254705.png filter=lfs diff=lfs merge=lfs -text
|
| 49 |
+
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/01_课件与电子教材/尚硅谷_第18章_JDK8-17新特性/images/image-20220529003920290.png filter=lfs diff=lfs merge=lfs -text
|
| 50 |
+
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/01_课件与电子教材/尚硅谷_第18章_JDK8-17新特性/images/jdkxintexing.jpg filter=lfs diff=lfs merge=lfs -text
|
| 51 |
+
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/01_课件与电子教材/尚硅谷_第18章_JDK8-17新特性/images/lambda表达式.jpg filter=lfs diff=lfs merge=lfs -text
|
| 52 |
+
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/01_课件与电子教材/尚硅谷_第18章_JDK8-17新特性/images/第3阶��:Java高级应用-第18章-1670946711240.png filter=lfs diff=lfs merge=lfs -text
|
| 53 |
+
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/01_课件与电子教材/尚硅谷_第18章_JDK8-17新特性/images/第3阶段:Java高级应用-第18章.png filter=lfs diff=lfs merge=lfs -text
|
| 54 |
+
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/01_课件与电子教材.zip filter=lfs diff=lfs merge=lfs -text
|
| 55 |
+
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/02_学习路线图.zip filter=lfs diff=lfs merge=lfs -text
|
| 56 |
+
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/03_复习与企业真题.zip filter=lfs diff=lfs merge=lfs -text
|
| 57 |
+
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/04_拓展练习.zip filter=lfs diff=lfs merge=lfs -text
|
| 58 |
+
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/05_实战项目/01-授课项目/Project1(谷粒记账软件)/Project1(谷粒记账软件).zip filter=lfs diff=lfs merge=lfs -text
|
| 59 |
+
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/05_实战项目/01-授课项目/Project2(拼电商客户管理系统)/Project2(拼电商客户管理系统).zip filter=lfs diff=lfs merge=lfs -text
|
| 60 |
+
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/05_实战项目/01-授课项目/Project3(优尚开发团队人员调度系统)/Project3(优尚开发团队人员调度系统).zip filter=lfs diff=lfs merge=lfs -text
|
| 61 |
+
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/05_实战项目/02-拓展项目/01-硅谷银行业务管理系统/01-硅谷银行业务管理系统.zip filter=lfs diff=lfs merge=lfs -text
|
| 62 |
+
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/05_实战项目/02-拓展项目/02-校园通在线考试系统/02-校园通在线考试系统.zip filter=lfs diff=lfs merge=lfs -text
|
| 63 |
+
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/05_实战项目/02-拓展项目/03-贪吃蛇/03-贪吃蛇.zip filter=lfs diff=lfs merge=lfs -text
|
| 64 |
+
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/05_实战项目/02-拓展项目/04-俄罗斯方块/04-俄罗斯方块/images/image-20220315104721073.png filter=lfs diff=lfs merge=lfs -text
|
| 65 |
+
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/05_实战项目/02-拓展项目/04-俄罗斯方块/04-俄罗斯方块/images/image-20220315164531501.png filter=lfs diff=lfs merge=lfs -text
|
| 66 |
+
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/05_实战项目/02-拓展项目/04-俄罗斯方块/04-俄罗斯方块/images/image-20220315165329674.png filter=lfs diff=lfs merge=lfs -text
|
| 67 |
+
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/05_实战项目/02-拓展项目/04-俄罗斯方块/04-俄罗斯方块/images/image-20220315170516971.png filter=lfs diff=lfs merge=lfs -text
|
| 68 |
+
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/05_实战项目/02-拓展项目/04-俄罗斯方块/04-俄罗斯方块/images/image-20220315172359303.png filter=lfs diff=lfs merge=lfs -text
|
| 69 |
+
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/05_实战项目/02-拓展项目/04-俄罗斯方块/04-俄罗斯方块.zip filter=lfs diff=lfs merge=lfs -text
|
| 70 |
+
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/05_实战项目/尚硅谷_宋红康_项目开发流程与角色.pptx filter=lfs diff=lfs merge=lfs -text
|
| 71 |
+
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/05_实战项目.zip filter=lfs diff=lfs merge=lfs -text
|
| 72 |
+
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/06_软件与资料/01-Java开发环境-JDK/jdk-17.0.2_windows-x64_bin.exe filter=lfs diff=lfs merge=lfs -text
|
| 73 |
+
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/06_软件与资料/01-Java开发环境-JDK/jdk-8u271-windows-x64.exe filter=lfs diff=lfs merge=lfs -text
|
| 74 |
+
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/06_软件与资料/01-Java开发环境-JDK/JDK其它各版本下载链接/jdk-7u7-windows-x64.exe filter=lfs diff=lfs merge=lfs -text
|
| 75 |
+
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/06_软件与资料/01-Java开发环境-JDK/JDK其它各版本下载链接/下载链接.docx filter=lfs diff=lfs merge=lfs -text
|
| 76 |
+
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/06_软件与资料/02-文本编辑器-EditPlus/editplus430_64bit.exe filter=lfs diff=lfs merge=lfs -text
|
| 77 |
+
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/06_软件与资料/02-文本编辑器-EditPlus/Editplus保姆级教程/Editplus保姆级教程/Java[[:space:]]jdk/jdk-8u121-windows-i586.exe filter=lfs diff=lfs merge=lfs -text
|
| 78 |
+
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/06_软件与资料/02-文本编辑器-EditPlus/Editplus保姆级教程/Editplus保姆级教��/java.[[:space:]]api/jdk[[:space:]]api[[:space:]]1.8_google.CHM filter=lfs diff=lfs merge=lfs -text
|
| 79 |
+
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/06_软件与资料/02-文本编辑器-EditPlus/Editplus保姆级教程/Editplus保姆级教程/第一步/EditPlus5.3.0.2542.7z filter=lfs diff=lfs merge=lfs -text
|
| 80 |
+
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/06_软件与资料/02-文本编辑器-EditPlus/Editplus保姆级教程/Editplus保姆级教程/第三步汉化/EditPlus.4.1.850.64位/EditPlus.exe filter=lfs diff=lfs merge=lfs -text
|
| 81 |
+
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/06_软件与资料/02-文本编辑器-EditPlus/Editplus保姆级教程/Editplus保姆级教程/第三步汉化/EditPlus.4.1.850.64位.7z filter=lfs diff=lfs merge=lfs -text
|
| 82 |
+
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/06_软件与资料/02-文本编辑器-EditPlus/Editplus保姆级教程/Editplus保姆级教程/第二步补丁/epp410p0917_0914_64bit.exe filter=lfs diff=lfs merge=lfs -text
|
| 83 |
+
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/06_软件与资料/02-文本编辑器-EditPlus/Editplus保姆级教程/Editplus保姆级教程/运行c++/x86_64-8.1.0-release-win32-seh-rt_v6-rev0.7z filter=lfs diff=lfs merge=lfs -text
|
| 84 |
+
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/06_软件与资料/02-文本编辑器-EditPlus/Editplus保姆级教程.zip filter=lfs diff=lfs merge=lfs -text
|
| 85 |
+
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/06_软件与资料/03-集成开发环境-IDEA/IDEA[[:space:]]2022.1[[:space:]]注册文档/IntelliJ[[:space:]]IDEA2022.1注册文档.docx filter=lfs diff=lfs merge=lfs -text
|
| 86 |
+
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/06_软件与资料/03-集成开发环境-IDEA/IDEA[[:space:]]2022.1[[:space:]]注册文档/jihuo-tool.zip filter=lfs diff=lfs merge=lfs -text
|
| 87 |
+
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/06_软件与资料/03-集成开发环境-IDEA/ideaIU-2022.1.2.exe filter=lfs diff=lfs merge=lfs -text
|
| 88 |
+
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/06_软件与资料/04-其它软件/01-学习必备-md文档工具-typora-setup-x64.exe filter=lfs diff=lfs merge=lfs -text
|
| 89 |
+
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/06_软件与资料/04-其它软件/02-学习必备-思维导图-XMindZEN/XMind[[:space:]]ZEN/XMind[[:space:]]ZEN/XMind-ZEN-for-Windows-32bit-10.0.0-201911180110.exe filter=lfs diff=lfs merge=lfs -text
|
| 90 |
+
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/06_软件与资料/04-其它软件/02-学习必备-思维导图-XMindZEN/XMind[[:space:]]ZEN/XMind[[:space:]]ZEN/XMind-ZEN-for-Windows-64bit-10.0.0-201911180033.exe filter=lfs diff=lfs merge=lfs -text
|
| 91 |
+
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/06_软件与资料/04-其它软件/02-学习必备-思维导图-XMindZEN/XMind[[:space:]]ZEN/XMind[[:space:]]ZEN/XMind-ZEN2020.10.0.0(x64)补丁/app.asar filter=lfs diff=lfs merge=lfs -text
|
| 92 |
+
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/06_软件与资料/04-其它软件/02-学习必备-思维导图-XMindZEN/XMind[[:space:]]ZEN/XMind[[:space:]]ZEN/XMind-ZEN2020.10.0.0(x86)补丁/app.asar filter=lfs diff=lfs merge=lfs -text
|
| 93 |
+
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/06_软件与资料/04-其它软件/02-学习必备-思维导图-XMindZEN.zip filter=lfs diff=lfs merge=lfs -text
|
| 94 |
+
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/06_软件与资料/04-其它软件/03-有道词典-YoudaoDictSetup.exe filter=lfs diff=lfs merge=lfs -text
|
| 95 |
+
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/06_软件与资料/04-其它软件/04-截图工具:QQScreenShotV2.5.zip filter=lfs diff=lfs merge=lfs -text
|
| 96 |
+
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/06_软件与资料/04-其它软件/04-截屏工具-Snipaste-2.7.3.zip filter=lfs diff=lfs merge=lfs -text
|
| 97 |
+
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/06_软件与资料/04-其它软件/05-反编译软件-jd-gui.exe filter=lfs diff=lfs merge=lfs -text
|
| 98 |
+
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/06_软件与资料/04-其它软件/06-文件对比工具-Beyond[[:space:]]Compare.zip filter=lfs diff=lfs merge=lfs -text
|
| 99 |
+
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/06_软件与资料/04-其它软件/07-金山打字通2.1.0.31.exe filter=lfs diff=lfs merge=lfs -text
|
| 100 |
+
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/06_软件与资料/04-其它软件/08-解压软件360zip_3.2.0.2220.exe filter=lfs diff=lfs merge=lfs -text
|
| 101 |
+
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/06_软件与资料/04-其它软件/09-360健康精灵(护眼卫士).rar filter=lfs diff=lfs merge=lfs -text
|
| 102 |
+
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/06_软件与资料/04-其它软件/10-Yuque-1.6.3.exe filter=lfs diff=lfs merge=lfs -text
|
| 103 |
+
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/06_软件与资料/04-其它软件/10-为知笔记-0.1.85-win-x64.exe filter=lfs diff=lfs merge=lfs -text
|
| 104 |
+
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/06_软件与资料/04-其它软件/先看说明再安装.docx filter=lfs diff=lfs merge=lfs -text
|
| 105 |
+
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/06_软件与资料/05-资料/API文档/Java[[:space:]]Platform[[:space:]]SE[[:space:]]8.chm filter=lfs diff=lfs merge=lfs -text
|
| 106 |
+
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/06_软件与资料/05-资料/API文档/jdk-17.0.2_doc-all.zip filter=lfs diff=lfs merge=lfs -text
|
| 107 |
+
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/06_软件与资料/05-资料/API文档/JDK_API_1.6_zh_中文.CHM filter=lfs diff=lfs merge=lfs -text
|
| 108 |
+
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/06_软件与资料/05-资料/API文档/JDK_API_1.6_zh_中文.chw filter=lfs diff=lfs merge=lfs -text
|
| 109 |
+
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/06_软件与资料/05-资料/Java基础全程单词/补充:《计算机英语词汇表》(高清晰pdf版).pdf filter=lfs diff=lfs merge=lfs -text
|
| 110 |
+
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/06_软件与资料/05-资料/Java基础全程单词/补充:中国程序员容易发音错误的单词.doc filter=lfs diff=lfs merge=lfs -text
|
| 111 |
+
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/06_软件与资料/05-资料/junit-libs/junit-4.12.jar filter=lfs diff=lfs merge=lfs -text
|
| 112 |
+
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/06_软件与资料/05-资料/阿里巴巴Java开发手册-1.7.1-黄山版.pdf filter=lfs diff=lfs merge=lfs -text
|
| 113 |
+
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/06_软件与资料.zip filter=lfs diff=lfs merge=lfs -text
|
| 114 |
+
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/07_授课代码.zip filter=lfs diff=lfs merge=lfs -text
|
| 115 |
+
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/08_授课视频/001.Java新版视频教程简介.mp4 filter=lfs diff=lfs merge=lfs -text
|
| 116 |
+
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/08_授课视频/02-Java语言概述-课程目录说明.mp4 filter=lfs diff=lfs merge=lfs -text
|
| 117 |
+
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/08_授课视频/03-Java语言概述-Java基础全程学习路线.mp4 filter=lfs diff=lfs merge=lfs -text
|
| 118 |
+
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/08_授课视频/04-Java语言概述-抽丝剥茧话Java.mp4 filter=lfs diff=lfs merge=lfs -text
|
| 119 |
+
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/08_授课视频/05-Java语言概述-Java工程师全程学习路线.mp4 filter=lfs diff=lfs merge=lfs -text
|
| 120 |
+
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/08_授课视频/06-Java语言概述-计算机硬件的介绍.mp4 filter=lfs diff=lfs merge=lfs -text
|
| 121 |
+
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/08_授课视频/07-Java语言概述-常见的DOS命令.mp4 filter=lfs diff=lfs merge=lfs -text
|
| 122 |
+
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/08_授课视频/08-Java语言概述-不同编程语言的介绍.mp4 filter=lfs diff=lfs merge=lfs -text
|
| 123 |
+
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/08_授课视频/09-Java语言概述-Java相关历史.mp4 filter=lfs diff=lfs merge=lfs -text
|
| 124 |
+
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/08_授课视频/10-Java语言概述-JDK的选择和下载.mp4 filter=lfs diff=lfs merge=lfs -text
|
| 125 |
+
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/08_授课视频/100-面向对象(进阶)-向下转型与多态性课后练习1-4.mp4 filter=lfs diff=lfs merge=lfs -text
|
| 126 |
+
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/08_授课视频/101-面向对象(进阶)-Object类及clone()、finalize()的理解.mp4 filter=lfs diff=lfs merge=lfs -text
|
| 127 |
+
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/08_授课视频/102-面向对象(进阶)-equals()方法的使用及练习1-2.mp4 filter=lfs diff=lfs merge=lfs -text
|
| 128 |
+
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/08_授课视频/103-面向对象(进阶)-toString()方法的使用及练习.mp4 filter=lfs diff=lfs merge=lfs -text
|
| 129 |
+
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/08_授课视频/104-面向对象(进阶)-第07章复习与企业真题.mp4 filter=lfs diff=lfs merge=lfs -text
|
| 130 |
+
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/08_授课视频/105-面向对象(高级)-关键字static修饰属性、方法.mp4 filter=lfs diff=lfs merge=lfs -text
|
| 131 |
+
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/08_授课视频/106-面向对象(高级)-static的应用举例及练习1,2.mp4 filter=lfs diff=lfs merge=lfs -text
|
| 132 |
+
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/08_授课视频/107-面向对象(高级)-单例设计模式与main()的理解.mp4 filter=lfs diff=lfs merge=lfs -text
|
| 133 |
+
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/08_授课视频/108-面向对象(高级)-类的成员之四:代码块.mp4 filter=lfs diff=lfs merge=lfs -text
|
| 134 |
+
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/08_授课视频/109-面向对象(高级)-小结:类中属性赋值的位置及过程.mp4 filter=lfs diff=lfs merge=lfs -text
|
| 135 |
+
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/08_授课视频/11-Java语言概述-JDK8的安装与path环境变量的配置.mp4 filter=lfs diff=lfs merge=lfs -text
|
| 136 |
+
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/08_授课视频/110-面向对象(高级)-关键字final的使用及真题.mp4 filter=lfs diff=lfs merge=lfs -text
|
| 137 |
+
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/08_授课视频/111-面向对象(高级)-抽象类与抽象方法的使用.mp4 filter=lfs diff=lfs merge=lfs -text
|
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/01_课件与电子教材.zip
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:b618acd0a2be7fa7b0847b10de6d15aa0bc6a77bebfbd52a8ffcc4cec3b65bc6
|
| 3 |
+
size 431855233
|
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/01_课件与电子教材/尚硅谷_第15章_File类与IO流/03-apache-common包/commons-io-2.5-bin.zip
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:be9c78df26d2997bf4ab5b0f2ea7fcf80c265fba9d962e7f20255e8a811fead0
|
| 3 |
+
size 1686431
|
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/01_课件与电子教材/尚硅谷_第15章_File类与IO流/03-apache-common包/commons-io-2.5-src.zip
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:d44c461dc110e1bf6e8a5e74c38101544d41c6b6e379308e5420521271bcf279
|
| 3 |
+
size 638391
|
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/01_课件与电子教材/尚硅谷_第15章_File类与IO流/03-apache-common包/commons-io-2.5-src/LICENSE.txt
ADDED
|
@@ -0,0 +1,203 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
Apache License
|
| 3 |
+
Version 2.0, January 2004
|
| 4 |
+
http://www.apache.org/licenses/
|
| 5 |
+
|
| 6 |
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
| 7 |
+
|
| 8 |
+
1. Definitions.
|
| 9 |
+
|
| 10 |
+
"License" shall mean the terms and conditions for use, reproduction,
|
| 11 |
+
and distribution as defined by Sections 1 through 9 of this document.
|
| 12 |
+
|
| 13 |
+
"Licensor" shall mean the copyright owner or entity authorized by
|
| 14 |
+
the copyright owner that is granting the License.
|
| 15 |
+
|
| 16 |
+
"Legal Entity" shall mean the union of the acting entity and all
|
| 17 |
+
other entities that control, are controlled by, or are under common
|
| 18 |
+
control with that entity. For the purposes of this definition,
|
| 19 |
+
"control" means (i) the power, direct or indirect, to cause the
|
| 20 |
+
direction or management of such entity, whether by contract or
|
| 21 |
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
| 22 |
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
| 23 |
+
|
| 24 |
+
"You" (or "Your") shall mean an individual or Legal Entity
|
| 25 |
+
exercising permissions granted by this License.
|
| 26 |
+
|
| 27 |
+
"Source" form shall mean the preferred form for making modifications,
|
| 28 |
+
including but not limited to software source code, documentation
|
| 29 |
+
source, and configuration files.
|
| 30 |
+
|
| 31 |
+
"Object" form shall mean any form resulting from mechanical
|
| 32 |
+
transformation or translation of a Source form, including but
|
| 33 |
+
not limited to compiled object code, generated documentation,
|
| 34 |
+
and conversions to other media types.
|
| 35 |
+
|
| 36 |
+
"Work" shall mean the work of authorship, whether in Source or
|
| 37 |
+
Object form, made available under the License, as indicated by a
|
| 38 |
+
copyright notice that is included in or attached to the work
|
| 39 |
+
(an example is provided in the Appendix below).
|
| 40 |
+
|
| 41 |
+
"Derivative Works" shall mean any work, whether in Source or Object
|
| 42 |
+
form, that is based on (or derived from) the Work and for which the
|
| 43 |
+
editorial revisions, annotations, elaborations, or other modifications
|
| 44 |
+
represent, as a whole, an original work of authorship. For the purposes
|
| 45 |
+
of this License, Derivative Works shall not include works that remain
|
| 46 |
+
separable from, or merely link (or bind by name) to the interfaces of,
|
| 47 |
+
the Work and Derivative Works thereof.
|
| 48 |
+
|
| 49 |
+
"Contribution" shall mean any work of authorship, including
|
| 50 |
+
the original version of the Work and any modifications or additions
|
| 51 |
+
to that Work or Derivative Works thereof, that is intentionally
|
| 52 |
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
| 53 |
+
or by an individual or Legal Entity authorized to submit on behalf of
|
| 54 |
+
the copyright owner. For the purposes of this definition, "submitted"
|
| 55 |
+
means any form of electronic, verbal, or written communication sent
|
| 56 |
+
to the Licensor or its representatives, including but not limited to
|
| 57 |
+
communication on electronic mailing lists, source code control systems,
|
| 58 |
+
and issue tracking systems that are managed by, or on behalf of, the
|
| 59 |
+
Licensor for the purpose of discussing and improving the Work, but
|
| 60 |
+
excluding communication that is conspicuously marked or otherwise
|
| 61 |
+
designated in writing by the copyright owner as "Not a Contribution."
|
| 62 |
+
|
| 63 |
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
| 64 |
+
on behalf of whom a Contribution has been received by Licensor and
|
| 65 |
+
subsequently incorporated within the Work.
|
| 66 |
+
|
| 67 |
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
| 68 |
+
this License, each Contributor hereby grants to You a perpetual,
|
| 69 |
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
| 70 |
+
copyright license to reproduce, prepare Derivative Works of,
|
| 71 |
+
publicly display, publicly perform, sublicense, and distribute the
|
| 72 |
+
Work and such Derivative Works in Source or Object form.
|
| 73 |
+
|
| 74 |
+
3. Grant of Patent License. Subject to the terms and conditions of
|
| 75 |
+
this License, each Contributor hereby grants to You a perpetual,
|
| 76 |
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
| 77 |
+
(except as stated in this section) patent license to make, have made,
|
| 78 |
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
| 79 |
+
where such license applies only to those patent claims licensable
|
| 80 |
+
by such Contributor that are necessarily infringed by their
|
| 81 |
+
Contribution(s) alone or by combination of their Contribution(s)
|
| 82 |
+
with the Work to which such Contribution(s) was submitted. If You
|
| 83 |
+
institute patent litigation against any entity (including a
|
| 84 |
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
| 85 |
+
or a Contribution incorporated within the Work constitutes direct
|
| 86 |
+
or contributory patent infringement, then any patent licenses
|
| 87 |
+
granted to You under this License for that Work shall terminate
|
| 88 |
+
as of the date such litigation is filed.
|
| 89 |
+
|
| 90 |
+
4. Redistribution. You may reproduce and distribute copies of the
|
| 91 |
+
Work or Derivative Works thereof in any medium, with or without
|
| 92 |
+
modifications, and in Source or Object form, provided that You
|
| 93 |
+
meet the following conditions:
|
| 94 |
+
|
| 95 |
+
(a) You must give any other recipients of the Work or
|
| 96 |
+
Derivative Works a copy of this License; and
|
| 97 |
+
|
| 98 |
+
(b) You must cause any modified files to carry prominent notices
|
| 99 |
+
stating that You changed the files; and
|
| 100 |
+
|
| 101 |
+
(c) You must retain, in the Source form of any Derivative Works
|
| 102 |
+
that You distribute, all copyright, patent, trademark, and
|
| 103 |
+
attribution notices from the Source form of the Work,
|
| 104 |
+
excluding those notices that do not pertain to any part of
|
| 105 |
+
the Derivative Works; and
|
| 106 |
+
|
| 107 |
+
(d) If the Work includes a "NOTICE" text file as part of its
|
| 108 |
+
distribution, then any Derivative Works that You distribute must
|
| 109 |
+
include a readable copy of the attribution notices contained
|
| 110 |
+
within such NOTICE file, excluding those notices that do not
|
| 111 |
+
pertain to any part of the Derivative Works, in at least one
|
| 112 |
+
of the following places: within a NOTICE text file distributed
|
| 113 |
+
as part of the Derivative Works; within the Source form or
|
| 114 |
+
documentation, if provided along with the Derivative Works; or,
|
| 115 |
+
within a display generated by the Derivative Works, if and
|
| 116 |
+
wherever such third-party notices normally appear. The contents
|
| 117 |
+
of the NOTICE file are for informational purposes only and
|
| 118 |
+
do not modify the License. You may add Your own attribution
|
| 119 |
+
notices within Derivative Works that You distribute, alongside
|
| 120 |
+
or as an addendum to the NOTICE text from the Work, provided
|
| 121 |
+
that such additional attribution notices cannot be construed
|
| 122 |
+
as modifying the License.
|
| 123 |
+
|
| 124 |
+
You may add Your own copyright statement to Your modifications and
|
| 125 |
+
may provide additional or different license terms and conditions
|
| 126 |
+
for use, reproduction, or distribution of Your modifications, or
|
| 127 |
+
for any such Derivative Works as a whole, provided Your use,
|
| 128 |
+
reproduction, and distribution of the Work otherwise complies with
|
| 129 |
+
the conditions stated in this License.
|
| 130 |
+
|
| 131 |
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
| 132 |
+
any Contribution intentionally submitted for inclusion in the Work
|
| 133 |
+
by You to the Licensor shall be under the terms and conditions of
|
| 134 |
+
this License, without any additional terms or conditions.
|
| 135 |
+
Notwithstanding the above, nothing herein shall supersede or modify
|
| 136 |
+
the terms of any separate license agreement you may have executed
|
| 137 |
+
with Licensor regarding such Contributions.
|
| 138 |
+
|
| 139 |
+
6. Trademarks. This License does not grant permission to use the trade
|
| 140 |
+
names, trademarks, service marks, or product names of the Licensor,
|
| 141 |
+
except as required for reasonable and customary use in describing the
|
| 142 |
+
origin of the Work and reproducing the content of the NOTICE file.
|
| 143 |
+
|
| 144 |
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
| 145 |
+
agreed to in writing, Licensor provides the Work (and each
|
| 146 |
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
| 147 |
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
| 148 |
+
implied, including, without limitation, any warranties or conditions
|
| 149 |
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
| 150 |
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
| 151 |
+
appropriateness of using or redistributing the Work and assume any
|
| 152 |
+
risks associated with Your exercise of permissions under this License.
|
| 153 |
+
|
| 154 |
+
8. Limitation of Liability. In no event and under no legal theory,
|
| 155 |
+
whether in tort (including negligence), contract, or otherwise,
|
| 156 |
+
unless required by applicable law (such as deliberate and grossly
|
| 157 |
+
negligent acts) or agreed to in writing, shall any Contributor be
|
| 158 |
+
liable to You for damages, including any direct, indirect, special,
|
| 159 |
+
incidental, or consequential damages of any character arising as a
|
| 160 |
+
result of this License or out of the use or inability to use the
|
| 161 |
+
Work (including but not limited to damages for loss of goodwill,
|
| 162 |
+
work stoppage, computer failure or malfunction, or any and all
|
| 163 |
+
other commercial damages or losses), even if such Contributor
|
| 164 |
+
has been advised of the possibility of such damages.
|
| 165 |
+
|
| 166 |
+
9. Accepting Warranty or Additional Liability. While redistributing
|
| 167 |
+
the Work or Derivative Works thereof, You may choose to offer,
|
| 168 |
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
| 169 |
+
or other liability obligations and/or rights consistent with this
|
| 170 |
+
License. However, in accepting such obligations, You may act only
|
| 171 |
+
on Your own behalf and on Your sole responsibility, not on behalf
|
| 172 |
+
of any other Contributor, and only if You agree to indemnify,
|
| 173 |
+
defend, and hold each Contributor harmless for any liability
|
| 174 |
+
incurred by, or claims asserted against, such Contributor by reason
|
| 175 |
+
of your accepting any such warranty or additional liability.
|
| 176 |
+
|
| 177 |
+
END OF TERMS AND CONDITIONS
|
| 178 |
+
|
| 179 |
+
APPENDIX: How to apply the Apache License to your work.
|
| 180 |
+
|
| 181 |
+
To apply the Apache License to your work, attach the following
|
| 182 |
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
| 183 |
+
replaced with your own identifying information. (Don't include
|
| 184 |
+
the brackets!) The text should be enclosed in the appropriate
|
| 185 |
+
comment syntax for the file format. We also recommend that a
|
| 186 |
+
file or class name and description of purpose be included on the
|
| 187 |
+
same "printed page" as the copyright notice for easier
|
| 188 |
+
identification within third-party archives.
|
| 189 |
+
|
| 190 |
+
Copyright [yyyy] [name of copyright owner]
|
| 191 |
+
|
| 192 |
+
Licensed under the Apache License, Version 2.0 (the "License");
|
| 193 |
+
you may not use this file except in compliance with the License.
|
| 194 |
+
You may obtain a copy of the License at
|
| 195 |
+
|
| 196 |
+
http://www.apache.org/licenses/LICENSE-2.0
|
| 197 |
+
|
| 198 |
+
Unless required by applicable law or agreed to in writing, software
|
| 199 |
+
distributed under the License is distributed on an "AS IS" BASIS,
|
| 200 |
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 201 |
+
See the License for the specific language governing permissions and
|
| 202 |
+
limitations under the License.
|
| 203 |
+
|
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/01_课件与电子教材/尚硅谷_第15章_File类与IO流/03-apache-common包/commons-io-2.5-src/NOTICE.txt
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Apache Commons IO
|
| 2 |
+
Copyright 2002-2016 The Apache Software Foundation
|
| 3 |
+
|
| 4 |
+
This product includes software developed at
|
| 5 |
+
The Apache Software Foundation (http://www.apache.org/).
|
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/01_课件与电子教材/尚硅谷_第15章_File类与IO流/03-apache-common包/commons-io-2.5-src/PROPOSAL.html
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
| 2 |
+
<!--
|
| 3 |
+
Licensed to the Apache Software Foundation (ASF) under one or more
|
| 4 |
+
contributor license agreements. See the NOTICE file distributed with
|
| 5 |
+
this work for additional information regarding copyright ownership.
|
| 6 |
+
The ASF licenses this file to You under the Apache License, Version 2.0
|
| 7 |
+
(the "License"); you may not use this file except in compliance with
|
| 8 |
+
the License. You may obtain a copy of the License at
|
| 9 |
+
|
| 10 |
+
http://www.apache.org/licenses/LICENSE-2.0
|
| 11 |
+
|
| 12 |
+
Unless required by applicable law or agreed to in writing, software
|
| 13 |
+
distributed under the License is distributed on an "AS IS" BASIS,
|
| 14 |
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 15 |
+
See the License for the specific language governing permissions and
|
| 16 |
+
limitations under the License.
|
| 17 |
+
-->
|
| 18 |
+
<html>
|
| 19 |
+
<head>
|
| 20 |
+
<title>Proposal for IO Package</title>
|
| 21 |
+
</head>
|
| 22 |
+
<body bgcolor="white">
|
| 23 |
+
|
| 24 |
+
<div align="center">
|
| 25 |
+
<h1>Proposal for <em>IO</em> Package</h1>
|
| 26 |
+
</div>
|
| 27 |
+
|
| 28 |
+
<h3>(0) Rationale</h3>
|
| 29 |
+
|
| 30 |
+
<p>Many software projects have a need to perform I/O in various ways, and
|
| 31 |
+
the JDK class libraries provide a lot of functionality, but sometimes you
|
| 32 |
+
need just a little bit more. The io package seeks to encapsulate some of
|
| 33 |
+
the most popular i/o base classes into one easy to use package.</p>
|
| 34 |
+
|
| 35 |
+
<h3>(1) Scope of the Package</h3>
|
| 36 |
+
|
| 37 |
+
<p>This proposal is to create a package of Java utility classes for various
|
| 38 |
+
types of i/o related activity.</p>
|
| 39 |
+
|
| 40 |
+
<h3>(1.5) Interaction With Other Packages</h3>
|
| 41 |
+
|
| 42 |
+
<p><em>IO</em> relies only on standard JDK 1.2 (or later) APIs for production
|
| 43 |
+
deployment. It utilizes the JUnit unit testing framework for developing
|
| 44 |
+
and executing unit tests, but this is of interest only to developers of the
|
| 45 |
+
component. IO will be a dependency for several existing components in the
|
| 46 |
+
open source world.</p>
|
| 47 |
+
|
| 48 |
+
<p>No external configuration files are utilized.</p>
|
| 49 |
+
|
| 50 |
+
<h3>(2) Initial Source of the Package</h3>
|
| 51 |
+
|
| 52 |
+
<p>The original Java classes are splashed around various Apache subprojects.
|
| 53 |
+
We intend to seek them out and integrate them.</p>
|
| 54 |
+
|
| 55 |
+
<p>The proposed package name for the new component is <code>org.apache.commons.io</code>.</p>
|
| 56 |
+
|
| 57 |
+
<h3>(3) Required Jakarta-Commons Resources</h3>
|
| 58 |
+
|
| 59 |
+
<ul>
|
| 60 |
+
<li>CVS Repository - New directory <code>io</code> in the <code>jakarta-commons</code>
|
| 61 |
+
CVS repository.</li>
|
| 62 |
+
<li>Mailing List - Discussions will take place on the general <em>dev@commons.apache.org</em>
|
| 63 |
+
mailing list. To help list subscribers identify messages of interest,
|
| 64 |
+
it is suggested that the message subject of messages about this component
|
| 65 |
+
be prefixed with [IO].</li>
|
| 66 |
+
<li>Bugzilla - New component "IO" under the "Commons" product category,
|
| 67 |
+
with appropriate version identifiers as needed.</li>
|
| 68 |
+
<li>Jyve FAQ - New category "commons-io" (when available).</li>
|
| 69 |
+
|
| 70 |
+
</ul>
|
| 71 |
+
|
| 72 |
+
<h3>(4) Initial Committers</h3>
|
| 73 |
+
|
| 74 |
+
<p>The initial committers on the IO component shall be Scott Sanders and
|
| 75 |
+
Nicola Ken Barozzi and Henri Yandell</p>
|
| 76 |
+
<br>
|
| 77 |
+
</body>
|
| 78 |
+
</html>
|
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/01_课件与电子教材/尚硅谷_第15章_File类与IO流/03-apache-common包/commons-io-2.5-src/RELEASE-NOTES.txt
ADDED
|
@@ -0,0 +1,993 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
Apache Commons IO
|
| 3 |
+
Version 2.5
|
| 4 |
+
Release Notes
|
| 5 |
+
|
| 6 |
+
INTRODUCTION:
|
| 7 |
+
|
| 8 |
+
Commons IO is a package of Java utility classes like java.io.
|
| 9 |
+
Classes in this package are considered to be so standard and of such high
|
| 10 |
+
reuse as to justify existence in java.io.
|
| 11 |
+
|
| 12 |
+
The Apache Commons IO library contains utility classes, stream implementations, file filters,
|
| 13 |
+
file comparators, endian transformation classes, and much more.
|
| 14 |
+
|
| 15 |
+
==============================================================================
|
| 16 |
+
Apache Commons IO Version 2.5
|
| 17 |
+
==============================================================================
|
| 18 |
+
New features and bug fixes.
|
| 19 |
+
|
| 20 |
+
Changes in this version include:
|
| 21 |
+
|
| 22 |
+
New features:
|
| 23 |
+
o IO-487: Add ValidatingObjectInputStream for controlled deserialization
|
| 24 |
+
o IO-471: Support for additional encodings in ReversedLinesFileReader Thanks to Leandro Reis.
|
| 25 |
+
o IO-425: Setter method for threshold on ThresholdingOutputStream Thanks to Craig Swank.
|
| 26 |
+
o IO-406: Introduce new class AppendableOutputStream Thanks to Niall Pemberton.
|
| 27 |
+
o IO-459: Add WindowsLineEndingInputStream and UnixLineEndingInputStream. Thanks to Kristian Rosenvold.
|
| 28 |
+
o IO-457: Add a BoundedReader, a wrapper that can be used to constrain access
|
| 29 |
+
to an underlying stream when used with mark/reset -
|
| 30 |
+
to avoid overflowing the mark limit of the underlying buffer. Thanks to Kristian Rosenvold.
|
| 31 |
+
o IO-426: Add API IOUtils.closeQuietly(Closeable...)
|
| 32 |
+
o IO-410: Readfully() That Returns A Byte Array Thanks to Beluga Behr.
|
| 33 |
+
o IO-395: Overload IOUtils buffer methods to accept buffer size Thanks to Beluga Behr.
|
| 34 |
+
o IO-382: Chunked IO for large arrays.
|
| 35 |
+
Added writeChunked(byte[], OutputStream) and writeChunked(char[] Writer)
|
| 36 |
+
Added ChunkedOutputStream, ChunkedWriter
|
| 37 |
+
o IO-233: Add Methods for Buffering Streams/Writers To IOUtils
|
| 38 |
+
Added overloaded buffer() methods - see also IO-330
|
| 39 |
+
o IO-330: IOUtils#toBufferedOutputStream/toBufferedWriter to conditionally wrap the output
|
| 40 |
+
Added overloaded buffer() methods - see also IO-233
|
| 41 |
+
o IO-381: Add FileUtils.copyInputStreamToFile API with option to leave the source open.
|
| 42 |
+
See copyInputStreamToFile(final InputStream source, final File destination, boolean closeSource)
|
| 43 |
+
o IO-379: CharSequenceInputStream - add tests for available()
|
| 44 |
+
Fix code so it really does reflect a minimum available.
|
| 45 |
+
o IO-346: Add ByteArrayOutputStream.toInputStream()
|
| 46 |
+
o IO-341: A constant for holding the BOM character (U+FEFF)
|
| 47 |
+
o IO-361: Add API FileUtils.forceMkdirsParent().
|
| 48 |
+
o IO-360: Add API Charsets.requiredCharsets().
|
| 49 |
+
o IO-359: Add IOUtils.skip and skipFully(ReadableByteChannel, long). Thanks to yukoba.
|
| 50 |
+
o IO-358: Add IOUtils.read and readFully(ReadableByteChannel, ByteBuffer buffer). Thanks to yukoba.
|
| 51 |
+
o IO-353: Add API IOUtils.copy(InputStream, OutputStream, int) Thanks to ggregory.
|
| 52 |
+
o IO-349: Add API with array offset and length argument to FileUtils.writeByteArrayToFile. Thanks to scop.
|
| 53 |
+
o IO-348: Missing information in IllegalArgumentException thrown by org.apache.commons.io.FileUtils#validateListFilesParameters. Thanks to plcstpierre.
|
| 54 |
+
o IO-345: Supply a hook method allowing Tailer actively determining stop condition. Thanks to mkresse.
|
| 55 |
+
o IO-437: Make IOUtils.EOF public and reuse it in various classes.
|
| 56 |
+
|
| 57 |
+
Fixed Bugs:
|
| 58 |
+
o IO-446: adds an endOfFileReached method to the TailerListener Thanks to Jeffrey Barrus.
|
| 59 |
+
o IO-484: FilenameUtils should handle embedded null bytes Thanks to Philippe Arteau.
|
| 60 |
+
o IO-481: Changed/Corrected algorithm for waitFor
|
| 61 |
+
o IO-428: BOMInputStream.skip returns wrong count if stream contains no BOM Thanks to Stefan Gmeiner.
|
| 62 |
+
o IO-488: FileUtils.waitFor(...) swallows thread interrupted status Thanks to Bj�rn Buchner.
|
| 63 |
+
o IO-452: Support for symlinks with missing target. Added support for JDK7 symlink features when present Thanks to David Standish.
|
| 64 |
+
o IO-453: Regression in FileUtils.readFileToString from 2.0.1 Thanks to Steven Christou.
|
| 65 |
+
o IO-451: ant test fails - resources missing from test classpath Thanks to David Standish.
|
| 66 |
+
o IO-435: Document that FileUtils.deleteDirectory, directoryContains and cleanDirectory
|
| 67 |
+
may throw an IllegalArgumentException in case the passed directory does not
|
| 68 |
+
exist or is not a directory. Thanks to Dominik Stadler.
|
| 69 |
+
o IO-424: Javadoc fixes, mostly to appease 1.8.0 Thanks to Ville Skytt�.
|
| 70 |
+
o IO-389: FileUtils.sizeOfDirectory can throw IllegalArgumentException Thanks to Austin Doupnik.
|
| 71 |
+
o IO-390: FileUtils.sizeOfDirectoryAsBigInteger can overflow.
|
| 72 |
+
Ensure that recursive calls all use BigInteger
|
| 73 |
+
o IO-385: FileUtils.doCopyFile can potentially loop for ever
|
| 74 |
+
Exit loop if no data to copy
|
| 75 |
+
o IO-383: FileUtils.doCopyFile caches the file size; needs to be documented
|
| 76 |
+
Added Javadoc; show file lengths in exception message
|
| 77 |
+
o IO-380: FileUtils.copyInputStreamToFile should document it closes the input source Thanks to claudio_ch.
|
| 78 |
+
o IO-279: Tailer erroneously considers file as new.
|
| 79 |
+
Fix to use file.lastModified() rather than System.currentTimeMillis()
|
| 80 |
+
o IO-356: CharSequenceInputStream#reset() behaves incorrectly in case when buffer size is not dividable by data size.
|
| 81 |
+
Fix code so skip relates to the encoded bytes; reset now re-encodes the data up to the point of the mark
|
| 82 |
+
o IO-368: ClassLoaderObjectInputStream does not handle primitive typed members
|
| 83 |
+
o IO-314: Deprecate all methods that use the default encoding
|
| 84 |
+
o IO-338: When a file is rotated, finish reading previous file prior to starting new one
|
| 85 |
+
o IO-354: Commons IO Tailer does not respect UTF-8 Charset.
|
| 86 |
+
o IO-323: What should happen in FileUtils.sizeOf[Directory] when an overflow takes place?
|
| 87 |
+
Added Javadoc.
|
| 88 |
+
o IO-372: FileUtils.moveDirectory can produce misleading error message on failiure
|
| 89 |
+
o IO-362: IOUtils.contentEquals* methods returns false if input1 == input2, should return true. Thanks to mmadson, ggregory.
|
| 90 |
+
o IO-357: [Tailer] InterruptedException while the thread is sleeping is silently ignored Thanks to mortenh.
|
| 91 |
+
o IO-352: Spelling fixes. Thanks to scop.
|
| 92 |
+
o IO-436: Improper JavaDoc comment for FilenameUtils.indexOfExtension. Thanks to christoph.schneegans.
|
| 93 |
+
|
| 94 |
+
Changes:
|
| 95 |
+
o IO-433: Converted all testcases to JUnit 4
|
| 96 |
+
o IO-466: Added testcase to show this was fixed with IO-423
|
| 97 |
+
o IO-479: Correct exception message in FileUtils.getFile(File, String...) Thanks to Zhouce Chen.
|
| 98 |
+
o IO-465: Update to JUnit 4.12 Thanks to based2.
|
| 99 |
+
o IO-462: IOExceptionWithCause no longer needed
|
| 100 |
+
o IO-422: Deprecate Charsets Charset constants in favor of Java 7's java.nio.charset.StandardCharsets
|
| 101 |
+
o IO-239: Convert IOCase to a Java 1.5+ Enumeration
|
| 102 |
+
[N.B. this is binary compatible]
|
| 103 |
+
o IO-328: getPrefixLength returns null if filename has leading slashes
|
| 104 |
+
Javadoc: add examples to show correct behaviour; add unit tests
|
| 105 |
+
o IO-299: FileUtils.listFilesAndDirs includes original dir in results even when it doesn't match filter
|
| 106 |
+
Javadoc: clarify that original dir is included in the results
|
| 107 |
+
o IO-375: FilenameUtils.splitOnTokens(String text) check for '**' could be simplified
|
| 108 |
+
o IO-374: WildcardFileFilter ctors should not use null to mean IOCase.SENSITIVE when delegating to other ctors
|
| 109 |
+
|
| 110 |
+
Compatibility with 2.4:
|
| 111 |
+
Binary compatible: Yes.
|
| 112 |
+
Source compatible: Yes.
|
| 113 |
+
Semantic compatible: Yes.
|
| 114 |
+
|
| 115 |
+
Compatibility with 2.2 and 1.4:
|
| 116 |
+
Binary compatible: Yes.
|
| 117 |
+
Source compatible: No, see the rare case in https://issues.apache.org/jira/browse/IO-318.
|
| 118 |
+
Semantic compatible: No, see the rare case in https://issues.apache.org/jira/browse/IO-318.
|
| 119 |
+
|
| 120 |
+
Commons IO 2.5 requires JDK 1.6 or later.
|
| 121 |
+
Commons IO 2.4 requires JDK 1.6 or later.
|
| 122 |
+
Commons IO 2.3 requires JDK 1.6 or later.
|
| 123 |
+
Commons IO 2.2 requires JDK 1.5 or later.
|
| 124 |
+
Commons IO 1.4 requires JDK 1.3 or later.
|
| 125 |
+
|
| 126 |
+
==============================================================================
|
| 127 |
+
Apache Commons IO Version 2.4
|
| 128 |
+
==============================================================================
|
| 129 |
+
|
| 130 |
+
Changes in this version include:
|
| 131 |
+
|
| 132 |
+
New features:
|
| 133 |
+
o IO-269: Tailer locks file from deletion/rename on Windows. Thanks to
|
| 134 |
+
sebb.
|
| 135 |
+
o IO-333: Export OSGi packages at version 1.x in addition to 2.x. Thanks
|
| 136 |
+
to fmeschbe.
|
| 137 |
+
o IO-320: Add XmlStreamReader support for UTF-32. Thanks to ggregory.
|
| 138 |
+
o IO-331: BOMInputStream wrongly detects UTF-32LE_BOM files as
|
| 139 |
+
UTF-16LE_BOM files in method getBOM(). Thanks to ggregory.
|
| 140 |
+
o IO-327: Add byteCountToDisplaySize(BigInteger). Thanks to ggregory.
|
| 141 |
+
o IO-326: Add new FileUtils.sizeOf[Directory] APIs to return BigInteger.
|
| 142 |
+
Thanks to ggregory.
|
| 143 |
+
o IO-325: Add IOUtils.toByteArray methods to work with URL and URI. Thanks
|
| 144 |
+
to raviprak.
|
| 145 |
+
o IO-324: Add missing Charset sister APIs to method that take a String
|
| 146 |
+
charset name. Thanks to raviprak.
|
| 147 |
+
|
| 148 |
+
Fixed Bugs:
|
| 149 |
+
o IO-336: Yottabyte (YB) incorrectly defined in FileUtils. Thanks to
|
| 150 |
+
rleavelle.
|
| 151 |
+
o IO-279: Tailer erroneously considers file as new. Thanks to Sergio
|
| 152 |
+
Bossa, Chris Baron.
|
| 153 |
+
o IO-335: Tailer#readLines - incorrect CR handling.
|
| 154 |
+
o IO-334: FileUtils.toURLs throws NPE for null parameter; document the
|
| 155 |
+
behavior.
|
| 156 |
+
o IO-332: Improve tailer's reading performance. Thanks to liangly.
|
| 157 |
+
o IO-279: Improve Tailer performance with buffered reads (see IO-332).
|
| 158 |
+
o IO-329: FileUtils.writeLines uses unbuffered IO. Thanks to tivv.
|
| 159 |
+
o IO-319: FileUtils.sizeOfDirectory follows symbolic links. Thanks to
|
| 160 |
+
raviprak.
|
| 161 |
+
|
| 162 |
+
|
| 163 |
+
Compatibility with 2.3:
|
| 164 |
+
Binary compatible: Yes.
|
| 165 |
+
Source compatible: Yes.
|
| 166 |
+
Semantic compatible: Yes.
|
| 167 |
+
|
| 168 |
+
Compatibility with 2.2 and 1.4:
|
| 169 |
+
Binary compatible: Yes.
|
| 170 |
+
Source compatible: No, see the rare case in https://issues.apache.org/jira/browse/IO-318.
|
| 171 |
+
Semantic compatible: No, see the rare case in https://issues.apache.org/jira/browse/IO-318.
|
| 172 |
+
|
| 173 |
+
Commons IO 2.4 requires JDK 1.6 or later.
|
| 174 |
+
Commons IO 2.3 requires JDK 1.6 or later.
|
| 175 |
+
Commons IO 2.2 requires JDK 1.5 or later.
|
| 176 |
+
Commons IO 1.4 requires JDK 1.3 or later.
|
| 177 |
+
|
| 178 |
+
==============================================================================
|
| 179 |
+
Apache Commons IO Version 2.3
|
| 180 |
+
==============================================================================
|
| 181 |
+
|
| 182 |
+
Changes in this version include:
|
| 183 |
+
|
| 184 |
+
New features:
|
| 185 |
+
o IO-322: Add and use class Charsets. Thanks to ggregory.
|
| 186 |
+
o IO-321: ByteOrderMark UTF_32LE is incorrect. Thanks to ggregory.
|
| 187 |
+
o IO-318: Add Charset sister APIs to method that take a String charset name. Thanks to ggregory.
|
| 188 |
+
|
| 189 |
+
Compatibility with 2.2 and 1.4:
|
| 190 |
+
Binary compatible: Yes.
|
| 191 |
+
Source compatible: No, see the rare case in https://issues.apache.org/jira/browse/IO-318.
|
| 192 |
+
Semantic compatible: No, see the rare case in https://issues.apache.org/jira/browse/IO-318.
|
| 193 |
+
|
| 194 |
+
Commons IO 2.3 requires JDK 1.6 or later.
|
| 195 |
+
Commons IO 2.2 requires JDK 1.5 or later.
|
| 196 |
+
Commons IO 1.4 requires JDK 1.3 or later.
|
| 197 |
+
|
| 198 |
+
==============================================================================
|
| 199 |
+
Apache Commons IO Version 2.2
|
| 200 |
+
==============================================================================
|
| 201 |
+
|
| 202 |
+
Changes in this version include:
|
| 203 |
+
|
| 204 |
+
New features:
|
| 205 |
+
o Add IOUTils.toBufferedReader(Reader) Issue: IO-313. Thanks to ggregory.
|
| 206 |
+
o Allow applications to provide buffer (or size) for copyLarge methods. Issue: IO-308. Thanks to Manoj Mokashi.
|
| 207 |
+
o New copyLarge() method in IOUtils that takes additional offset, length arguments Issue: IO-305. Thanks to Manoj Mokashi.
|
| 208 |
+
o Use terabyte (TB), petabyte (PB) and exabyte (EB) in FileUtils.byteCountToDisplaySize(long size) Issue: IO-287. Thanks to Ron Kuris, Gary Gregory.
|
| 209 |
+
o FileUtils.listFiles() doesn't return directories Issue: IO-173. Thanks to Marcos Vin�cius da Silva.
|
| 210 |
+
o CharSequenceInputStream to efficiently stream content of a CharSequence Issue: IO-297. Thanks to Oleg Kalnichevski.
|
| 211 |
+
o The second constructor of Tailer class does not pass 'delay' to the third one Issue: IO-304. Thanks to liangly.
|
| 212 |
+
o TeeOutputStream does not call branch.close() when main.close() throws an exception Issue: IO-303. Thanks to fabian.barney.
|
| 213 |
+
o ArrayIndexOutOfBoundsException in BOMInputStream when reading a file without BOM multiple times Issue: IO-302. Thanks to jsteuerwald, detinho.
|
| 214 |
+
o Add IOUtils.closeQuietly(Selector) necessary Issue: IO-301. Thanks to kaykay.unique.
|
| 215 |
+
o IOUtils.closeQuietly() should take a ServerSocket as a parameter Issue: IO-292. Thanks to sebb.
|
| 216 |
+
o Add read/readFully methods to IOUtils Issue: IO-290. Thanks to sebb.
|
| 217 |
+
o Supply a ReversedLinesFileReader Issue: IO-288. Thanks to Georg Henzler.
|
| 218 |
+
o Add new function FileUtils.directoryContains. Issue: IO-291. Thanks to ggregory.
|
| 219 |
+
o FileUtils.contentEquals and IOUtils.contentEquals - Add option to ignore "line endings"
|
| 220 |
+
Added contentEqualsIgnoreEOL methods to both classes Issue: IO-275. Thanks to CJ Aspromgos.
|
| 221 |
+
|
| 222 |
+
Fixed Bugs:
|
| 223 |
+
o IOUtils.read(InputStream/Reader) ignores the offset parameter Issue: IO-311. Thanks to Robert Muir.
|
| 224 |
+
o CharSequenceInputStream(CharSequence s, Charset charset, int bufferSize) ignores bufferSize Issue: IO-312.
|
| 225 |
+
o FileUtils.moveDirectoryToDirectory removes source directory if destination is a subdirectory Issue: IO-300.
|
| 226 |
+
o ReaderInputStream#read(byte[] b, int off, int len) should check for valid parameters Issue: IO-307.
|
| 227 |
+
o ReaderInputStream#read(byte[] b, int off, int len) should always return 0 for length == 0 Issue: IO-306.
|
| 228 |
+
o "FileUtils#deleteDirectoryOnExit(File)" does not work Issue: IO-276. Thanks to nkami.
|
| 229 |
+
o BoundedInputStream.read() treats max differently from BoundedInputStream.read(byte[]...) Issue: IO-273. Thanks to sebb.
|
| 230 |
+
o Various methods of class 'org.apache.commons.io.FileUtils' incorrectly suppress 'java.io.IOException' Issue: IO-298. Thanks to Christian Schulte.
|
| 231 |
+
|
| 232 |
+
Changes:
|
| 233 |
+
o ReaderInputStream optimization: more efficient reading of small chunks of data Issue: IO-296. Thanks to Oleg Kalnichevski.
|
| 234 |
+
|
| 235 |
+
|
| 236 |
+
Compatibility with 2.1 and 1.4:
|
| 237 |
+
Binary compatible: Yes
|
| 238 |
+
Source compatible: Yes
|
| 239 |
+
Semantic compatible: Yes. Check the bug fixes section for semantic bug fixes
|
| 240 |
+
|
| 241 |
+
Commons IO 2.2 requires a minimum of JDK 1.5.
|
| 242 |
+
Commons IO 1.4 requires a minimum of JDK 1.3.
|
| 243 |
+
|
| 244 |
+
==============================================================================
|
| 245 |
+
Apache Commons IO Version 2.1
|
| 246 |
+
==============================================================================
|
| 247 |
+
|
| 248 |
+
New features:
|
| 249 |
+
o Use standard Maven directory layout Issue: IO-285. Thanks to ggregory.
|
| 250 |
+
o Add IOUtils API toString for URL and URI to get contents Issue: IO-284. Thanks to ggregory.
|
| 251 |
+
o Add API FileUtils.copyFile(File input, OutputStream output) Issue: IO-282. Thanks to ggregory.
|
| 252 |
+
o FileAlterationObserver has no getter for FileFilter Issue: IO-262.
|
| 253 |
+
o Add FileUtils.getFile API with varargs parameter Issue: IO-261.
|
| 254 |
+
o Add new APPEND parameter for writing string into files Issue: IO-182.
|
| 255 |
+
o Add new read method "toByteArray" to handle InputStream with known size. Issue: IO-251. Thanks to Marco Albini.
|
| 256 |
+
|
| 257 |
+
Fixed Bugs:
|
| 258 |
+
o Dubious use of mkdirs() return code Issue: IO-280. Thanks to sebb.
|
| 259 |
+
o ReaderInputStream enters infinite loop when it encounters an unmappable character Issue: IO-277.
|
| 260 |
+
o FileUtils.moveFile() JavaDoc should specify FileExistsException thrown Issue: IO-264.
|
| 261 |
+
o ClassLoaderObjectInputStream does not handle Proxy classes Issue: IO-260.
|
| 262 |
+
o Tailer returning partial lines when reaching EOF before EOL Issue: IO-274. Thanks to Frank Grimes.
|
| 263 |
+
o FileUtils.copyFile() throws IOException when copying large files to a shared directory (on Windows) Issue: IO-266. Thanks to Igor Smereka.
|
| 264 |
+
o FileSystemUtils.freeSpaceKb throws exception for Windows volumes with no visible files.
|
| 265 |
+
Improve coverage by also looking for hidden files. Issue: IO-263. Thanks to Gil Adam.
|
| 266 |
+
|
| 267 |
+
Changes:
|
| 268 |
+
o FileAlterationMonitor.stop(boolean allowIntervalToFinish) Issue: IO-259.
|
| 269 |
+
|
| 270 |
+
==============================================================================
|
| 271 |
+
Apache Commons IO Package 2.0.1
|
| 272 |
+
==============================================================================
|
| 273 |
+
|
| 274 |
+
Compatibility with 2.0 and 1.4
|
| 275 |
+
------------------------------
|
| 276 |
+
Binary compatible - Yes
|
| 277 |
+
|
| 278 |
+
Source compatible - Yes
|
| 279 |
+
|
| 280 |
+
Semantic compatible - Yes
|
| 281 |
+
Check the bug fixes section for semantic bug fixes
|
| 282 |
+
|
| 283 |
+
Commons IO 2.0.1 requires a minimum of JDK 1.5
|
| 284 |
+
(Commons IO 1.4 had a minimum of JDK 1.3)
|
| 285 |
+
|
| 286 |
+
Enhancements from 2.0
|
| 287 |
+
---------------------
|
| 288 |
+
|
| 289 |
+
* [IO-256] - Provide thread factory for FileAlternationMonitor
|
| 290 |
+
|
| 291 |
+
Bug fixes from 2.0
|
| 292 |
+
------------------
|
| 293 |
+
|
| 294 |
+
* [IO-257] - BOMInputStream.read(byte[]) can return 0 which it should not
|
| 295 |
+
* [IO-258] - XmlStreamReader consumes the stream during encoding detection
|
| 296 |
+
|
| 297 |
+
==============================================================================
|
| 298 |
+
Apache Commons IO Package 2.0
|
| 299 |
+
==============================================================================
|
| 300 |
+
|
| 301 |
+
Compatibility with 1.4
|
| 302 |
+
----------------------
|
| 303 |
+
Binary compatible - Yes
|
| 304 |
+
|
| 305 |
+
Source compatible - Yes
|
| 306 |
+
|
| 307 |
+
Semantic compatible - Yes
|
| 308 |
+
Check the bug fixes section for semantic bug fixes
|
| 309 |
+
|
| 310 |
+
Commons IO 2.0 requires a minimum of JDK 1.5
|
| 311 |
+
(Commons IO 1.4 had a minimum of JDK 1.3)
|
| 312 |
+
|
| 313 |
+
Deprecations from 1.4
|
| 314 |
+
---------------------
|
| 315 |
+
|
| 316 |
+
- IOUtils
|
| 317 |
+
- write(StringBuffer, Writer) in favour of write(CharSequence, Writer)
|
| 318 |
+
- write(StringBuffer, OutputStream) in favour of write(CharSequence, OutputStream)
|
| 319 |
+
- write(StringBuffer, OutputStream, String) in favour of write(CharSequence, OutputStream, String)
|
| 320 |
+
|
| 321 |
+
- FileFilterUtils
|
| 322 |
+
- andFileFilter(IOFileFilter, IOFileFilter) in favour of and(IOFileFilter...)
|
| 323 |
+
- orFileFilter(IOFileFilter, IOFileFilter) in favour of or(IOFileFilter...)
|
| 324 |
+
|
| 325 |
+
Enhancements from 1.4
|
| 326 |
+
---------------------
|
| 327 |
+
|
| 328 |
+
* [IO-140] Move minimum Java requirement from JDK 1.3 to JDK 1.5
|
| 329 |
+
- use Generics
|
| 330 |
+
- add new CharSequence write() flavour methods to IOUtils and FileUtils
|
| 331 |
+
- replace StringBuffer with StringBuilder, where appropriate
|
| 332 |
+
- add new Reader/Writer methods to ProxyReader and ProxyWriter
|
| 333 |
+
- Annotate with @Override and @Deprecated
|
| 334 |
+
|
| 335 |
+
* [IO-178] New BOMInputStream and ByteOrderMark implementations - to detect and optionally exclude an initial Byte Order mark (BOM)
|
| 336 |
+
* [IO-197] New BoundedInputStream (copied from from Apache JackRabbit)
|
| 337 |
+
* [IO-193] New Broken Input and Output streams
|
| 338 |
+
* [IO-132] New File Listener/Monitor facility
|
| 339 |
+
* [IO-158] New ReaderInputStream and WriterOutputStream implementations
|
| 340 |
+
* [IO-139] New StringBuilder Writer implementation
|
| 341 |
+
* [IO-192] New Tagged Input and Output streams
|
| 342 |
+
* [IO-177] New Tailer class - simple implementation of the Unix "tail -f" functionality
|
| 343 |
+
* [IO-162] New XML Stream Reader/Writer implementations (from ROME via plexus-utils)
|
| 344 |
+
|
| 345 |
+
* [IO-142] Comparators - add facility to sort file lists/arrays
|
| 346 |
+
* [IO-186] Comparators - new Composite and Directory File Comparator implementations
|
| 347 |
+
* [IO-176] DirectoryWalker - add filterDirectoryContents() callback method for filtering directory contents
|
| 348 |
+
* [IO-210] FileFilter - new Magic Number FileFilter
|
| 349 |
+
* [IO-221] FileFilterUtils - add methods for suffix and prefix filters which take an IOCase object
|
| 350 |
+
* [IO-232] FileFilterUtils - add method for name filters which take an IOCase object
|
| 351 |
+
* [IO-229] FileFilterUtils - add varargs and() and or() methods
|
| 352 |
+
* [IO-198] FileFilterUtils - add ability to apply file filters to collections and arrays
|
| 353 |
+
* [IO-156] FilenameUtils - add normalize() and normalizeNoEndSeparator() methods which allow the separator character to be specified
|
| 354 |
+
* [IO-194] FileSystemUtils - add freeSpaceKb() method with no input arguments
|
| 355 |
+
* [IO-185] FileSystemUtils - add freeSpaceKb() methods that take a timeout parameter - fixes freeSpaceWindows() blocks
|
| 356 |
+
* [IO-155] FileUtils - use NIO to copy files
|
| 357 |
+
* [IO-168] FileUtils - add new isSymlink() method
|
| 358 |
+
* [IO-219] FileUtils - throw FileExistsException when moving a file or directory if the destination already exists
|
| 359 |
+
* [IO-234] FileUtils - add Methods for retrieving System User/Temp directories/paths
|
| 360 |
+
* [IO-208] FileUtils - add timeout (connection and read) support for copyURLToFile() method
|
| 361 |
+
* [IO-238] FileUtils - add sizeOf(File) method
|
| 362 |
+
* [IO-181] LineIterator now implements Iterable
|
| 363 |
+
* [IO-224] IOUtils - add closeQuietly(Closeable) and closeQuietly(Socket) methods
|
| 364 |
+
* [IO-203] IOUtils - add skipFully() method for InputStreams
|
| 365 |
+
* [IO-137] IOUtils and ByteArrayOutputStream - add toBufferedInputStream() method to avoid unnecessary array allocation/copy
|
| 366 |
+
* [IO-195] Proxy streams/Reader/Writer - provide exception handling methods
|
| 367 |
+
* [IO-211] Proxy Input/Output streams - add pre/post processing support
|
| 368 |
+
* [IO-242] Proxy Reader/Writer - add pre/post processing support
|
| 369 |
+
|
| 370 |
+
Bug fixes from 1.4
|
| 371 |
+
------------------
|
| 372 |
+
* [IO-214] ByteArrayOutputStream - fix inconsistent synchronization of fields
|
| 373 |
+
* [IO-201] Counting Input/Output streams - fix inconsistent synchronization
|
| 374 |
+
* [IO-159] FileCleaningTracker - fix remove() never returns null
|
| 375 |
+
* [IO-220] FileCleaningTracker - fix Vector performs badly under load
|
| 376 |
+
* [IO-167] FilenameUtils - fix case-insensitive string handling in FilenameUtils and FilesystemUtils
|
| 377 |
+
* [IO-179] FilenameUtils - fix StringIndexOutOfBounds exception in getPathNoEndSeparator()
|
| 378 |
+
* [IO-248] FilenameUtils - fix getFullPathNoEndSeparator() returns empty while path is a one level directory
|
| 379 |
+
* [IO-246] FilenameUtils - fix wildcardMatch gives incorrect results
|
| 380 |
+
* [IO-187] FileSystemUtils - fix freeSpaceKb() doesn't work with relative paths on Linux
|
| 381 |
+
* [IO-160] FileSystemUtils - fix freeSpace() fails on solaris
|
| 382 |
+
* [IO-209] FileSystemUtils - fix freeSpaceKb() fails to return correct size for a windows mount point
|
| 383 |
+
* [IO-163] FileUtils - fix toURLs() using deprecated method of conversion to URL
|
| 384 |
+
* [IO-168] FileUtils - fix Symbolic links followed when deleting directory
|
| 385 |
+
* [IO-231] FileUtils - fix wrong exception message generated in isFileNewer() method
|
| 386 |
+
* [IO-207] FileUtils - fix race condition in forceMkdir() method
|
| 387 |
+
* [IO-217] FileUtils - fix copyDirectoryToDirectory() makes infinite loops
|
| 388 |
+
* [IO-166] FileUtils - fix URL decoding in toFile(URL)
|
| 389 |
+
* [IO-190] FileUtils - fix copyDirectory not preserving lastmodified date on sub-directories
|
| 390 |
+
* [IO-240] FileFilterUtils - ensure cvsFilter and svnFilter are only created once.
|
| 391 |
+
* [IO-175] IOUtils - fix copyFile() issues with very large files
|
| 392 |
+
* [IO-191] Improvements from static analysis
|
| 393 |
+
* [IO-216] LockableFileWriter - delete files quietly when an exception is thrown during initialization
|
| 394 |
+
* [IO-243] SwappedDataInputStream - fix readBoolean is inverted
|
| 395 |
+
* [IO-235] Tests - remove unused YellOnFlushAndCloseOutputStream from CopyUtilsTest
|
| 396 |
+
* [IO-161] Tests - fix FileCleaningTrackerTestCase hanging
|
| 397 |
+
|
| 398 |
+
Documentation changes from 1.4
|
| 399 |
+
------------------------------
|
| 400 |
+
* [IO-183 FilenameUtils.getExtension() method documentation improvements
|
| 401 |
+
* [IO-226 FileUtils.byteCountToDisplaySize() documentation corrections
|
| 402 |
+
* [IO-205 FileUtils.forceMkdir() documentation improvements
|
| 403 |
+
* [IO-215 FileUtils copy file/directory improve documentation regarding preserving the last modified date
|
| 404 |
+
* [IO-189 HexDump.dump() method documentation improvements
|
| 405 |
+
* [IO-171 IOCase document that it assumes there are only two OSes: Windows and Unix
|
| 406 |
+
* [IO-223 IOUtils.copy() documentation corrections
|
| 407 |
+
* [IO-247 IOUtils.closeQuietly() improve documentation with examples
|
| 408 |
+
* [IO-202 NotFileFilter documentation corrections
|
| 409 |
+
* [IO-206 ProxyInputStream - fix misleading parameter names
|
| 410 |
+
* [IO-212 ProxyInputStream.skip() documentation corrections
|
| 411 |
+
|
| 412 |
+
==============================================================================
|
| 413 |
+
Apache Commons IO Version 1.4
|
| 414 |
+
==============================================================================
|
| 415 |
+
|
| 416 |
+
Compatibility with 1.3.2
|
| 417 |
+
------------------------
|
| 418 |
+
Binary compatible - Yes
|
| 419 |
+
|
| 420 |
+
Source compatible - Yes
|
| 421 |
+
|
| 422 |
+
Semantic compatible - Yes
|
| 423 |
+
Check the bug fixes section for semantic bug fixes
|
| 424 |
+
|
| 425 |
+
Commons IO 1.4 introduces four new implementations which depend on JDK 1.4 features
|
| 426 |
+
(CharSequenceReader, FileWriterWithEncoding, IOExceptionWithCause and RegexFileFilter).
|
| 427 |
+
It has been built with the JDK source and target options set to JDK 1.3 and, except for
|
| 428 |
+
those implementations, can be used with JDK 1.3 (see IO IO-127).
|
| 429 |
+
|
| 430 |
+
Deprecations from 1.3.2
|
| 431 |
+
-----------------------
|
| 432 |
+
- FileCleaner deprecated in favour of FileCleaningTracker [see IO-116]
|
| 433 |
+
|
| 434 |
+
Bug fixes from 1.3.2
|
| 435 |
+
--------------------
|
| 436 |
+
- FileUtils
|
| 437 |
+
- forceDelete of orphaned Softlinks does not work [IO-147]
|
| 438 |
+
- Infinite loop on FileUtils.copyDirectory when the destination directory is within
|
| 439 |
+
the source directory [IO-141]
|
| 440 |
+
- Add a copyDirectory() method that makes use of FileFilter [IO-105]
|
| 441 |
+
- Add moveDirectory() and moveFile() methods [IO-77]
|
| 442 |
+
|
| 443 |
+
- HexDump
|
| 444 |
+
- HexDump's use of static StringBuffers isn't thread-safe [IO-136]
|
| 445 |
+
|
| 446 |
+
Enhancements from 1.3.2
|
| 447 |
+
-----------------------
|
| 448 |
+
- FileUtils
|
| 449 |
+
- Add a deleteQuietly method [IO-135]
|
| 450 |
+
|
| 451 |
+
- FilenameUtils
|
| 452 |
+
- Add file name extension separator constants[IO-149]
|
| 453 |
+
|
| 454 |
+
- IOExceptionWithCause [IO-148]
|
| 455 |
+
- Add a new IOException implementation with constructors which take a cause
|
| 456 |
+
|
| 457 |
+
- TeeInputStream [IO-129]
|
| 458 |
+
- Add new Tee input stream implementation
|
| 459 |
+
|
| 460 |
+
- FileWriterWithEncoding [IO-153]
|
| 461 |
+
- Add new File Writer implementation that accepts an encoding
|
| 462 |
+
|
| 463 |
+
- CharSequenceReader [IO-138]
|
| 464 |
+
- Add new Reader implementation that handles any CharSequence (String,
|
| 465 |
+
StringBuffer, StringBuilder or CharBuffer)
|
| 466 |
+
|
| 467 |
+
- ThesholdingOuputStream [IO-121]
|
| 468 |
+
- Add a reset() method which sets the count of the bytes written back to zero.
|
| 469 |
+
|
| 470 |
+
- DeferredFileOutputStream [IO-130]
|
| 471 |
+
- Add support for temporary files
|
| 472 |
+
|
| 473 |
+
- ByteArrayOutputStream
|
| 474 |
+
- Add a new write(InputStream) method [IO-152]
|
| 475 |
+
|
| 476 |
+
- New Closed Input/Output stream implementations [IO-122]
|
| 477 |
+
- AutoCloseInputStream - automatically closes and discards the underlying input stream
|
| 478 |
+
- ClosedInputStream - returns -1 for any read attempts
|
| 479 |
+
- ClosedOutputStream - throws an IOException for any write attempts
|
| 480 |
+
- CloseShieldInputStream - prevents the underlying input stream from being closed.
|
| 481 |
+
- CloseShieldOutputStream - prevents the underlying output stream from being closed.
|
| 482 |
+
|
| 483 |
+
- Add Singleton Constants to several stream classes [IO-143]
|
| 484 |
+
|
| 485 |
+
- PrefixFileFilter [IO-126]
|
| 486 |
+
- Add faciltiy to specify case sensitivity on prefix matching
|
| 487 |
+
|
| 488 |
+
- SuffixFileFilter [IO-126]
|
| 489 |
+
- Add faciltiy to specify case sensitivity on suffix matching
|
| 490 |
+
|
| 491 |
+
- RegexFileFilter [IO-74]
|
| 492 |
+
- Add new regular expression file filter implementation
|
| 493 |
+
|
| 494 |
+
- Make IOFileFilter implementations Serializable [IO-131]
|
| 495 |
+
|
| 496 |
+
- Improve IOFileFilter toString() methods [IO-120]
|
| 497 |
+
|
| 498 |
+
- Make fields final so classes are immutable/threadsafe [IO-133]
|
| 499 |
+
- changes to Age, Delegate, Name, Not, Prefix, Regex, Size, Suffix and Wildcard IOFileFilter
|
| 500 |
+
implementations.
|
| 501 |
+
|
| 502 |
+
- IOCase
|
| 503 |
+
- Add a compare method to IOCase [IO-144]
|
| 504 |
+
|
| 505 |
+
- Add a package of java.util.Comparator implementations for files [IO-145]
|
| 506 |
+
- DefaultFileComparator - compare files using the default File.compareTo(File) method.
|
| 507 |
+
- ExtensionFileComparator - compares files using file name extensions.
|
| 508 |
+
- LastModifiedFileComparator - compares files using the last modified date/time.
|
| 509 |
+
- NameFileComparator - compares files using file names.
|
| 510 |
+
- PathFileComparator - compares files using file paths.
|
| 511 |
+
- SizeFileComparator - compares files using file sizes.
|
| 512 |
+
|
| 513 |
+
==============================================================================
|
| 514 |
+
Apache Commons IO Version 1.3.2
|
| 515 |
+
==============================================================================
|
| 516 |
+
|
| 517 |
+
Compatibility with 1.3.1
|
| 518 |
+
----------------------
|
| 519 |
+
Binary compatible - Yes
|
| 520 |
+
|
| 521 |
+
Source compatible - Yes
|
| 522 |
+
|
| 523 |
+
Semantic compatible - Yes
|
| 524 |
+
|
| 525 |
+
Compatibility with 1.3
|
| 526 |
+
----------------------
|
| 527 |
+
Binary compatible - No
|
| 528 |
+
See [IO-113]
|
| 529 |
+
|
| 530 |
+
Source compatible - No
|
| 531 |
+
See [IO-113]
|
| 532 |
+
|
| 533 |
+
Semantic compatible - Yes
|
| 534 |
+
|
| 535 |
+
Enhancements since 1.3.1
|
| 536 |
+
------------------------
|
| 537 |
+
|
| 538 |
+
- Created the FileCleaningTracker, basically a non-static version of the
|
| 539 |
+
FileCleaner, which can be controlled by the user. [IO-116]
|
| 540 |
+
- The FileCleaner is deprecated.
|
| 541 |
+
|
| 542 |
+
Bug fixes from 1.3.1
|
| 543 |
+
--------------------
|
| 544 |
+
|
| 545 |
+
- Some tests, which are implicitly assuming a Unix-like file system, are
|
| 546 |
+
now skipped on Windows. [IO-115]
|
| 547 |
+
- EndianUtils
|
| 548 |
+
- Both readSwappedUnsignedInteger(...) methods could return negative
|
| 549 |
+
numbers due to int/long casting. [IO-117]
|
| 550 |
+
|
| 551 |
+
Bug fixes from 1.3
|
| 552 |
+
------------------
|
| 553 |
+
|
| 554 |
+
- FileUtils
|
| 555 |
+
- NPE in openOutputStream(File) when file has no parent in path [IO-112]
|
| 556 |
+
- readFileToString(File) is not static [IO-113]
|
| 557 |
+
|
| 558 |
+
==============================================================================
|
| 559 |
+
Apache Commons IO Version 1.3.1
|
| 560 |
+
==============================================================================
|
| 561 |
+
|
| 562 |
+
Compatibility with 1.3
|
| 563 |
+
----------------------
|
| 564 |
+
Binary compatible - No
|
| 565 |
+
See [IO-113]
|
| 566 |
+
|
| 567 |
+
Source compatible - No
|
| 568 |
+
See [IO-113]
|
| 569 |
+
|
| 570 |
+
Semantic compatible - Yes
|
| 571 |
+
|
| 572 |
+
Bug fixes from 1.3
|
| 573 |
+
------------------
|
| 574 |
+
|
| 575 |
+
- FileUtils
|
| 576 |
+
- NPE in openOutputStream(File) when file has no parent in path [IO-112]
|
| 577 |
+
- readFileToString(File) is not static [IO-113]
|
| 578 |
+
|
| 579 |
+
==============================================================================
|
| 580 |
+
Apache Commons IO Version 1.3
|
| 581 |
+
==============================================================================
|
| 582 |
+
|
| 583 |
+
Compatibility with 1.2
|
| 584 |
+
----------------------
|
| 585 |
+
Binary compatible - Yes
|
| 586 |
+
|
| 587 |
+
Source compatible - Yes
|
| 588 |
+
|
| 589 |
+
Semantic compatible - Yes
|
| 590 |
+
Check the bug fixes section for semantic bug fixes
|
| 591 |
+
|
| 592 |
+
Deprecations from 1.2
|
| 593 |
+
---------------------
|
| 594 |
+
- WildcardFilter deprecated, replaced by WildcardFileFilter
|
| 595 |
+
- old class only accepted files, thus had a confusing dual purpose
|
| 596 |
+
|
| 597 |
+
- FileSystemUtils.freeSpace deprecated, replaced by freeSpaceKb
|
| 598 |
+
- freeSpace returns a result that varies by operating system and
|
| 599 |
+
thus isn't that useful
|
| 600 |
+
- freeSpaceKb returns much better and more consistent results
|
| 601 |
+
- freeSpaceKb existed in v1.2, so this is a gentle cutover
|
| 602 |
+
|
| 603 |
+
Bug fixes from 1.2
|
| 604 |
+
------------------
|
| 605 |
+
- LineIterator now implements Iterator
|
| 606 |
+
- It was always supposed to...
|
| 607 |
+
|
| 608 |
+
- FileSystemUtils.freeSpace/freeSpaceKb [IO-83]
|
| 609 |
+
- These should now work on AIX and HP-UX
|
| 610 |
+
|
| 611 |
+
- FileSystemUtils.freeSpace/freeSpaceKb [IO-90]
|
| 612 |
+
- Avoid infinite looping in Windows
|
| 613 |
+
- Catch more errors with nice messages
|
| 614 |
+
|
| 615 |
+
- FileSystemUtils.freeSpace [IO-91]
|
| 616 |
+
- This is now documented not to work on SunOS 5
|
| 617 |
+
|
| 618 |
+
- FileSystemUtils [IO-93]
|
| 619 |
+
- Fixed resource leak leading to 'Too many open files' error
|
| 620 |
+
- Previously did not destroy Process instances (as JDK Javadoc is so poor)
|
| 621 |
+
- http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4801027
|
| 622 |
+
|
| 623 |
+
- FileUtils.touch [IO-100]
|
| 624 |
+
- The touch method previously gave no indication when the file could not
|
| 625 |
+
be touched successfully (such as due to access restrictions) - it now
|
| 626 |
+
throws an IOException if the last modified date cannot be changed
|
| 627 |
+
|
| 628 |
+
- FileCleaner
|
| 629 |
+
- This now handles the situation where an error occurs when deleting the file
|
| 630 |
+
|
| 631 |
+
- IOUtils.copy [IO-84]
|
| 632 |
+
- Copy methods could return inaccurate byte/char count for large streams
|
| 633 |
+
- The copy(InputStream, OutputStream) method now returns -1 if the count is greater than an int
|
| 634 |
+
- The copy(Reader, Writer) method now throws now returns -1 if the count is greater than an int
|
| 635 |
+
- Added a new copyLarge(InputStream, OutputStream) method that returns a long
|
| 636 |
+
- Added a new copyLarge(Reader, Writer) method that returns a long
|
| 637 |
+
|
| 638 |
+
- CountingInputStream/CountingOutputStream [IO-84]
|
| 639 |
+
- Methods were declared as int thus the count was innacurate for large streams
|
| 640 |
+
- new long based methods getByteCount()/resetByteCount() added
|
| 641 |
+
- existing methods changed to throw an exception if the count is greater than an int
|
| 642 |
+
|
| 643 |
+
- FileBasedTestCase
|
| 644 |
+
- Fixed bug in compare content methods identified by GNU classpath
|
| 645 |
+
|
| 646 |
+
- EndianUtils.writeSwappedLong(byte[], int) [IO-101]
|
| 647 |
+
- An int overrun in the bit shifting when it should have been a long
|
| 648 |
+
|
| 649 |
+
- EndianUtils.writeSwappedLong(InputStream) [IO-102]
|
| 650 |
+
- The return of input.read(byte[]) was not being checked to ensure all 8 bytes were read
|
| 651 |
+
|
| 652 |
+
Enhancements from 1.2
|
| 653 |
+
---------------------
|
| 654 |
+
- DirectoryWalker [IO-86]
|
| 655 |
+
- New class designed for subclassing to walk through a set of files.
|
| 656 |
+
DirectoryWalker provides the walk of the directories, filtering of
|
| 657 |
+
directories and files, and cancellation support. The subclass must provide
|
| 658 |
+
the specific behaviour, such as text searching or image processing.
|
| 659 |
+
|
| 660 |
+
- IOCase
|
| 661 |
+
- New class/enumeration for case-sensitivity control
|
| 662 |
+
|
| 663 |
+
- FilenameUtils
|
| 664 |
+
- New methods to handle case-sensitivity
|
| 665 |
+
- wildcardMatch - new method that has IOCase as a parameter
|
| 666 |
+
- equals - new method that has IOCase as a parameter
|
| 667 |
+
|
| 668 |
+
- FileUtils [IO-108] - new default encoding methods for:
|
| 669 |
+
- readFileToString(File)
|
| 670 |
+
- readLines(File)
|
| 671 |
+
- lineIterator(File)
|
| 672 |
+
- writeStringToFile(File, String)
|
| 673 |
+
- writeLines(File, Collection)
|
| 674 |
+
- writeLines(File, Collection, String)
|
| 675 |
+
|
| 676 |
+
- FileUtils.openOutputStream [IO-107]
|
| 677 |
+
- new method to open a FileOutputStream, creating parent directories if required
|
| 678 |
+
- FileUtils.touch
|
| 679 |
+
- FileUtils.copyURLToFile
|
| 680 |
+
- FileUtils.writeStringToFile
|
| 681 |
+
- FileUtils.writeByteArrayToFile
|
| 682 |
+
- FileUtils.writeLines
|
| 683 |
+
- enhanced to create parent directories if required
|
| 684 |
+
- FileUtils.openInputStream [IO-107]
|
| 685 |
+
- new method to open a FileInputStream, providing better error messages than the JDK
|
| 686 |
+
|
| 687 |
+
- FileUtils.isFileOlder
|
| 688 |
+
- new methods to check if a file is older (i.e. isFileOlder()) - counterparts
|
| 689 |
+
to the existing isFileNewer() methods.
|
| 690 |
+
|
| 691 |
+
- FileUtils.checksum, FileUtils.checksumCRC32
|
| 692 |
+
- new methods to create a checksum of a file
|
| 693 |
+
|
| 694 |
+
- FileUtils.copyFileToDirectory [IO-104]
|
| 695 |
+
- new variant that optionally retains the file date
|
| 696 |
+
|
| 697 |
+
- FileDeleteStrategy
|
| 698 |
+
- FileCleaner [IO-56,IO-70]
|
| 699 |
+
- FileDeleteStrategy is a strategy for handling file deletion
|
| 700 |
+
- This can be used as a calback in FileCleaner
|
| 701 |
+
- Together these allow FileCleaner to do a forceDelete to kill directories
|
| 702 |
+
|
| 703 |
+
- FileCleaner.exitWhenFinished [IO-99]
|
| 704 |
+
- A new method that allows the internal cleaner thread to be cleanly terminated
|
| 705 |
+
|
| 706 |
+
- WildcardFileFilter
|
| 707 |
+
- Replacement for WildcardFilter
|
| 708 |
+
- Accepts both files and directories
|
| 709 |
+
- Ability to control case-sensitivity
|
| 710 |
+
|
| 711 |
+
- NameFileFilter
|
| 712 |
+
- Ability to control case-sensitivity
|
| 713 |
+
|
| 714 |
+
- FileFileFilter
|
| 715 |
+
- New IOFileFilter implementation
|
| 716 |
+
- Accepts files where File.isFile() is true
|
| 717 |
+
- In other words it filters out directories
|
| 718 |
+
- Singleton instance provided (FILE)
|
| 719 |
+
|
| 720 |
+
- CanReadFileFilter
|
| 721 |
+
- New IOFileFilter implementation
|
| 722 |
+
- Accepts files where File.canRead() is true
|
| 723 |
+
- Singleton instances provided (CAN_READ/CANNOT_READ/READ_ONLY)
|
| 724 |
+
|
| 725 |
+
- CanWriteFileFilter
|
| 726 |
+
- New IOFileFilter implementation
|
| 727 |
+
- Accepts files where File.canWrite() is true
|
| 728 |
+
- Singleton instances provided (CAN_WRITE/CANNOT_WRITE)
|
| 729 |
+
|
| 730 |
+
- HiddenFileFilter
|
| 731 |
+
- New IOFileFilter implementation
|
| 732 |
+
- Accepts files where File.isHidden() is true
|
| 733 |
+
- Singleton instances provided (HIDDEN/VISIBLE)
|
| 734 |
+
|
| 735 |
+
- EmptyFileFilter
|
| 736 |
+
- New IOFileFilter implementation
|
| 737 |
+
- Accepts files or directories that are empty
|
| 738 |
+
- Singleton instances provided (EMPTY/NOT_EMPTY)
|
| 739 |
+
|
| 740 |
+
- TrueFileFilter/FalseFileFilter/DirectoryFileFilter
|
| 741 |
+
- New singleton instance constants (TRUE/FALSE/DIRECTORY)
|
| 742 |
+
- The new constants are more JDK 1.5 friendly with regards to static imports
|
| 743 |
+
(whereas if everything uses INSTANCE, then they just clash)
|
| 744 |
+
- The old INSTANCE constants are still present and have not been deprecated
|
| 745 |
+
|
| 746 |
+
- FileFilterUtils.sizeRangeFileFilter
|
| 747 |
+
- new sizeRangeFileFilter(long minimumSize, long maximumSize) method which
|
| 748 |
+
creates a filter that accepts files within the specified size range.
|
| 749 |
+
|
| 750 |
+
- FileFilterUtils.makeDirectoryOnly/makeFileOnly
|
| 751 |
+
- two new methods that decorate a file filter to make it apply to
|
| 752 |
+
directories only or files only
|
| 753 |
+
|
| 754 |
+
- NullWriter
|
| 755 |
+
- New writer that acts as a sink for all data, as per /dev/null
|
| 756 |
+
|
| 757 |
+
- NullInputStream
|
| 758 |
+
- New input stream that emulates a stream of a specified size
|
| 759 |
+
|
| 760 |
+
- NullReader
|
| 761 |
+
- New reader that emulates a reader of a specified size
|
| 762 |
+
|
| 763 |
+
- ByteArrayOutputStream [IO-97]
|
| 764 |
+
- Performance enhancements
|
| 765 |
+
|
| 766 |
+
==============================================================================
|
| 767 |
+
Apache Commons IO Version 1.2
|
| 768 |
+
==============================================================================
|
| 769 |
+
|
| 770 |
+
Compatibility with 1.1
|
| 771 |
+
----------------------
|
| 772 |
+
Binary compatible - Yes
|
| 773 |
+
|
| 774 |
+
Source compatible - Yes
|
| 775 |
+
|
| 776 |
+
Semantic compatible - Yes
|
| 777 |
+
|
| 778 |
+
Deprecations from 1.1
|
| 779 |
+
---------------------
|
| 780 |
+
|
| 781 |
+
Bug fixes from 1.1
|
| 782 |
+
------------------
|
| 783 |
+
- FileSystemUtils.freeSpace(drive)
|
| 784 |
+
Fix to allow Windows based command to function in French locale
|
| 785 |
+
|
| 786 |
+
- FileUtils.read*
|
| 787 |
+
Increase certainty that files are closed in case of error
|
| 788 |
+
|
| 789 |
+
- LockableFileWriter
|
| 790 |
+
Locking mechanism was broken and only provided limited protection [38942]
|
| 791 |
+
File deletion and locking in case of constructor error was broken
|
| 792 |
+
|
| 793 |
+
Enhancements from 1.1
|
| 794 |
+
---------------------
|
| 795 |
+
- AgeFileFilter/SizeFileFilter
|
| 796 |
+
New file filters that compares against the age and size of the file
|
| 797 |
+
|
| 798 |
+
- FileSystemUtils.freeSpaceKb(drive)
|
| 799 |
+
New method that unifies result to be in kilobytes [38574]
|
| 800 |
+
|
| 801 |
+
- FileUtils.contentEquals(File,File)
|
| 802 |
+
Performance improved by adding length and file location checking
|
| 803 |
+
|
| 804 |
+
- FileUtils.iterateFiles
|
| 805 |
+
Two new method to provide direct access to iterators over files
|
| 806 |
+
|
| 807 |
+
- FileUtils.lineIterator
|
| 808 |
+
IOUtils.lineIterator
|
| 809 |
+
New methods to provide an iterator over the lines in a file [38083]
|
| 810 |
+
|
| 811 |
+
- FileUtils.copyDirectoryToDirectory
|
| 812 |
+
New method to copy a directory to within another directory [36315]
|
| 813 |
+
|
| 814 |
+
==============================================================================
|
| 815 |
+
Apache Commons IO Version 1.1
|
| 816 |
+
==============================================================================
|
| 817 |
+
|
| 818 |
+
Incompatible changes from 1.0
|
| 819 |
+
-----------------------------
|
| 820 |
+
Binary compatible - Yes
|
| 821 |
+
|
| 822 |
+
Source compatible - Yes
|
| 823 |
+
|
| 824 |
+
Semantic compatible - Yes, except:
|
| 825 |
+
- FileUtils.writeStringToFile()
|
| 826 |
+
A null encoding previously used 'ISO-8859-1', now it uses the platform default
|
| 827 |
+
Generally this will make no difference
|
| 828 |
+
|
| 829 |
+
- LockableFileWriter
|
| 830 |
+
Improved validation and now create directories if necesssary
|
| 831 |
+
|
| 832 |
+
plus these bug fixes may affect you semantically:
|
| 833 |
+
- FileUtils.touch() (Bug fix 29821)
|
| 834 |
+
Now creates the file if it did not previously exist
|
| 835 |
+
|
| 836 |
+
- FileUtils.toFile(URL) (Bug fix 32575)
|
| 837 |
+
Now handles escape syntax such as %20
|
| 838 |
+
|
| 839 |
+
- FileUtils.sizeOfDirectory() (Bug fix 36801)
|
| 840 |
+
May now return a size of 0 if the directory is security restricted
|
| 841 |
+
|
| 842 |
+
Deprecations from 1.0
|
| 843 |
+
---------------------
|
| 844 |
+
- CopyUtils has been deprecated.
|
| 845 |
+
Its methods have been moved to IOUtils.
|
| 846 |
+
The new IOUtils methods handle nulls better, and have clearer names.
|
| 847 |
+
|
| 848 |
+
- IOUtils.toByteArray(String) - Use {@link String#getBytes()}
|
| 849 |
+
- IOUtils.toString(byte[]) - Use {@link String#String(byte[])}
|
| 850 |
+
- IOUtils.toString(byte[],String) - Use {@link String#String(byte[],String)}
|
| 851 |
+
|
| 852 |
+
Bug fixes from 1.0
|
| 853 |
+
------------------
|
| 854 |
+
- FileUtils - touch() [29821]
|
| 855 |
+
Now creates the file if it did not previously exist
|
| 856 |
+
|
| 857 |
+
- FileUtils - toFile(URL) [32575]
|
| 858 |
+
Now handles escape syntax such as %20
|
| 859 |
+
|
| 860 |
+
- FileFilterUtils - makeCVSAware(IOFileFilter) [33023]
|
| 861 |
+
Fixed bug that caused method to be completely broken
|
| 862 |
+
|
| 863 |
+
- CountingInputStream [33336]
|
| 864 |
+
Fixed bug that caused the count to reduce by one at the end of the stream
|
| 865 |
+
|
| 866 |
+
- CountingInputStream - skip(long) [34311]
|
| 867 |
+
Bytes from calls to this method were not previously counted
|
| 868 |
+
|
| 869 |
+
- NullOutputStream [33481]
|
| 870 |
+
Remove unnecessary synchronization
|
| 871 |
+
|
| 872 |
+
- AbstractFileFilter - accept(File, String) [30992]
|
| 873 |
+
Fixed broken implementation
|
| 874 |
+
|
| 875 |
+
- FileUtils [36801]
|
| 876 |
+
Previously threw NPE when listing files in a security restricted directory
|
| 877 |
+
Now throw IOException with a better message
|
| 878 |
+
|
| 879 |
+
- FileUtils - writeStringToFile()
|
| 880 |
+
Null encoding now correctly uses the platform default
|
| 881 |
+
|
| 882 |
+
Enhancements from 1.0
|
| 883 |
+
---------------------
|
| 884 |
+
- FilenameUtils - new class [33303,29351]
|
| 885 |
+
A static utility class for working with filenames
|
| 886 |
+
Seeks to ease the pain of developing on Windows and deploying on Unix
|
| 887 |
+
|
| 888 |
+
- FileSystemUtils - new class [32982,36325]
|
| 889 |
+
A static utility class for working with file systems
|
| 890 |
+
Provides one method at present, to get the free space on the filing system
|
| 891 |
+
|
| 892 |
+
- IOUtils - new public constants
|
| 893 |
+
Constants for directory and line separators on Windows and Unix
|
| 894 |
+
|
| 895 |
+
- IOUtils - toByteArray(Reader,encoding)
|
| 896 |
+
Handles encodings when reading to a byte array
|
| 897 |
+
|
| 898 |
+
- IOUtils - toCharArray(InputStream) [28979]
|
| 899 |
+
- toCharArray(InputStream,encoding)
|
| 900 |
+
- toCharArray(Reader)
|
| 901 |
+
Reads a stream/reader into a charatcter array
|
| 902 |
+
|
| 903 |
+
- IOUtils - readLines(InputStream) [36214]
|
| 904 |
+
- readLines(InputStream,encoding)
|
| 905 |
+
- readLines(Reader)
|
| 906 |
+
Reads a stream/reader line by line into a List of Strings
|
| 907 |
+
|
| 908 |
+
- IOUtils - toInputStream(String) [32958]
|
| 909 |
+
- toInputStream(String,encoding)
|
| 910 |
+
Creates an input stream that uses the string as a source of data
|
| 911 |
+
|
| 912 |
+
- IOUtils - writeLines(Collection,lineEnding,OutputStream) [36214]
|
| 913 |
+
- writeLines(Collection,lineEnding,OutputStream,encoding)
|
| 914 |
+
- writeLines(Collection,lineEnding,Writer)
|
| 915 |
+
Writes a collection to a stream/writer line by line
|
| 916 |
+
|
| 917 |
+
- IOUtils - write(...)
|
| 918 |
+
Write data to a stream/writer (moved from CopyUtils with better null handling)
|
| 919 |
+
|
| 920 |
+
- IOUtils - copy(...)
|
| 921 |
+
Copy data between streams (moved from CopyUtils with better null handling)
|
| 922 |
+
|
| 923 |
+
- IOUtils - contentEquals(Reader,Reader)
|
| 924 |
+
Method to compare the contents of two readers
|
| 925 |
+
|
| 926 |
+
- FileUtils - toFiles(URL[])
|
| 927 |
+
Converts an array of URLs to an array of Files
|
| 928 |
+
|
| 929 |
+
- FileUtils - copyDirectory() [32944]
|
| 930 |
+
New methods to copy a directory
|
| 931 |
+
|
| 932 |
+
- FileUtils - readFileToByteArray(File)
|
| 933 |
+
Reads an entire file into a byte array
|
| 934 |
+
|
| 935 |
+
- FileUtils - writeByteArrayToFile(File,byte[])
|
| 936 |
+
Writes a byte array to a file
|
| 937 |
+
|
| 938 |
+
- FileUtils - readLines(File,encoding) [36214]
|
| 939 |
+
Reads a file line by line into a List of Strings
|
| 940 |
+
|
| 941 |
+
- FileUtils - writeLines(File,encoding,List)
|
| 942 |
+
writeLines(File,encoding,List,lineEnding)
|
| 943 |
+
Writes a collection to a file line by line
|
| 944 |
+
|
| 945 |
+
- FileUtils - EMPTY_FILE_ARRAY
|
| 946 |
+
Constant for an empty array of File objects
|
| 947 |
+
|
| 948 |
+
- ConditionalFileFilter - new interface [30705]
|
| 949 |
+
Defines the behaviour of list based filters
|
| 950 |
+
|
| 951 |
+
- AndFileFilter, OrFileFilter [30705]
|
| 952 |
+
Now support a list of filters to and/or
|
| 953 |
+
|
| 954 |
+
- WildcardFilter [31115]
|
| 955 |
+
New filter that can match using wildcard file names
|
| 956 |
+
|
| 957 |
+
- FileFilterUtils - makeSVNAware(IOFileFilter)
|
| 958 |
+
New method, like makeCVSAware, that ignores Subversion source control directories
|
| 959 |
+
|
| 960 |
+
- ClassLoaderObjectInputStream
|
| 961 |
+
An ObjectInputStream that supports a ClassLoader
|
| 962 |
+
|
| 963 |
+
- CountingInputStream,CountingOutputStream - resetCount() [28976]
|
| 964 |
+
Adds the ability to reset the count part way through reading/writing the stream
|
| 965 |
+
|
| 966 |
+
- DeferredFileOutputStream - writeTo(OutputStream) [34173]
|
| 967 |
+
New method to allow current contents to be written to a stream
|
| 968 |
+
|
| 969 |
+
- DeferredFileOutputStream [34142]
|
| 970 |
+
Performance optimizations avoiding double buffering
|
| 971 |
+
|
| 972 |
+
- LockableFileWriter - encoding support [36825]
|
| 973 |
+
Add support for character encodings to LockableFileWriter
|
| 974 |
+
Improve the validation
|
| 975 |
+
Create directories if necesssary
|
| 976 |
+
|
| 977 |
+
- IOUtils and EndianUtils are no longer final [28978]
|
| 978 |
+
Allows developers to have subclasses if desired
|
| 979 |
+
|
| 980 |
+
==============================================================================
|
| 981 |
+
Feedback
|
| 982 |
+
==============================================================================
|
| 983 |
+
|
| 984 |
+
Open source works best when you give feedback:
|
| 985 |
+
http://commons.apache.org/io/
|
| 986 |
+
|
| 987 |
+
Please direct all bug reports to JIRA
|
| 988 |
+
http://issues.apache.org/jira/browse/IO
|
| 989 |
+
|
| 990 |
+
Or subscribe to the commons-user mailing list (prefix emails by [io])
|
| 991 |
+
http://commons.apache.org/mail-lists.html
|
| 992 |
+
|
| 993 |
+
The Commons-IO Team
|
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/01_课件与电子教材/尚硅谷_第15章_File类与IO流/03-apache-common包/commons-io-2.5-src/build.xml
ADDED
|
@@ -0,0 +1,355 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!--
|
| 2 |
+
Licensed to the Apache Software Foundation (ASF) under one or more
|
| 3 |
+
contributor license agreements. See the NOTICE file distributed with
|
| 4 |
+
this work for additional information regarding copyright ownership.
|
| 5 |
+
The ASF licenses this file to You under the Apache License, Version 2.0
|
| 6 |
+
(the "License"); you may not use this file except in compliance with
|
| 7 |
+
the License. You may obtain a copy of the License at
|
| 8 |
+
|
| 9 |
+
http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
|
| 11 |
+
Unless required by applicable law or agreed to in writing, software
|
| 12 |
+
distributed under the License is distributed on an "AS IS" BASIS,
|
| 13 |
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 14 |
+
See the License for the specific language governing permissions and
|
| 15 |
+
limitations under the License.
|
| 16 |
+
-->
|
| 17 |
+
<project name="Commons IO" default="jar" basedir=".">
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
<!--
|
| 21 |
+
"IO" component of the Apache Commons Subproject
|
| 22 |
+
$Id: build.xml 1714367 2015-11-14 20:46:56Z adrianc $
|
| 23 |
+
-->
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
<!-- ========== Initialize Properties ===================================== -->
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
<property file="project.properties"/> <!-- Project local -->
|
| 30 |
+
<property file="build.properties"/> <!-- Component local -->
|
| 31 |
+
<property file="${user.home}/build.properties"/> <!-- User local -->
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
<!-- ========== External Dependencies ===================================== -->
|
| 35 |
+
|
| 36 |
+
<!-- Repository base path -->
|
| 37 |
+
<property name="repository" value="${user.home}/.m2/repository"/>
|
| 38 |
+
|
| 39 |
+
<!-- The directories corresponding to your necessary dependencies -->
|
| 40 |
+
<property name="junit.version" value="4.12"/>
|
| 41 |
+
<property name="junit.home" value="${repository}/junit/junit/${junit.version}"/>
|
| 42 |
+
<property name="junit.jar" value="${junit.home}/junit-${junit.version}.jar"/>
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
<!-- ========== Component Declarations ==================================== -->
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
<!-- The name of this component -->
|
| 49 |
+
<property name="component.name" value="commons-io"/>
|
| 50 |
+
|
| 51 |
+
<!-- The primary package name of this component -->
|
| 52 |
+
<property name="component.package" value="org.apache.commons.io"/>
|
| 53 |
+
|
| 54 |
+
<!-- The title of this component -->
|
| 55 |
+
<property name="component.title" value="Commons IO"/>
|
| 56 |
+
|
| 57 |
+
<!-- The current version number of this component -->
|
| 58 |
+
<property name="component.version" value="2.5-SNAPSHOT"/>
|
| 59 |
+
|
| 60 |
+
<!-- The base directory for component sources -->
|
| 61 |
+
<property name="source.home" value="src/main/java"/>
|
| 62 |
+
|
| 63 |
+
<!-- The base directory for unit test sources -->
|
| 64 |
+
<property name="test.home" value="src/test/java"/>
|
| 65 |
+
|
| 66 |
+
<!-- The base directory for unit test resources -->
|
| 67 |
+
<property name="test.resources.home" value="src/test/resources"/>
|
| 68 |
+
|
| 69 |
+
<!-- Download lib dir -->
|
| 70 |
+
<property name="download.lib.dir" value="lib"/>
|
| 71 |
+
|
| 72 |
+
<!-- The base directory for compilation targets -->
|
| 73 |
+
<property name="build.home" value="target"/>
|
| 74 |
+
|
| 75 |
+
<!-- The base directory for distribution targets -->
|
| 76 |
+
<property name="dist.home" value="${build.home}"/>
|
| 77 |
+
|
| 78 |
+
<!-- Base file name for dist files -->
|
| 79 |
+
<property name="final.name" value="${component.name}-${component.version}"/>
|
| 80 |
+
|
| 81 |
+
<!-- Directory where binary release files are staged -->
|
| 82 |
+
<property name="stage.bin.dir" value="${dist.home}/stage-bin"/>
|
| 83 |
+
|
| 84 |
+
<!-- Directory where source release files are staged -->
|
| 85 |
+
<property name="stage.src.dir" value="${dist.home}/stage-src"/>
|
| 86 |
+
|
| 87 |
+
<!-- ========== Compiler Defaults ========================================= -->
|
| 88 |
+
|
| 89 |
+
<!-- compiler source JDK version -->
|
| 90 |
+
<property name="compile.source" value="1.6"/>
|
| 91 |
+
|
| 92 |
+
<!-- compiler target JDK version -->
|
| 93 |
+
<property name="compile.target" value="1.6"/>
|
| 94 |
+
|
| 95 |
+
<!-- Should Java compilations set the 'debug' compiler option? -->
|
| 96 |
+
<property name="compile.debug" value="true"/>
|
| 97 |
+
|
| 98 |
+
<!-- Should Java compilations set the 'deprecation' compiler option? -->
|
| 99 |
+
<property name="compile.deprecation" value="false"/>
|
| 100 |
+
|
| 101 |
+
<!-- Should Java compilations set the 'optimize' compiler option? -->
|
| 102 |
+
<property name="compile.optimize" value="true"/>
|
| 103 |
+
|
| 104 |
+
<!-- Construct compile classpath -->
|
| 105 |
+
<path id="compile.classpath">
|
| 106 |
+
<pathelement location="${build.home}/classes"/>
|
| 107 |
+
</path>
|
| 108 |
+
|
| 109 |
+
<!-- Construct compile classpath -->
|
| 110 |
+
<path id="downloaded.lib.classpath">
|
| 111 |
+
<pathelement location="${download.lib.dir}/junit-${junit.version}.jar"/>
|
| 112 |
+
<pathelement location="${download.lib.dir}/hamcrest-core-1.3.jar"/>
|
| 113 |
+
</path>
|
| 114 |
+
|
| 115 |
+
<!-- ========== Test Execution Defaults =================================== -->
|
| 116 |
+
|
| 117 |
+
|
| 118 |
+
<!-- Construct unit test classpath -->
|
| 119 |
+
<path id="test.classpath">
|
| 120 |
+
<pathelement location="${build.home}/classes"/>
|
| 121 |
+
<pathelement location="${build.home}/test-classes"/>
|
| 122 |
+
<pathelement location="${build.home}/test-resources"/>
|
| 123 |
+
<pathelement location="${junit.jar}"/>
|
| 124 |
+
<path refid="downloaded.lib.classpath"/>
|
| 125 |
+
</path>
|
| 126 |
+
|
| 127 |
+
<!-- Should all tests fail if one does? -->
|
| 128 |
+
<property name="test.failonerror" value="true"/>
|
| 129 |
+
|
| 130 |
+
<!-- The test runner to execute -->
|
| 131 |
+
<property name="test.runner" value="junit.textui.TestRunner"/>
|
| 132 |
+
|
| 133 |
+
|
| 134 |
+
<!-- ========== Executable Targets ======================================== -->
|
| 135 |
+
|
| 136 |
+
<target name="clean" description="Clean build and distribution directories">
|
| 137 |
+
<delete dir="${build.home}"/>
|
| 138 |
+
<delete dir="test"/>
|
| 139 |
+
</target>
|
| 140 |
+
|
| 141 |
+
|
| 142 |
+
<target name="init"
|
| 143 |
+
description="Initialize and evaluate conditionals">
|
| 144 |
+
<echo message="-------- ${component.title} ${component.version} --------"/>
|
| 145 |
+
<filter token="name" value="${component.name}"/>
|
| 146 |
+
<filter token="package" value="${component.package}"/>
|
| 147 |
+
<filter token="version" value="${component.version}"/>
|
| 148 |
+
<filter token="compilesource" value="${compile.source}"/>
|
| 149 |
+
<filter token="compiletarget" value="${compile.target}"/>
|
| 150 |
+
<tstamp/>
|
| 151 |
+
<mkdir dir="${build.home}"/>
|
| 152 |
+
<mkdir dir="${build.home}/classes"/>
|
| 153 |
+
<mkdir dir="${build.home}/test-classes"/>
|
| 154 |
+
</target>
|
| 155 |
+
|
| 156 |
+
<!-- ========== Compile Targets =========================================== -->
|
| 157 |
+
|
| 158 |
+
<target name="compile" depends="init" description="Compile">
|
| 159 |
+
|
| 160 |
+
<javac srcdir="${source.home}"
|
| 161 |
+
destdir="${build.home}/classes"
|
| 162 |
+
source="${compile.source}"
|
| 163 |
+
target="${compile.target}"
|
| 164 |
+
debug="${compile.debug}"
|
| 165 |
+
deprecation="${compile.deprecation}"
|
| 166 |
+
optimize="${compile.optimize}"
|
| 167 |
+
includeantruntime="false">
|
| 168 |
+
<classpath refid="compile.classpath"/>
|
| 169 |
+
</javac>
|
| 170 |
+
</target>
|
| 171 |
+
|
| 172 |
+
|
| 173 |
+
<!-- ========== Unit Test Targets ========================================= -->
|
| 174 |
+
|
| 175 |
+
<target name="compile.tests" depends="compile, download-dependencies" description="Compile unit test cases dependent on JDK version">
|
| 176 |
+
|
| 177 |
+
<javac srcdir="${test.home}"
|
| 178 |
+
destdir="${build.home}/test-classes"
|
| 179 |
+
debug="${compile.debug}"
|
| 180 |
+
deprecation="${compile.deprecation}"
|
| 181 |
+
optimize="${compile.optimize}"
|
| 182 |
+
includeantruntime="false">
|
| 183 |
+
<classpath refid="test.classpath"/>
|
| 184 |
+
</javac>
|
| 185 |
+
<copy todir="${build.home}/test-resources">
|
| 186 |
+
<fileset dir="${test.resources.home}"/>
|
| 187 |
+
</copy>
|
| 188 |
+
</target>
|
| 189 |
+
|
| 190 |
+
<target name="test" depends="compile.tests"
|
| 191 |
+
description="Run all unit test cases">
|
| 192 |
+
<mkdir dir="${build.home}/ant-reports"/>
|
| 193 |
+
<junit printsummary="true" showoutput="true" fork="yes" haltonfailure="${test.failonerror}">
|
| 194 |
+
<classpath refid="test.classpath"/>
|
| 195 |
+
<formatter type="plain" usefile="true" />
|
| 196 |
+
<!-- If test.entry is defined, run a single test, otherwise run all valid tests -->
|
| 197 |
+
<test name="${test.entry}" if="test.entry"/>
|
| 198 |
+
<batchtest todir="${build.home}/ant-reports" unless="test.entry">
|
| 199 |
+
<fileset dir="${test.home}">
|
| 200 |
+
<include name="**/*Test*.java"/>
|
| 201 |
+
<!-- Test support files -->
|
| 202 |
+
<exclude name="**/testtools/**"/>
|
| 203 |
+
<!-- Ant JUnit does not handle abstract classes -->
|
| 204 |
+
<exclude name="**/*AbstractTestCase*"/>
|
| 205 |
+
<exclude name="**/Abstract*TestCase*"/>
|
| 206 |
+
</fileset>
|
| 207 |
+
</batchtest>
|
| 208 |
+
</junit>
|
| 209 |
+
</target>
|
| 210 |
+
|
| 211 |
+
|
| 212 |
+
<!-- ========== Produce JavaDocs ========================================== -->
|
| 213 |
+
|
| 214 |
+
<target name="javadoc" depends="compile" description="Create component Javadoc documentation">
|
| 215 |
+
<mkdir dir="${build.home}/apidocs"/>
|
| 216 |
+
<tstamp>
|
| 217 |
+
<format property="current.year" pattern="yyyy"/>
|
| 218 |
+
</tstamp>
|
| 219 |
+
<javadoc sourcepath="${source.home}"
|
| 220 |
+
destdir="${build.home}/apidocs"
|
| 221 |
+
packagenames="org.apache.commons.*"
|
| 222 |
+
author="true"
|
| 223 |
+
private="true"
|
| 224 |
+
version="true"
|
| 225 |
+
doctitle="<h1>${component.title} ${component.version}</h1>"
|
| 226 |
+
windowtitle="${component.title} ${component.version}"
|
| 227 |
+
bottom="Copyright (c) 2002-${current.year} Apache Software Foundation"
|
| 228 |
+
classpathref="compile.classpath">
|
| 229 |
+
<link href="http://java.sun.com/javaee/5/docs/api/"/>
|
| 230 |
+
<link href="http://download.oracle.com/javase/1.5.0/docs/api/index.html"/>
|
| 231 |
+
</javadoc>
|
| 232 |
+
</target>
|
| 233 |
+
|
| 234 |
+
|
| 235 |
+
<!-- ========== Create Jar ================================================ -->
|
| 236 |
+
|
| 237 |
+
<target name="jar" depends="compile" description="Create jar file">
|
| 238 |
+
|
| 239 |
+
<mkdir dir="${build.home}/classes/META-INF"/>
|
| 240 |
+
<copy file="LICENSE.txt" tofile="${build.home}/classes/META-INF/LICENSE.txt"/>
|
| 241 |
+
<copy file="NOTICE.txt" tofile="${build.home}/classes/META-INF/NOTICE.txt"/>
|
| 242 |
+
|
| 243 |
+
<manifest file="${build.home}/MANIFEST.MF">
|
| 244 |
+
<attribute name="Specification-Title" value="${component.title}"/>
|
| 245 |
+
<attribute name="Specification-Version" value="${component.version}"/>
|
| 246 |
+
<attribute name="Specification-Vendor" value="The Apache Software Foundation"/>
|
| 247 |
+
<attribute name="Implementation-Title" value="${component.title}"/>
|
| 248 |
+
<attribute name="Implementation-Version" value="${component.version}"/>
|
| 249 |
+
<attribute name="Implementation-Vendor" value="The Apache Software Foundation"/>
|
| 250 |
+
<attribute name="Implementation-Vendor-Id" value="org.apache"/>
|
| 251 |
+
<attribute name="X-Compile-Source-JDK" value="${compile.source}"/>
|
| 252 |
+
<attribute name="X-Compile-Target-JDK" value="${compile.target}"/>
|
| 253 |
+
</manifest>
|
| 254 |
+
|
| 255 |
+
<jar jarfile="${build.home}/${final.name}.jar"
|
| 256 |
+
basedir="${build.home}/classes"
|
| 257 |
+
manifest="${build.home}/MANIFEST.MF"/>
|
| 258 |
+
</target>
|
| 259 |
+
|
| 260 |
+
|
| 261 |
+
<!-- ========== Distribution Target =========================================== -->
|
| 262 |
+
|
| 263 |
+
<target name="dist" depends="clean,jar,javadoc" description="Create distribution artifacts">
|
| 264 |
+
|
| 265 |
+
<mkdir dir="${dist.home}"/>
|
| 266 |
+
|
| 267 |
+
<!-- jar(s) -->
|
| 268 |
+
<copy todir="${dist.home}">
|
| 269 |
+
<fileset dir=".">
|
| 270 |
+
<include name="RELEASE-NOTES.txt"/>
|
| 271 |
+
</fileset>
|
| 272 |
+
<fileset dir="${build.home}">
|
| 273 |
+
<include name="*.jar"/>
|
| 274 |
+
</fileset>
|
| 275 |
+
</copy>
|
| 276 |
+
|
| 277 |
+
<!-- Binary Distro -->
|
| 278 |
+
<mkdir dir="${stage.bin.dir}/${final.name}"/>
|
| 279 |
+
<copy todir="${stage.bin.dir}/${final.name}">
|
| 280 |
+
<fileset dir=".">
|
| 281 |
+
<include name="LICENSE.txt"/>
|
| 282 |
+
<include name="NOTICE.txt"/>
|
| 283 |
+
<include name="RELEASE-NOTES.txt"/>
|
| 284 |
+
</fileset>
|
| 285 |
+
<fileset dir="${build.home}">
|
| 286 |
+
<include name="*.jar"/>
|
| 287 |
+
</fileset>
|
| 288 |
+
</copy>
|
| 289 |
+
<copy todir="${stage.bin.dir}/${final.name}/apidocs">
|
| 290 |
+
<fileset dir="${build.home}/apidocs" />
|
| 291 |
+
</copy>
|
| 292 |
+
|
| 293 |
+
<!-- Source Distro -->
|
| 294 |
+
<mkdir dir="${stage.src.dir}/${final.name}-src"/>
|
| 295 |
+
<copy todir="${stage.src.dir}/${final.name}-src">
|
| 296 |
+
<fileset dir=".">
|
| 297 |
+
<include name="build.xml"/>
|
| 298 |
+
<include name="checkstyle.xml"/>
|
| 299 |
+
<include name="LICENSE.txt"/>
|
| 300 |
+
<include name="NOTICE.txt"/>
|
| 301 |
+
<include name="pom.xml"/>
|
| 302 |
+
<include name="PROPOSAL.html"/>
|
| 303 |
+
<include name="RELEASE-NOTES.txt"/>
|
| 304 |
+
</fileset>
|
| 305 |
+
</copy>
|
| 306 |
+
<copy todir="${stage.src.dir}/${final.name}-src/src">
|
| 307 |
+
<fileset dir="src" />
|
| 308 |
+
</copy>
|
| 309 |
+
|
| 310 |
+
<zip zipfile="${dist.home}/${final.name}.zip" basedir="${stage.bin.dir}"/>
|
| 311 |
+
<zip zipfile="${dist.home}/${final.name}-src.zip" basedir="${stage.src.dir}"/>
|
| 312 |
+
<tar tarfile="${dist.home}/${final.name}.tar" basedir="${stage.bin.dir}" longfile="gnu"/>
|
| 313 |
+
<tar tarfile="${dist.home}/${final.name}-src.tar" basedir="${stage.src.dir}" longfile="gnu"/>
|
| 314 |
+
<gzip src="${dist.home}/${final.name}.tar" zipfile="${dist.home}/${final.name}.tar.gz"/>
|
| 315 |
+
<gzip src="${dist.home}/${final.name}-src.tar" zipfile="${dist.home}/${final.name}-src.tar.gz"/>
|
| 316 |
+
|
| 317 |
+
<!-- clean up staging directories -->
|
| 318 |
+
<delete dir="${stage.bin.dir}"/>
|
| 319 |
+
<delete dir="${stage.src.dir}"/>
|
| 320 |
+
|
| 321 |
+
</target>
|
| 322 |
+
|
| 323 |
+
|
| 324 |
+
<!-- ========== Gump Target ===================================================== -->
|
| 325 |
+
|
| 326 |
+
<target name="gump" depends="clean,test,javadoc,jar" description="Gump Target - clean,test,javadoc,jar"/>
|
| 327 |
+
|
| 328 |
+
|
| 329 |
+
<!-- ========== Download Dependencies =========================================== -->
|
| 330 |
+
|
| 331 |
+
<target name="download-dependencies"
|
| 332 |
+
depends="check-availability" unless="skip.download">
|
| 333 |
+
<echo message="doing download-dependencies..." />
|
| 334 |
+
<antcall target="download-junit" />
|
| 335 |
+
</target>
|
| 336 |
+
|
| 337 |
+
<target name="check-availability">
|
| 338 |
+
<echo message="doing check-availability..." />
|
| 339 |
+
<available file="${download.lib.dir}/junit-${junit.version}.jar" property="junit.found"/>
|
| 340 |
+
</target>
|
| 341 |
+
|
| 342 |
+
<target name="download-junit" unless="junit.found">
|
| 343 |
+
<echo message="Downloading junit..."/>
|
| 344 |
+
<mkdir dir="${download.lib.dir}" />
|
| 345 |
+
<!-- TODO check hash of jar -->
|
| 346 |
+
<get dest="${download.lib.dir}"
|
| 347 |
+
usetimestamp="true" ignoreerrors="true"
|
| 348 |
+
src="http://repo1.maven.org/maven2/junit/junit/${junit.version}/junit-${junit.version}.jar"/>
|
| 349 |
+
<get dest="${download.lib.dir}"
|
| 350 |
+
usetimestamp="true" ignoreerrors="true"
|
| 351 |
+
src="https://hamcrest.googlecode.com/files/hamcrest-core-1.3.jar"/>
|
| 352 |
+
</target>
|
| 353 |
+
|
| 354 |
+
</project>
|
| 355 |
+
|
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/01_课件与电子教材/尚硅谷_第15章_File类与IO流/03-apache-common包/commons-io-2.5-src/checkstyle.xml
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?xml version="1.0"?>
|
| 2 |
+
<!--
|
| 3 |
+
Licensed to the Apache Software Foundation (ASF) under one or more
|
| 4 |
+
contributor license agreements. See the NOTICE file distributed with
|
| 5 |
+
this work for additional information regarding copyright ownership.
|
| 6 |
+
The ASF licenses this file to You under the Apache License, Version 2.0
|
| 7 |
+
(the "License"); you may not use this file except in compliance with
|
| 8 |
+
the License. You may obtain a copy of the License at
|
| 9 |
+
|
| 10 |
+
http://www.apache.org/licenses/LICENSE-2.0
|
| 11 |
+
|
| 12 |
+
Unless required by applicable law or agreed to in writing, software
|
| 13 |
+
distributed under the License is distributed on an "AS IS" BASIS,
|
| 14 |
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 15 |
+
See the License for the specific language governing permissions and
|
| 16 |
+
limitations under the License.
|
| 17 |
+
-->
|
| 18 |
+
|
| 19 |
+
<!DOCTYPE module PUBLIC
|
| 20 |
+
"-//Puppy Crawl//DTD Check Configuration 1.1//EN"
|
| 21 |
+
"http://www.puppycrawl.com/dtds/configuration_1_1.dtd">
|
| 22 |
+
|
| 23 |
+
<!-- commons lang customization of default Checkstyle behavior -->
|
| 24 |
+
<module name="Checker">
|
| 25 |
+
<property name="localeLanguage" value="en"/>
|
| 26 |
+
<module name="JavadocPackage">
|
| 27 |
+
<!-- setting allowLegacy means it will check for package.html instead of just package-info.java -->
|
| 28 |
+
<property name="allowLegacy" value="true"/>
|
| 29 |
+
</module>
|
| 30 |
+
<module name="FileTabCharacter">
|
| 31 |
+
<property name="fileExtensions" value="java,xml"/>
|
| 32 |
+
</module>
|
| 33 |
+
<module name="TreeWalker">
|
| 34 |
+
<property name="cacheFile" value="target/cachefile"/>
|
| 35 |
+
<module name="AvoidStarImport"/>
|
| 36 |
+
<module name="RedundantImport"/>
|
| 37 |
+
<module name="UnusedImports"/>
|
| 38 |
+
<module name="NeedBraces"/>
|
| 39 |
+
<module name="RedundantThrows">
|
| 40 |
+
<property name="allowUnchecked" value="true"/>
|
| 41 |
+
<property name="allowSubclasses" value="true"/>
|
| 42 |
+
</module>
|
| 43 |
+
<module name="LineLength">
|
| 44 |
+
<property name="max" value="160"/>
|
| 45 |
+
</module>
|
| 46 |
+
<module name="JavadocMethod">
|
| 47 |
+
<property name="allowUndeclaredRTE" value="true"/>
|
| 48 |
+
<property name="allowThrowsTagsForSubclasses" value="true"/>
|
| 49 |
+
</module>
|
| 50 |
+
</module>
|
| 51 |
+
</module>
|
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/01_课件与电子教材/尚硅谷_第15章_File类与IO流/03-apache-common包/commons-io-2.5-src/findbugs-exclude-filter.xml
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?xml version="1.0"?>
|
| 2 |
+
<!--
|
| 3 |
+
Licensed to the Apache Software Foundation (ASF) under one or more
|
| 4 |
+
contributor license agreements. See the NOTICE file distributed with
|
| 5 |
+
this work for additional information regarding copyright ownership.
|
| 6 |
+
The ASF licenses this file to You under the Apache License, Version 2.0
|
| 7 |
+
(the "License"); you may not use this file except in compliance with
|
| 8 |
+
the License. You may obtain a copy of the License at
|
| 9 |
+
|
| 10 |
+
http://www.apache.org/licenses/LICENSE-2.0
|
| 11 |
+
|
| 12 |
+
Unless required by applicable law or agreed to in writing, software
|
| 13 |
+
distributed under the License is distributed on an "AS IS" BASIS,
|
| 14 |
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 15 |
+
See the License for the specific language governing permissions and
|
| 16 |
+
limitations under the License.
|
| 17 |
+
-->
|
| 18 |
+
|
| 19 |
+
<!--
|
| 20 |
+
This file contains some false positive bugs detected by findbugs. Their
|
| 21 |
+
false positive nature has been analyzed individually and they have been
|
| 22 |
+
put here to instruct findbugs it must ignore them.
|
| 23 |
+
-->
|
| 24 |
+
<FindBugsFilter>
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
<!-- See discussion on https://issues.apache.org/jira/browse/IO-215 -->
|
| 28 |
+
<Match>
|
| 29 |
+
<Class name="org.apache.commons.io.FileUtils" />
|
| 30 |
+
<Or>
|
| 31 |
+
<Method name="doCopyDirectory" params="java.io.File,java.io.File,java.io.FileFilter,boolean,java.util.List" returns="void" />
|
| 32 |
+
<Method name="doCopyFile" params="java.io.File,java.io.File,boolean" returns="void" />
|
| 33 |
+
</Or>
|
| 34 |
+
<Bug pattern="RV_RETURN_VALUE_IGNORED_BAD_PRACTICE" />
|
| 35 |
+
</Match>
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
<!--
|
| 39 |
+
Ignoring the return from mkdirs() is a false positives since the
|
| 40 |
+
following line in both those methods checks for the existence of
|
| 41 |
+
the directory and throws an exception if it doesn't exist.
|
| 42 |
+
-->
|
| 43 |
+
<Match>
|
| 44 |
+
<Class name="org.apache.commons.io.FileUtils" />
|
| 45 |
+
<Or>
|
| 46 |
+
<Method name="moveDirectoryToDirectory" params="java.io.File,java.io.File,boolean" returns="void" />
|
| 47 |
+
<Method name="moveFileToDirectory" params="java.io.File,java.io.File,boolean" returns="void" />
|
| 48 |
+
</Or>
|
| 49 |
+
<Bug pattern="RV_RETURN_VALUE_IGNORED_BAD_PRACTICE" />
|
| 50 |
+
</Match>
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
<!--
|
| 54 |
+
FileEntry is used internally by FileAlterationObserver to refresh and
|
| 55 |
+
update the state of files it is monitoring and in that context this is
|
| 56 |
+
not an issue. If people re-use it elsewhere then they need to
|
| 57 |
+
take care - but its not its primary purpose here and so its OK
|
| 58 |
+
-->
|
| 59 |
+
<Match>
|
| 60 |
+
<Class name="org.apache.commons.io.monitor.FileEntry" />
|
| 61 |
+
<Method name="setChildren" params="org.apache.commons.io.monitor.FileEntry[]" returns="void" />
|
| 62 |
+
<Bug pattern="EI_EXPOSE_REP2" />
|
| 63 |
+
</Match>
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
<!-- See discussion on https://issues.apache.org/jira/browse/IO-214 -->
|
| 67 |
+
<Match>
|
| 68 |
+
<Class name="org.apache.commons.io.output.ByteArrayOutputStream" />
|
| 69 |
+
<Bug pattern="IS2_INCONSISTENT_SYNC" />
|
| 70 |
+
</Match>
|
| 71 |
+
|
| 72 |
+
|
| 73 |
+
<!-- This is a false positive since close() does nothing in the Stream implementation being used -->
|
| 74 |
+
<Match>
|
| 75 |
+
<Class name="org.apache.commons.io.output.ByteArrayOutputStream" />
|
| 76 |
+
<Method name="toBufferedInputStream" params="java.io.InputStream" returns="java.io.InputStream" />
|
| 77 |
+
<Bug pattern="OS_OPEN_STREAM" />
|
| 78 |
+
</Match>
|
| 79 |
+
|
| 80 |
+
|
| 81 |
+
<!-- See discussion on https://issues.apache.org/jira/browse/IO-216 -->
|
| 82 |
+
<Match>
|
| 83 |
+
<Class name="org.apache.commons.io.output.LockableFileWriter" />
|
| 84 |
+
<Method name="close" params="" returns="void" />
|
| 85 |
+
<Bug pattern="RV_RETURN_VALUE_IGNORED_BAD_PRACTICE" />
|
| 86 |
+
</Match>
|
| 87 |
+
|
| 88 |
+
<Match>
|
| 89 |
+
<Class name="org.apache.commons.io.output.DeferredFileOutputStream" />
|
| 90 |
+
<Or>
|
| 91 |
+
<Method name="thresholdReached" params="" returns="void" />
|
| 92 |
+
</Or>
|
| 93 |
+
<Bug pattern="OBL_UNSATISFIED_OBLIGATION" />
|
| 94 |
+
</Match>
|
| 95 |
+
</FindBugsFilter>
|
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/01_课件与电子教材/尚硅谷_第15章_File类与IO流/03-apache-common包/commons-io-2.5-src/pom.xml
ADDED
|
@@ -0,0 +1,422 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?xml version="1.0"?>
|
| 2 |
+
<!--
|
| 3 |
+
Licensed to the Apache Software Foundation (ASF) under one or more
|
| 4 |
+
contributor license agreements. See the NOTICE file distributed with
|
| 5 |
+
this work for additional information regarding copyright ownership.
|
| 6 |
+
The ASF licenses this file to You under the Apache License, Version 2.0
|
| 7 |
+
(the "License"); you may not use this file except in compliance with
|
| 8 |
+
the License. You may obtain a copy of the License at
|
| 9 |
+
|
| 10 |
+
http://www.apache.org/licenses/LICENSE-2.0
|
| 11 |
+
|
| 12 |
+
Unless required by applicable law or agreed to in writing, software
|
| 13 |
+
distributed under the License is distributed on an "AS IS" BASIS,
|
| 14 |
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 15 |
+
See the License for the specific language governing permissions and
|
| 16 |
+
limitations under the License.
|
| 17 |
+
-->
|
| 18 |
+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
| 19 |
+
<parent>
|
| 20 |
+
<groupId>org.apache.commons</groupId>
|
| 21 |
+
<artifactId>commons-parent</artifactId>
|
| 22 |
+
<version>39</version>
|
| 23 |
+
</parent>
|
| 24 |
+
<modelVersion>4.0.0</modelVersion>
|
| 25 |
+
<groupId>commons-io</groupId>
|
| 26 |
+
<artifactId>commons-io</artifactId>
|
| 27 |
+
<version>2.5</version>
|
| 28 |
+
<name>Apache Commons IO</name>
|
| 29 |
+
|
| 30 |
+
<inceptionYear>2002</inceptionYear>
|
| 31 |
+
<description>
|
| 32 |
+
The Apache Commons IO library contains utility classes, stream implementations, file filters,
|
| 33 |
+
file comparators, endian transformation classes, and much more.
|
| 34 |
+
</description>
|
| 35 |
+
|
| 36 |
+
<url>http://commons.apache.org/proper/commons-io/</url>
|
| 37 |
+
|
| 38 |
+
<issueManagement>
|
| 39 |
+
<system>jira</system>
|
| 40 |
+
<url>http://issues.apache.org/jira/browse/IO</url>
|
| 41 |
+
</issueManagement>
|
| 42 |
+
|
| 43 |
+
<distributionManagement>
|
| 44 |
+
<site>
|
| 45 |
+
<id>apache.website</id>
|
| 46 |
+
<name>Apache Commons Site</name>
|
| 47 |
+
<url>scm:svn:https://svn.apache.org/repos/infra/websites/production/commons/content/proper/commons-i/</url>
|
| 48 |
+
</site>
|
| 49 |
+
</distributionManagement>
|
| 50 |
+
|
| 51 |
+
<scm>
|
| 52 |
+
<connection>scm:svn:http://svn.apache.org/repos/asf/commons/proper/io/tags/commons-io-2.5</connection>
|
| 53 |
+
<developerConnection>scm:svn:https://svn.apache.org/repos/asf/commons/proper/io/tags/commons-io-2.5</developerConnection>
|
| 54 |
+
<url>http://svn.apache.org/viewvc/commons/proper/io/tags/commons-io-2.5</url>
|
| 55 |
+
</scm>
|
| 56 |
+
|
| 57 |
+
<developers>
|
| 58 |
+
<developer>
|
| 59 |
+
<name>Scott Sanders</name>
|
| 60 |
+
<id>sanders</id>
|
| 61 |
+
<email>sanders@apache.org</email>
|
| 62 |
+
<organization />
|
| 63 |
+
<roles>
|
| 64 |
+
<role>Java Developer</role>
|
| 65 |
+
</roles>
|
| 66 |
+
</developer>
|
| 67 |
+
<developer>
|
| 68 |
+
<name>dIon Gillard</name>
|
| 69 |
+
<!-- Note: first name is correctly capitalised above -->
|
| 70 |
+
<id>dion</id>
|
| 71 |
+
<email>dion@apache.org</email>
|
| 72 |
+
<organization />
|
| 73 |
+
<roles>
|
| 74 |
+
<role>Java Developer</role>
|
| 75 |
+
</roles>
|
| 76 |
+
</developer>
|
| 77 |
+
<developer>
|
| 78 |
+
<name>Nicola Ken Barozzi</name>
|
| 79 |
+
<id>nicolaken</id>
|
| 80 |
+
<email>nicolaken@apache.org</email>
|
| 81 |
+
<organization />
|
| 82 |
+
<roles>
|
| 83 |
+
<role>Java Developer</role>
|
| 84 |
+
</roles>
|
| 85 |
+
</developer>
|
| 86 |
+
<developer>
|
| 87 |
+
<name>Henri Yandell</name>
|
| 88 |
+
<id>bayard</id>
|
| 89 |
+
<email>bayard@apache.org</email>
|
| 90 |
+
<organization />
|
| 91 |
+
<roles>
|
| 92 |
+
<role>Java Developer</role>
|
| 93 |
+
</roles>
|
| 94 |
+
</developer>
|
| 95 |
+
<developer>
|
| 96 |
+
<name>Stephen Colebourne</name>
|
| 97 |
+
<id>scolebourne</id>
|
| 98 |
+
<organization />
|
| 99 |
+
<roles>
|
| 100 |
+
<role>Java Developer</role>
|
| 101 |
+
</roles>
|
| 102 |
+
<timezone>0</timezone>
|
| 103 |
+
</developer>
|
| 104 |
+
<developer>
|
| 105 |
+
<name>Jeremias Maerki</name>
|
| 106 |
+
<id>jeremias</id>
|
| 107 |
+
<email>jeremias@apache.org</email>
|
| 108 |
+
<organization />
|
| 109 |
+
<roles>
|
| 110 |
+
<role>Java Developer</role>
|
| 111 |
+
</roles>
|
| 112 |
+
<timezone>+1</timezone>
|
| 113 |
+
</developer>
|
| 114 |
+
<developer>
|
| 115 |
+
<name>Matthew Hawthorne</name>
|
| 116 |
+
<id>matth</id>
|
| 117 |
+
<email>matth@apache.org</email>
|
| 118 |
+
<organization />
|
| 119 |
+
<roles>
|
| 120 |
+
<role>Java Developer</role>
|
| 121 |
+
</roles>
|
| 122 |
+
</developer>
|
| 123 |
+
<developer>
|
| 124 |
+
<name>Martin Cooper</name>
|
| 125 |
+
<id>martinc</id>
|
| 126 |
+
<email>martinc@apache.org</email>
|
| 127 |
+
<organization />
|
| 128 |
+
<roles>
|
| 129 |
+
<role>Java Developer</role>
|
| 130 |
+
</roles>
|
| 131 |
+
</developer>
|
| 132 |
+
<developer>
|
| 133 |
+
<name>Rob Oxspring</name>
|
| 134 |
+
<id>roxspring</id>
|
| 135 |
+
<email>roxspring@apache.org</email>
|
| 136 |
+
<organization />
|
| 137 |
+
<roles>
|
| 138 |
+
<role>Java Developer</role>
|
| 139 |
+
</roles>
|
| 140 |
+
</developer>
|
| 141 |
+
<developer>
|
| 142 |
+
<name>Jochen Wiedmann</name>
|
| 143 |
+
<id>jochen</id>
|
| 144 |
+
<email>jochen.wiedmann@gmail.com</email>
|
| 145 |
+
</developer>
|
| 146 |
+
<developer>
|
| 147 |
+
<name>Niall Pemberton</name>
|
| 148 |
+
<id>niallp</id>
|
| 149 |
+
<roles>
|
| 150 |
+
<role>Java Developer</role>
|
| 151 |
+
</roles>
|
| 152 |
+
</developer>
|
| 153 |
+
<developer>
|
| 154 |
+
<name>Jukka Zitting</name>
|
| 155 |
+
<id>jukka</id>
|
| 156 |
+
<roles>
|
| 157 |
+
<role>Java Developer</role>
|
| 158 |
+
</roles>
|
| 159 |
+
</developer>
|
| 160 |
+
<developer>
|
| 161 |
+
<name>Gary Gregory</name>
|
| 162 |
+
<id>ggregory</id>
|
| 163 |
+
<email>ggregory@apache.org</email>
|
| 164 |
+
<url>http://www.garygregory.com</url>
|
| 165 |
+
<timezone>-5</timezone>
|
| 166 |
+
</developer>
|
| 167 |
+
<developer>
|
| 168 |
+
<name>Kristian Rosenvold</name>
|
| 169 |
+
<id>krosenvold</id>
|
| 170 |
+
<email>krosenvold@apache.org</email>
|
| 171 |
+
<timezone>+1</timezone>
|
| 172 |
+
</developer>
|
| 173 |
+
</developers>
|
| 174 |
+
|
| 175 |
+
<contributors>
|
| 176 |
+
<contributor>
|
| 177 |
+
<name>Rahul Akolkar</name>
|
| 178 |
+
</contributor>
|
| 179 |
+
<contributor>
|
| 180 |
+
<name>Jason Anderson</name>
|
| 181 |
+
</contributor>
|
| 182 |
+
<contributor>
|
| 183 |
+
<name>Nathan Beyer</name>
|
| 184 |
+
</contributor>
|
| 185 |
+
<contributor>
|
| 186 |
+
<name>Emmanuel Bourg</name>
|
| 187 |
+
</contributor>
|
| 188 |
+
<contributor>
|
| 189 |
+
<name>Chris Eldredge</name>
|
| 190 |
+
</contributor>
|
| 191 |
+
<contributor>
|
| 192 |
+
<name>Magnus Grimsell</name>
|
| 193 |
+
</contributor>
|
| 194 |
+
<contributor>
|
| 195 |
+
<name>Jim Harrington</name>
|
| 196 |
+
</contributor>
|
| 197 |
+
<contributor>
|
| 198 |
+
<name>Thomas Ledoux</name>
|
| 199 |
+
</contributor>
|
| 200 |
+
<contributor>
|
| 201 |
+
<name>Andy Lehane</name>
|
| 202 |
+
</contributor>
|
| 203 |
+
<contributor>
|
| 204 |
+
<name>Marcelo Liberato</name>
|
| 205 |
+
</contributor>
|
| 206 |
+
<contributor>
|
| 207 |
+
<name>Alban Peignier</name>
|
| 208 |
+
<email>alban.peignier at free.fr</email>
|
| 209 |
+
</contributor>
|
| 210 |
+
<contributor>
|
| 211 |
+
<name>Ian Springer</name>
|
| 212 |
+
</contributor>
|
| 213 |
+
<contributor>
|
| 214 |
+
<name>Dominik Stadler</name>
|
| 215 |
+
</contributor>
|
| 216 |
+
<contributor>
|
| 217 |
+
<name>Masato Tezuka</name>
|
| 218 |
+
</contributor>
|
| 219 |
+
<contributor>
|
| 220 |
+
<name>James Urie</name>
|
| 221 |
+
</contributor>
|
| 222 |
+
<contributor>
|
| 223 |
+
<name>Frank W. Zammetti</name>
|
| 224 |
+
</contributor>
|
| 225 |
+
</contributors>
|
| 226 |
+
|
| 227 |
+
<dependencies>
|
| 228 |
+
<dependency>
|
| 229 |
+
<groupId>junit</groupId>
|
| 230 |
+
<artifactId>junit</artifactId>
|
| 231 |
+
<version>4.12</version>
|
| 232 |
+
<scope>test</scope>
|
| 233 |
+
</dependency>
|
| 234 |
+
</dependencies>
|
| 235 |
+
|
| 236 |
+
<properties>
|
| 237 |
+
<maven.compiler.source>1.6</maven.compiler.source>
|
| 238 |
+
<maven.compiler.target>1.6</maven.compiler.target>
|
| 239 |
+
<commons.componentid>io</commons.componentid>
|
| 240 |
+
<commons.rc.version>RC4</commons.rc.version>
|
| 241 |
+
<commons.release.version>2.5</commons.release.version>
|
| 242 |
+
<commons.release.desc>(requires JDK 1.6+)</commons.release.desc>
|
| 243 |
+
<commons.jira.id>IO</commons.jira.id>
|
| 244 |
+
<commons.jira.pid>12310477</commons.jira.pid>
|
| 245 |
+
<commons.osgi.export>
|
| 246 |
+
<!-- Explicit list of packages from IO 1.4 -->
|
| 247 |
+
org.apache.commons.io;
|
| 248 |
+
org.apache.commons.io.comparator;
|
| 249 |
+
org.apache.commons.io.filefilter;
|
| 250 |
+
org.apache.commons.io.input;
|
| 251 |
+
org.apache.commons.io.output;version=1.4.9999;-noimport:=true,
|
| 252 |
+
<!-- Same list plus * for new packages -->
|
| 253 |
+
org.apache.commons.io;
|
| 254 |
+
org.apache.commons.io.comparator;
|
| 255 |
+
org.apache.commons.io.filefilter;
|
| 256 |
+
org.apache.commons.io.input;
|
| 257 |
+
org.apache.commons.io.output;
|
| 258 |
+
org.apache.commons.io.*;version=${project.version};-noimport:=true
|
| 259 |
+
</commons.osgi.export>
|
| 260 |
+
|
| 261 |
+
<commons.scmPubCheckoutDirectory>site-content</commons.scmPubCheckoutDirectory>
|
| 262 |
+
</properties>
|
| 263 |
+
|
| 264 |
+
<build>
|
| 265 |
+
<pluginManagement>
|
| 266 |
+
</pluginManagement>
|
| 267 |
+
<plugins>
|
| 268 |
+
<plugin>
|
| 269 |
+
<groupId>org.apache.maven.plugins</groupId>
|
| 270 |
+
<artifactId>maven-surefire-plugin</artifactId>
|
| 271 |
+
<version>2.14.1</version>
|
| 272 |
+
<configuration>
|
| 273 |
+
<classpathDependencyExcludes>
|
| 274 |
+
<classpathDependencyExclude>xerces:xercesImpl</classpathDependencyExclude>
|
| 275 |
+
</classpathDependencyExcludes>
|
| 276 |
+
<forkMode>pertest</forkMode>
|
| 277 |
+
<!-- limit memory size see IO-161 -->
|
| 278 |
+
<argLine>-Xmx25M</argLine>
|
| 279 |
+
<includes>
|
| 280 |
+
<!-- Only include test classes, not test data -->
|
| 281 |
+
<include>**/*Test*.class</include>
|
| 282 |
+
</includes>
|
| 283 |
+
<excludes>
|
| 284 |
+
<exclude>**/*AbstractTestCase*</exclude>
|
| 285 |
+
<exclude>**/testtools/**</exclude>
|
| 286 |
+
<!-- http://jira.codehaus.org/browse/SUREFIRE-44 -->
|
| 287 |
+
<exclude>**/*$*</exclude>
|
| 288 |
+
</excludes>
|
| 289 |
+
</configuration>
|
| 290 |
+
</plugin>
|
| 291 |
+
<plugin>
|
| 292 |
+
<artifactId>maven-assembly-plugin</artifactId>
|
| 293 |
+
<configuration>
|
| 294 |
+
<descriptors>
|
| 295 |
+
<descriptor>src/assembly/bin.xml</descriptor>
|
| 296 |
+
<descriptor>src/assembly/src.xml</descriptor>
|
| 297 |
+
</descriptors>
|
| 298 |
+
<tarLongFileMode>gnu</tarLongFileMode>
|
| 299 |
+
</configuration>
|
| 300 |
+
</plugin>
|
| 301 |
+
<plugin>
|
| 302 |
+
<groupId>org.apache.maven.plugins</groupId>
|
| 303 |
+
<artifactId>maven-scm-publish-plugin</artifactId>
|
| 304 |
+
<configuration>
|
| 305 |
+
<ignorePathsToDelete>
|
| 306 |
+
<ignorePathToDelete>javadocs</ignorePathToDelete>
|
| 307 |
+
</ignorePathsToDelete>
|
| 308 |
+
</configuration>
|
| 309 |
+
</plugin>
|
| 310 |
+
<!-- Configure RAT for CLI invocation: mvn apache-rat:rat -->
|
| 311 |
+
<plugin>
|
| 312 |
+
<groupId>org.apache.rat</groupId>
|
| 313 |
+
<artifactId>apache-rat-plugin</artifactId>
|
| 314 |
+
<!-- Must agree with report section RAT config -->
|
| 315 |
+
<configuration>
|
| 316 |
+
<excludes>
|
| 317 |
+
<exclude>src/test/resources/**/*.bin</exclude>
|
| 318 |
+
<exclude>test/**</exclude>
|
| 319 |
+
|
| 320 |
+
<!-- The next 3 excludes can be dropped when using CP30 -->
|
| 321 |
+
<exclude>site-content/**</exclude>
|
| 322 |
+
<exclude>.pmd</exclude>
|
| 323 |
+
<exclude>src/site/resources/download_*.cgi</exclude>
|
| 324 |
+
|
| 325 |
+
</excludes>
|
| 326 |
+
</configuration>
|
| 327 |
+
</plugin>
|
| 328 |
+
</plugins>
|
| 329 |
+
</build>
|
| 330 |
+
|
| 331 |
+
<reporting>
|
| 332 |
+
<plugins>
|
| 333 |
+
<plugin>
|
| 334 |
+
<groupId>org.codehaus.mojo</groupId>
|
| 335 |
+
<artifactId>cobertura-maven-plugin</artifactId>
|
| 336 |
+
<version>2.7</version>
|
| 337 |
+
</plugin>
|
| 338 |
+
<plugin>
|
| 339 |
+
<groupId>org.apache.maven.plugins</groupId>
|
| 340 |
+
<artifactId>maven-checkstyle-plugin</artifactId>
|
| 341 |
+
<version>2.12.1</version>
|
| 342 |
+
<configuration>
|
| 343 |
+
<configLocation>${basedir}/checkstyle.xml</configLocation>
|
| 344 |
+
<enableRulesSummary>false</enableRulesSummary>
|
| 345 |
+
</configuration>
|
| 346 |
+
</plugin>
|
| 347 |
+
<plugin>
|
| 348 |
+
<groupId>org.codehaus.mojo</groupId>
|
| 349 |
+
<artifactId>findbugs-maven-plugin</artifactId>
|
| 350 |
+
<version>${commons.findbugs.version}</version>
|
| 351 |
+
<configuration>
|
| 352 |
+
<threshold>Normal</threshold>
|
| 353 |
+
<effort>Default</effort>
|
| 354 |
+
<excludeFilterFile>${basedir}/findbugs-exclude-filter.xml</excludeFilterFile>
|
| 355 |
+
</configuration>
|
| 356 |
+
</plugin>
|
| 357 |
+
<plugin>
|
| 358 |
+
<groupId>org.apache.rat</groupId>
|
| 359 |
+
<artifactId>apache-rat-plugin</artifactId>
|
| 360 |
+
<!-- Must agree with build section RAT config -->
|
| 361 |
+
<configuration>
|
| 362 |
+
<excludes>
|
| 363 |
+
<exclude>src/test/resources/**/*.bin</exclude>
|
| 364 |
+
<exclude>test/**</exclude>
|
| 365 |
+
|
| 366 |
+
<!-- The next 3 excludes can be dropped when using CP30 -->
|
| 367 |
+
<exclude>site-content/**</exclude>
|
| 368 |
+
<exclude>.pmd</exclude>
|
| 369 |
+
<exclude>src/site/resources/download_*.cgi</exclude>
|
| 370 |
+
|
| 371 |
+
</excludes>
|
| 372 |
+
</configuration>
|
| 373 |
+
</plugin>
|
| 374 |
+
</plugins>
|
| 375 |
+
</reporting>
|
| 376 |
+
<profiles>
|
| 377 |
+
<profile>
|
| 378 |
+
<id>setup-checkout</id>
|
| 379 |
+
<activation>
|
| 380 |
+
<file>
|
| 381 |
+
<missing>site-content</missing>
|
| 382 |
+
</file>
|
| 383 |
+
</activation>
|
| 384 |
+
<build>
|
| 385 |
+
<plugins>
|
| 386 |
+
<plugin>
|
| 387 |
+
<groupId>org.apache.maven.plugins</groupId>
|
| 388 |
+
<artifactId>maven-antrun-plugin</artifactId>
|
| 389 |
+
<version>1.8</version>
|
| 390 |
+
<executions>
|
| 391 |
+
<execution>
|
| 392 |
+
<id>prepare-checkout</id>
|
| 393 |
+
<phase>pre-site</phase>
|
| 394 |
+
<goals>
|
| 395 |
+
<goal>run</goal>
|
| 396 |
+
</goals>
|
| 397 |
+
<configuration>
|
| 398 |
+
<target>
|
| 399 |
+
<exec executable="svn">
|
| 400 |
+
<arg line="checkout --depth immediates ${commons.scmPubUrl} ${commons.scmPubCheckoutDirectory}" />
|
| 401 |
+
</exec>
|
| 402 |
+
|
| 403 |
+
<exec executable="svn">
|
| 404 |
+
<arg line="update --set-depth exclude ${commons.scmPubCheckoutDirectory}/javadocs" />
|
| 405 |
+
</exec>
|
| 406 |
+
|
| 407 |
+
<pathconvert pathsep=" " property="dirs">
|
| 408 |
+
<dirset dir="${commons.scmPubCheckoutDirectory}" includes="*" />
|
| 409 |
+
</pathconvert>
|
| 410 |
+
<exec executable="svn">
|
| 411 |
+
<arg line="update --set-depth infinity ${dirs}" />
|
| 412 |
+
</exec>
|
| 413 |
+
</target>
|
| 414 |
+
</configuration>
|
| 415 |
+
</execution>
|
| 416 |
+
</executions>
|
| 417 |
+
</plugin>
|
| 418 |
+
</plugins>
|
| 419 |
+
</build>
|
| 420 |
+
</profile>
|
| 421 |
+
</profiles>
|
| 422 |
+
</project>
|
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/01_课件与电子教材/尚硅谷_第15章_File类与IO流/03-apache-common包/commons-io-2.5-src/src/assembly/bin.xml
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!--
|
| 2 |
+
Licensed to the Apache Software Foundation (ASF) under one or more
|
| 3 |
+
contributor license agreements. See the NOTICE file distributed with
|
| 4 |
+
this work for additional information regarding copyright ownership.
|
| 5 |
+
The ASF licenses this file to You under the Apache License, Version 2.0
|
| 6 |
+
(the "License"); you may not use this file except in compliance with
|
| 7 |
+
the License. You may obtain a copy of the License at
|
| 8 |
+
|
| 9 |
+
http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
|
| 11 |
+
Unless required by applicable law or agreed to in writing, software
|
| 12 |
+
distributed under the License is distributed on an "AS IS" BASIS,
|
| 13 |
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 14 |
+
See the License for the specific language governing permissions and
|
| 15 |
+
limitations under the License.
|
| 16 |
+
-->
|
| 17 |
+
<assembly>
|
| 18 |
+
<id>bin</id>
|
| 19 |
+
<formats>
|
| 20 |
+
<format>tar.gz</format>
|
| 21 |
+
<format>zip</format>
|
| 22 |
+
</formats>
|
| 23 |
+
<includeSiteDirectory>false</includeSiteDirectory>
|
| 24 |
+
<fileSets>
|
| 25 |
+
<fileSet>
|
| 26 |
+
<includes>
|
| 27 |
+
<include>LICENSE.txt</include>
|
| 28 |
+
<include>NOTICE.txt</include>
|
| 29 |
+
<include>RELEASE-NOTES.txt</include>
|
| 30 |
+
</includes>
|
| 31 |
+
</fileSet>
|
| 32 |
+
<fileSet>
|
| 33 |
+
<directory>target</directory>
|
| 34 |
+
<outputDirectory></outputDirectory>
|
| 35 |
+
<includes>
|
| 36 |
+
<include>*.jar</include>
|
| 37 |
+
</includes>
|
| 38 |
+
</fileSet>
|
| 39 |
+
<fileSet>
|
| 40 |
+
<directory>target/site/apidocs</directory>
|
| 41 |
+
<outputDirectory>docs</outputDirectory>
|
| 42 |
+
<excludes>
|
| 43 |
+
<exclude>**/customsorttypes.js</exclude>
|
| 44 |
+
<exclude>**/sortabletable.js</exclude>
|
| 45 |
+
<exclude>**/stringbuilder.js</exclude>
|
| 46 |
+
</excludes>
|
| 47 |
+
</fileSet>
|
| 48 |
+
</fileSets>
|
| 49 |
+
</assembly>
|
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/01_课件与电子教材/尚硅谷_第15章_File类与IO流/03-apache-common包/commons-io-2.5-src/src/assembly/src.xml
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!--
|
| 2 |
+
Licensed to the Apache Software Foundation (ASF) under one or more
|
| 3 |
+
contributor license agreements. See the NOTICE file distributed with
|
| 4 |
+
this work for additional information regarding copyright ownership.
|
| 5 |
+
The ASF licenses this file to You under the Apache License, Version 2.0
|
| 6 |
+
(the "License"); you may not use this file except in compliance with
|
| 7 |
+
the License. You may obtain a copy of the License at
|
| 8 |
+
|
| 9 |
+
http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
|
| 11 |
+
Unless required by applicable law or agreed to in writing, software
|
| 12 |
+
distributed under the License is distributed on an "AS IS" BASIS,
|
| 13 |
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 14 |
+
See the License for the specific language governing permissions and
|
| 15 |
+
limitations under the License.
|
| 16 |
+
-->
|
| 17 |
+
<assembly>
|
| 18 |
+
<id>src</id>
|
| 19 |
+
<formats>
|
| 20 |
+
<format>tar.gz</format>
|
| 21 |
+
<format>zip</format>
|
| 22 |
+
</formats>
|
| 23 |
+
<baseDirectory>${artifactId}-${commons.release.version}-src</baseDirectory>
|
| 24 |
+
<fileSets>
|
| 25 |
+
<fileSet>
|
| 26 |
+
<includes>
|
| 27 |
+
<include>build.xml</include>
|
| 28 |
+
<include>checkstyle.xml</include>
|
| 29 |
+
<include>findbugs-exclude-filter.xml</include>
|
| 30 |
+
<include>LICENSE.txt</include>
|
| 31 |
+
<include>NOTICE.txt</include>
|
| 32 |
+
<include>pom.xml</include>
|
| 33 |
+
<include>PROPOSAL.html</include>
|
| 34 |
+
<include>RELEASE-NOTES.txt</include>
|
| 35 |
+
</includes>
|
| 36 |
+
</fileSet>
|
| 37 |
+
<fileSet>
|
| 38 |
+
<directory>src</directory>
|
| 39 |
+
</fileSet>
|
| 40 |
+
</fileSets>
|
| 41 |
+
</assembly>
|
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/01_课件与电子教材/尚硅谷_第15章_File类与IO流/03-apache-common包/commons-io-2.5-src/src/changes/changes.xml
ADDED
|
@@ -0,0 +1,488 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?xml version="1.0"?>
|
| 2 |
+
<!--
|
| 3 |
+
Licensed to the Apache Software Foundation (ASF) under one or more
|
| 4 |
+
contributor license agreements. See the NOTICE file distributed with
|
| 5 |
+
this work for additional information regarding copyright ownership.
|
| 6 |
+
The ASF licenses this file to You under the Apache License, Version 2.0
|
| 7 |
+
(the "License"); you may not use this file except in compliance with
|
| 8 |
+
the License. You may obtain a copy of the License at
|
| 9 |
+
|
| 10 |
+
http://www.apache.org/licenses/LICENSE-2.0
|
| 11 |
+
|
| 12 |
+
Unless required by applicable law or agreed to in writing, software
|
| 13 |
+
distributed under the License is distributed on an "AS IS" BASIS,
|
| 14 |
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 15 |
+
See the License for the specific language governing permissions and
|
| 16 |
+
limitations under the License.
|
| 17 |
+
-->
|
| 18 |
+
|
| 19 |
+
<!--
|
| 20 |
+
This file is used by the maven-changes-plugin to generate the release notes.
|
| 21 |
+
Useful ways of finding items to add to this file are:
|
| 22 |
+
|
| 23 |
+
1. Add items when you fix a bug or add a feature (this makes the
|
| 24 |
+
release process easy :-).
|
| 25 |
+
|
| 26 |
+
2. Do a Jira search for tickets closed since the previous release.
|
| 27 |
+
|
| 28 |
+
3. Use the report generated by the maven-changelog-plugin to see all
|
| 29 |
+
CVS commits. Set the project.properties' maven.changelog.range
|
| 30 |
+
property to the number of days since the last release.
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
To generate the release notes from this file:
|
| 34 |
+
|
| 35 |
+
mvn changes:announcement-generate -Prelease-notes [-Dchanges.version=nnn]
|
| 36 |
+
|
| 37 |
+
then tweak the source formatting if necessary and regenerate, then commit
|
| 38 |
+
|
| 39 |
+
The <action> type attribute can be add,update,fix,remove.
|
| 40 |
+
-->
|
| 41 |
+
|
| 42 |
+
<document>
|
| 43 |
+
<properties>
|
| 44 |
+
<title>Release Notes</title>
|
| 45 |
+
</properties>
|
| 46 |
+
|
| 47 |
+
<body>
|
| 48 |
+
<!-- The release date is the date RC is cut -->
|
| 49 |
+
<release version="2.5" date="2015-12-DD" description="New features and bug fixes.">
|
| 50 |
+
<action issue="IO-492" dev="ggregory" type="fix" due-to="Santiago Castro">
|
| 51 |
+
Typo: In an IOUtils.java comment it says "focussed" instead of "focused".
|
| 52 |
+
</action>
|
| 53 |
+
<action issue="IO-433" dev="krosenvold" type="update">
|
| 54 |
+
Converted all testcases to JUnit 4
|
| 55 |
+
</action>
|
| 56 |
+
<action issue="IO-487" dev="bdelacretaz" type="add">
|
| 57 |
+
Add ValidatingObjectInputStream for controlled deserialization
|
| 58 |
+
</action>
|
| 59 |
+
<action issue="IO-446" dev="krosenvold" type="fix" due-to="Jeffrey Barrus">
|
| 60 |
+
adds an endOfFileReached method to the TailerListener
|
| 61 |
+
</action>
|
| 62 |
+
<action issue="IO-484" dev="krosenvold" type="fix" due-to="Philippe Arteau">
|
| 63 |
+
FilenameUtils should handle embedded null bytes
|
| 64 |
+
</action>
|
| 65 |
+
<action issue="IO-481" dev="krosenvold" type="fix">
|
| 66 |
+
Changed/Corrected algorithm for waitFor
|
| 67 |
+
</action>
|
| 68 |
+
<action issue="IO-471" dev="krosenvold" type="add" due-to="Leandro Reis">
|
| 69 |
+
Support for additional encodings in ReversedLinesFileReader
|
| 70 |
+
</action>
|
| 71 |
+
<action issue="IO-428" dev="krosenvold" type="fix" due-to="Stefan Gmeiner">
|
| 72 |
+
BOMInputStream.skip returns wrong count if stream contains no BOM
|
| 73 |
+
</action>
|
| 74 |
+
<action issue="IO-425" dev="krosenvold" type="add" due-to="Craig Swank">
|
| 75 |
+
Setter method for threshold on ThresholdingOutputStream
|
| 76 |
+
</action>
|
| 77 |
+
<action issue="IO-488" dev="krosenvold" type="fix" due-to="Björn Buchner">
|
| 78 |
+
FileUtils.waitFor(...) swallows thread interrupted status
|
| 79 |
+
</action>
|
| 80 |
+
<action issue="IO-452" dev="krosenvold" type="fix" due-to="David Standish">
|
| 81 |
+
Support for symlinks with missing target. Added support for JDK7 symlink features when present
|
| 82 |
+
</action>
|
| 83 |
+
<action issue="IO-466" dev="krosenvold" type="update">
|
| 84 |
+
Added testcase to show this was fixed with IO-423
|
| 85 |
+
</action>
|
| 86 |
+
<action issue="IO-479" dev="sebb" type="update" due-to="Zhouce Chen">
|
| 87 |
+
Correct exception message in FileUtils.getFile(File, String...)
|
| 88 |
+
</action>
|
| 89 |
+
<action issue="IO-406" dev="britter" type="add" due-to="Niall Pemberton">
|
| 90 |
+
Introduce new class AppendableOutputStream
|
| 91 |
+
</action>
|
| 92 |
+
<action issue="IO-465" dev="britter" type="update" due-to="based2">
|
| 93 |
+
Update to JUnit 4.12
|
| 94 |
+
</action>
|
| 95 |
+
<action issue="IO-462" dev="sebb" type="update">
|
| 96 |
+
IOExceptionWithCause no longer needed
|
| 97 |
+
</action>
|
| 98 |
+
<action issue="IO-459" dev="olamy" type="add" due-to="Kristian Rosenvold">
|
| 99 |
+
Add WindowsLineEndingInputStream and UnixLineEndingInputStream.
|
| 100 |
+
</action>
|
| 101 |
+
<action issue="IO-457" dev="olamy" type="add" due-to="Kristian Rosenvold">
|
| 102 |
+
Add a BoundedReader, a wrapper that can be used to constrain access
|
| 103 |
+
to an underlying stream when used with mark/reset -
|
| 104 |
+
to avoid overflowing the mark limit of the underlying buffer.
|
| 105 |
+
</action>
|
| 106 |
+
<action issue="IO-453" dev="sebb" type="fix" due-to="Steven Christou">
|
| 107 |
+
Regression in FileUtils.readFileToString from 2.0.1
|
| 108 |
+
</action>
|
| 109 |
+
<action issue="IO-451" dev="sebb" type="fix" due-to="David Standish">
|
| 110 |
+
ant test fails - resources missing from test classpath
|
| 111 |
+
</action>
|
| 112 |
+
<action issue="IO-435" dev="tn" type="fix" due-to="Dominik Stadler">
|
| 113 |
+
Document that FileUtils.deleteDirectory, directoryContains and cleanDirectory
|
| 114 |
+
may throw an IllegalArgumentException in case the passed directory does not
|
| 115 |
+
exist or is not a directory.
|
| 116 |
+
</action>
|
| 117 |
+
<action issue="IO-426" dev="ggregory" type="add">
|
| 118 |
+
Add API IOUtils.closeQuietly(Closeable...)
|
| 119 |
+
</action>
|
| 120 |
+
<action issue="IO-424" dev="ggregory" type="fix" due-to="Ville Skyttä">
|
| 121 |
+
Javadoc fixes, mostly to appease 1.8.0
|
| 122 |
+
</action>
|
| 123 |
+
<action issue="IO-422" dev="ggregory" type="update">
|
| 124 |
+
Deprecate Charsets Charset constants in favor of Java 7's java.nio.charset.StandardCharsets
|
| 125 |
+
</action>
|
| 126 |
+
<action issue="IO-410" dev="sebb" type="add" due-to="Beluga Behr">
|
| 127 |
+
Readfully() That Returns A Byte Array
|
| 128 |
+
</action>
|
| 129 |
+
<action issue="IO-395" dev="brentworden" type="add" due-to="Beluga Behr">
|
| 130 |
+
Overload IOUtils buffer methods to accept buffer size
|
| 131 |
+
</action>
|
| 132 |
+
<action issue="IO-389" dev="sebb" type="fix" due-to="Austin Doupnik">
|
| 133 |
+
FileUtils.sizeOfDirectory can throw IllegalArgumentException
|
| 134 |
+
</action>
|
| 135 |
+
<action issue="IO-390" dev="sebb" type="fix">
|
| 136 |
+
FileUtils.sizeOfDirectoryAsBigInteger can overflow.
|
| 137 |
+
Ensure that recursive calls all use BigInteger
|
| 138 |
+
</action>
|
| 139 |
+
<action issue="IO-382" dev="sebb" type="add">
|
| 140 |
+
Chunked IO for large arrays.
|
| 141 |
+
Added writeChunked(byte[], OutputStream) and writeChunked(char[] Writer)
|
| 142 |
+
Added ChunkedOutputStream, ChunkedWriter
|
| 143 |
+
</action>
|
| 144 |
+
<action issue="IO-385" dev="sebb" type="fix">
|
| 145 |
+
FileUtils.doCopyFile can potentially loop for ever
|
| 146 |
+
Exit loop if no data to copy
|
| 147 |
+
</action>
|
| 148 |
+
<action issue="IO-383" dev="sebb" type="fix">
|
| 149 |
+
FileUtils.doCopyFile caches the file size; needs to be documented
|
| 150 |
+
Added Javadoc; show file lengths in exception message
|
| 151 |
+
</action>
|
| 152 |
+
<action issue="IO-239" dev="sebb" type="update">
|
| 153 |
+
Convert IOCase to a Java 1.5+ Enumeration
|
| 154 |
+
[N.B. this is binary compatible]
|
| 155 |
+
</action>
|
| 156 |
+
<action issue="IO-233" dev="sebb" type="add">
|
| 157 |
+
Add Methods for Buffering Streams/Writers To IOUtils
|
| 158 |
+
Added overloaded buffer() methods - see also IO-330
|
| 159 |
+
</action>
|
| 160 |
+
<action issue="IO-330" dev="sebb" type="add">
|
| 161 |
+
IOUtils#toBufferedOutputStream/toBufferedWriter to conditionally wrap the output
|
| 162 |
+
Added overloaded buffer() methods - see also IO-233
|
| 163 |
+
</action>
|
| 164 |
+
<action issue="IO-381" dev="ggregory" type="add">
|
| 165 |
+
Add FileUtils.copyInputStreamToFile API with option to leave the source open.
|
| 166 |
+
See copyInputStreamToFile(final InputStream source, final File destination, boolean closeSource)
|
| 167 |
+
</action>
|
| 168 |
+
<action issue="IO-380" dev="sebb" type="fix" due-to="claudio_ch">
|
| 169 |
+
FileUtils.copyInputStreamToFile should document it closes the input source
|
| 170 |
+
</action>
|
| 171 |
+
<action issue="IO-279" dev="sebb" type="fix">
|
| 172 |
+
Tailer erroneously considers file as new.
|
| 173 |
+
Fix to use file.lastModified() rather than System.currentTimeMillis()
|
| 174 |
+
</action>
|
| 175 |
+
<action issue="IO-356" dev="sebb" type="fix">
|
| 176 |
+
CharSequenceInputStream#reset() behaves incorrectly in case when buffer size is not dividable by data size.
|
| 177 |
+
Fix code so skip relates to the encoded bytes; reset now re-encodes the data up to the point of the mark
|
| 178 |
+
</action>
|
| 179 |
+
<action issue="IO-379" dev="sebb" type="add">
|
| 180 |
+
CharSequenceInputStream - add tests for available()
|
| 181 |
+
Fix code so it really does reflect a minimum available.
|
| 182 |
+
</action>
|
| 183 |
+
<action issue="IO-328" dev="sebb" type="update">
|
| 184 |
+
getPrefixLength returns null if filename has leading slashes
|
| 185 |
+
Javadoc: add examples to show correct behaviour; add unit tests
|
| 186 |
+
</action>
|
| 187 |
+
<action issue="IO-299" dev="sebb" type="update">
|
| 188 |
+
FileUtils.listFilesAndDirs includes original dir in results even when it doesn't match filter
|
| 189 |
+
Javadoc: clarify that original dir is included in the results
|
| 190 |
+
</action>
|
| 191 |
+
<action issue="IO-346" dev="sebb" type="add">
|
| 192 |
+
Add ByteArrayOutputStream.toInputStream()
|
| 193 |
+
</action>
|
| 194 |
+
<action issue="IO-368" dev="sebb" type="fix">
|
| 195 |
+
ClassLoaderObjectInputStream does not handle primitive typed members
|
| 196 |
+
</action>
|
| 197 |
+
<action issue="IO-341" dev="sebb" type="add">
|
| 198 |
+
A constant for holding the BOM character (U+FEFF)
|
| 199 |
+
</action>
|
| 200 |
+
<action issue="IO-314" dev="sebb" type="fix">
|
| 201 |
+
Deprecate all methods that use the default encoding
|
| 202 |
+
</action>
|
| 203 |
+
<action issue="IO-338" dev="sebb" type="fix">
|
| 204 |
+
When a file is rotated, finish reading previous file prior to starting new one
|
| 205 |
+
</action>
|
| 206 |
+
<action issue="IO-354" dev="sebb" type="fix">
|
| 207 |
+
Commons IO Tailer does not respect UTF-8 Charset.
|
| 208 |
+
</action>
|
| 209 |
+
<action issue="IO-323" dev="sebb" type="fix">
|
| 210 |
+
What should happen in FileUtils.sizeOf[Directory] when an overflow takes place?
|
| 211 |
+
Added Javadoc.
|
| 212 |
+
</action>
|
| 213 |
+
<action issue="IO-372" dev="sebb" type="fix">
|
| 214 |
+
FileUtils.moveDirectory can produce misleading error message on failiure
|
| 215 |
+
</action>
|
| 216 |
+
<action issue="IO-375" dev="sebb" type="update">
|
| 217 |
+
FilenameUtils.splitOnTokens(String text) check for '**' could be simplified
|
| 218 |
+
</action>
|
| 219 |
+
<action issue="IO-374" dev="sebb" type="update">
|
| 220 |
+
WildcardFileFilter ctors should not use null to mean IOCase.SENSITIVE when delegating to other ctors
|
| 221 |
+
</action>
|
| 222 |
+
<action issue="IO-362" dev="ggregory" type="fix" due-to="mmadson, ggregory">
|
| 223 |
+
IOUtils.contentEquals* methods returns false if input1 == input2, should return true.
|
| 224 |
+
</action>
|
| 225 |
+
<action issue="IO-361" dev="ggregory" type="add">
|
| 226 |
+
Add API FileUtils.forceMkdirsParent().
|
| 227 |
+
</action>
|
| 228 |
+
<action issue="IO-360" dev="ggregory" type="add">
|
| 229 |
+
Add API Charsets.requiredCharsets().
|
| 230 |
+
</action>
|
| 231 |
+
<action issue="IO-359" dev="ggregory" type="add" due-to="yukoba">
|
| 232 |
+
Add IOUtils.skip and skipFully(ReadableByteChannel, long).
|
| 233 |
+
</action>
|
| 234 |
+
<action issue="IO-358" dev="ggregory" type="add" due-to="yukoba">
|
| 235 |
+
Add IOUtils.read and readFully(ReadableByteChannel, ByteBuffer buffer).
|
| 236 |
+
</action>
|
| 237 |
+
<action issue="IO-357" dev="ggregory" type="fix" due-to="mortenh">
|
| 238 |
+
[Tailer] InterruptedException while the thread is sleeping is silently ignored
|
| 239 |
+
</action>
|
| 240 |
+
<action issue="IO-353" dev="ggregory" type="add" due-to="ggregory">
|
| 241 |
+
Add API IOUtils.copy(InputStream, OutputStream, int)
|
| 242 |
+
</action>
|
| 243 |
+
<action issue="IO-349" dev="ggregory" type="add" due-to="scop">
|
| 244 |
+
Add API with array offset and length argument to FileUtils.writeByteArrayToFile.
|
| 245 |
+
</action>
|
| 246 |
+
<action issue="IO-352" dev="ggregory" type="fix" due-to="scop">
|
| 247 |
+
Spelling fixes.
|
| 248 |
+
</action>
|
| 249 |
+
<action issue="IO-348" dev="ggregory" type="add" due-to="plcstpierre">
|
| 250 |
+
Missing information in IllegalArgumentException thrown by org.apache.commons.io.FileUtils#validateListFilesParameters.
|
| 251 |
+
</action>
|
| 252 |
+
<action issue="IO-345" dev="ggregory" type="add" due-to="mkresse">
|
| 253 |
+
Supply a hook method allowing Tailer actively determining stop condition.
|
| 254 |
+
</action>
|
| 255 |
+
<action issue="IO-436" dev="ggregory" type="fix" due-to="christoph.schneegans">
|
| 256 |
+
Improper JavaDoc comment for FilenameUtils.indexOfExtension.
|
| 257 |
+
</action>
|
| 258 |
+
<action issue="IO-437" dev="ggregory" type="add">
|
| 259 |
+
Make IOUtils.EOF public and reuse it in various classes.
|
| 260 |
+
</action>
|
| 261 |
+
</release>
|
| 262 |
+
<!-- The release date is the date RC is cut -->
|
| 263 |
+
<release version="2.4" date="2012-06-12" description="New features and bug fixes.">
|
| 264 |
+
<action issue="IO-343" dev="ggregory" type="fix" due-to="igorlash">
|
| 265 |
+
org.apache.commons.io.comparator Javadoc is inconsistent with real code.
|
| 266 |
+
</action>
|
| 267 |
+
<action issue="IO-336" dev="ggregory" type="fix" due-to="rleavelle">
|
| 268 |
+
Yottabyte (YB) incorrectly defined in FileUtils.
|
| 269 |
+
</action>
|
| 270 |
+
<action issue="IO-269" dev="ggregory" type="add" due-to="sebb">
|
| 271 |
+
Tailer locks file from deletion/rename on Windows.
|
| 272 |
+
</action>
|
| 273 |
+
<action issue="IO-279" dev="sebb" type="fix" due-to="Sergio Bossa, Chris Baron">
|
| 274 |
+
Tailer erroneously considers file as new.
|
| 275 |
+
</action>
|
| 276 |
+
<action issue="IO-335" dev="sebb" type="fix">
|
| 277 |
+
Tailer#readLines - incorrect CR handling.
|
| 278 |
+
</action>
|
| 279 |
+
<action issue="IO-334" dev="sebb" type="fix">
|
| 280 |
+
FileUtils.toURLs throws NPE for null parameter; document the behavior.
|
| 281 |
+
</action>
|
| 282 |
+
<action issue="IO-333" dev="ggregory" type="add" due-to="fmeschbe">
|
| 283 |
+
Export OSGi packages at version 1.x in addition to 2.x.
|
| 284 |
+
</action>
|
| 285 |
+
<action issue="IO-320" dev="ggregory" type="add" due-to="ggregory">
|
| 286 |
+
Add XmlStreamReader support for UTF-32.
|
| 287 |
+
</action>
|
| 288 |
+
<action issue="IO-331" dev="ggregory" type="add" due-to="ggregory">
|
| 289 |
+
BOMInputStream wrongly detects UTF-32LE_BOM files as UTF-16LE_BOM files in method getBOM().
|
| 290 |
+
</action>
|
| 291 |
+
<action issue="IO-332" dev="ggregory" type="fix" due-to="liangly">
|
| 292 |
+
Improve tailer's reading performance.
|
| 293 |
+
</action>
|
| 294 |
+
<action issue="IO-279" dev="ggregory" type="fix">
|
| 295 |
+
Improve Tailer performance with buffered reads (see IO-332).
|
| 296 |
+
</action>
|
| 297 |
+
<action issue="IO-329" dev="ggregory" type="fix" due-to="tivv">
|
| 298 |
+
FileUtils.writeLines uses unbuffered IO.
|
| 299 |
+
</action>
|
| 300 |
+
<action issue="IO-327" dev="ggregory" type="add" due-to="ggregory">
|
| 301 |
+
Add byteCountToDisplaySize(BigInteger).
|
| 302 |
+
</action>
|
| 303 |
+
<action issue="IO-326" dev="ggregory" type="add" due-to="ggregory, kinow">
|
| 304 |
+
Add new FileUtils.sizeOf[Directory] APIs to return BigInteger.
|
| 305 |
+
</action>
|
| 306 |
+
<action issue="IO-325" dev="ggregory" type="add" due-to="raviprak">
|
| 307 |
+
Add IOUtils.toByteArray methods to work with URL and URI.
|
| 308 |
+
</action>
|
| 309 |
+
<action issue="IO-324" dev="ggregory" type="add" due-to="raviprak">
|
| 310 |
+
Add missing Charset sister APIs to method that take a String charset name.
|
| 311 |
+
</action>
|
| 312 |
+
<action issue="IO-319" dev="ggregory" type="fix" due-to="raviprak">
|
| 313 |
+
FileUtils.sizeOfDirectory follows symbolic links.
|
| 314 |
+
</action>
|
| 315 |
+
</release>
|
| 316 |
+
<!-- The release date is the date RC is cut -->
|
| 317 |
+
<release version="2.3" date="2012-April-10" description="New features and bug fixes.">
|
| 318 |
+
<action issue="IO-322" dev="ggregory" type="add" due-to="ggregory">
|
| 319 |
+
Add and use class Charsets.
|
| 320 |
+
</action>
|
| 321 |
+
<action issue="IO-321" dev="ggregory" type="add" due-to="ggregory">
|
| 322 |
+
ByteOrderMark UTF_32LE is incorrect.
|
| 323 |
+
</action>
|
| 324 |
+
<action issue="IO-318" dev="ggregory" type="add" due-to="ggregory">
|
| 325 |
+
Add Charset sister APIs to method that take a String charset name.
|
| 326 |
+
</action>
|
| 327 |
+
</release>
|
| 328 |
+
<release version="2.2" date="2012-March-26" description="New features and bug fixes.">
|
| 329 |
+
<action issue="IO-313" dev="ggregory" type="add" due-to="ggregory">
|
| 330 |
+
Add IOUTils.toBufferedReader(Reader)
|
| 331 |
+
</action>
|
| 332 |
+
<!-- Note: the issue was not raised by Manoj, but arose from IO-305 and tests he performed -->
|
| 333 |
+
<action issue="IO-308" dev="sebb" type="add" due-to="Manoj Mokashi">
|
| 334 |
+
Allow applications to provide buffer (or size) for copyLarge methods.
|
| 335 |
+
</action>
|
| 336 |
+
<action issue="IO-311" dev="sebb" type="fix" due-to="Robert Muir">
|
| 337 |
+
IOUtils.read(InputStream/Reader) ignores the offset parameter
|
| 338 |
+
</action>
|
| 339 |
+
<action issue="IO-312" dev="sebb" type="fix">
|
| 340 |
+
CharSequenceInputStream(CharSequence s, Charset charset, int bufferSize) ignores bufferSize
|
| 341 |
+
</action>
|
| 342 |
+
<action issue="IO-305" dev="sebb" type="add" due-to="Manoj Mokashi">
|
| 343 |
+
New copyLarge() method in IOUtils that takes additional offset, length arguments
|
| 344 |
+
</action>
|
| 345 |
+
<action issue="IO-300" dev="sebb" type="fix">
|
| 346 |
+
FileUtils.moveDirectoryToDirectory removes source directory if destination is a sub-directory
|
| 347 |
+
</action>
|
| 348 |
+
<action issue="IO-307" dev="sebb" type="fix">
|
| 349 |
+
ReaderInputStream#read(byte[] b, int off, int len) should check for valid parameters
|
| 350 |
+
</action>
|
| 351 |
+
<action issue="IO-287" dev="bayard" type="add" due-to="Ron Kuris, Gary Gregory">
|
| 352 |
+
Use terabyte (TB), petabyte (PB) and exabyte (EB) in FileUtils.byteCountToDisplaySize(long size)
|
| 353 |
+
</action>
|
| 354 |
+
<action issue="IO-306" dev="sebb" type="fix">
|
| 355 |
+
ReaderInputStream#read(byte[] b, int off, int len) should always return 0 for length == 0
|
| 356 |
+
</action>
|
| 357 |
+
<action issue="IO-173" dev="sebb" type="add" due-to="Marcos Vinícius da Silva">
|
| 358 |
+
FileUtils.listFiles() doesn't return directories
|
| 359 |
+
</action>
|
| 360 |
+
<action issue="IO-276" dev="sebb" type="fix" due-to="nkami">
|
| 361 |
+
"FileUtils#deleteDirectoryOnExit(File)" does not work
|
| 362 |
+
</action>
|
| 363 |
+
<action issue="IO-273" dev="sebb" type="fix" due-to="sebb">
|
| 364 |
+
BoundedInputStream.read() treats max differently from BoundedInputStream.read(byte[]...)
|
| 365 |
+
</action>
|
| 366 |
+
<action issue="IO-297" dev="sebb" type="add" due-to="Oleg Kalnichevski">
|
| 367 |
+
CharSequenceInputStream to efficiently stream content of a CharSequence
|
| 368 |
+
</action>
|
| 369 |
+
<action issue="IO-296" dev="sebb" type="update" due-to="Oleg Kalnichevski">
|
| 370 |
+
ReaderInputStream optimization: more efficient reading of small chunks of data
|
| 371 |
+
</action>
|
| 372 |
+
<action issue="IO-298" dev="sebb" type="fix" due-to="Christian Schulte">
|
| 373 |
+
Various methods of class 'org.apache.commons.io.FileUtils' incorrectly suppress 'java.io.IOException'
|
| 374 |
+
</action>
|
| 375 |
+
<action issue="IO-304" dev="ggregory" type="add" due-to="liangly">
|
| 376 |
+
The second constructor of Tailer class does not pass 'delay' to the third one
|
| 377 |
+
</action>
|
| 378 |
+
<action issue="IO-303" dev="ggregory" type="add" due-to="fabian.barney">
|
| 379 |
+
TeeOutputStream does not call branch.close() when main.close() throws an exception
|
| 380 |
+
</action>
|
| 381 |
+
<action issue="IO-302" dev="ggregory" type="add" due-to="jsteuerwald, detinho">
|
| 382 |
+
ArrayIndexOutOfBoundsException in BOMInputStream when reading a file without BOM multiple times
|
| 383 |
+
</action>
|
| 384 |
+
<action issue="IO-301" dev="ggregory" type="add" due-to="kaykay.unique">
|
| 385 |
+
Add IOUtils.closeQuietly(Selector) necessary
|
| 386 |
+
</action>
|
| 387 |
+
<action issue="IO-292" dev="sebb" type="add" due-to="sebb">
|
| 388 |
+
IOUtils.closeQuietly() should take a ServerSocket as a parameter
|
| 389 |
+
</action>
|
| 390 |
+
<action issue="IO-290" dev="sebb" type="add" due-to="sebb">
|
| 391 |
+
Add read/readFully methods to IOUtils
|
| 392 |
+
</action>
|
| 393 |
+
<action issue="IO-288" dev="sebb" type="add" due-to="Georg Henzler">
|
| 394 |
+
Supply a ReversedLinesFileReader
|
| 395 |
+
</action>
|
| 396 |
+
<action issue="IO-291" dev="ggregory" type="add" due-to="ggregory">
|
| 397 |
+
Add new function FileUtils.directoryContains.
|
| 398 |
+
</action>
|
| 399 |
+
<action issue="IO-275" dev="sebb" type="add" due-to="CJ Aspromgos">
|
| 400 |
+
FileUtils.contentEquals and IOUtils.contentEquals - Add option to ignore "line endings"
|
| 401 |
+
Added contentEqualsIgnoreEOL methods to both classes
|
| 402 |
+
</action>
|
| 403 |
+
</release>
|
| 404 |
+
<release version="2.1" date="2011-Sep-28" description="New features and bug fixes.">
|
| 405 |
+
<action dev="ggregory" type="add" issue="IO-285" due-to="ggregory">
|
| 406 |
+
Use standard Maven directory layout
|
| 407 |
+
</action>
|
| 408 |
+
<action dev="ggregory" type="add" issue="IO-284" due-to="ggregory">
|
| 409 |
+
Add IOUtils API toString for URL and URI to get contents
|
| 410 |
+
</action>
|
| 411 |
+
<action dev="ggregory" type="add" issue="IO-282" due-to="ggregory">
|
| 412 |
+
Add API FileUtils.copyFile(File input, OutputStream output)
|
| 413 |
+
</action>
|
| 414 |
+
<action dev="sebb" type="fix" issue="IO-280" due-to="sebb">
|
| 415 |
+
Dubious use of mkdirs() return code
|
| 416 |
+
</action>
|
| 417 |
+
<action type="fix" issue="IO-277">
|
| 418 |
+
ReaderInputStream enters infinite loop when it encounters an unmappable character
|
| 419 |
+
</action>
|
| 420 |
+
<action type="fix" issue="IO-264">
|
| 421 |
+
FileUtils.moveFile() JavaDoc should specify FileExistsException thrown
|
| 422 |
+
</action>
|
| 423 |
+
<action type="add" issue="IO-262">
|
| 424 |
+
FileAlterationObserver has no getter for FileFilter
|
| 425 |
+
</action>
|
| 426 |
+
<action type="add" issue="IO-261">
|
| 427 |
+
Add FileUtils.getFile API with varargs parameter
|
| 428 |
+
</action>
|
| 429 |
+
<action type="fix" issue="IO-260">
|
| 430 |
+
ClassLoaderObjectInputStream does not handle Proxy classes
|
| 431 |
+
</action>
|
| 432 |
+
<action type="update" issue="IO-259">
|
| 433 |
+
FileAlterationMonitor.stop(boolean allowIntervalToFinish)
|
| 434 |
+
</action>
|
| 435 |
+
<action type="add" issue="IO-182">
|
| 436 |
+
Add new APPEND parameter for writing string into files
|
| 437 |
+
</action>
|
| 438 |
+
<action dev="sebb" type="fix" issue="IO-274" due-to="Frank Grimes">
|
| 439 |
+
Tailer returning partial lines when reaching EOF before EOL
|
| 440 |
+
</action>
|
| 441 |
+
<action dev="sebb" type="fix" issue="IO-266" due-to="Igor Smereka">
|
| 442 |
+
FileUtils.copyFile() throws IOException when copying large files to a shared directory (on Windows)
|
| 443 |
+
</action>
|
| 444 |
+
<action dev="sebb" type="fix" issue="IO-263" due-to="Gil Adam">
|
| 445 |
+
FileSystemUtils.freeSpaceKb throws exception for Windows volumes with no visible files.
|
| 446 |
+
Improve coverage by also looking for hidden files.
|
| 447 |
+
</action>
|
| 448 |
+
<action dev="sebb" type="add" issue="IO-251" due-to="Marco Albini">
|
| 449 |
+
Add new read method "toByteArray" to handle InputStream with known size.
|
| 450 |
+
</action>
|
| 451 |
+
|
| 452 |
+
</release>
|
| 453 |
+
|
| 454 |
+
<release version="2.0.1" date="2010-Dec-26">
|
| 455 |
+
<action type="update">
|
| 456 |
+
TODO: Convert RELEASE-NOTES.txt from 2.0.1?
|
| 457 |
+
</action>
|
| 458 |
+
</release>
|
| 459 |
+
|
| 460 |
+
<release version="2.0" date="2010-Oct-18">
|
| 461 |
+
<action type="update">
|
| 462 |
+
TODO: Convert RELEASE-NOTES.txt from 2.0?
|
| 463 |
+
</action>
|
| 464 |
+
</release>
|
| 465 |
+
|
| 466 |
+
<release version="1.4" date="2008-Jan-21">
|
| 467 |
+
<action type="update">
|
| 468 |
+
TODO: Convert RELEASE-NOTES.txt from 1.4?
|
| 469 |
+
</action>
|
| 470 |
+
</release>
|
| 471 |
+
|
| 472 |
+
<release version="1.3.2" date="2007-Jul-02" description="Bug fixes.">
|
| 473 |
+
<action dev="jochen" type="fix" issue="IO-115">
|
| 474 |
+
Some tests, which are implicitly assuming a Unix-like file
|
| 475 |
+
system, are now skipped on Windows.
|
| 476 |
+
</action>
|
| 477 |
+
<action dev="jochen" type="fix" issue="IO-116">
|
| 478 |
+
Created the FileCleaningTracker, basically a non-static
|
| 479 |
+
version of the FileCleaner, which can be controlled by
|
| 480 |
+
the user.
|
| 481 |
+
</action>
|
| 482 |
+
<action dev="bayard" type="fix" issue="IO-117" due-to="Hiroshi Ikeda">
|
| 483 |
+
EndianUtils - both readSwappedUnsignedInteger(...) methods could
|
| 484 |
+
return negative numbers due to int/long casting.
|
| 485 |
+
</action>
|
| 486 |
+
</release>
|
| 487 |
+
</body>
|
| 488 |
+
</document>
|
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/01_课件与电子教材/尚硅谷_第15章_File类与IO流/03-apache-common包/commons-io-2.5-src/src/changes/release-notes.vm
ADDED
|
@@ -0,0 +1,1029 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
## Licensed to the Apache Software Foundation (ASF) under one
|
| 2 |
+
## or more contributor license agreements. See the NOTICE file
|
| 3 |
+
## distributed with this work for additional information
|
| 4 |
+
## regarding copyright ownership. The ASF licenses this file
|
| 5 |
+
## to you under the Apache License, Version 2.0 (the
|
| 6 |
+
## "License"); you may not use this file except in compliance
|
| 7 |
+
## with the License. You may obtain a copy of the License at
|
| 8 |
+
##
|
| 9 |
+
## http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
##
|
| 11 |
+
## Unless required by applicable law or agreed to in writing,
|
| 12 |
+
## software distributed under the License is distributed on an
|
| 13 |
+
## "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
| 14 |
+
## KIND, either express or implied. See the License for the
|
| 15 |
+
## specific language governing permissions and limitations
|
| 16 |
+
## under the License.
|
| 17 |
+
|
| 18 |
+
Apache Commons IO
|
| 19 |
+
Version ${version}
|
| 20 |
+
Release Notes
|
| 21 |
+
|
| 22 |
+
INTRODUCTION:
|
| 23 |
+
|
| 24 |
+
Commons IO is a package of Java utility classes like java.io.
|
| 25 |
+
Classes in this package are considered to be so standard and of such high
|
| 26 |
+
reuse as to justify existence in java.io.
|
| 27 |
+
|
| 28 |
+
$introduction.replaceAll("(?<!\015)\012", "
|
| 29 |
+
")
|
| 30 |
+
|
| 31 |
+
==============================================================================
|
| 32 |
+
Apache Commons IO Version ${version}
|
| 33 |
+
==============================================================================
|
| 34 |
+
##
|
| 35 |
+
## N.B. the available variables are described here:
|
| 36 |
+
## http://maven.apache.org/plugins/maven-changes-plugin/examples/using-a-custom-announcement-template.html
|
| 37 |
+
##
|
| 38 |
+
## Hack to improve layout: replace all pairs of spaces with a single new-line
|
| 39 |
+
$release.description.replaceAll(" ", "
|
| 40 |
+
")
|
| 41 |
+
|
| 42 |
+
##
|
| 43 |
+
#if ($release.getActions().size() == 0)
|
| 44 |
+
No changes defined in this version.
|
| 45 |
+
#else
|
| 46 |
+
Changes in this version include:
|
| 47 |
+
|
| 48 |
+
## indent to be used if there is no issue attribute.
|
| 49 |
+
## should be the same as the indent in the changes.xml file
|
| 50 |
+
## less 2 spaces for the 'o' and trailing space
|
| 51 |
+
#set($indent=' ')
|
| 52 |
+
#if ($release.getActions('add').size() !=0)
|
| 53 |
+
New features:
|
| 54 |
+
#foreach($actionItem in $release.getActions('add'))
|
| 55 |
+
## Use replaceAll to fix up LF-only line ends on Windows.
|
| 56 |
+
#set($action=$actionItem.getAction().replaceAll("\n","
|
| 57 |
+
"))
|
| 58 |
+
#if ($actionItem.getIssue())
|
| 59 |
+
#set($issue=$actionItem.getIssue())
|
| 60 |
+
#else
|
| 61 |
+
#set($issue="")
|
| 62 |
+
#end
|
| 63 |
+
#if ($actionItem.getDueTo())
|
| 64 |
+
#set($dueto=$actionItem.getDueTo())
|
| 65 |
+
#else
|
| 66 |
+
#set($dueto="")
|
| 67 |
+
#end
|
| 68 |
+
o#if($!issue != "") $issue: #else$indent#end ${action} #if($!dueto != "")Thanks to $dueto. #end
|
| 69 |
+
|
| 70 |
+
#set($issue="")
|
| 71 |
+
#set($dueto="")
|
| 72 |
+
#end
|
| 73 |
+
#end
|
| 74 |
+
|
| 75 |
+
#if ($release.getActions('fix').size() !=0)
|
| 76 |
+
Fixed Bugs:
|
| 77 |
+
#foreach($actionItem in $release.getActions('fix'))
|
| 78 |
+
## Use replaceAll to fix up LF-only line ends on Windows.
|
| 79 |
+
#set($action=$actionItem.getAction().replaceAll("\n","
|
| 80 |
+
"))
|
| 81 |
+
#if ($actionItem.getIssue())
|
| 82 |
+
#set($issue=$actionItem.getIssue())
|
| 83 |
+
#else
|
| 84 |
+
#set($issue="")
|
| 85 |
+
#end
|
| 86 |
+
#if ($actionItem.getDueTo())
|
| 87 |
+
#set($dueto=$actionItem.getDueTo())
|
| 88 |
+
#else
|
| 89 |
+
#set($dueto="")
|
| 90 |
+
#end
|
| 91 |
+
o#if($!issue != "") $issue: #else$indent#end ${action} #if($!dueto != "")Thanks to $dueto. #end
|
| 92 |
+
|
| 93 |
+
#set($issue="")
|
| 94 |
+
#set($dueto="")
|
| 95 |
+
#end
|
| 96 |
+
#end
|
| 97 |
+
|
| 98 |
+
#if ($release.getActions('update').size() !=0)
|
| 99 |
+
Changes:
|
| 100 |
+
#foreach($actionItem in $release.getActions('update'))
|
| 101 |
+
## Use replaceAll to fix up LF-only line ends on Windows.
|
| 102 |
+
#set($action=$actionItem.getAction().replaceAll("\n","
|
| 103 |
+
"))
|
| 104 |
+
#if ($actionItem.getIssue())
|
| 105 |
+
#set($issue=$actionItem.getIssue())
|
| 106 |
+
#else
|
| 107 |
+
#set($issue="")
|
| 108 |
+
#end
|
| 109 |
+
#if ($actionItem.getDueTo())
|
| 110 |
+
#set($dueto=$actionItem.getDueTo())
|
| 111 |
+
#else
|
| 112 |
+
#set($dueto="")
|
| 113 |
+
#end
|
| 114 |
+
o#if($!issue != "") $issue: #else$indent#end ${action} #if($!dueto != "")Thanks to $dueto. #end
|
| 115 |
+
|
| 116 |
+
#set($issue="")
|
| 117 |
+
#set($dueto="")
|
| 118 |
+
#end
|
| 119 |
+
#end
|
| 120 |
+
|
| 121 |
+
#if ($release.getActions('remove').size() !=0)
|
| 122 |
+
Removed:
|
| 123 |
+
#foreach($actionItem in $release.getActions('remove'))
|
| 124 |
+
## Use replaceAll to fix up LF-only line ends on Windows.
|
| 125 |
+
#set($action=$actionItem.getAction().replaceAll("\n","
|
| 126 |
+
"))
|
| 127 |
+
#if ($actionItem.getIssue())
|
| 128 |
+
#set($issue=$actionItem.getIssue())
|
| 129 |
+
#else
|
| 130 |
+
#set($issue="")
|
| 131 |
+
#end
|
| 132 |
+
#if ($actionItem.getDueTo())
|
| 133 |
+
#set($dueto=$actionItem.getDueTo())
|
| 134 |
+
#else
|
| 135 |
+
#set($dueto="")
|
| 136 |
+
#end
|
| 137 |
+
o#if($!issue != "") $issue: #else$indent#end ${action} #if($!dueto != "")Thanks to $dueto. #end
|
| 138 |
+
##
|
| 139 |
+
#set($issue="")
|
| 140 |
+
#set($dueto="")
|
| 141 |
+
#end
|
| 142 |
+
#end
|
| 143 |
+
## End of main loop
|
| 144 |
+
#end
|
| 145 |
+
##
|
| 146 |
+
Compatibility with 2.4:
|
| 147 |
+
Binary compatible: Yes.
|
| 148 |
+
Source compatible: Yes.
|
| 149 |
+
Semantic compatible: Yes.
|
| 150 |
+
|
| 151 |
+
Compatibility with 2.2 and 1.4:
|
| 152 |
+
Binary compatible: Yes.
|
| 153 |
+
Source compatible: No, see the rare case in https://issues.apache.org/jira/browse/IO-318.
|
| 154 |
+
Semantic compatible: No, see the rare case in https://issues.apache.org/jira/browse/IO-318.
|
| 155 |
+
|
| 156 |
+
Commons IO 2.5 requires JDK 1.6 or later.
|
| 157 |
+
Commons IO 2.4 requires JDK 1.6 or later.
|
| 158 |
+
Commons IO 2.3 requires JDK 1.6 or later.
|
| 159 |
+
Commons IO 2.2 requires JDK 1.5 or later.
|
| 160 |
+
Commons IO 1.4 requires JDK 1.3 or later.
|
| 161 |
+
|
| 162 |
+
==============================================================================
|
| 163 |
+
Apache Commons IO Version 2.4
|
| 164 |
+
==============================================================================
|
| 165 |
+
|
| 166 |
+
Changes in this version include:
|
| 167 |
+
|
| 168 |
+
New features:
|
| 169 |
+
o IO-269: Tailer locks file from deletion/rename on Windows. Thanks to
|
| 170 |
+
sebb.
|
| 171 |
+
o IO-333: Export OSGi packages at version 1.x in addition to 2.x. Thanks
|
| 172 |
+
to fmeschbe.
|
| 173 |
+
o IO-320: Add XmlStreamReader support for UTF-32. Thanks to ggregory.
|
| 174 |
+
o IO-331: BOMInputStream wrongly detects UTF-32LE_BOM files as
|
| 175 |
+
UTF-16LE_BOM files in method getBOM(). Thanks to ggregory.
|
| 176 |
+
o IO-327: Add byteCountToDisplaySize(BigInteger). Thanks to ggregory.
|
| 177 |
+
o IO-326: Add new FileUtils.sizeOf[Directory] APIs to return BigInteger.
|
| 178 |
+
Thanks to ggregory.
|
| 179 |
+
o IO-325: Add IOUtils.toByteArray methods to work with URL and URI. Thanks
|
| 180 |
+
to raviprak.
|
| 181 |
+
o IO-324: Add missing Charset sister APIs to method that take a String
|
| 182 |
+
charset name. Thanks to raviprak.
|
| 183 |
+
|
| 184 |
+
Fixed Bugs:
|
| 185 |
+
o IO-336: Yottabyte (YB) incorrectly defined in FileUtils. Thanks to
|
| 186 |
+
rleavelle.
|
| 187 |
+
o IO-279: Tailer erroneously considers file as new. Thanks to Sergio
|
| 188 |
+
Bossa, Chris Baron.
|
| 189 |
+
o IO-335: Tailer#readLines - incorrect CR handling.
|
| 190 |
+
o IO-334: FileUtils.toURLs throws NPE for null parameter; document the
|
| 191 |
+
behavior.
|
| 192 |
+
o IO-332: Improve tailer's reading performance. Thanks to liangly.
|
| 193 |
+
o IO-279: Improve Tailer performance with buffered reads (see IO-332).
|
| 194 |
+
o IO-329: FileUtils.writeLines uses unbuffered IO. Thanks to tivv.
|
| 195 |
+
o IO-319: FileUtils.sizeOfDirectory follows symbolic links. Thanks to
|
| 196 |
+
raviprak.
|
| 197 |
+
|
| 198 |
+
|
| 199 |
+
Compatibility with 2.3:
|
| 200 |
+
Binary compatible: Yes.
|
| 201 |
+
Source compatible: Yes.
|
| 202 |
+
Semantic compatible: Yes.
|
| 203 |
+
|
| 204 |
+
Compatibility with 2.2 and 1.4:
|
| 205 |
+
Binary compatible: Yes.
|
| 206 |
+
Source compatible: No, see the rare case in https://issues.apache.org/jira/browse/IO-318.
|
| 207 |
+
Semantic compatible: No, see the rare case in https://issues.apache.org/jira/browse/IO-318.
|
| 208 |
+
|
| 209 |
+
Commons IO 2.4 requires JDK 1.6 or later.
|
| 210 |
+
Commons IO 2.3 requires JDK 1.6 or later.
|
| 211 |
+
Commons IO 2.2 requires JDK 1.5 or later.
|
| 212 |
+
Commons IO 1.4 requires JDK 1.3 or later.
|
| 213 |
+
|
| 214 |
+
==============================================================================
|
| 215 |
+
Apache Commons IO Version 2.3
|
| 216 |
+
==============================================================================
|
| 217 |
+
|
| 218 |
+
Changes in this version include:
|
| 219 |
+
|
| 220 |
+
New features:
|
| 221 |
+
o IO-322: Add and use class Charsets. Thanks to ggregory.
|
| 222 |
+
o IO-321: ByteOrderMark UTF_32LE is incorrect. Thanks to ggregory.
|
| 223 |
+
o IO-318: Add Charset sister APIs to method that take a String charset name. Thanks to ggregory.
|
| 224 |
+
|
| 225 |
+
Compatibility with 2.2 and 1.4:
|
| 226 |
+
Binary compatible: Yes.
|
| 227 |
+
Source compatible: No, see the rare case in https://issues.apache.org/jira/browse/IO-318.
|
| 228 |
+
Semantic compatible: No, see the rare case in https://issues.apache.org/jira/browse/IO-318.
|
| 229 |
+
|
| 230 |
+
Commons IO 2.3 requires JDK 1.6 or later.
|
| 231 |
+
Commons IO 2.2 requires JDK 1.5 or later.
|
| 232 |
+
Commons IO 1.4 requires JDK 1.3 or later.
|
| 233 |
+
|
| 234 |
+
==============================================================================
|
| 235 |
+
Apache Commons IO Version 2.2
|
| 236 |
+
==============================================================================
|
| 237 |
+
|
| 238 |
+
Changes in this version include:
|
| 239 |
+
|
| 240 |
+
New features:
|
| 241 |
+
o Add IOUTils.toBufferedReader(Reader) Issue: IO-313. Thanks to ggregory.
|
| 242 |
+
o Allow applications to provide buffer (or size) for copyLarge methods. Issue: IO-308. Thanks to Manoj Mokashi.
|
| 243 |
+
o New copyLarge() method in IOUtils that takes additional offset, length arguments Issue: IO-305. Thanks to Manoj Mokashi.
|
| 244 |
+
o Use terabyte (TB), petabyte (PB) and exabyte (EB) in FileUtils.byteCountToDisplaySize(long size) Issue: IO-287. Thanks to Ron Kuris, Gary Gregory.
|
| 245 |
+
o FileUtils.listFiles() doesn't return directories Issue: IO-173. Thanks to Marcos Vin�cius da Silva.
|
| 246 |
+
o CharSequenceInputStream to efficiently stream content of a CharSequence Issue: IO-297. Thanks to Oleg Kalnichevski.
|
| 247 |
+
o The second constructor of Tailer class does not pass 'delay' to the third one Issue: IO-304. Thanks to liangly.
|
| 248 |
+
o TeeOutputStream does not call branch.close() when main.close() throws an exception Issue: IO-303. Thanks to fabian.barney.
|
| 249 |
+
o ArrayIndexOutOfBoundsException in BOMInputStream when reading a file without BOM multiple times Issue: IO-302. Thanks to jsteuerwald, detinho.
|
| 250 |
+
o Add IOUtils.closeQuietly(Selector) necessary Issue: IO-301. Thanks to kaykay.unique.
|
| 251 |
+
o IOUtils.closeQuietly() should take a ServerSocket as a parameter Issue: IO-292. Thanks to sebb.
|
| 252 |
+
o Add read/readFully methods to IOUtils Issue: IO-290. Thanks to sebb.
|
| 253 |
+
o Supply a ReversedLinesFileReader Issue: IO-288. Thanks to Georg Henzler.
|
| 254 |
+
o Add new function FileUtils.directoryContains. Issue: IO-291. Thanks to ggregory.
|
| 255 |
+
o FileUtils.contentEquals and IOUtils.contentEquals - Add option to ignore "line endings"
|
| 256 |
+
Added contentEqualsIgnoreEOL methods to both classes Issue: IO-275. Thanks to CJ Aspromgos.
|
| 257 |
+
|
| 258 |
+
Fixed Bugs:
|
| 259 |
+
o IOUtils.read(InputStream/Reader) ignores the offset parameter Issue: IO-311. Thanks to Robert Muir.
|
| 260 |
+
o CharSequenceInputStream(CharSequence s, Charset charset, int bufferSize) ignores bufferSize Issue: IO-312.
|
| 261 |
+
o FileUtils.moveDirectoryToDirectory removes source directory if destination is a subdirectory Issue: IO-300.
|
| 262 |
+
o ReaderInputStream#read(byte[] b, int off, int len) should check for valid parameters Issue: IO-307.
|
| 263 |
+
o ReaderInputStream#read(byte[] b, int off, int len) should always return 0 for length == 0 Issue: IO-306.
|
| 264 |
+
o "FileUtils#deleteDirectoryOnExit(File)" does not work Issue: IO-276. Thanks to nkami.
|
| 265 |
+
o BoundedInputStream.read() treats max differently from BoundedInputStream.read(byte[]...) Issue: IO-273. Thanks to sebb.
|
| 266 |
+
o Various methods of class 'org.apache.commons.io.FileUtils' incorrectly suppress 'java.io.IOException' Issue: IO-298. Thanks to Christian Schulte.
|
| 267 |
+
|
| 268 |
+
Changes:
|
| 269 |
+
o ReaderInputStream optimization: more efficient reading of small chunks of data Issue: IO-296. Thanks to Oleg Kalnichevski.
|
| 270 |
+
|
| 271 |
+
|
| 272 |
+
Compatibility with 2.1 and 1.4:
|
| 273 |
+
Binary compatible: Yes
|
| 274 |
+
Source compatible: Yes
|
| 275 |
+
Semantic compatible: Yes. Check the bug fixes section for semantic bug fixes
|
| 276 |
+
|
| 277 |
+
Commons IO 2.2 requires a minimum of JDK 1.5.
|
| 278 |
+
Commons IO 1.4 requires a minimum of JDK 1.3.
|
| 279 |
+
|
| 280 |
+
==============================================================================
|
| 281 |
+
Apache Commons IO Version 2.1
|
| 282 |
+
==============================================================================
|
| 283 |
+
|
| 284 |
+
New features:
|
| 285 |
+
o Use standard Maven directory layout Issue: IO-285. Thanks to ggregory.
|
| 286 |
+
o Add IOUtils API toString for URL and URI to get contents Issue: IO-284. Thanks to ggregory.
|
| 287 |
+
o Add API FileUtils.copyFile(File input, OutputStream output) Issue: IO-282. Thanks to ggregory.
|
| 288 |
+
o FileAlterationObserver has no getter for FileFilter Issue: IO-262.
|
| 289 |
+
o Add FileUtils.getFile API with varargs parameter Issue: IO-261.
|
| 290 |
+
o Add new APPEND parameter for writing string into files Issue: IO-182.
|
| 291 |
+
o Add new read method "toByteArray" to handle InputStream with known size. Issue: IO-251. Thanks to Marco Albini.
|
| 292 |
+
|
| 293 |
+
Fixed Bugs:
|
| 294 |
+
o Dubious use of mkdirs() return code Issue: IO-280. Thanks to sebb.
|
| 295 |
+
o ReaderInputStream enters infinite loop when it encounters an unmappable character Issue: IO-277.
|
| 296 |
+
o FileUtils.moveFile() JavaDoc should specify FileExistsException thrown Issue: IO-264.
|
| 297 |
+
o ClassLoaderObjectInputStream does not handle Proxy classes Issue: IO-260.
|
| 298 |
+
o Tailer returning partial lines when reaching EOF before EOL Issue: IO-274. Thanks to Frank Grimes.
|
| 299 |
+
o FileUtils.copyFile() throws IOException when copying large files to a shared directory (on Windows) Issue: IO-266. Thanks to Igor Smereka.
|
| 300 |
+
o FileSystemUtils.freeSpaceKb throws exception for Windows volumes with no visible files.
|
| 301 |
+
Improve coverage by also looking for hidden files. Issue: IO-263. Thanks to Gil Adam.
|
| 302 |
+
|
| 303 |
+
Changes:
|
| 304 |
+
o FileAlterationMonitor.stop(boolean allowIntervalToFinish) Issue: IO-259.
|
| 305 |
+
|
| 306 |
+
==============================================================================
|
| 307 |
+
Apache Commons IO Package 2.0.1
|
| 308 |
+
==============================================================================
|
| 309 |
+
|
| 310 |
+
Compatibility with 2.0 and 1.4
|
| 311 |
+
------------------------------
|
| 312 |
+
Binary compatible - Yes
|
| 313 |
+
|
| 314 |
+
Source compatible - Yes
|
| 315 |
+
|
| 316 |
+
Semantic compatible - Yes
|
| 317 |
+
Check the bug fixes section for semantic bug fixes
|
| 318 |
+
|
| 319 |
+
Commons IO 2.0.1 requires a minimum of JDK 1.5
|
| 320 |
+
(Commons IO 1.4 had a minimum of JDK 1.3)
|
| 321 |
+
|
| 322 |
+
Enhancements from 2.0
|
| 323 |
+
---------------------
|
| 324 |
+
|
| 325 |
+
* [IO-256] - Provide thread factory for FileAlternationMonitor
|
| 326 |
+
|
| 327 |
+
Bug fixes from 2.0
|
| 328 |
+
------------------
|
| 329 |
+
|
| 330 |
+
* [IO-257] - BOMInputStream.read(byte[]) can return 0 which it should not
|
| 331 |
+
* [IO-258] - XmlStreamReader consumes the stream during encoding detection
|
| 332 |
+
|
| 333 |
+
==============================================================================
|
| 334 |
+
Apache Commons IO Package 2.0
|
| 335 |
+
==============================================================================
|
| 336 |
+
|
| 337 |
+
Compatibility with 1.4
|
| 338 |
+
----------------------
|
| 339 |
+
Binary compatible - Yes
|
| 340 |
+
|
| 341 |
+
Source compatible - Yes
|
| 342 |
+
|
| 343 |
+
Semantic compatible - Yes
|
| 344 |
+
Check the bug fixes section for semantic bug fixes
|
| 345 |
+
|
| 346 |
+
Commons IO 2.0 requires a minimum of JDK 1.5
|
| 347 |
+
(Commons IO 1.4 had a minimum of JDK 1.3)
|
| 348 |
+
|
| 349 |
+
Deprecations from 1.4
|
| 350 |
+
---------------------
|
| 351 |
+
|
| 352 |
+
- IOUtils
|
| 353 |
+
- write(StringBuffer, Writer) in favour of write(CharSequence, Writer)
|
| 354 |
+
- write(StringBuffer, OutputStream) in favour of write(CharSequence, OutputStream)
|
| 355 |
+
- write(StringBuffer, OutputStream, String) in favour of write(CharSequence, OutputStream, String)
|
| 356 |
+
|
| 357 |
+
- FileFilterUtils
|
| 358 |
+
- andFileFilter(IOFileFilter, IOFileFilter) in favour of and(IOFileFilter...)
|
| 359 |
+
- orFileFilter(IOFileFilter, IOFileFilter) in favour of or(IOFileFilter...)
|
| 360 |
+
|
| 361 |
+
Enhancements from 1.4
|
| 362 |
+
---------------------
|
| 363 |
+
|
| 364 |
+
* [IO-140] Move minimum Java requirement from JDK 1.3 to JDK 1.5
|
| 365 |
+
- use Generics
|
| 366 |
+
- add new CharSequence write() flavour methods to IOUtils and FileUtils
|
| 367 |
+
- replace StringBuffer with StringBuilder, where appropriate
|
| 368 |
+
- add new Reader/Writer methods to ProxyReader and ProxyWriter
|
| 369 |
+
- Annotate with @Override and @Deprecated
|
| 370 |
+
|
| 371 |
+
* [IO-178] New BOMInputStream and ByteOrderMark implementations - to detect and optionally exclude an initial Byte Order mark (BOM)
|
| 372 |
+
* [IO-197] New BoundedInputStream (copied from from Apache JackRabbit)
|
| 373 |
+
* [IO-193] New Broken Input and Output streams
|
| 374 |
+
* [IO-132] New File Listener/Monitor facility
|
| 375 |
+
* [IO-158] New ReaderInputStream and WriterOutputStream implementations
|
| 376 |
+
* [IO-139] New StringBuilder Writer implementation
|
| 377 |
+
* [IO-192] New Tagged Input and Output streams
|
| 378 |
+
* [IO-177] New Tailer class - simple implementation of the Unix "tail -f" functionality
|
| 379 |
+
* [IO-162] New XML Stream Reader/Writer implementations (from ROME via plexus-utils)
|
| 380 |
+
|
| 381 |
+
* [IO-142] Comparators - add facility to sort file lists/arrays
|
| 382 |
+
* [IO-186] Comparators - new Composite and Directory File Comparator implementations
|
| 383 |
+
* [IO-176] DirectoryWalker - add filterDirectoryContents() callback method for filtering directory contents
|
| 384 |
+
* [IO-210] FileFilter - new Magic Number FileFilter
|
| 385 |
+
* [IO-221] FileFilterUtils - add methods for suffix and prefix filters which take an IOCase object
|
| 386 |
+
* [IO-232] FileFilterUtils - add method for name filters which take an IOCase object
|
| 387 |
+
* [IO-229] FileFilterUtils - add varargs and() and or() methods
|
| 388 |
+
* [IO-198] FileFilterUtils - add ability to apply file filters to collections and arrays
|
| 389 |
+
* [IO-156] FilenameUtils - add normalize() and normalizeNoEndSeparator() methods which allow the separator character to be specified
|
| 390 |
+
* [IO-194] FileSystemUtils - add freeSpaceKb() method with no input arguments
|
| 391 |
+
* [IO-185] FileSystemUtils - add freeSpaceKb() methods that take a timeout parameter - fixes freeSpaceWindows() blocks
|
| 392 |
+
* [IO-155] FileUtils - use NIO to copy files
|
| 393 |
+
* [IO-168] FileUtils - add new isSymlink() method
|
| 394 |
+
* [IO-219] FileUtils - throw FileExistsException when moving a file or directory if the destination already exists
|
| 395 |
+
* [IO-234] FileUtils - add Methods for retrieving System User/Temp directories/paths
|
| 396 |
+
* [IO-208] FileUtils - add timeout (connection and read) support for copyURLToFile() method
|
| 397 |
+
* [IO-238] FileUtils - add sizeOf(File) method
|
| 398 |
+
* [IO-181] LineIterator now implements Iterable
|
| 399 |
+
* [IO-224] IOUtils - add closeQuietly(Closeable) and closeQuietly(Socket) methods
|
| 400 |
+
* [IO-203] IOUtils - add skipFully() method for InputStreams
|
| 401 |
+
* [IO-137] IOUtils and ByteArrayOutputStream - add toBufferedInputStream() method to avoid unnecessary array allocation/copy
|
| 402 |
+
* [IO-195] Proxy streams/Reader/Writer - provide exception handling methods
|
| 403 |
+
* [IO-211] Proxy Input/Output streams - add pre/post processing support
|
| 404 |
+
* [IO-242] Proxy Reader/Writer - add pre/post processing support
|
| 405 |
+
|
| 406 |
+
Bug fixes from 1.4
|
| 407 |
+
------------------
|
| 408 |
+
* [IO-214] ByteArrayOutputStream - fix inconsistent synchronization of fields
|
| 409 |
+
* [IO-201] Counting Input/Output streams - fix inconsistent synchronization
|
| 410 |
+
* [IO-159] FileCleaningTracker - fix remove() never returns null
|
| 411 |
+
* [IO-220] FileCleaningTracker - fix Vector performs badly under load
|
| 412 |
+
* [IO-167] FilenameUtils - fix case-insensitive string handling in FilenameUtils and FilesystemUtils
|
| 413 |
+
* [IO-179] FilenameUtils - fix StringIndexOutOfBounds exception in getPathNoEndSeparator()
|
| 414 |
+
* [IO-248] FilenameUtils - fix getFullPathNoEndSeparator() returns empty while path is a one level directory
|
| 415 |
+
* [IO-246] FilenameUtils - fix wildcardMatch gives incorrect results
|
| 416 |
+
* [IO-187] FileSystemUtils - fix freeSpaceKb() doesn't work with relative paths on Linux
|
| 417 |
+
* [IO-160] FileSystemUtils - fix freeSpace() fails on solaris
|
| 418 |
+
* [IO-209] FileSystemUtils - fix freeSpaceKb() fails to return correct size for a windows mount point
|
| 419 |
+
* [IO-163] FileUtils - fix toURLs() using deprecated method of conversion to URL
|
| 420 |
+
* [IO-168] FileUtils - fix Symbolic links followed when deleting directory
|
| 421 |
+
* [IO-231] FileUtils - fix wrong exception message generated in isFileNewer() method
|
| 422 |
+
* [IO-207] FileUtils - fix race condition in forceMkdir() method
|
| 423 |
+
* [IO-217] FileUtils - fix copyDirectoryToDirectory() makes infinite loops
|
| 424 |
+
* [IO-166] FileUtils - fix URL decoding in toFile(URL)
|
| 425 |
+
* [IO-190] FileUtils - fix copyDirectory not preserving lastmodified date on sub-directories
|
| 426 |
+
* [IO-240] FileFilterUtils - ensure cvsFilter and svnFilter are only created once.
|
| 427 |
+
* [IO-175] IOUtils - fix copyFile() issues with very large files
|
| 428 |
+
* [IO-191] Improvements from static analysis
|
| 429 |
+
* [IO-216] LockableFileWriter - delete files quietly when an exception is thrown during initialization
|
| 430 |
+
* [IO-243] SwappedDataInputStream - fix readBoolean is inverted
|
| 431 |
+
* [IO-235] Tests - remove unused YellOnFlushAndCloseOutputStream from CopyUtilsTest
|
| 432 |
+
* [IO-161] Tests - fix FileCleaningTrackerTestCase hanging
|
| 433 |
+
|
| 434 |
+
Documentation changes from 1.4
|
| 435 |
+
------------------------------
|
| 436 |
+
* [IO-183 FilenameUtils.getExtension() method documentation improvements
|
| 437 |
+
* [IO-226 FileUtils.byteCountToDisplaySize() documentation corrections
|
| 438 |
+
* [IO-205 FileUtils.forceMkdir() documentation improvements
|
| 439 |
+
* [IO-215 FileUtils copy file/directory improve documentation regarding preserving the last modified date
|
| 440 |
+
* [IO-189 HexDump.dump() method documentation improvements
|
| 441 |
+
* [IO-171 IOCase document that it assumes there are only two OSes: Windows and Unix
|
| 442 |
+
* [IO-223 IOUtils.copy() documentation corrections
|
| 443 |
+
* [IO-247 IOUtils.closeQuietly() improve documentation with examples
|
| 444 |
+
* [IO-202 NotFileFilter documentation corrections
|
| 445 |
+
* [IO-206 ProxyInputStream - fix misleading parameter names
|
| 446 |
+
* [IO-212 ProxyInputStream.skip() documentation corrections
|
| 447 |
+
|
| 448 |
+
==============================================================================
|
| 449 |
+
Apache Commons IO Version 1.4
|
| 450 |
+
==============================================================================
|
| 451 |
+
|
| 452 |
+
Compatibility with 1.3.2
|
| 453 |
+
------------------------
|
| 454 |
+
Binary compatible - Yes
|
| 455 |
+
|
| 456 |
+
Source compatible - Yes
|
| 457 |
+
|
| 458 |
+
Semantic compatible - Yes
|
| 459 |
+
Check the bug fixes section for semantic bug fixes
|
| 460 |
+
|
| 461 |
+
Commons IO 1.4 introduces four new implementations which depend on JDK 1.4 features
|
| 462 |
+
(CharSequenceReader, FileWriterWithEncoding, IOExceptionWithCause and RegexFileFilter).
|
| 463 |
+
It has been built with the JDK source and target options set to JDK 1.3 and, except for
|
| 464 |
+
those implementations, can be used with JDK 1.3 (see IO IO-127).
|
| 465 |
+
|
| 466 |
+
Deprecations from 1.3.2
|
| 467 |
+
-----------------------
|
| 468 |
+
- FileCleaner deprecated in favour of FileCleaningTracker [see IO-116]
|
| 469 |
+
|
| 470 |
+
Bug fixes from 1.3.2
|
| 471 |
+
--------------------
|
| 472 |
+
- FileUtils
|
| 473 |
+
- forceDelete of orphaned Softlinks does not work [IO-147]
|
| 474 |
+
- Infinite loop on FileUtils.copyDirectory when the destination directory is within
|
| 475 |
+
the source directory [IO-141]
|
| 476 |
+
- Add a copyDirectory() method that makes use of FileFilter [IO-105]
|
| 477 |
+
- Add moveDirectory() and moveFile() methods [IO-77]
|
| 478 |
+
|
| 479 |
+
- HexDump
|
| 480 |
+
- HexDump's use of static StringBuffers isn't thread-safe [IO-136]
|
| 481 |
+
|
| 482 |
+
Enhancements from 1.3.2
|
| 483 |
+
-----------------------
|
| 484 |
+
- FileUtils
|
| 485 |
+
- Add a deleteQuietly method [IO-135]
|
| 486 |
+
|
| 487 |
+
- FilenameUtils
|
| 488 |
+
- Add file name extension separator constants[IO-149]
|
| 489 |
+
|
| 490 |
+
- IOExceptionWithCause [IO-148]
|
| 491 |
+
- Add a new IOException implementation with constructors which take a cause
|
| 492 |
+
|
| 493 |
+
- TeeInputStream [IO-129]
|
| 494 |
+
- Add new Tee input stream implementation
|
| 495 |
+
|
| 496 |
+
- FileWriterWithEncoding [IO-153]
|
| 497 |
+
- Add new File Writer implementation that accepts an encoding
|
| 498 |
+
|
| 499 |
+
- CharSequenceReader [IO-138]
|
| 500 |
+
- Add new Reader implementation that handles any CharSequence (String,
|
| 501 |
+
StringBuffer, StringBuilder or CharBuffer)
|
| 502 |
+
|
| 503 |
+
- ThesholdingOuputStream [IO-121]
|
| 504 |
+
- Add a reset() method which sets the count of the bytes written back to zero.
|
| 505 |
+
|
| 506 |
+
- DeferredFileOutputStream [IO-130]
|
| 507 |
+
- Add support for temporary files
|
| 508 |
+
|
| 509 |
+
- ByteArrayOutputStream
|
| 510 |
+
- Add a new write(InputStream) method [IO-152]
|
| 511 |
+
|
| 512 |
+
- New Closed Input/Output stream implementations [IO-122]
|
| 513 |
+
- AutoCloseInputStream - automatically closes and discards the underlying input stream
|
| 514 |
+
- ClosedInputStream - returns -1 for any read attempts
|
| 515 |
+
- ClosedOutputStream - throws an IOException for any write attempts
|
| 516 |
+
- CloseShieldInputStream - prevents the underlying input stream from being closed.
|
| 517 |
+
- CloseShieldOutputStream - prevents the underlying output stream from being closed.
|
| 518 |
+
|
| 519 |
+
- Add Singleton Constants to several stream classes [IO-143]
|
| 520 |
+
|
| 521 |
+
- PrefixFileFilter [IO-126]
|
| 522 |
+
- Add faciltiy to specify case sensitivity on prefix matching
|
| 523 |
+
|
| 524 |
+
- SuffixFileFilter [IO-126]
|
| 525 |
+
- Add faciltiy to specify case sensitivity on suffix matching
|
| 526 |
+
|
| 527 |
+
- RegexFileFilter [IO-74]
|
| 528 |
+
- Add new regular expression file filter implementation
|
| 529 |
+
|
| 530 |
+
- Make IOFileFilter implementations Serializable [IO-131]
|
| 531 |
+
|
| 532 |
+
- Improve IOFileFilter toString() methods [IO-120]
|
| 533 |
+
|
| 534 |
+
- Make fields final so classes are immutable/threadsafe [IO-133]
|
| 535 |
+
- changes to Age, Delegate, Name, Not, Prefix, Regex, Size, Suffix and Wildcard IOFileFilter
|
| 536 |
+
implementations.
|
| 537 |
+
|
| 538 |
+
- IOCase
|
| 539 |
+
- Add a compare method to IOCase [IO-144]
|
| 540 |
+
|
| 541 |
+
- Add a package of java.util.Comparator implementations for files [IO-145]
|
| 542 |
+
- DefaultFileComparator - compare files using the default File.compareTo(File) method.
|
| 543 |
+
- ExtensionFileComparator - compares files using file name extensions.
|
| 544 |
+
- LastModifiedFileComparator - compares files using the last modified date/time.
|
| 545 |
+
- NameFileComparator - compares files using file names.
|
| 546 |
+
- PathFileComparator - compares files using file paths.
|
| 547 |
+
- SizeFileComparator - compares files using file sizes.
|
| 548 |
+
|
| 549 |
+
==============================================================================
|
| 550 |
+
Apache Commons IO Version 1.3.2
|
| 551 |
+
==============================================================================
|
| 552 |
+
|
| 553 |
+
Compatibility with 1.3.1
|
| 554 |
+
----------------------
|
| 555 |
+
Binary compatible - Yes
|
| 556 |
+
|
| 557 |
+
Source compatible - Yes
|
| 558 |
+
|
| 559 |
+
Semantic compatible - Yes
|
| 560 |
+
|
| 561 |
+
Compatibility with 1.3
|
| 562 |
+
----------------------
|
| 563 |
+
Binary compatible - No
|
| 564 |
+
See [IO-113]
|
| 565 |
+
|
| 566 |
+
Source compatible - No
|
| 567 |
+
See [IO-113]
|
| 568 |
+
|
| 569 |
+
Semantic compatible - Yes
|
| 570 |
+
|
| 571 |
+
Enhancements since 1.3.1
|
| 572 |
+
------------------------
|
| 573 |
+
|
| 574 |
+
- Created the FileCleaningTracker, basically a non-static version of the
|
| 575 |
+
FileCleaner, which can be controlled by the user. [IO-116]
|
| 576 |
+
- The FileCleaner is deprecated.
|
| 577 |
+
|
| 578 |
+
Bug fixes from 1.3.1
|
| 579 |
+
--------------------
|
| 580 |
+
|
| 581 |
+
- Some tests, which are implicitly assuming a Unix-like file system, are
|
| 582 |
+
now skipped on Windows. [IO-115]
|
| 583 |
+
- EndianUtils
|
| 584 |
+
- Both readSwappedUnsignedInteger(...) methods could return negative
|
| 585 |
+
numbers due to int/long casting. [IO-117]
|
| 586 |
+
|
| 587 |
+
Bug fixes from 1.3
|
| 588 |
+
------------------
|
| 589 |
+
|
| 590 |
+
- FileUtils
|
| 591 |
+
- NPE in openOutputStream(File) when file has no parent in path [IO-112]
|
| 592 |
+
- readFileToString(File) is not static [IO-113]
|
| 593 |
+
|
| 594 |
+
==============================================================================
|
| 595 |
+
Apache Commons IO Version 1.3.1
|
| 596 |
+
==============================================================================
|
| 597 |
+
|
| 598 |
+
Compatibility with 1.3
|
| 599 |
+
----------------------
|
| 600 |
+
Binary compatible - No
|
| 601 |
+
See [IO-113]
|
| 602 |
+
|
| 603 |
+
Source compatible - No
|
| 604 |
+
See [IO-113]
|
| 605 |
+
|
| 606 |
+
Semantic compatible - Yes
|
| 607 |
+
|
| 608 |
+
Bug fixes from 1.3
|
| 609 |
+
------------------
|
| 610 |
+
|
| 611 |
+
- FileUtils
|
| 612 |
+
- NPE in openOutputStream(File) when file has no parent in path [IO-112]
|
| 613 |
+
- readFileToString(File) is not static [IO-113]
|
| 614 |
+
|
| 615 |
+
==============================================================================
|
| 616 |
+
Apache Commons IO Version 1.3
|
| 617 |
+
==============================================================================
|
| 618 |
+
|
| 619 |
+
Compatibility with 1.2
|
| 620 |
+
----------------------
|
| 621 |
+
Binary compatible - Yes
|
| 622 |
+
|
| 623 |
+
Source compatible - Yes
|
| 624 |
+
|
| 625 |
+
Semantic compatible - Yes
|
| 626 |
+
Check the bug fixes section for semantic bug fixes
|
| 627 |
+
|
| 628 |
+
Deprecations from 1.2
|
| 629 |
+
---------------------
|
| 630 |
+
- WildcardFilter deprecated, replaced by WildcardFileFilter
|
| 631 |
+
- old class only accepted files, thus had a confusing dual purpose
|
| 632 |
+
|
| 633 |
+
- FileSystemUtils.freeSpace deprecated, replaced by freeSpaceKb
|
| 634 |
+
- freeSpace returns a result that varies by operating system and
|
| 635 |
+
thus isn't that useful
|
| 636 |
+
- freeSpaceKb returns much better and more consistent results
|
| 637 |
+
- freeSpaceKb existed in v1.2, so this is a gentle cutover
|
| 638 |
+
|
| 639 |
+
Bug fixes from 1.2
|
| 640 |
+
------------------
|
| 641 |
+
- LineIterator now implements Iterator
|
| 642 |
+
- It was always supposed to...
|
| 643 |
+
|
| 644 |
+
- FileSystemUtils.freeSpace/freeSpaceKb [IO-83]
|
| 645 |
+
- These should now work on AIX and HP-UX
|
| 646 |
+
|
| 647 |
+
- FileSystemUtils.freeSpace/freeSpaceKb [IO-90]
|
| 648 |
+
- Avoid infinite looping in Windows
|
| 649 |
+
- Catch more errors with nice messages
|
| 650 |
+
|
| 651 |
+
- FileSystemUtils.freeSpace [IO-91]
|
| 652 |
+
- This is now documented not to work on SunOS 5
|
| 653 |
+
|
| 654 |
+
- FileSystemUtils [IO-93]
|
| 655 |
+
- Fixed resource leak leading to 'Too many open files' error
|
| 656 |
+
- Previously did not destroy Process instances (as JDK Javadoc is so poor)
|
| 657 |
+
- http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4801027
|
| 658 |
+
|
| 659 |
+
- FileUtils.touch [IO-100]
|
| 660 |
+
- The touch method previously gave no indication when the file could not
|
| 661 |
+
be touched successfully (such as due to access restrictions) - it now
|
| 662 |
+
throws an IOException if the last modified date cannot be changed
|
| 663 |
+
|
| 664 |
+
- FileCleaner
|
| 665 |
+
- This now handles the situation where an error occurs when deleting the file
|
| 666 |
+
|
| 667 |
+
- IOUtils.copy [IO-84]
|
| 668 |
+
- Copy methods could return inaccurate byte/char count for large streams
|
| 669 |
+
- The copy(InputStream, OutputStream) method now returns -1 if the count is greater than an int
|
| 670 |
+
- The copy(Reader, Writer) method now throws now returns -1 if the count is greater than an int
|
| 671 |
+
- Added a new copyLarge(InputStream, OutputStream) method that returns a long
|
| 672 |
+
- Added a new copyLarge(Reader, Writer) method that returns a long
|
| 673 |
+
|
| 674 |
+
- CountingInputStream/CountingOutputStream [IO-84]
|
| 675 |
+
- Methods were declared as int thus the count was innacurate for large streams
|
| 676 |
+
- new long based methods getByteCount()/resetByteCount() added
|
| 677 |
+
- existing methods changed to throw an exception if the count is greater than an int
|
| 678 |
+
|
| 679 |
+
- FileBasedTestCase
|
| 680 |
+
- Fixed bug in compare content methods identified by GNU classpath
|
| 681 |
+
|
| 682 |
+
- EndianUtils.writeSwappedLong(byte[], int) [IO-101]
|
| 683 |
+
- An int overrun in the bit shifting when it should have been a long
|
| 684 |
+
|
| 685 |
+
- EndianUtils.writeSwappedLong(InputStream) [IO-102]
|
| 686 |
+
- The return of input.read(byte[]) was not being checked to ensure all 8 bytes were read
|
| 687 |
+
|
| 688 |
+
Enhancements from 1.2
|
| 689 |
+
---------------------
|
| 690 |
+
- DirectoryWalker [IO-86]
|
| 691 |
+
- New class designed for subclassing to walk through a set of files.
|
| 692 |
+
DirectoryWalker provides the walk of the directories, filtering of
|
| 693 |
+
directories and files, and cancellation support. The subclass must provide
|
| 694 |
+
the specific behaviour, such as text searching or image processing.
|
| 695 |
+
|
| 696 |
+
- IOCase
|
| 697 |
+
- New class/enumeration for case-sensitivity control
|
| 698 |
+
|
| 699 |
+
- FilenameUtils
|
| 700 |
+
- New methods to handle case-sensitivity
|
| 701 |
+
- wildcardMatch - new method that has IOCase as a parameter
|
| 702 |
+
- equals - new method that has IOCase as a parameter
|
| 703 |
+
|
| 704 |
+
- FileUtils [IO-108] - new default encoding methods for:
|
| 705 |
+
- readFileToString(File)
|
| 706 |
+
- readLines(File)
|
| 707 |
+
- lineIterator(File)
|
| 708 |
+
- writeStringToFile(File, String)
|
| 709 |
+
- writeLines(File, Collection)
|
| 710 |
+
- writeLines(File, Collection, String)
|
| 711 |
+
|
| 712 |
+
- FileUtils.openOutputStream [IO-107]
|
| 713 |
+
- new method to open a FileOutputStream, creating parent directories if required
|
| 714 |
+
- FileUtils.touch
|
| 715 |
+
- FileUtils.copyURLToFile
|
| 716 |
+
- FileUtils.writeStringToFile
|
| 717 |
+
- FileUtils.writeByteArrayToFile
|
| 718 |
+
- FileUtils.writeLines
|
| 719 |
+
- enhanced to create parent directories if required
|
| 720 |
+
- FileUtils.openInputStream [IO-107]
|
| 721 |
+
- new method to open a FileInputStream, providing better error messages than the JDK
|
| 722 |
+
|
| 723 |
+
- FileUtils.isFileOlder
|
| 724 |
+
- new methods to check if a file is older (i.e. isFileOlder()) - counterparts
|
| 725 |
+
to the existing isFileNewer() methods.
|
| 726 |
+
|
| 727 |
+
- FileUtils.checksum, FileUtils.checksumCRC32
|
| 728 |
+
- new methods to create a checksum of a file
|
| 729 |
+
|
| 730 |
+
- FileUtils.copyFileToDirectory [IO-104]
|
| 731 |
+
- new variant that optionally retains the file date
|
| 732 |
+
|
| 733 |
+
- FileDeleteStrategy
|
| 734 |
+
- FileCleaner [IO-56,IO-70]
|
| 735 |
+
- FileDeleteStrategy is a strategy for handling file deletion
|
| 736 |
+
- This can be used as a calback in FileCleaner
|
| 737 |
+
- Together these allow FileCleaner to do a forceDelete to kill directories
|
| 738 |
+
|
| 739 |
+
- FileCleaner.exitWhenFinished [IO-99]
|
| 740 |
+
- A new method that allows the internal cleaner thread to be cleanly terminated
|
| 741 |
+
|
| 742 |
+
- WildcardFileFilter
|
| 743 |
+
- Replacement for WildcardFilter
|
| 744 |
+
- Accepts both files and directories
|
| 745 |
+
- Ability to control case-sensitivity
|
| 746 |
+
|
| 747 |
+
- NameFileFilter
|
| 748 |
+
- Ability to control case-sensitivity
|
| 749 |
+
|
| 750 |
+
- FileFileFilter
|
| 751 |
+
- New IOFileFilter implementation
|
| 752 |
+
- Accepts files where File.isFile() is true
|
| 753 |
+
- In other words it filters out directories
|
| 754 |
+
- Singleton instance provided (FILE)
|
| 755 |
+
|
| 756 |
+
- CanReadFileFilter
|
| 757 |
+
- New IOFileFilter implementation
|
| 758 |
+
- Accepts files where File.canRead() is true
|
| 759 |
+
- Singleton instances provided (CAN_READ/CANNOT_READ/READ_ONLY)
|
| 760 |
+
|
| 761 |
+
- CanWriteFileFilter
|
| 762 |
+
- New IOFileFilter implementation
|
| 763 |
+
- Accepts files where File.canWrite() is true
|
| 764 |
+
- Singleton instances provided (CAN_WRITE/CANNOT_WRITE)
|
| 765 |
+
|
| 766 |
+
- HiddenFileFilter
|
| 767 |
+
- New IOFileFilter implementation
|
| 768 |
+
- Accepts files where File.isHidden() is true
|
| 769 |
+
- Singleton instances provided (HIDDEN/VISIBLE)
|
| 770 |
+
|
| 771 |
+
- EmptyFileFilter
|
| 772 |
+
- New IOFileFilter implementation
|
| 773 |
+
- Accepts files or directories that are empty
|
| 774 |
+
- Singleton instances provided (EMPTY/NOT_EMPTY)
|
| 775 |
+
|
| 776 |
+
- TrueFileFilter/FalseFileFilter/DirectoryFileFilter
|
| 777 |
+
- New singleton instance constants (TRUE/FALSE/DIRECTORY)
|
| 778 |
+
- The new constants are more JDK 1.5 friendly with regards to static imports
|
| 779 |
+
(whereas if everything uses INSTANCE, then they just clash)
|
| 780 |
+
- The old INSTANCE constants are still present and have not been deprecated
|
| 781 |
+
|
| 782 |
+
- FileFilterUtils.sizeRangeFileFilter
|
| 783 |
+
- new sizeRangeFileFilter(long minimumSize, long maximumSize) method which
|
| 784 |
+
creates a filter that accepts files within the specified size range.
|
| 785 |
+
|
| 786 |
+
- FileFilterUtils.makeDirectoryOnly/makeFileOnly
|
| 787 |
+
- two new methods that decorate a file filter to make it apply to
|
| 788 |
+
directories only or files only
|
| 789 |
+
|
| 790 |
+
- NullWriter
|
| 791 |
+
- New writer that acts as a sink for all data, as per /dev/null
|
| 792 |
+
|
| 793 |
+
- NullInputStream
|
| 794 |
+
- New input stream that emulates a stream of a specified size
|
| 795 |
+
|
| 796 |
+
- NullReader
|
| 797 |
+
- New reader that emulates a reader of a specified size
|
| 798 |
+
|
| 799 |
+
- ByteArrayOutputStream [IO-97]
|
| 800 |
+
- Performance enhancements
|
| 801 |
+
|
| 802 |
+
==============================================================================
|
| 803 |
+
Apache Commons IO Version 1.2
|
| 804 |
+
==============================================================================
|
| 805 |
+
|
| 806 |
+
Compatibility with 1.1
|
| 807 |
+
----------------------
|
| 808 |
+
Binary compatible - Yes
|
| 809 |
+
|
| 810 |
+
Source compatible - Yes
|
| 811 |
+
|
| 812 |
+
Semantic compatible - Yes
|
| 813 |
+
|
| 814 |
+
Deprecations from 1.1
|
| 815 |
+
---------------------
|
| 816 |
+
|
| 817 |
+
Bug fixes from 1.1
|
| 818 |
+
------------------
|
| 819 |
+
- FileSystemUtils.freeSpace(drive)
|
| 820 |
+
Fix to allow Windows based command to function in French locale
|
| 821 |
+
|
| 822 |
+
- FileUtils.read*
|
| 823 |
+
Increase certainty that files are closed in case of error
|
| 824 |
+
|
| 825 |
+
- LockableFileWriter
|
| 826 |
+
Locking mechanism was broken and only provided limited protection [38942]
|
| 827 |
+
File deletion and locking in case of constructor error was broken
|
| 828 |
+
|
| 829 |
+
Enhancements from 1.1
|
| 830 |
+
---------------------
|
| 831 |
+
- AgeFileFilter/SizeFileFilter
|
| 832 |
+
New file filters that compares against the age and size of the file
|
| 833 |
+
|
| 834 |
+
- FileSystemUtils.freeSpaceKb(drive)
|
| 835 |
+
New method that unifies result to be in kilobytes [38574]
|
| 836 |
+
|
| 837 |
+
- FileUtils.contentEquals(File,File)
|
| 838 |
+
Performance improved by adding length and file location checking
|
| 839 |
+
|
| 840 |
+
- FileUtils.iterateFiles
|
| 841 |
+
Two new method to provide direct access to iterators over files
|
| 842 |
+
|
| 843 |
+
- FileUtils.lineIterator
|
| 844 |
+
IOUtils.lineIterator
|
| 845 |
+
New methods to provide an iterator over the lines in a file [38083]
|
| 846 |
+
|
| 847 |
+
- FileUtils.copyDirectoryToDirectory
|
| 848 |
+
New method to copy a directory to within another directory [36315]
|
| 849 |
+
|
| 850 |
+
==============================================================================
|
| 851 |
+
Apache Commons IO Version 1.1
|
| 852 |
+
==============================================================================
|
| 853 |
+
|
| 854 |
+
Incompatible changes from 1.0
|
| 855 |
+
-----------------------------
|
| 856 |
+
Binary compatible - Yes
|
| 857 |
+
|
| 858 |
+
Source compatible - Yes
|
| 859 |
+
|
| 860 |
+
Semantic compatible - Yes, except:
|
| 861 |
+
- FileUtils.writeStringToFile()
|
| 862 |
+
A null encoding previously used 'ISO-8859-1', now it uses the platform default
|
| 863 |
+
Generally this will make no difference
|
| 864 |
+
|
| 865 |
+
- LockableFileWriter
|
| 866 |
+
Improved validation and now create directories if necesssary
|
| 867 |
+
|
| 868 |
+
plus these bug fixes may affect you semantically:
|
| 869 |
+
- FileUtils.touch() (Bug fix 29821)
|
| 870 |
+
Now creates the file if it did not previously exist
|
| 871 |
+
|
| 872 |
+
- FileUtils.toFile(URL) (Bug fix 32575)
|
| 873 |
+
Now handles escape syntax such as %20
|
| 874 |
+
|
| 875 |
+
- FileUtils.sizeOfDirectory() (Bug fix 36801)
|
| 876 |
+
May now return a size of 0 if the directory is security restricted
|
| 877 |
+
|
| 878 |
+
Deprecations from 1.0
|
| 879 |
+
---------------------
|
| 880 |
+
- CopyUtils has been deprecated.
|
| 881 |
+
Its methods have been moved to IOUtils.
|
| 882 |
+
The new IOUtils methods handle nulls better, and have clearer names.
|
| 883 |
+
|
| 884 |
+
- IOUtils.toByteArray(String) - Use {@link String#getBytes()}
|
| 885 |
+
- IOUtils.toString(byte[]) - Use {@link String#String(byte[])}
|
| 886 |
+
- IOUtils.toString(byte[],String) - Use {@link String#String(byte[],String)}
|
| 887 |
+
|
| 888 |
+
Bug fixes from 1.0
|
| 889 |
+
------------------
|
| 890 |
+
- FileUtils - touch() [29821]
|
| 891 |
+
Now creates the file if it did not previously exist
|
| 892 |
+
|
| 893 |
+
- FileUtils - toFile(URL) [32575]
|
| 894 |
+
Now handles escape syntax such as %20
|
| 895 |
+
|
| 896 |
+
- FileFilterUtils - makeCVSAware(IOFileFilter) [33023]
|
| 897 |
+
Fixed bug that caused method to be completely broken
|
| 898 |
+
|
| 899 |
+
- CountingInputStream [33336]
|
| 900 |
+
Fixed bug that caused the count to reduce by one at the end of the stream
|
| 901 |
+
|
| 902 |
+
- CountingInputStream - skip(long) [34311]
|
| 903 |
+
Bytes from calls to this method were not previously counted
|
| 904 |
+
|
| 905 |
+
- NullOutputStream [33481]
|
| 906 |
+
Remove unnecessary synchronization
|
| 907 |
+
|
| 908 |
+
- AbstractFileFilter - accept(File, String) [30992]
|
| 909 |
+
Fixed broken implementation
|
| 910 |
+
|
| 911 |
+
- FileUtils [36801]
|
| 912 |
+
Previously threw NPE when listing files in a security restricted directory
|
| 913 |
+
Now throw IOException with a better message
|
| 914 |
+
|
| 915 |
+
- FileUtils - writeStringToFile()
|
| 916 |
+
Null encoding now correctly uses the platform default
|
| 917 |
+
|
| 918 |
+
Enhancements from 1.0
|
| 919 |
+
---------------------
|
| 920 |
+
- FilenameUtils - new class [33303,29351]
|
| 921 |
+
A static utility class for working with filenames
|
| 922 |
+
Seeks to ease the pain of developing on Windows and deploying on Unix
|
| 923 |
+
|
| 924 |
+
- FileSystemUtils - new class [32982,36325]
|
| 925 |
+
A static utility class for working with file systems
|
| 926 |
+
Provides one method at present, to get the free space on the filing system
|
| 927 |
+
|
| 928 |
+
- IOUtils - new public constants
|
| 929 |
+
Constants for directory and line separators on Windows and Unix
|
| 930 |
+
|
| 931 |
+
- IOUtils - toByteArray(Reader,encoding)
|
| 932 |
+
Handles encodings when reading to a byte array
|
| 933 |
+
|
| 934 |
+
- IOUtils - toCharArray(InputStream) [28979]
|
| 935 |
+
- toCharArray(InputStream,encoding)
|
| 936 |
+
- toCharArray(Reader)
|
| 937 |
+
Reads a stream/reader into a charatcter array
|
| 938 |
+
|
| 939 |
+
- IOUtils - readLines(InputStream) [36214]
|
| 940 |
+
- readLines(InputStream,encoding)
|
| 941 |
+
- readLines(Reader)
|
| 942 |
+
Reads a stream/reader line by line into a List of Strings
|
| 943 |
+
|
| 944 |
+
- IOUtils - toInputStream(String) [32958]
|
| 945 |
+
- toInputStream(String,encoding)
|
| 946 |
+
Creates an input stream that uses the string as a source of data
|
| 947 |
+
|
| 948 |
+
- IOUtils - writeLines(Collection,lineEnding,OutputStream) [36214]
|
| 949 |
+
- writeLines(Collection,lineEnding,OutputStream,encoding)
|
| 950 |
+
- writeLines(Collection,lineEnding,Writer)
|
| 951 |
+
Writes a collection to a stream/writer line by line
|
| 952 |
+
|
| 953 |
+
- IOUtils - write(...)
|
| 954 |
+
Write data to a stream/writer (moved from CopyUtils with better null handling)
|
| 955 |
+
|
| 956 |
+
- IOUtils - copy(...)
|
| 957 |
+
Copy data between streams (moved from CopyUtils with better null handling)
|
| 958 |
+
|
| 959 |
+
- IOUtils - contentEquals(Reader,Reader)
|
| 960 |
+
Method to compare the contents of two readers
|
| 961 |
+
|
| 962 |
+
- FileUtils - toFiles(URL[])
|
| 963 |
+
Converts an array of URLs to an array of Files
|
| 964 |
+
|
| 965 |
+
- FileUtils - copyDirectory() [32944]
|
| 966 |
+
New methods to copy a directory
|
| 967 |
+
|
| 968 |
+
- FileUtils - readFileToByteArray(File)
|
| 969 |
+
Reads an entire file into a byte array
|
| 970 |
+
|
| 971 |
+
- FileUtils - writeByteArrayToFile(File,byte[])
|
| 972 |
+
Writes a byte array to a file
|
| 973 |
+
|
| 974 |
+
- FileUtils - readLines(File,encoding) [36214]
|
| 975 |
+
Reads a file line by line into a List of Strings
|
| 976 |
+
|
| 977 |
+
- FileUtils - writeLines(File,encoding,List)
|
| 978 |
+
writeLines(File,encoding,List,lineEnding)
|
| 979 |
+
Writes a collection to a file line by line
|
| 980 |
+
|
| 981 |
+
- FileUtils - EMPTY_FILE_ARRAY
|
| 982 |
+
Constant for an empty array of File objects
|
| 983 |
+
|
| 984 |
+
- ConditionalFileFilter - new interface [30705]
|
| 985 |
+
Defines the behaviour of list based filters
|
| 986 |
+
|
| 987 |
+
- AndFileFilter, OrFileFilter [30705]
|
| 988 |
+
Now support a list of filters to and/or
|
| 989 |
+
|
| 990 |
+
- WildcardFilter [31115]
|
| 991 |
+
New filter that can match using wildcard file names
|
| 992 |
+
|
| 993 |
+
- FileFilterUtils - makeSVNAware(IOFileFilter)
|
| 994 |
+
New method, like makeCVSAware, that ignores Subversion source control directories
|
| 995 |
+
|
| 996 |
+
- ClassLoaderObjectInputStream
|
| 997 |
+
An ObjectInputStream that supports a ClassLoader
|
| 998 |
+
|
| 999 |
+
- CountingInputStream,CountingOutputStream - resetCount() [28976]
|
| 1000 |
+
Adds the ability to reset the count part way through reading/writing the stream
|
| 1001 |
+
|
| 1002 |
+
- DeferredFileOutputStream - writeTo(OutputStream) [34173]
|
| 1003 |
+
New method to allow current contents to be written to a stream
|
| 1004 |
+
|
| 1005 |
+
- DeferredFileOutputStream [34142]
|
| 1006 |
+
Performance optimizations avoiding double buffering
|
| 1007 |
+
|
| 1008 |
+
- LockableFileWriter - encoding support [36825]
|
| 1009 |
+
Add support for character encodings to LockableFileWriter
|
| 1010 |
+
Improve the validation
|
| 1011 |
+
Create directories if necesssary
|
| 1012 |
+
|
| 1013 |
+
- IOUtils and EndianUtils are no longer final [28978]
|
| 1014 |
+
Allows developers to have subclasses if desired
|
| 1015 |
+
|
| 1016 |
+
==============================================================================
|
| 1017 |
+
Feedback
|
| 1018 |
+
==============================================================================
|
| 1019 |
+
|
| 1020 |
+
Open source works best when you give feedback:
|
| 1021 |
+
http://commons.apache.org/io/
|
| 1022 |
+
|
| 1023 |
+
Please direct all bug reports to JIRA
|
| 1024 |
+
http://issues.apache.org/jira/browse/IO
|
| 1025 |
+
|
| 1026 |
+
Or subscribe to the commons-user mailing list (prefix emails by [io])
|
| 1027 |
+
http://commons.apache.org/mail-lists.html
|
| 1028 |
+
|
| 1029 |
+
The Commons-IO Team
|
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/01_课件与电子教材/尚硅谷_第15章_File类与IO流/03-apache-common包/commons-io-2.5-src/src/main/java/org/apache/commons/io/ByteOrderMark.java
ADDED
|
@@ -0,0 +1,191 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Licensed to the Apache Software Foundation (ASF) under one or more
|
| 3 |
+
* contributor license agreements. See the NOTICE file distributed with
|
| 4 |
+
* this work for additional information regarding copyright ownership.
|
| 5 |
+
* The ASF licenses this file to You under the Apache License, Version 2.0
|
| 6 |
+
* (the "License"); you may not use this file except in compliance with
|
| 7 |
+
* the License. You may obtain a copy of the License at
|
| 8 |
+
*
|
| 9 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
*
|
| 11 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 12 |
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
| 13 |
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 14 |
+
* See the License for the specific language governing permissions and
|
| 15 |
+
* limitations under the License.
|
| 16 |
+
*/
|
| 17 |
+
package org.apache.commons.io;
|
| 18 |
+
|
| 19 |
+
import java.io.Serializable;
|
| 20 |
+
|
| 21 |
+
/**
|
| 22 |
+
* Byte Order Mark (BOM) representation - see {@link org.apache.commons.io.input.BOMInputStream}.
|
| 23 |
+
*
|
| 24 |
+
* @see org.apache.commons.io.input.BOMInputStream
|
| 25 |
+
* @see <a href="http://en.wikipedia.org/wiki/Byte_order_mark">Wikipedia: Byte Order Mark</a>
|
| 26 |
+
* @see <a href="http://www.w3.org/TR/2006/REC-xml-20060816/#sec-guessing">W3C: Autodetection of Character Encodings
|
| 27 |
+
* (Non-Normative)</a>
|
| 28 |
+
* @version $Id: ByteOrderMark.java 1586504 2014-04-10 23:34:37Z ggregory $
|
| 29 |
+
* @since 2.0
|
| 30 |
+
*/
|
| 31 |
+
public class ByteOrderMark implements Serializable {
|
| 32 |
+
|
| 33 |
+
private static final long serialVersionUID = 1L;
|
| 34 |
+
|
| 35 |
+
/** UTF-8 BOM */
|
| 36 |
+
public static final ByteOrderMark UTF_8 = new ByteOrderMark("UTF-8", 0xEF, 0xBB, 0xBF);
|
| 37 |
+
|
| 38 |
+
/** UTF-16BE BOM (Big-Endian) */
|
| 39 |
+
public static final ByteOrderMark UTF_16BE = new ByteOrderMark("UTF-16BE", 0xFE, 0xFF);
|
| 40 |
+
|
| 41 |
+
/** UTF-16LE BOM (Little-Endian) */
|
| 42 |
+
public static final ByteOrderMark UTF_16LE = new ByteOrderMark("UTF-16LE", 0xFF, 0xFE);
|
| 43 |
+
|
| 44 |
+
/**
|
| 45 |
+
* UTF-32BE BOM (Big-Endian)
|
| 46 |
+
* @since 2.2
|
| 47 |
+
*/
|
| 48 |
+
public static final ByteOrderMark UTF_32BE = new ByteOrderMark("UTF-32BE", 0x00, 0x00, 0xFE, 0xFF);
|
| 49 |
+
|
| 50 |
+
/**
|
| 51 |
+
* UTF-32LE BOM (Little-Endian)
|
| 52 |
+
* @since 2.2
|
| 53 |
+
*/
|
| 54 |
+
public static final ByteOrderMark UTF_32LE = new ByteOrderMark("UTF-32LE", 0xFF, 0xFE, 0x00, 0x00);
|
| 55 |
+
|
| 56 |
+
/**
|
| 57 |
+
* Unicode BOM character; external form depends on the encoding.
|
| 58 |
+
* @see <a href="http://unicode.org/faq/utf_bom.html#BOM">Byte Order Mark (BOM) FAQ</a>
|
| 59 |
+
* @since 2.5
|
| 60 |
+
*/
|
| 61 |
+
public static final char UTF_BOM = '\uFEFF';
|
| 62 |
+
|
| 63 |
+
private final String charsetName;
|
| 64 |
+
private final int[] bytes;
|
| 65 |
+
|
| 66 |
+
/**
|
| 67 |
+
* Construct a new BOM.
|
| 68 |
+
*
|
| 69 |
+
* @param charsetName The name of the charset the BOM represents
|
| 70 |
+
* @param bytes The BOM's bytes
|
| 71 |
+
* @throws IllegalArgumentException if the charsetName is null or
|
| 72 |
+
* zero length
|
| 73 |
+
* @throws IllegalArgumentException if the bytes are null or zero
|
| 74 |
+
* length
|
| 75 |
+
*/
|
| 76 |
+
public ByteOrderMark(final String charsetName, final int... bytes) {
|
| 77 |
+
if (charsetName == null || charsetName.isEmpty()) {
|
| 78 |
+
throw new IllegalArgumentException("No charsetName specified");
|
| 79 |
+
}
|
| 80 |
+
if (bytes == null || bytes.length == 0) {
|
| 81 |
+
throw new IllegalArgumentException("No bytes specified");
|
| 82 |
+
}
|
| 83 |
+
this.charsetName = charsetName;
|
| 84 |
+
this.bytes = new int[bytes.length];
|
| 85 |
+
System.arraycopy(bytes, 0, this.bytes, 0, bytes.length);
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
/**
|
| 89 |
+
* Return the name of the {@link java.nio.charset.Charset} the BOM represents.
|
| 90 |
+
*
|
| 91 |
+
* @return the character set name
|
| 92 |
+
*/
|
| 93 |
+
public String getCharsetName() {
|
| 94 |
+
return charsetName;
|
| 95 |
+
}
|
| 96 |
+
|
| 97 |
+
/**
|
| 98 |
+
* Return the length of the BOM's bytes.
|
| 99 |
+
*
|
| 100 |
+
* @return the length of the BOM's bytes
|
| 101 |
+
*/
|
| 102 |
+
public int length() {
|
| 103 |
+
return bytes.length;
|
| 104 |
+
}
|
| 105 |
+
|
| 106 |
+
/**
|
| 107 |
+
* The byte at the specified position.
|
| 108 |
+
*
|
| 109 |
+
* @param pos The position
|
| 110 |
+
* @return The specified byte
|
| 111 |
+
*/
|
| 112 |
+
public int get(final int pos) {
|
| 113 |
+
return bytes[pos];
|
| 114 |
+
}
|
| 115 |
+
|
| 116 |
+
/**
|
| 117 |
+
* Return a copy of the BOM's bytes.
|
| 118 |
+
*
|
| 119 |
+
* @return a copy of the BOM's bytes
|
| 120 |
+
*/
|
| 121 |
+
public byte[] getBytes() {
|
| 122 |
+
final byte[] copy = new byte[bytes.length];
|
| 123 |
+
for (int i = 0; i < bytes.length; i++) {
|
| 124 |
+
copy[i] = (byte)bytes[i];
|
| 125 |
+
}
|
| 126 |
+
return copy;
|
| 127 |
+
}
|
| 128 |
+
|
| 129 |
+
/**
|
| 130 |
+
* Indicates if this BOM's bytes equals another.
|
| 131 |
+
*
|
| 132 |
+
* @param obj The object to compare to
|
| 133 |
+
* @return true if the bom's bytes are equal, otherwise
|
| 134 |
+
* false
|
| 135 |
+
*/
|
| 136 |
+
@Override
|
| 137 |
+
public boolean equals(final Object obj) {
|
| 138 |
+
if (!(obj instanceof ByteOrderMark)) {
|
| 139 |
+
return false;
|
| 140 |
+
}
|
| 141 |
+
final ByteOrderMark bom = (ByteOrderMark)obj;
|
| 142 |
+
if (bytes.length != bom.length()) {
|
| 143 |
+
return false;
|
| 144 |
+
}
|
| 145 |
+
for (int i = 0; i < bytes.length; i++) {
|
| 146 |
+
if (bytes[i] != bom.get(i)) {
|
| 147 |
+
return false;
|
| 148 |
+
}
|
| 149 |
+
}
|
| 150 |
+
return true;
|
| 151 |
+
}
|
| 152 |
+
|
| 153 |
+
/**
|
| 154 |
+
* Return the hashcode for this BOM.
|
| 155 |
+
*
|
| 156 |
+
* @return the hashcode for this BOM.
|
| 157 |
+
* @see java.lang.Object#hashCode()
|
| 158 |
+
*/
|
| 159 |
+
@Override
|
| 160 |
+
public int hashCode() {
|
| 161 |
+
int hashCode = getClass().hashCode();
|
| 162 |
+
for (final int b : bytes) {
|
| 163 |
+
hashCode += b;
|
| 164 |
+
}
|
| 165 |
+
return hashCode;
|
| 166 |
+
}
|
| 167 |
+
|
| 168 |
+
/**
|
| 169 |
+
* Provide a String representation of the BOM.
|
| 170 |
+
*
|
| 171 |
+
* @return the length of the BOM's bytes
|
| 172 |
+
*/
|
| 173 |
+
@Override
|
| 174 |
+
public String toString() {
|
| 175 |
+
final StringBuilder builder = new StringBuilder();
|
| 176 |
+
builder.append(getClass().getSimpleName());
|
| 177 |
+
builder.append('[');
|
| 178 |
+
builder.append(charsetName);
|
| 179 |
+
builder.append(": ");
|
| 180 |
+
for (int i = 0; i < bytes.length; i++) {
|
| 181 |
+
if (i > 0) {
|
| 182 |
+
builder.append(",");
|
| 183 |
+
}
|
| 184 |
+
builder.append("0x");
|
| 185 |
+
builder.append(Integer.toHexString(0xFF & bytes[i]).toUpperCase());
|
| 186 |
+
}
|
| 187 |
+
builder.append(']');
|
| 188 |
+
return builder.toString();
|
| 189 |
+
}
|
| 190 |
+
|
| 191 |
+
}
|
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/01_课件与电子教材/尚硅谷_第15章_File类与IO流/03-apache-common包/commons-io-2.5-src/src/main/java/org/apache/commons/io/Charsets.java
ADDED
|
@@ -0,0 +1,192 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Licensed to the Apache Software Foundation (ASF) under one or more
|
| 3 |
+
* contributor license agreements. See the NOTICE file distributed with
|
| 4 |
+
* this work for additional information regarding copyright ownership.
|
| 5 |
+
* The ASF licenses this file to You under the Apache License, Version 2.0
|
| 6 |
+
* (the "License"); you may not use this file except in compliance with
|
| 7 |
+
* the License. You may obtain a copy of the License at
|
| 8 |
+
*
|
| 9 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
*
|
| 11 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 12 |
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
| 13 |
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 14 |
+
* See the License for the specific language governing permissions and
|
| 15 |
+
* limitations under the License.
|
| 16 |
+
*/
|
| 17 |
+
package org.apache.commons.io;
|
| 18 |
+
|
| 19 |
+
import java.nio.charset.Charset;
|
| 20 |
+
import java.util.Collections;
|
| 21 |
+
import java.util.SortedMap;
|
| 22 |
+
import java.util.TreeMap;
|
| 23 |
+
|
| 24 |
+
/**
|
| 25 |
+
* Charsets required of every implementation of the Java platform.
|
| 26 |
+
*
|
| 27 |
+
* From the Java documentation <a href="http://docs.oracle.com/javase/6/docs/api/java/nio/charset/Charset.html">
|
| 28 |
+
* Standard charsets</a>:
|
| 29 |
+
* <p>
|
| 30 |
+
* <cite>Every implementation of the Java platform is required to support the following character encodings. Consult
|
| 31 |
+
* the release documentation for your implementation to see if any other encodings are supported. Consult the release
|
| 32 |
+
* documentation for your implementation to see if any other encodings are supported. </cite>
|
| 33 |
+
* </p>
|
| 34 |
+
*
|
| 35 |
+
* <ul>
|
| 36 |
+
* <li><code>US-ASCII</code><br>
|
| 37 |
+
* Seven-bit ASCII, a.k.a. ISO646-US, a.k.a. the Basic Latin block of the Unicode character set.</li>
|
| 38 |
+
* <li><code>ISO-8859-1</code><br>
|
| 39 |
+
* ISO Latin Alphabet No. 1, a.k.a. ISO-LATIN-1.</li>
|
| 40 |
+
* <li><code>UTF-8</code><br>
|
| 41 |
+
* Eight-bit Unicode Transformation Format.</li>
|
| 42 |
+
* <li><code>UTF-16BE</code><br>
|
| 43 |
+
* Sixteen-bit Unicode Transformation Format, big-endian byte order.</li>
|
| 44 |
+
* <li><code>UTF-16LE</code><br>
|
| 45 |
+
* Sixteen-bit Unicode Transformation Format, little-endian byte order.</li>
|
| 46 |
+
* <li><code>UTF-16</code><br>
|
| 47 |
+
* Sixteen-bit Unicode Transformation Format, byte order specified by a mandatory initial byte-order mark (either order
|
| 48 |
+
* accepted on input, big-endian used on output.)</li>
|
| 49 |
+
* </ul>
|
| 50 |
+
*
|
| 51 |
+
* @see <a href="http://docs.oracle.com/javase/6/docs/api/java/nio/charset/Charset.html">Standard charsets</a>
|
| 52 |
+
* @since 2.3
|
| 53 |
+
* @version $Id: Charsets.java 1686747 2015-06-21 18:44:49Z krosenvold $
|
| 54 |
+
*/
|
| 55 |
+
public class Charsets {
|
| 56 |
+
//
|
| 57 |
+
// This class should only contain Charset instances for required encodings. This guarantees that it will load
|
| 58 |
+
// correctly and without delay on all Java platforms.
|
| 59 |
+
//
|
| 60 |
+
|
| 61 |
+
/**
|
| 62 |
+
* Constructs a sorted map from canonical charset names to charset objects required of every implementation of the
|
| 63 |
+
* Java platform.
|
| 64 |
+
* <p>
|
| 65 |
+
* From the Java documentation <a href="http://docs.oracle.com/javase/6/docs/api/java/nio/charset/Charset.html">
|
| 66 |
+
* Standard charsets</a>:
|
| 67 |
+
* </p>
|
| 68 |
+
*
|
| 69 |
+
* @return An immutable, case-insensitive map from canonical charset names to charset objects.
|
| 70 |
+
* @see Charset#availableCharsets()
|
| 71 |
+
* @since 2.5
|
| 72 |
+
*/
|
| 73 |
+
public static SortedMap<String, Charset> requiredCharsets() {
|
| 74 |
+
// maybe cache?
|
| 75 |
+
// TODO Re-implement on Java 7 to use java.nio.charset.StandardCharsets
|
| 76 |
+
final TreeMap<String, Charset> m = new TreeMap<String, Charset>(String.CASE_INSENSITIVE_ORDER);
|
| 77 |
+
m.put(ISO_8859_1.name(), ISO_8859_1);
|
| 78 |
+
m.put(US_ASCII.name(), US_ASCII);
|
| 79 |
+
m.put(UTF_16.name(), UTF_16);
|
| 80 |
+
m.put(UTF_16BE.name(), UTF_16BE);
|
| 81 |
+
m.put(UTF_16LE.name(), UTF_16LE);
|
| 82 |
+
m.put(UTF_8.name(), UTF_8);
|
| 83 |
+
return Collections.unmodifiableSortedMap(m);
|
| 84 |
+
}
|
| 85 |
+
|
| 86 |
+
/**
|
| 87 |
+
* Returns the given Charset or the default Charset if the given Charset is null.
|
| 88 |
+
*
|
| 89 |
+
* @param charset
|
| 90 |
+
* A charset or null.
|
| 91 |
+
* @return the given Charset or the default Charset if the given Charset is null
|
| 92 |
+
*/
|
| 93 |
+
public static Charset toCharset(final Charset charset) {
|
| 94 |
+
return charset == null ? Charset.defaultCharset() : charset;
|
| 95 |
+
}
|
| 96 |
+
|
| 97 |
+
/**
|
| 98 |
+
* Returns a Charset for the named charset. If the name is null, return the default Charset.
|
| 99 |
+
*
|
| 100 |
+
* @param charset
|
| 101 |
+
* The name of the requested charset, may be null.
|
| 102 |
+
* @return a Charset for the named charset
|
| 103 |
+
* @throws java.nio.charset.UnsupportedCharsetException
|
| 104 |
+
* If the named charset is unavailable
|
| 105 |
+
*/
|
| 106 |
+
public static Charset toCharset(final String charset) {
|
| 107 |
+
return charset == null ? Charset.defaultCharset() : Charset.forName(charset);
|
| 108 |
+
}
|
| 109 |
+
|
| 110 |
+
/**
|
| 111 |
+
* CharEncodingISO Latin Alphabet No. 1, a.k.a. ISO-LATIN-1.
|
| 112 |
+
* <p>
|
| 113 |
+
* Every implementation of the Java platform is required to support this character encoding.
|
| 114 |
+
* </p>
|
| 115 |
+
*
|
| 116 |
+
* @see <a href="http://docs.oracle.com/javase/6/docs/api/java/nio/charset/Charset.html">Standard charsets</a>
|
| 117 |
+
* @deprecated Use Java 7's {@link java.nio.charset.StandardCharsets}
|
| 118 |
+
*/
|
| 119 |
+
@Deprecated
|
| 120 |
+
public static final Charset ISO_8859_1 = Charset.forName("ISO-8859-1");
|
| 121 |
+
|
| 122 |
+
/**
|
| 123 |
+
* <p>
|
| 124 |
+
* Seven-bit ASCII, also known as ISO646-US, also known as the Basic Latin block of the Unicode character set.
|
| 125 |
+
* </p>
|
| 126 |
+
* <p>
|
| 127 |
+
* Every implementation of the Java platform is required to support this character encoding.
|
| 128 |
+
* </p>
|
| 129 |
+
*
|
| 130 |
+
* @see <a href="http://docs.oracle.com/javase/6/docs/api/java/nio/charset/Charset.html">Standard charsets</a>
|
| 131 |
+
* @deprecated Use Java 7's {@link java.nio.charset.StandardCharsets}
|
| 132 |
+
*/
|
| 133 |
+
@Deprecated
|
| 134 |
+
public static final Charset US_ASCII = Charset.forName("US-ASCII");
|
| 135 |
+
|
| 136 |
+
/**
|
| 137 |
+
* <p>
|
| 138 |
+
* Sixteen-bit Unicode Transformation Format, The byte order specified by a mandatory initial byte-order mark
|
| 139 |
+
* (either order accepted on input, big-endian used on output)
|
| 140 |
+
* </p>
|
| 141 |
+
* <p>
|
| 142 |
+
* Every implementation of the Java platform is required to support this character encoding.
|
| 143 |
+
* </p>
|
| 144 |
+
*
|
| 145 |
+
* @see <a href="http://docs.oracle.com/javase/6/docs/api/java/nio/charset/Charset.html">Standard charsets</a>
|
| 146 |
+
* @deprecated Use Java 7's {@link java.nio.charset.StandardCharsets}
|
| 147 |
+
*/
|
| 148 |
+
@Deprecated
|
| 149 |
+
public static final Charset UTF_16 = Charset.forName("UTF-16");
|
| 150 |
+
|
| 151 |
+
/**
|
| 152 |
+
* <p>
|
| 153 |
+
* Sixteen-bit Unicode Transformation Format, big-endian byte order.
|
| 154 |
+
* </p>
|
| 155 |
+
* <p>
|
| 156 |
+
* Every implementation of the Java platform is required to support this character encoding.
|
| 157 |
+
* </p>
|
| 158 |
+
*
|
| 159 |
+
* @see <a href="http://docs.oracle.com/javase/6/docs/api/java/nio/charset/Charset.html">Standard charsets</a>
|
| 160 |
+
* @deprecated Use Java 7's {@link java.nio.charset.StandardCharsets}
|
| 161 |
+
*/
|
| 162 |
+
@Deprecated
|
| 163 |
+
public static final Charset UTF_16BE = Charset.forName("UTF-16BE");
|
| 164 |
+
|
| 165 |
+
/**
|
| 166 |
+
* <p>
|
| 167 |
+
* Sixteen-bit Unicode Transformation Format, little-endian byte order.
|
| 168 |
+
* </p>
|
| 169 |
+
* <p>
|
| 170 |
+
* Every implementation of the Java platform is required to support this character encoding.
|
| 171 |
+
* </p>
|
| 172 |
+
*
|
| 173 |
+
* @see <a href="http://docs.oracle.com/javase/6/docs/api/java/nio/charset/Charset.html">Standard charsets</a>
|
| 174 |
+
* @deprecated Use Java 7's {@link java.nio.charset.StandardCharsets}
|
| 175 |
+
*/
|
| 176 |
+
@Deprecated
|
| 177 |
+
public static final Charset UTF_16LE = Charset.forName("UTF-16LE");
|
| 178 |
+
|
| 179 |
+
/**
|
| 180 |
+
* <p>
|
| 181 |
+
* Eight-bit Unicode Transformation Format.
|
| 182 |
+
* </p>
|
| 183 |
+
* <p>
|
| 184 |
+
* Every implementation of the Java platform is required to support this character encoding.
|
| 185 |
+
* </p>
|
| 186 |
+
*
|
| 187 |
+
* @see <a href="http://docs.oracle.com/javase/6/docs/api/java/nio/charset/Charset.html">Standard charsets</a>
|
| 188 |
+
* @deprecated Use Java 7's {@link java.nio.charset.StandardCharsets}
|
| 189 |
+
*/
|
| 190 |
+
@Deprecated
|
| 191 |
+
public static final Charset UTF_8 = Charset.forName("UTF-8");
|
| 192 |
+
}
|
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/01_课件与电子教材/尚硅谷_第15章_File类与IO流/03-apache-common包/commons-io-2.5-src/src/main/java/org/apache/commons/io/CopyUtils.java
ADDED
|
@@ -0,0 +1,392 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Licensed to the Apache Software Foundation (ASF) under one or more
|
| 3 |
+
* contributor license agreements. See the NOTICE file distributed with
|
| 4 |
+
* this work for additional information regarding copyright ownership.
|
| 5 |
+
* The ASF licenses this file to You under the Apache License, Version 2.0
|
| 6 |
+
* (the "License"); you may not use this file except in compliance with
|
| 7 |
+
* the License. You may obtain a copy of the License at
|
| 8 |
+
*
|
| 9 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
*
|
| 11 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 12 |
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
| 13 |
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 14 |
+
* See the License for the specific language governing permissions and
|
| 15 |
+
* limitations under the License.
|
| 16 |
+
*/
|
| 17 |
+
package org.apache.commons.io;
|
| 18 |
+
|
| 19 |
+
import java.io.ByteArrayInputStream;
|
| 20 |
+
import java.io.IOException;
|
| 21 |
+
import java.io.InputStream;
|
| 22 |
+
import java.io.InputStreamReader;
|
| 23 |
+
import java.io.OutputStream;
|
| 24 |
+
import java.io.OutputStreamWriter;
|
| 25 |
+
import java.io.Reader;
|
| 26 |
+
import java.io.StringReader;
|
| 27 |
+
import java.io.Writer;
|
| 28 |
+
import java.nio.charset.Charset;
|
| 29 |
+
|
| 30 |
+
/**
|
| 31 |
+
* This class provides static utility methods for buffered
|
| 32 |
+
* copying between sources (<code>InputStream</code>, <code>Reader</code>,
|
| 33 |
+
* <code>String</code> and <code>byte[]</code>) and destinations
|
| 34 |
+
* (<code>OutputStream</code>, <code>Writer</code>, <code>String</code> and
|
| 35 |
+
* <code>byte[]</code>).
|
| 36 |
+
* <p>
|
| 37 |
+
* Unless otherwise noted, these <code>copy</code> methods do <em>not</em>
|
| 38 |
+
* flush or close the streams. Often doing so would require making non-portable
|
| 39 |
+
* assumptions about the streams' origin and further use. This means that both
|
| 40 |
+
* streams' <code>close()</code> methods must be called after copying. if one
|
| 41 |
+
* omits this step, then the stream resources (sockets, file descriptors) are
|
| 42 |
+
* released when the associated Stream is garbage-collected. It is not a good
|
| 43 |
+
* idea to rely on this mechanism. For a good overview of the distinction
|
| 44 |
+
* between "memory management" and "resource management", see
|
| 45 |
+
* <a href="http://www.unixreview.com/articles/1998/9804/9804ja/ja.htm">this
|
| 46 |
+
* UnixReview article</a>.
|
| 47 |
+
* <p>
|
| 48 |
+
* For byte-to-char methods, a <code>copy</code> variant allows the encoding
|
| 49 |
+
* to be selected (otherwise the platform default is used). We would like to
|
| 50 |
+
* encourage you to always specify the encoding because relying on the platform
|
| 51 |
+
* default can lead to unexpected results.
|
| 52 |
+
* <p>
|
| 53 |
+
* We don't provide special variants for the <code>copy</code> methods that
|
| 54 |
+
* let you specify the buffer size because in modern VMs the impact on speed
|
| 55 |
+
* seems to be minimal. We're using a default buffer size of 4 KB.
|
| 56 |
+
* <p>
|
| 57 |
+
* The <code>copy</code> methods use an internal buffer when copying. It is
|
| 58 |
+
* therefore advisable <em>not</em> to deliberately wrap the stream arguments
|
| 59 |
+
* to the <code>copy</code> methods in <code>Buffered*</code> streams. For
|
| 60 |
+
* example, don't do the following:
|
| 61 |
+
* <pre>
|
| 62 |
+
* copy( new BufferedInputStream( in ), new BufferedOutputStream( out ) );
|
| 63 |
+
* </pre>
|
| 64 |
+
* The rationale is as follows:
|
| 65 |
+
* <p>
|
| 66 |
+
* Imagine that an InputStream's read() is a very expensive operation, which
|
| 67 |
+
* would usually suggest wrapping in a BufferedInputStream. The
|
| 68 |
+
* BufferedInputStream works by issuing infrequent
|
| 69 |
+
* {@link java.io.InputStream#read(byte[] b, int off, int len)} requests on the
|
| 70 |
+
* underlying InputStream, to fill an internal buffer, from which further
|
| 71 |
+
* <code>read</code> requests can inexpensively get their data (until the buffer
|
| 72 |
+
* runs out).
|
| 73 |
+
* <p>
|
| 74 |
+
* However, the <code>copy</code> methods do the same thing, keeping an
|
| 75 |
+
* internal buffer, populated by
|
| 76 |
+
* {@link InputStream#read(byte[] b, int off, int len)} requests. Having two
|
| 77 |
+
* buffers (or three if the destination stream is also buffered) is pointless,
|
| 78 |
+
* and the unnecessary buffer management hurts performance slightly (about 3%,
|
| 79 |
+
* according to some simple experiments).
|
| 80 |
+
* <p>
|
| 81 |
+
* Behold, intrepid explorers; a map of this class:
|
| 82 |
+
* <pre>
|
| 83 |
+
* Method Input Output Dependency
|
| 84 |
+
* ------ ----- ------ -------
|
| 85 |
+
* 1 copy InputStream OutputStream (primitive)
|
| 86 |
+
* 2 copy Reader Writer (primitive)
|
| 87 |
+
*
|
| 88 |
+
* 3 copy InputStream Writer 2
|
| 89 |
+
*
|
| 90 |
+
* 4 copy Reader OutputStream 2
|
| 91 |
+
*
|
| 92 |
+
* 5 copy String OutputStream 2
|
| 93 |
+
* 6 copy String Writer (trivial)
|
| 94 |
+
*
|
| 95 |
+
* 7 copy byte[] Writer 3
|
| 96 |
+
* 8 copy byte[] OutputStream (trivial)
|
| 97 |
+
* </pre>
|
| 98 |
+
* <p>
|
| 99 |
+
* Note that only the first two methods shuffle bytes; the rest use these
|
| 100 |
+
* two, or (if possible) copy using native Java copy methods. As there are
|
| 101 |
+
* method variants to specify the encoding, each row may
|
| 102 |
+
* correspond to up to 2 methods.
|
| 103 |
+
* <p>
|
| 104 |
+
* Origin of code: Excalibur.
|
| 105 |
+
*
|
| 106 |
+
* @version $Id: CopyUtils.java 1680650 2015-05-20 18:36:40Z britter $
|
| 107 |
+
* @deprecated Use IOUtils. Will be removed in 2.0.
|
| 108 |
+
* Methods renamed to IOUtils.write() or IOUtils.copy().
|
| 109 |
+
* Null handling behaviour changed in IOUtils (null data does not
|
| 110 |
+
* throw NullPointerException).
|
| 111 |
+
*/
|
| 112 |
+
@Deprecated
|
| 113 |
+
public class CopyUtils {
|
| 114 |
+
|
| 115 |
+
/**
|
| 116 |
+
* The default size of the buffer.
|
| 117 |
+
*/
|
| 118 |
+
private static final int DEFAULT_BUFFER_SIZE = 1024 * 4;
|
| 119 |
+
|
| 120 |
+
/**
|
| 121 |
+
* Instances should NOT be constructed in standard programming.
|
| 122 |
+
*/
|
| 123 |
+
public CopyUtils() { }
|
| 124 |
+
|
| 125 |
+
// ----------------------------------------------------------------
|
| 126 |
+
// byte[] -> OutputStream
|
| 127 |
+
// ----------------------------------------------------------------
|
| 128 |
+
|
| 129 |
+
/**
|
| 130 |
+
* Copy bytes from a <code>byte[]</code> to an <code>OutputStream</code>.
|
| 131 |
+
* @param input the byte array to read from
|
| 132 |
+
* @param output the <code>OutputStream</code> to write to
|
| 133 |
+
* @throws IOException In case of an I/O problem
|
| 134 |
+
*/
|
| 135 |
+
public static void copy(final byte[] input, final OutputStream output)
|
| 136 |
+
throws IOException {
|
| 137 |
+
output.write(input);
|
| 138 |
+
}
|
| 139 |
+
|
| 140 |
+
// ----------------------------------------------------------------
|
| 141 |
+
// byte[] -> Writer
|
| 142 |
+
// ----------------------------------------------------------------
|
| 143 |
+
|
| 144 |
+
/**
|
| 145 |
+
* Copy and convert bytes from a <code>byte[]</code> to chars on a
|
| 146 |
+
* <code>Writer</code>.
|
| 147 |
+
* The platform's default encoding is used for the byte-to-char conversion.
|
| 148 |
+
* @param input the byte array to read from
|
| 149 |
+
* @param output the <code>Writer</code> to write to
|
| 150 |
+
* @throws IOException In case of an I/O problem
|
| 151 |
+
* @deprecated 2.5 use {@link #copy(byte[], Writer, String)} instead
|
| 152 |
+
*/
|
| 153 |
+
@Deprecated
|
| 154 |
+
public static void copy(final byte[] input, final Writer output)
|
| 155 |
+
throws IOException {
|
| 156 |
+
final ByteArrayInputStream in = new ByteArrayInputStream(input);
|
| 157 |
+
copy(in, output);
|
| 158 |
+
}
|
| 159 |
+
|
| 160 |
+
|
| 161 |
+
/**
|
| 162 |
+
* Copy and convert bytes from a <code>byte[]</code> to chars on a
|
| 163 |
+
* <code>Writer</code>, using the specified encoding.
|
| 164 |
+
* @param input the byte array to read from
|
| 165 |
+
* @param output the <code>Writer</code> to write to
|
| 166 |
+
* @param encoding The name of a supported character encoding. See the
|
| 167 |
+
* <a href="http://www.iana.org/assignments/character-sets">IANA
|
| 168 |
+
* Charset Registry</a> for a list of valid encoding types.
|
| 169 |
+
* @throws IOException In case of an I/O problem
|
| 170 |
+
*/
|
| 171 |
+
public static void copy(
|
| 172 |
+
final byte[] input,
|
| 173 |
+
final Writer output,
|
| 174 |
+
final String encoding)
|
| 175 |
+
throws IOException {
|
| 176 |
+
final ByteArrayInputStream in = new ByteArrayInputStream(input);
|
| 177 |
+
copy(in, output, encoding);
|
| 178 |
+
}
|
| 179 |
+
|
| 180 |
+
|
| 181 |
+
// ----------------------------------------------------------------
|
| 182 |
+
// Core copy methods
|
| 183 |
+
// ----------------------------------------------------------------
|
| 184 |
+
|
| 185 |
+
/**
|
| 186 |
+
* Copy bytes from an <code>InputStream</code> to an
|
| 187 |
+
* <code>OutputStream</code>.
|
| 188 |
+
* @param input the <code>InputStream</code> to read from
|
| 189 |
+
* @param output the <code>OutputStream</code> to write to
|
| 190 |
+
* @return the number of bytes copied
|
| 191 |
+
* @throws IOException In case of an I/O problem
|
| 192 |
+
*/
|
| 193 |
+
public static int copy(
|
| 194 |
+
final InputStream input,
|
| 195 |
+
final OutputStream output)
|
| 196 |
+
throws IOException {
|
| 197 |
+
final byte[] buffer = new byte[DEFAULT_BUFFER_SIZE];
|
| 198 |
+
int count = 0;
|
| 199 |
+
int n = 0;
|
| 200 |
+
while (-1 != (n = input.read(buffer))) {
|
| 201 |
+
output.write(buffer, 0, n);
|
| 202 |
+
count += n;
|
| 203 |
+
}
|
| 204 |
+
return count;
|
| 205 |
+
}
|
| 206 |
+
|
| 207 |
+
// ----------------------------------------------------------------
|
| 208 |
+
// Reader -> Writer
|
| 209 |
+
// ----------------------------------------------------------------
|
| 210 |
+
|
| 211 |
+
/**
|
| 212 |
+
* Copy chars from a <code>Reader</code> to a <code>Writer</code>.
|
| 213 |
+
* @param input the <code>Reader</code> to read from
|
| 214 |
+
* @param output the <code>Writer</code> to write to
|
| 215 |
+
* @return the number of characters copied
|
| 216 |
+
* @throws IOException In case of an I/O problem
|
| 217 |
+
*/
|
| 218 |
+
public static int copy(
|
| 219 |
+
final Reader input,
|
| 220 |
+
final Writer output)
|
| 221 |
+
throws IOException {
|
| 222 |
+
final char[] buffer = new char[DEFAULT_BUFFER_SIZE];
|
| 223 |
+
int count = 0;
|
| 224 |
+
int n = 0;
|
| 225 |
+
while (-1 != (n = input.read(buffer))) {
|
| 226 |
+
output.write(buffer, 0, n);
|
| 227 |
+
count += n;
|
| 228 |
+
}
|
| 229 |
+
return count;
|
| 230 |
+
}
|
| 231 |
+
|
| 232 |
+
// ----------------------------------------------------------------
|
| 233 |
+
// InputStream -> Writer
|
| 234 |
+
// ----------------------------------------------------------------
|
| 235 |
+
|
| 236 |
+
/**
|
| 237 |
+
* Copy and convert bytes from an <code>InputStream</code> to chars on a
|
| 238 |
+
* <code>Writer</code>.
|
| 239 |
+
* The platform's default encoding is used for the byte-to-char conversion.
|
| 240 |
+
* @param input the <code>InputStream</code> to read from
|
| 241 |
+
* @param output the <code>Writer</code> to write to
|
| 242 |
+
* @throws IOException In case of an I/O problem
|
| 243 |
+
* @deprecated 2.5 use {@link #copy(InputStream, Writer, String)} instead
|
| 244 |
+
*/
|
| 245 |
+
@Deprecated
|
| 246 |
+
public static void copy(
|
| 247 |
+
final InputStream input,
|
| 248 |
+
final Writer output)
|
| 249 |
+
throws IOException {
|
| 250 |
+
// make explicit the dependency on the default encoding
|
| 251 |
+
final InputStreamReader in = new InputStreamReader(input, Charset.defaultCharset());
|
| 252 |
+
copy(in, output);
|
| 253 |
+
}
|
| 254 |
+
|
| 255 |
+
/**
|
| 256 |
+
* Copy and convert bytes from an <code>InputStream</code> to chars on a
|
| 257 |
+
* <code>Writer</code>, using the specified encoding.
|
| 258 |
+
* @param input the <code>InputStream</code> to read from
|
| 259 |
+
* @param output the <code>Writer</code> to write to
|
| 260 |
+
* @param encoding The name of a supported character encoding. See the
|
| 261 |
+
* <a href="http://www.iana.org/assignments/character-sets">IANA
|
| 262 |
+
* Charset Registry</a> for a list of valid encoding types.
|
| 263 |
+
* @throws IOException In case of an I/O problem
|
| 264 |
+
*/
|
| 265 |
+
public static void copy(
|
| 266 |
+
final InputStream input,
|
| 267 |
+
final Writer output,
|
| 268 |
+
final String encoding)
|
| 269 |
+
throws IOException {
|
| 270 |
+
final InputStreamReader in = new InputStreamReader(input, encoding);
|
| 271 |
+
copy(in, output);
|
| 272 |
+
}
|
| 273 |
+
|
| 274 |
+
|
| 275 |
+
// ----------------------------------------------------------------
|
| 276 |
+
// Reader -> OutputStream
|
| 277 |
+
// ----------------------------------------------------------------
|
| 278 |
+
|
| 279 |
+
/**
|
| 280 |
+
* Serialize chars from a <code>Reader</code> to bytes on an
|
| 281 |
+
* <code>OutputStream</code>, and flush the <code>OutputStream</code>.
|
| 282 |
+
* Uses the default platform encoding.
|
| 283 |
+
* @param input the <code>Reader</code> to read from
|
| 284 |
+
* @param output the <code>OutputStream</code> to write to
|
| 285 |
+
* @throws IOException In case of an I/O problem
|
| 286 |
+
* @deprecated 2.5 use {@link #copy(Reader, OutputStream, String)} instead
|
| 287 |
+
*/
|
| 288 |
+
@Deprecated
|
| 289 |
+
public static void copy(
|
| 290 |
+
final Reader input,
|
| 291 |
+
final OutputStream output)
|
| 292 |
+
throws IOException {
|
| 293 |
+
// make explicit the dependency on the default encoding
|
| 294 |
+
final OutputStreamWriter out = new OutputStreamWriter(output, Charset.defaultCharset());
|
| 295 |
+
copy(input, out);
|
| 296 |
+
// XXX Unless anyone is planning on rewriting OutputStreamWriter, we
|
| 297 |
+
// have to flush here.
|
| 298 |
+
out.flush();
|
| 299 |
+
}
|
| 300 |
+
|
| 301 |
+
/**
|
| 302 |
+
* Serialize chars from a <code>Reader</code> to bytes on an
|
| 303 |
+
* <code>OutputStream</code>, and flush the <code>OutputStream</code>.
|
| 304 |
+
* @param input the <code>Reader</code> to read from
|
| 305 |
+
* @param output the <code>OutputStream</code> to write to
|
| 306 |
+
* @param encoding The name of a supported character encoding. See the
|
| 307 |
+
* <a href="http://www.iana.org/assignments/character-sets">IANA
|
| 308 |
+
* Charset Registry</a> for a list of valid encoding types.
|
| 309 |
+
* @throws IOException In case of an I/O problem
|
| 310 |
+
* @since 2.5
|
| 311 |
+
*/
|
| 312 |
+
public static void copy(
|
| 313 |
+
final Reader input,
|
| 314 |
+
final OutputStream output,
|
| 315 |
+
final String encoding)
|
| 316 |
+
throws IOException {
|
| 317 |
+
final OutputStreamWriter out = new OutputStreamWriter(output, encoding);
|
| 318 |
+
copy(input, out);
|
| 319 |
+
// XXX Unless anyone is planning on rewriting OutputStreamWriter, we
|
| 320 |
+
// have to flush here.
|
| 321 |
+
out.flush();
|
| 322 |
+
}
|
| 323 |
+
|
| 324 |
+
// ----------------------------------------------------------------
|
| 325 |
+
// String -> OutputStream
|
| 326 |
+
// ----------------------------------------------------------------
|
| 327 |
+
|
| 328 |
+
/**
|
| 329 |
+
* Serialize chars from a <code>String</code> to bytes on an
|
| 330 |
+
* <code>OutputStream</code>, and
|
| 331 |
+
* flush the <code>OutputStream</code>.
|
| 332 |
+
* Uses the platform default encoding.
|
| 333 |
+
* @param input the <code>String</code> to read from
|
| 334 |
+
* @param output the <code>OutputStream</code> to write to
|
| 335 |
+
* @throws IOException In case of an I/O problem
|
| 336 |
+
* @deprecated 2.5 use {@link #copy(String, OutputStream, String)} instead
|
| 337 |
+
*/
|
| 338 |
+
@Deprecated
|
| 339 |
+
public static void copy(
|
| 340 |
+
final String input,
|
| 341 |
+
final OutputStream output)
|
| 342 |
+
throws IOException {
|
| 343 |
+
final StringReader in = new StringReader(input);
|
| 344 |
+
// make explicit the dependency on the default encoding
|
| 345 |
+
final OutputStreamWriter out = new OutputStreamWriter(output, Charset.defaultCharset());
|
| 346 |
+
copy(in, out);
|
| 347 |
+
// XXX Unless anyone is planning on rewriting OutputStreamWriter, we
|
| 348 |
+
// have to flush here.
|
| 349 |
+
out.flush();
|
| 350 |
+
}
|
| 351 |
+
|
| 352 |
+
/**
|
| 353 |
+
* Serialize chars from a <code>String</code> to bytes on an
|
| 354 |
+
* <code>OutputStream</code>, and
|
| 355 |
+
* flush the <code>OutputStream</code>.
|
| 356 |
+
* @param input the <code>String</code> to read from
|
| 357 |
+
* @param output the <code>OutputStream</code> to write to
|
| 358 |
+
* @param encoding The name of a supported character encoding. See the
|
| 359 |
+
* <a href="http://www.iana.org/assignments/character-sets">IANA
|
| 360 |
+
* Charset Registry</a> for a list of valid encoding types.
|
| 361 |
+
* @throws IOException In case of an I/O problem
|
| 362 |
+
* @since 2.5
|
| 363 |
+
*/
|
| 364 |
+
public static void copy(
|
| 365 |
+
final String input,
|
| 366 |
+
final OutputStream output,
|
| 367 |
+
final String encoding)
|
| 368 |
+
throws IOException {
|
| 369 |
+
final StringReader in = new StringReader(input);
|
| 370 |
+
final OutputStreamWriter out = new OutputStreamWriter(output, encoding);
|
| 371 |
+
copy(in, out);
|
| 372 |
+
// XXX Unless anyone is planning on rewriting OutputStreamWriter, we
|
| 373 |
+
// have to flush here.
|
| 374 |
+
out.flush();
|
| 375 |
+
}
|
| 376 |
+
|
| 377 |
+
// ----------------------------------------------------------------
|
| 378 |
+
// String -> Writer
|
| 379 |
+
// ----------------------------------------------------------------
|
| 380 |
+
|
| 381 |
+
/**
|
| 382 |
+
* Copy chars from a <code>String</code> to a <code>Writer</code>.
|
| 383 |
+
* @param input the <code>String</code> to read from
|
| 384 |
+
* @param output the <code>Writer</code> to write to
|
| 385 |
+
* @throws IOException In case of an I/O problem
|
| 386 |
+
*/
|
| 387 |
+
public static void copy(final String input, final Writer output)
|
| 388 |
+
throws IOException {
|
| 389 |
+
output.write(input);
|
| 390 |
+
}
|
| 391 |
+
|
| 392 |
+
}
|
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/01_课件与电子教材/尚硅谷_第15章_File类与IO流/03-apache-common包/commons-io-2.5-src/src/main/java/org/apache/commons/io/DirectoryWalker.java
ADDED
|
@@ -0,0 +1,642 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Licensed to the Apache Software Foundation (ASF) under one or more
|
| 3 |
+
* contributor license agreements. See the NOTICE file distributed with
|
| 4 |
+
* this work for additional information regarding copyright ownership.
|
| 5 |
+
* The ASF licenses this file to You under the Apache License, Version 2.0
|
| 6 |
+
* (the "License"); you may not use this file except in compliance with
|
| 7 |
+
* the License. You may obtain a copy of the License at
|
| 8 |
+
*
|
| 9 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
*
|
| 11 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 12 |
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
| 13 |
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 14 |
+
* See the License for the specific language governing permissions and
|
| 15 |
+
* limitations under the License.
|
| 16 |
+
*/
|
| 17 |
+
package org.apache.commons.io;
|
| 18 |
+
|
| 19 |
+
import java.io.File;
|
| 20 |
+
import java.io.FileFilter;
|
| 21 |
+
import java.io.IOException;
|
| 22 |
+
import java.util.Collection;
|
| 23 |
+
|
| 24 |
+
import org.apache.commons.io.filefilter.FileFilterUtils;
|
| 25 |
+
import org.apache.commons.io.filefilter.IOFileFilter;
|
| 26 |
+
import org.apache.commons.io.filefilter.TrueFileFilter;
|
| 27 |
+
|
| 28 |
+
/**
|
| 29 |
+
* Abstract class that walks through a directory hierarchy and provides
|
| 30 |
+
* subclasses with convenient hooks to add specific behaviour.
|
| 31 |
+
* <p>
|
| 32 |
+
* This class operates with a {@link FileFilter} and maximum depth to
|
| 33 |
+
* limit the files and direcories visited.
|
| 34 |
+
* Commons IO supplies many common filter implementations in the
|
| 35 |
+
* <a href="filefilter/package-summary.html"> filefilter</a> package.
|
| 36 |
+
* <p>
|
| 37 |
+
* The following sections describe:
|
| 38 |
+
* <ul>
|
| 39 |
+
* <li><a href="#example">1. Example Implementation</a> - example
|
| 40 |
+
* <code>FileCleaner</code> implementation.</li>
|
| 41 |
+
* <li><a href="#filter">2. Filter Example</a> - using
|
| 42 |
+
* {@link FileFilter}(s) with <code>DirectoryWalker</code>.</li>
|
| 43 |
+
* <li><a href="#cancel">3. Cancellation</a> - how to implement cancellation
|
| 44 |
+
* behaviour.</li>
|
| 45 |
+
* </ul>
|
| 46 |
+
*
|
| 47 |
+
* <a name="example"></a>
|
| 48 |
+
* <h3>1. Example Implementation</h3>
|
| 49 |
+
*
|
| 50 |
+
* There are many possible extensions, for example, to delete all
|
| 51 |
+
* files and '.svn' directories, and return a list of deleted files:
|
| 52 |
+
* <pre>
|
| 53 |
+
* public class FileCleaner extends DirectoryWalker {
|
| 54 |
+
*
|
| 55 |
+
* public FileCleaner() {
|
| 56 |
+
* super();
|
| 57 |
+
* }
|
| 58 |
+
*
|
| 59 |
+
* public List clean(File startDirectory) {
|
| 60 |
+
* List results = new ArrayList();
|
| 61 |
+
* walk(startDirectory, results);
|
| 62 |
+
* return results;
|
| 63 |
+
* }
|
| 64 |
+
*
|
| 65 |
+
* protected boolean handleDirectory(File directory, int depth, Collection results) {
|
| 66 |
+
* // delete svn directories and then skip
|
| 67 |
+
* if (".svn".equals(directory.getName())) {
|
| 68 |
+
* directory.delete();
|
| 69 |
+
* return false;
|
| 70 |
+
* } else {
|
| 71 |
+
* return true;
|
| 72 |
+
* }
|
| 73 |
+
*
|
| 74 |
+
* }
|
| 75 |
+
*
|
| 76 |
+
* protected void handleFile(File file, int depth, Collection results) {
|
| 77 |
+
* // delete file and add to list of deleted
|
| 78 |
+
* file.delete();
|
| 79 |
+
* results.add(file);
|
| 80 |
+
* }
|
| 81 |
+
* }
|
| 82 |
+
* </pre>
|
| 83 |
+
*
|
| 84 |
+
* <a name="filter"></a>
|
| 85 |
+
* <h3>2. Filter Example</h3>
|
| 86 |
+
*
|
| 87 |
+
* Choosing which directories and files to process can be a key aspect
|
| 88 |
+
* of using this class. This information can be setup in three ways,
|
| 89 |
+
* via three different constructors.
|
| 90 |
+
* <p>
|
| 91 |
+
* The first option is to visit all directories and files.
|
| 92 |
+
* This is achieved via the no-args constructor.
|
| 93 |
+
* <p>
|
| 94 |
+
* The second constructor option is to supply a single {@link FileFilter}
|
| 95 |
+
* that describes the files and directories to visit. Care must be taken
|
| 96 |
+
* with this option as the same filter is used for both directories
|
| 97 |
+
* and files.
|
| 98 |
+
* <p>
|
| 99 |
+
* For example, if you wanted all directories which are not hidden
|
| 100 |
+
* and files which end in ".txt":
|
| 101 |
+
* <pre>
|
| 102 |
+
* public class FooDirectoryWalker extends DirectoryWalker {
|
| 103 |
+
* public FooDirectoryWalker(FileFilter filter) {
|
| 104 |
+
* super(filter, -1);
|
| 105 |
+
* }
|
| 106 |
+
* }
|
| 107 |
+
*
|
| 108 |
+
* // Build up the filters and create the walker
|
| 109 |
+
* // Create a filter for Non-hidden directories
|
| 110 |
+
* IOFileFilter fooDirFilter =
|
| 111 |
+
* FileFilterUtils.andFileFilter(FileFilterUtils.directoryFileFilter,
|
| 112 |
+
* HiddenFileFilter.VISIBLE);
|
| 113 |
+
*
|
| 114 |
+
* // Create a filter for Files ending in ".txt"
|
| 115 |
+
* IOFileFilter fooFileFilter =
|
| 116 |
+
* FileFilterUtils.andFileFilter(FileFilterUtils.fileFileFilter,
|
| 117 |
+
* FileFilterUtils.suffixFileFilter(".txt"));
|
| 118 |
+
*
|
| 119 |
+
* // Combine the directory and file filters using an OR condition
|
| 120 |
+
* java.io.FileFilter fooFilter =
|
| 121 |
+
* FileFilterUtils.orFileFilter(fooDirFilter, fooFileFilter);
|
| 122 |
+
*
|
| 123 |
+
* // Use the filter to construct a DirectoryWalker implementation
|
| 124 |
+
* FooDirectoryWalker walker = new FooDirectoryWalker(fooFilter);
|
| 125 |
+
* </pre>
|
| 126 |
+
* <p>
|
| 127 |
+
* The third constructor option is to specify separate filters, one for
|
| 128 |
+
* directories and one for files. These are combined internally to form
|
| 129 |
+
* the correct <code>FileFilter</code>, something which is very easy to
|
| 130 |
+
* get wrong when attempted manually, particularly when trying to
|
| 131 |
+
* express constructs like 'any file in directories named docs'.
|
| 132 |
+
* <p>
|
| 133 |
+
* For example, if you wanted all directories which are not hidden
|
| 134 |
+
* and files which end in ".txt":
|
| 135 |
+
* <pre>
|
| 136 |
+
* public class FooDirectoryWalker extends DirectoryWalker {
|
| 137 |
+
* public FooDirectoryWalker(IOFileFilter dirFilter, IOFileFilter fileFilter) {
|
| 138 |
+
* super(dirFilter, fileFilter, -1);
|
| 139 |
+
* }
|
| 140 |
+
* }
|
| 141 |
+
*
|
| 142 |
+
* // Use the filters to construct the walker
|
| 143 |
+
* FooDirectoryWalker walker = new FooDirectoryWalker(
|
| 144 |
+
* HiddenFileFilter.VISIBLE,
|
| 145 |
+
* FileFilterUtils.suffixFileFilter(".txt"),
|
| 146 |
+
* );
|
| 147 |
+
* </pre>
|
| 148 |
+
* This is much simpler than the previous example, and is why it is the preferred
|
| 149 |
+
* option for filtering.
|
| 150 |
+
*
|
| 151 |
+
* <a name="cancel"></a>
|
| 152 |
+
* <h3>3. Cancellation</h3>
|
| 153 |
+
*
|
| 154 |
+
* The DirectoryWalker contains some of the logic required for cancel processing.
|
| 155 |
+
* Subclasses must complete the implementation.
|
| 156 |
+
* <p>
|
| 157 |
+
* What <code>DirectoryWalker</code> does provide for cancellation is:
|
| 158 |
+
* <ul>
|
| 159 |
+
* <li>{@link CancelException} which can be thrown in any of the
|
| 160 |
+
* <i>lifecycle</i> methods to stop processing.</li>
|
| 161 |
+
* <li>The <code>walk()</code> method traps thrown {@link CancelException}
|
| 162 |
+
* and calls the <code>handleCancelled()</code> method, providing
|
| 163 |
+
* a place for custom cancel processing.</li>
|
| 164 |
+
* </ul>
|
| 165 |
+
* <p>
|
| 166 |
+
* Implementations need to provide:
|
| 167 |
+
* <ul>
|
| 168 |
+
* <li>The decision logic on whether to cancel processing or not.</li>
|
| 169 |
+
* <li>Constructing and throwing a {@link CancelException}.</li>
|
| 170 |
+
* <li>Custom cancel processing in the <code>handleCancelled()</code> method.
|
| 171 |
+
* </ul>
|
| 172 |
+
* <p>
|
| 173 |
+
* Two possible scenarios are envisaged for cancellation:
|
| 174 |
+
* <ul>
|
| 175 |
+
* <li><a href="#external">3.1 External / Mult-threaded</a> - cancellation being
|
| 176 |
+
* decided/initiated by an external process.</li>
|
| 177 |
+
* <li><a href="#internal">3.2 Internal</a> - cancellation being decided/initiated
|
| 178 |
+
* from within a DirectoryWalker implementation.</li>
|
| 179 |
+
* </ul>
|
| 180 |
+
* <p>
|
| 181 |
+
* The following sections provide example implementations for these two different
|
| 182 |
+
* scenarios.
|
| 183 |
+
*
|
| 184 |
+
* <a name="external"></a>
|
| 185 |
+
* <h4>3.1 External / Multi-threaded</h4>
|
| 186 |
+
*
|
| 187 |
+
* This example provides a public <code>cancel()</code> method that can be
|
| 188 |
+
* called by another thread to stop the processing. A typical example use-case
|
| 189 |
+
* would be a cancel button on a GUI. Calling this method sets a
|
| 190 |
+
* <a href="http://java.sun.com/docs/books/jls/second_edition/html/classes.doc.html#36930">
|
| 191 |
+
* volatile</a> flag to ensure it will work properly in a multi-threaded environment.
|
| 192 |
+
* The flag is returned by the <code>handleIsCancelled()</code> method, which
|
| 193 |
+
* will cause the walk to stop immediately. The <code>handleCancelled()</code>
|
| 194 |
+
* method will be the next, and last, callback method received once cancellation
|
| 195 |
+
* has occurred.
|
| 196 |
+
*
|
| 197 |
+
* <pre>
|
| 198 |
+
* public class FooDirectoryWalker extends DirectoryWalker {
|
| 199 |
+
*
|
| 200 |
+
* private volatile boolean cancelled = false;
|
| 201 |
+
*
|
| 202 |
+
* public void cancel() {
|
| 203 |
+
* cancelled = true;
|
| 204 |
+
* }
|
| 205 |
+
*
|
| 206 |
+
* protected boolean handleIsCancelled(File file, int depth, Collection results) {
|
| 207 |
+
* return cancelled;
|
| 208 |
+
* }
|
| 209 |
+
*
|
| 210 |
+
* protected void handleCancelled(File startDirectory, Collection results, CancelException cancel) {
|
| 211 |
+
* // implement processing required when a cancellation occurs
|
| 212 |
+
* }
|
| 213 |
+
* }
|
| 214 |
+
* </pre>
|
| 215 |
+
*
|
| 216 |
+
* <a name="internal"></a>
|
| 217 |
+
* <h4>3.2 Internal</h4>
|
| 218 |
+
*
|
| 219 |
+
* This shows an example of how internal cancellation processing could be implemented.
|
| 220 |
+
* <b>Note</b> the decision logic and throwing a {@link CancelException} could be implemented
|
| 221 |
+
* in any of the <i>lifecycle</i> methods.
|
| 222 |
+
*
|
| 223 |
+
* <pre>
|
| 224 |
+
* public class BarDirectoryWalker extends DirectoryWalker {
|
| 225 |
+
*
|
| 226 |
+
* protected boolean handleDirectory(File directory, int depth, Collection results) throws IOException {
|
| 227 |
+
* // cancel if hidden directory
|
| 228 |
+
* if (directory.isHidden()) {
|
| 229 |
+
* throw new CancelException(file, depth);
|
| 230 |
+
* }
|
| 231 |
+
* return true;
|
| 232 |
+
* }
|
| 233 |
+
*
|
| 234 |
+
* protected void handleFile(File file, int depth, Collection results) throws IOException {
|
| 235 |
+
* // cancel if read-only file
|
| 236 |
+
* if (!file.canWrite()) {
|
| 237 |
+
* throw new CancelException(file, depth);
|
| 238 |
+
* }
|
| 239 |
+
* results.add(file);
|
| 240 |
+
* }
|
| 241 |
+
*
|
| 242 |
+
* protected void handleCancelled(File startDirectory, Collection results, CancelException cancel) {
|
| 243 |
+
* // implement processing required when a cancellation occurs
|
| 244 |
+
* }
|
| 245 |
+
* }
|
| 246 |
+
* </pre>
|
| 247 |
+
*
|
| 248 |
+
* @since 1.3
|
| 249 |
+
* @version $Id: DirectoryWalker.java 1723627 2016-01-07 21:15:47Z niallp $
|
| 250 |
+
*/
|
| 251 |
+
public abstract class DirectoryWalker<T> {
|
| 252 |
+
|
| 253 |
+
/**
|
| 254 |
+
* The file filter to use to filter files and directories.
|
| 255 |
+
*/
|
| 256 |
+
private final FileFilter filter;
|
| 257 |
+
/**
|
| 258 |
+
* The limit on the directory depth to walk.
|
| 259 |
+
*/
|
| 260 |
+
private final int depthLimit;
|
| 261 |
+
|
| 262 |
+
/**
|
| 263 |
+
* Construct an instance with no filtering and unlimited <i>depth</i>.
|
| 264 |
+
*/
|
| 265 |
+
protected DirectoryWalker() {
|
| 266 |
+
this(null, -1);
|
| 267 |
+
}
|
| 268 |
+
|
| 269 |
+
/**
|
| 270 |
+
* Construct an instance with a filter and limit the <i>depth</i> navigated to.
|
| 271 |
+
* <p>
|
| 272 |
+
* The filter controls which files and directories will be navigated to as
|
| 273 |
+
* part of the walk. The {@link FileFilterUtils} class is useful for combining
|
| 274 |
+
* various filters together. A {@code null} filter means that no
|
| 275 |
+
* filtering should occur and all files and directories will be visited.
|
| 276 |
+
*
|
| 277 |
+
* @param filter the filter to apply, null means visit all files
|
| 278 |
+
* @param depthLimit controls how <i>deep</i> the hierarchy is
|
| 279 |
+
* navigated to (less than 0 means unlimited)
|
| 280 |
+
*/
|
| 281 |
+
protected DirectoryWalker(final FileFilter filter, final int depthLimit) {
|
| 282 |
+
this.filter = filter;
|
| 283 |
+
this.depthLimit = depthLimit;
|
| 284 |
+
}
|
| 285 |
+
|
| 286 |
+
/**
|
| 287 |
+
* Construct an instance with a directory and a file filter and an optional
|
| 288 |
+
* limit on the <i>depth</i> navigated to.
|
| 289 |
+
* <p>
|
| 290 |
+
* The filters control which files and directories will be navigated to as part
|
| 291 |
+
* of the walk. This constructor uses {@link FileFilterUtils#makeDirectoryOnly(IOFileFilter)}
|
| 292 |
+
* and {@link FileFilterUtils#makeFileOnly(IOFileFilter)} internally to combine the filters.
|
| 293 |
+
* A {@code null} filter means that no filtering should occur.
|
| 294 |
+
*
|
| 295 |
+
* @param directoryFilter the filter to apply to directories, null means visit all directories
|
| 296 |
+
* @param fileFilter the filter to apply to files, null means visit all files
|
| 297 |
+
* @param depthLimit controls how <i>deep</i> the hierarchy is
|
| 298 |
+
* navigated to (less than 0 means unlimited)
|
| 299 |
+
*/
|
| 300 |
+
protected DirectoryWalker(IOFileFilter directoryFilter, IOFileFilter fileFilter, final int depthLimit) {
|
| 301 |
+
if (directoryFilter == null && fileFilter == null) {
|
| 302 |
+
this.filter = null;
|
| 303 |
+
} else {
|
| 304 |
+
directoryFilter = directoryFilter != null ? directoryFilter : TrueFileFilter.TRUE;
|
| 305 |
+
fileFilter = fileFilter != null ? fileFilter : TrueFileFilter.TRUE;
|
| 306 |
+
directoryFilter = FileFilterUtils.makeDirectoryOnly(directoryFilter);
|
| 307 |
+
fileFilter = FileFilterUtils.makeFileOnly(fileFilter);
|
| 308 |
+
this.filter = FileFilterUtils.or(directoryFilter, fileFilter);
|
| 309 |
+
}
|
| 310 |
+
this.depthLimit = depthLimit;
|
| 311 |
+
}
|
| 312 |
+
|
| 313 |
+
//-----------------------------------------------------------------------
|
| 314 |
+
/**
|
| 315 |
+
* Internal method that walks the directory hierarchy in a depth-first manner.
|
| 316 |
+
* <p>
|
| 317 |
+
* Users of this class do not need to call this method. This method will
|
| 318 |
+
* be called automatically by another (public) method on the specific subclass.
|
| 319 |
+
* <p>
|
| 320 |
+
* Writers of subclasses should call this method to start the directory walk.
|
| 321 |
+
* Once called, this method will emit events as it walks the hierarchy.
|
| 322 |
+
* The event methods have the prefix <code>handle</code>.
|
| 323 |
+
*
|
| 324 |
+
* @param startDirectory the directory to start from, not null
|
| 325 |
+
* @param results the collection of result objects, may be updated
|
| 326 |
+
* @throws NullPointerException if the start directory is null
|
| 327 |
+
* @throws IOException if an I/O Error occurs
|
| 328 |
+
*/
|
| 329 |
+
protected final void walk(final File startDirectory, final Collection<T> results) throws IOException {
|
| 330 |
+
if (startDirectory == null) {
|
| 331 |
+
throw new NullPointerException("Start Directory is null");
|
| 332 |
+
}
|
| 333 |
+
try {
|
| 334 |
+
handleStart(startDirectory, results);
|
| 335 |
+
walk(startDirectory, 0, results);
|
| 336 |
+
handleEnd(results);
|
| 337 |
+
} catch(final CancelException cancel) {
|
| 338 |
+
handleCancelled(startDirectory, results, cancel);
|
| 339 |
+
}
|
| 340 |
+
}
|
| 341 |
+
|
| 342 |
+
/**
|
| 343 |
+
* Main recursive method to examine the directory hierarchy.
|
| 344 |
+
*
|
| 345 |
+
* @param directory the directory to examine, not null
|
| 346 |
+
* @param depth the directory level (starting directory = 0)
|
| 347 |
+
* @param results the collection of result objects, may be updated
|
| 348 |
+
* @throws IOException if an I/O Error occurs
|
| 349 |
+
*/
|
| 350 |
+
private void walk(final File directory, final int depth, final Collection<T> results) throws IOException {
|
| 351 |
+
checkIfCancelled(directory, depth, results);
|
| 352 |
+
if (handleDirectory(directory, depth, results)) {
|
| 353 |
+
handleDirectoryStart(directory, depth, results);
|
| 354 |
+
final int childDepth = depth + 1;
|
| 355 |
+
if (depthLimit < 0 || childDepth <= depthLimit) {
|
| 356 |
+
checkIfCancelled(directory, depth, results);
|
| 357 |
+
File[] childFiles = filter == null ? directory.listFiles() : directory.listFiles(filter);
|
| 358 |
+
childFiles = filterDirectoryContents(directory, depth, childFiles);
|
| 359 |
+
if (childFiles == null) {
|
| 360 |
+
handleRestricted(directory, childDepth, results);
|
| 361 |
+
} else {
|
| 362 |
+
for (final File childFile : childFiles) {
|
| 363 |
+
if (childFile.isDirectory()) {
|
| 364 |
+
walk(childFile, childDepth, results);
|
| 365 |
+
} else {
|
| 366 |
+
checkIfCancelled(childFile, childDepth, results);
|
| 367 |
+
handleFile(childFile, childDepth, results);
|
| 368 |
+
checkIfCancelled(childFile, childDepth, results);
|
| 369 |
+
}
|
| 370 |
+
}
|
| 371 |
+
}
|
| 372 |
+
}
|
| 373 |
+
handleDirectoryEnd(directory, depth, results);
|
| 374 |
+
}
|
| 375 |
+
checkIfCancelled(directory, depth, results);
|
| 376 |
+
}
|
| 377 |
+
|
| 378 |
+
//-----------------------------------------------------------------------
|
| 379 |
+
/**
|
| 380 |
+
* Checks whether the walk has been cancelled by calling {@link #handleIsCancelled},
|
| 381 |
+
* throwing a <code>CancelException</code> if it has.
|
| 382 |
+
* <p>
|
| 383 |
+
* Writers of subclasses should not normally call this method as it is called
|
| 384 |
+
* automatically by the walk of the tree. However, sometimes a single method,
|
| 385 |
+
* typically {@link #handleFile}, may take a long time to run. In that case,
|
| 386 |
+
* you may wish to check for cancellation by calling this method.
|
| 387 |
+
*
|
| 388 |
+
* @param file the current file being processed
|
| 389 |
+
* @param depth the current file level (starting directory = 0)
|
| 390 |
+
* @param results the collection of result objects, may be updated
|
| 391 |
+
* @throws IOException if an I/O Error occurs
|
| 392 |
+
*/
|
| 393 |
+
protected final void checkIfCancelled(final File file, final int depth, final Collection<T> results) throws
|
| 394 |
+
IOException {
|
| 395 |
+
if (handleIsCancelled(file, depth, results)) {
|
| 396 |
+
throw new CancelException(file, depth);
|
| 397 |
+
}
|
| 398 |
+
}
|
| 399 |
+
|
| 400 |
+
/**
|
| 401 |
+
* Overridable callback method invoked to determine if the entire walk
|
| 402 |
+
* operation should be immediately cancelled.
|
| 403 |
+
* <p>
|
| 404 |
+
* This method should be implemented by those subclasses that want to
|
| 405 |
+
* provide a public <code>cancel()</code> method available from another
|
| 406 |
+
* thread. The design pattern for the subclass should be as follows:
|
| 407 |
+
* <pre>
|
| 408 |
+
* public class FooDirectoryWalker extends DirectoryWalker {
|
| 409 |
+
* private volatile boolean cancelled = false;
|
| 410 |
+
*
|
| 411 |
+
* public void cancel() {
|
| 412 |
+
* cancelled = true;
|
| 413 |
+
* }
|
| 414 |
+
* private void handleIsCancelled(File file, int depth, Collection results) {
|
| 415 |
+
* return cancelled;
|
| 416 |
+
* }
|
| 417 |
+
* protected void handleCancelled(File startDirectory,
|
| 418 |
+
* Collection results, CancelException cancel) {
|
| 419 |
+
* // implement processing required when a cancellation occurs
|
| 420 |
+
* }
|
| 421 |
+
* }
|
| 422 |
+
* </pre>
|
| 423 |
+
* <p>
|
| 424 |
+
* If this method returns true, then the directory walk is immediately
|
| 425 |
+
* cancelled. The next callback method will be {@link #handleCancelled}.
|
| 426 |
+
* <p>
|
| 427 |
+
* This implementation returns false.
|
| 428 |
+
*
|
| 429 |
+
* @param file the file or directory being processed
|
| 430 |
+
* @param depth the current directory level (starting directory = 0)
|
| 431 |
+
* @param results the collection of result objects, may be updated
|
| 432 |
+
* @return true if the walk has been cancelled
|
| 433 |
+
* @throws IOException if an I/O Error occurs
|
| 434 |
+
*/
|
| 435 |
+
protected boolean handleIsCancelled(
|
| 436 |
+
final File file, final int depth, final Collection<T> results) throws IOException {
|
| 437 |
+
// do nothing - overridable by subclass
|
| 438 |
+
return false; // not cancelled
|
| 439 |
+
}
|
| 440 |
+
|
| 441 |
+
/**
|
| 442 |
+
* Overridable callback method invoked when the operation is cancelled.
|
| 443 |
+
* The file being processed when the cancellation occurred can be
|
| 444 |
+
* obtained from the exception.
|
| 445 |
+
* <p>
|
| 446 |
+
* This implementation just re-throws the {@link CancelException}.
|
| 447 |
+
*
|
| 448 |
+
* @param startDirectory the directory that the walk started from
|
| 449 |
+
* @param results the collection of result objects, may be updated
|
| 450 |
+
* @param cancel the exception throw to cancel further processing
|
| 451 |
+
* containing details at the point of cancellation.
|
| 452 |
+
* @throws IOException if an I/O Error occurs
|
| 453 |
+
*/
|
| 454 |
+
protected void handleCancelled(final File startDirectory, final Collection<T> results,
|
| 455 |
+
final CancelException cancel) throws IOException {
|
| 456 |
+
// re-throw exception - overridable by subclass
|
| 457 |
+
throw cancel;
|
| 458 |
+
}
|
| 459 |
+
|
| 460 |
+
//-----------------------------------------------------------------------
|
| 461 |
+
/**
|
| 462 |
+
* Overridable callback method invoked at the start of processing.
|
| 463 |
+
* <p>
|
| 464 |
+
* This implementation does nothing.
|
| 465 |
+
*
|
| 466 |
+
* @param startDirectory the directory to start from
|
| 467 |
+
* @param results the collection of result objects, may be updated
|
| 468 |
+
* @throws IOException if an I/O Error occurs
|
| 469 |
+
*/
|
| 470 |
+
protected void handleStart(final File startDirectory, final Collection<T> results) throws IOException {
|
| 471 |
+
// do nothing - overridable by subclass
|
| 472 |
+
}
|
| 473 |
+
|
| 474 |
+
/**
|
| 475 |
+
* Overridable callback method invoked to determine if a directory should be processed.
|
| 476 |
+
* <p>
|
| 477 |
+
* This method returns a boolean to indicate if the directory should be examined or not.
|
| 478 |
+
* If you return false, the entire directory and any subdirectories will be skipped.
|
| 479 |
+
* Note that this functionality is in addition to the filtering by file filter.
|
| 480 |
+
* <p>
|
| 481 |
+
* This implementation does nothing and returns true.
|
| 482 |
+
*
|
| 483 |
+
* @param directory the current directory being processed
|
| 484 |
+
* @param depth the current directory level (starting directory = 0)
|
| 485 |
+
* @param results the collection of result objects, may be updated
|
| 486 |
+
* @return true to process this directory, false to skip this directory
|
| 487 |
+
* @throws IOException if an I/O Error occurs
|
| 488 |
+
*/
|
| 489 |
+
protected boolean handleDirectory(final File directory, final int depth, final Collection<T> results) throws
|
| 490 |
+
IOException {
|
| 491 |
+
// do nothing - overridable by subclass
|
| 492 |
+
return true; // process directory
|
| 493 |
+
}
|
| 494 |
+
|
| 495 |
+
/**
|
| 496 |
+
* Overridable callback method invoked at the start of processing each directory.
|
| 497 |
+
* <p>
|
| 498 |
+
* This implementation does nothing.
|
| 499 |
+
*
|
| 500 |
+
* @param directory the current directory being processed
|
| 501 |
+
* @param depth the current directory level (starting directory = 0)
|
| 502 |
+
* @param results the collection of result objects, may be updated
|
| 503 |
+
* @throws IOException if an I/O Error occurs
|
| 504 |
+
*/
|
| 505 |
+
protected void handleDirectoryStart(final File directory, final int depth, final Collection<T> results) throws
|
| 506 |
+
IOException {
|
| 507 |
+
// do nothing - overridable by subclass
|
| 508 |
+
}
|
| 509 |
+
|
| 510 |
+
/**
|
| 511 |
+
* Overridable callback method invoked with the contents of each directory.
|
| 512 |
+
* <p>
|
| 513 |
+
* This implementation returns the files unchanged
|
| 514 |
+
*
|
| 515 |
+
* @param directory the current directory being processed
|
| 516 |
+
* @param depth the current directory level (starting directory = 0)
|
| 517 |
+
* @param files the files (possibly filtered) in the directory, may be {@code null}
|
| 518 |
+
* @return the filtered list of files
|
| 519 |
+
* @throws IOException if an I/O Error occurs
|
| 520 |
+
* @since 2.0
|
| 521 |
+
*/
|
| 522 |
+
protected File[] filterDirectoryContents(final File directory, final int depth, final File[] files) throws
|
| 523 |
+
IOException {
|
| 524 |
+
return files;
|
| 525 |
+
}
|
| 526 |
+
|
| 527 |
+
/**
|
| 528 |
+
* Overridable callback method invoked for each (non-directory) file.
|
| 529 |
+
* <p>
|
| 530 |
+
* This implementation does nothing.
|
| 531 |
+
*
|
| 532 |
+
* @param file the current file being processed
|
| 533 |
+
* @param depth the current directory level (starting directory = 0)
|
| 534 |
+
* @param results the collection of result objects, may be updated
|
| 535 |
+
* @throws IOException if an I/O Error occurs
|
| 536 |
+
*/
|
| 537 |
+
protected void handleFile(final File file, final int depth, final Collection<T> results) throws IOException {
|
| 538 |
+
// do nothing - overridable by subclass
|
| 539 |
+
}
|
| 540 |
+
|
| 541 |
+
/**
|
| 542 |
+
* Overridable callback method invoked for each restricted directory.
|
| 543 |
+
* <p>
|
| 544 |
+
* This implementation does nothing.
|
| 545 |
+
*
|
| 546 |
+
* @param directory the restricted directory
|
| 547 |
+
* @param depth the current directory level (starting directory = 0)
|
| 548 |
+
* @param results the collection of result objects, may be updated
|
| 549 |
+
* @throws IOException if an I/O Error occurs
|
| 550 |
+
*/
|
| 551 |
+
protected void handleRestricted(final File directory, final int depth, final Collection<T> results) throws
|
| 552 |
+
IOException {
|
| 553 |
+
// do nothing - overridable by subclass
|
| 554 |
+
}
|
| 555 |
+
|
| 556 |
+
/**
|
| 557 |
+
* Overridable callback method invoked at the end of processing each directory.
|
| 558 |
+
* <p>
|
| 559 |
+
* This implementation does nothing.
|
| 560 |
+
*
|
| 561 |
+
* @param directory the directory being processed
|
| 562 |
+
* @param depth the current directory level (starting directory = 0)
|
| 563 |
+
* @param results the collection of result objects, may be updated
|
| 564 |
+
* @throws IOException if an I/O Error occurs
|
| 565 |
+
*/
|
| 566 |
+
protected void handleDirectoryEnd(final File directory, final int depth, final Collection<T> results) throws
|
| 567 |
+
IOException {
|
| 568 |
+
// do nothing - overridable by subclass
|
| 569 |
+
}
|
| 570 |
+
|
| 571 |
+
/**
|
| 572 |
+
* Overridable callback method invoked at the end of processing.
|
| 573 |
+
* <p>
|
| 574 |
+
* This implementation does nothing.
|
| 575 |
+
*
|
| 576 |
+
* @param results the collection of result objects, may be updated
|
| 577 |
+
* @throws IOException if an I/O Error occurs
|
| 578 |
+
*/
|
| 579 |
+
protected void handleEnd(final Collection<T> results) throws IOException {
|
| 580 |
+
// do nothing - overridable by subclass
|
| 581 |
+
}
|
| 582 |
+
|
| 583 |
+
//-----------------------------------------------------------------------
|
| 584 |
+
/**
|
| 585 |
+
* CancelException is thrown in DirectoryWalker to cancel the current
|
| 586 |
+
* processing.
|
| 587 |
+
*/
|
| 588 |
+
public static class CancelException extends IOException {
|
| 589 |
+
|
| 590 |
+
/** Serialization id. */
|
| 591 |
+
private static final long serialVersionUID = 1347339620135041008L;
|
| 592 |
+
|
| 593 |
+
/** The file being processed when the exception was thrown. */
|
| 594 |
+
private final File file;
|
| 595 |
+
/** The file depth when the exception was thrown. */
|
| 596 |
+
private final int depth;
|
| 597 |
+
|
| 598 |
+
/**
|
| 599 |
+
* Constructs a <code>CancelException</code> with
|
| 600 |
+
* the file and depth when cancellation occurred.
|
| 601 |
+
*
|
| 602 |
+
* @param file the file when the operation was cancelled, may be null
|
| 603 |
+
* @param depth the depth when the operation was cancelled, may be null
|
| 604 |
+
*/
|
| 605 |
+
public CancelException(final File file, final int depth) {
|
| 606 |
+
this("Operation Cancelled", file, depth);
|
| 607 |
+
}
|
| 608 |
+
|
| 609 |
+
/**
|
| 610 |
+
* Constructs a <code>CancelException</code> with
|
| 611 |
+
* an appropriate message and the file and depth when
|
| 612 |
+
* cancellation occurred.
|
| 613 |
+
*
|
| 614 |
+
* @param message the detail message
|
| 615 |
+
* @param file the file when the operation was cancelled
|
| 616 |
+
* @param depth the depth when the operation was cancelled
|
| 617 |
+
*/
|
| 618 |
+
public CancelException(final String message, final File file, final int depth) {
|
| 619 |
+
super(message);
|
| 620 |
+
this.file = file;
|
| 621 |
+
this.depth = depth;
|
| 622 |
+
}
|
| 623 |
+
|
| 624 |
+
/**
|
| 625 |
+
* Return the file when the operation was cancelled.
|
| 626 |
+
*
|
| 627 |
+
* @return the file when the operation was cancelled
|
| 628 |
+
*/
|
| 629 |
+
public File getFile() {
|
| 630 |
+
return file;
|
| 631 |
+
}
|
| 632 |
+
|
| 633 |
+
/**
|
| 634 |
+
* Return the depth when the operation was cancelled.
|
| 635 |
+
*
|
| 636 |
+
* @return the depth when the operation was cancelled
|
| 637 |
+
*/
|
| 638 |
+
public int getDepth() {
|
| 639 |
+
return depth;
|
| 640 |
+
}
|
| 641 |
+
}
|
| 642 |
+
}
|
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/01_课件与电子教材/尚硅谷_第15章_File类与IO流/03-apache-common包/commons-io-2.5-src/src/main/java/org/apache/commons/io/EndianUtils.java
ADDED
|
@@ -0,0 +1,482 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Licensed to the Apache Software Foundation (ASF) under one or more
|
| 3 |
+
* contributor license agreements. See the NOTICE file distributed with
|
| 4 |
+
* this work for additional information regarding copyright ownership.
|
| 5 |
+
* The ASF licenses this file to You under the Apache License, Version 2.0
|
| 6 |
+
* (the "License"); you may not use this file except in compliance with
|
| 7 |
+
* the License. You may obtain a copy of the License at
|
| 8 |
+
*
|
| 9 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
*
|
| 11 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 12 |
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
| 13 |
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 14 |
+
* See the License for the specific language governing permissions and
|
| 15 |
+
* limitations under the License.
|
| 16 |
+
*/
|
| 17 |
+
package org.apache.commons.io;
|
| 18 |
+
|
| 19 |
+
import static org.apache.commons.io.IOUtils.EOF;
|
| 20 |
+
|
| 21 |
+
import java.io.EOFException;
|
| 22 |
+
import java.io.IOException;
|
| 23 |
+
import java.io.InputStream;
|
| 24 |
+
import java.io.OutputStream;
|
| 25 |
+
|
| 26 |
+
/**
|
| 27 |
+
* Utility code for dealing with different endian systems.
|
| 28 |
+
* <p>
|
| 29 |
+
* Different computer architectures adopt different conventions for
|
| 30 |
+
* byte ordering. In so-called "Little Endian" architectures (eg Intel),
|
| 31 |
+
* the low-order byte is stored in memory at the lowest address, and
|
| 32 |
+
* subsequent bytes at higher addresses. For "Big Endian" architectures
|
| 33 |
+
* (eg Motorola), the situation is reversed.
|
| 34 |
+
* This class helps you solve this incompatibility.
|
| 35 |
+
* <p>
|
| 36 |
+
* Origin of code: Excalibur
|
| 37 |
+
*
|
| 38 |
+
* @version $Id: EndianUtils.java 1686450 2015-06-19 16:43:48Z krosenvold $
|
| 39 |
+
* @see org.apache.commons.io.input.SwappedDataInputStream
|
| 40 |
+
*/
|
| 41 |
+
public class EndianUtils {
|
| 42 |
+
|
| 43 |
+
/**
|
| 44 |
+
* Instances should NOT be constructed in standard programming.
|
| 45 |
+
*/
|
| 46 |
+
public EndianUtils() {
|
| 47 |
+
super();
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
// ========================================== Swapping routines
|
| 51 |
+
|
| 52 |
+
/**
|
| 53 |
+
* Converts a "short" value between endian systems.
|
| 54 |
+
* @param value value to convert
|
| 55 |
+
* @return the converted value
|
| 56 |
+
*/
|
| 57 |
+
public static short swapShort(final short value) {
|
| 58 |
+
return (short) ( ( ( ( value >> 0 ) & 0xff ) << 8 ) +
|
| 59 |
+
( ( ( value >> 8 ) & 0xff ) << 0 ) );
|
| 60 |
+
}
|
| 61 |
+
|
| 62 |
+
/**
|
| 63 |
+
* Converts a "int" value between endian systems.
|
| 64 |
+
* @param value value to convert
|
| 65 |
+
* @return the converted value
|
| 66 |
+
*/
|
| 67 |
+
public static int swapInteger(final int value) {
|
| 68 |
+
return
|
| 69 |
+
( ( ( value >> 0 ) & 0xff ) << 24 ) +
|
| 70 |
+
( ( ( value >> 8 ) & 0xff ) << 16 ) +
|
| 71 |
+
( ( ( value >> 16 ) & 0xff ) << 8 ) +
|
| 72 |
+
( ( ( value >> 24 ) & 0xff ) << 0 );
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
/**
|
| 76 |
+
* Converts a "long" value between endian systems.
|
| 77 |
+
* @param value value to convert
|
| 78 |
+
* @return the converted value
|
| 79 |
+
*/
|
| 80 |
+
public static long swapLong(final long value) {
|
| 81 |
+
return
|
| 82 |
+
( ( ( value >> 0 ) & 0xff ) << 56 ) +
|
| 83 |
+
( ( ( value >> 8 ) & 0xff ) << 48 ) +
|
| 84 |
+
( ( ( value >> 16 ) & 0xff ) << 40 ) +
|
| 85 |
+
( ( ( value >> 24 ) & 0xff ) << 32 ) +
|
| 86 |
+
( ( ( value >> 32 ) & 0xff ) << 24 ) +
|
| 87 |
+
( ( ( value >> 40 ) & 0xff ) << 16 ) +
|
| 88 |
+
( ( ( value >> 48 ) & 0xff ) << 8 ) +
|
| 89 |
+
( ( ( value >> 56 ) & 0xff ) << 0 );
|
| 90 |
+
}
|
| 91 |
+
|
| 92 |
+
/**
|
| 93 |
+
* Converts a "float" value between endian systems.
|
| 94 |
+
* @param value value to convert
|
| 95 |
+
* @return the converted value
|
| 96 |
+
*/
|
| 97 |
+
public static float swapFloat(final float value) {
|
| 98 |
+
return Float.intBitsToFloat( swapInteger( Float.floatToIntBits( value ) ) );
|
| 99 |
+
}
|
| 100 |
+
|
| 101 |
+
/**
|
| 102 |
+
* Converts a "double" value between endian systems.
|
| 103 |
+
* @param value value to convert
|
| 104 |
+
* @return the converted value
|
| 105 |
+
*/
|
| 106 |
+
public static double swapDouble(final double value) {
|
| 107 |
+
return Double.longBitsToDouble( swapLong( Double.doubleToLongBits( value ) ) );
|
| 108 |
+
}
|
| 109 |
+
|
| 110 |
+
// ========================================== Swapping read/write routines
|
| 111 |
+
|
| 112 |
+
/**
|
| 113 |
+
* Writes a "short" value to a byte array at a given offset. The value is
|
| 114 |
+
* converted to the opposed endian system while writing.
|
| 115 |
+
* @param data target byte array
|
| 116 |
+
* @param offset starting offset in the byte array
|
| 117 |
+
* @param value value to write
|
| 118 |
+
*/
|
| 119 |
+
public static void writeSwappedShort(final byte[] data, final int offset, final short value) {
|
| 120 |
+
data[ offset + 0 ] = (byte)( ( value >> 0 ) & 0xff );
|
| 121 |
+
data[ offset + 1 ] = (byte)( ( value >> 8 ) & 0xff );
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
+
/**
|
| 125 |
+
* Reads a "short" value from a byte array at a given offset. The value is
|
| 126 |
+
* converted to the opposed endian system while reading.
|
| 127 |
+
* @param data source byte array
|
| 128 |
+
* @param offset starting offset in the byte array
|
| 129 |
+
* @return the value read
|
| 130 |
+
*/
|
| 131 |
+
public static short readSwappedShort(final byte[] data, final int offset) {
|
| 132 |
+
return (short)( ( ( data[ offset + 0 ] & 0xff ) << 0 ) +
|
| 133 |
+
( ( data[ offset + 1 ] & 0xff ) << 8 ) );
|
| 134 |
+
}
|
| 135 |
+
|
| 136 |
+
/**
|
| 137 |
+
* Reads an unsigned short (16-bit) value from a byte array at a given
|
| 138 |
+
* offset. The value is converted to the opposed endian system while
|
| 139 |
+
* reading.
|
| 140 |
+
* @param data source byte array
|
| 141 |
+
* @param offset starting offset in the byte array
|
| 142 |
+
* @return the value read
|
| 143 |
+
*/
|
| 144 |
+
public static int readSwappedUnsignedShort(final byte[] data, final int offset) {
|
| 145 |
+
return ( ( ( data[ offset + 0 ] & 0xff ) << 0 ) +
|
| 146 |
+
( ( data[ offset + 1 ] & 0xff ) << 8 ) );
|
| 147 |
+
}
|
| 148 |
+
|
| 149 |
+
/**
|
| 150 |
+
* Writes a "int" value to a byte array at a given offset. The value is
|
| 151 |
+
* converted to the opposed endian system while writing.
|
| 152 |
+
* @param data target byte array
|
| 153 |
+
* @param offset starting offset in the byte array
|
| 154 |
+
* @param value value to write
|
| 155 |
+
*/
|
| 156 |
+
public static void writeSwappedInteger(final byte[] data, final int offset, final int value) {
|
| 157 |
+
data[ offset + 0 ] = (byte)( ( value >> 0 ) & 0xff );
|
| 158 |
+
data[ offset + 1 ] = (byte)( ( value >> 8 ) & 0xff );
|
| 159 |
+
data[ offset + 2 ] = (byte)( ( value >> 16 ) & 0xff );
|
| 160 |
+
data[ offset + 3 ] = (byte)( ( value >> 24 ) & 0xff );
|
| 161 |
+
}
|
| 162 |
+
|
| 163 |
+
/**
|
| 164 |
+
* Reads a "int" value from a byte array at a given offset. The value is
|
| 165 |
+
* converted to the opposed endian system while reading.
|
| 166 |
+
* @param data source byte array
|
| 167 |
+
* @param offset starting offset in the byte array
|
| 168 |
+
* @return the value read
|
| 169 |
+
*/
|
| 170 |
+
public static int readSwappedInteger(final byte[] data, final int offset) {
|
| 171 |
+
return ( ( ( data[ offset + 0 ] & 0xff ) << 0 ) +
|
| 172 |
+
( ( data[ offset + 1 ] & 0xff ) << 8 ) +
|
| 173 |
+
( ( data[ offset + 2 ] & 0xff ) << 16 ) +
|
| 174 |
+
( ( data[ offset + 3 ] & 0xff ) << 24 ) );
|
| 175 |
+
}
|
| 176 |
+
|
| 177 |
+
/**
|
| 178 |
+
* Reads an unsigned integer (32-bit) value from a byte array at a given
|
| 179 |
+
* offset. The value is converted to the opposed endian system while
|
| 180 |
+
* reading.
|
| 181 |
+
* @param data source byte array
|
| 182 |
+
* @param offset starting offset in the byte array
|
| 183 |
+
* @return the value read
|
| 184 |
+
*/
|
| 185 |
+
public static long readSwappedUnsignedInteger(final byte[] data, final int offset) {
|
| 186 |
+
final long low = ( ( ( data[ offset + 0 ] & 0xff ) << 0 ) +
|
| 187 |
+
( ( data[ offset + 1 ] & 0xff ) << 8 ) +
|
| 188 |
+
( ( data[ offset + 2 ] & 0xff ) << 16 ) );
|
| 189 |
+
|
| 190 |
+
final long high = data[ offset + 3 ] & 0xff;
|
| 191 |
+
|
| 192 |
+
return (high << 24) + (0xffffffffL & low);
|
| 193 |
+
}
|
| 194 |
+
|
| 195 |
+
/**
|
| 196 |
+
* Writes a "long" value to a byte array at a given offset. The value is
|
| 197 |
+
* converted to the opposed endian system while writing.
|
| 198 |
+
* @param data target byte array
|
| 199 |
+
* @param offset starting offset in the byte array
|
| 200 |
+
* @param value value to write
|
| 201 |
+
*/
|
| 202 |
+
public static void writeSwappedLong(final byte[] data, final int offset, final long value) {
|
| 203 |
+
data[ offset + 0 ] = (byte)( ( value >> 0 ) & 0xff );
|
| 204 |
+
data[ offset + 1 ] = (byte)( ( value >> 8 ) & 0xff );
|
| 205 |
+
data[ offset + 2 ] = (byte)( ( value >> 16 ) & 0xff );
|
| 206 |
+
data[ offset + 3 ] = (byte)( ( value >> 24 ) & 0xff );
|
| 207 |
+
data[ offset + 4 ] = (byte)( ( value >> 32 ) & 0xff );
|
| 208 |
+
data[ offset + 5 ] = (byte)( ( value >> 40 ) & 0xff );
|
| 209 |
+
data[ offset + 6 ] = (byte)( ( value >> 48 ) & 0xff );
|
| 210 |
+
data[ offset + 7 ] = (byte)( ( value >> 56 ) & 0xff );
|
| 211 |
+
}
|
| 212 |
+
|
| 213 |
+
/**
|
| 214 |
+
* Reads a "long" value from a byte array at a given offset. The value is
|
| 215 |
+
* converted to the opposed endian system while reading.
|
| 216 |
+
* @param data source byte array
|
| 217 |
+
* @param offset starting offset in the byte array
|
| 218 |
+
* @return the value read
|
| 219 |
+
*/
|
| 220 |
+
public static long readSwappedLong(final byte[] data, final int offset) {
|
| 221 |
+
final long low = readSwappedInteger(data, offset);
|
| 222 |
+
final long high = readSwappedInteger(data, offset + 4);
|
| 223 |
+
return (high << 32) + (0xffffffffL & low);
|
| 224 |
+
}
|
| 225 |
+
|
| 226 |
+
/**
|
| 227 |
+
* Writes a "float" value to a byte array at a given offset. The value is
|
| 228 |
+
* converted to the opposed endian system while writing.
|
| 229 |
+
* @param data target byte array
|
| 230 |
+
* @param offset starting offset in the byte array
|
| 231 |
+
* @param value value to write
|
| 232 |
+
*/
|
| 233 |
+
public static void writeSwappedFloat(final byte[] data, final int offset, final float value) {
|
| 234 |
+
writeSwappedInteger( data, offset, Float.floatToIntBits( value ) );
|
| 235 |
+
}
|
| 236 |
+
|
| 237 |
+
/**
|
| 238 |
+
* Reads a "float" value from a byte array at a given offset. The value is
|
| 239 |
+
* converted to the opposed endian system while reading.
|
| 240 |
+
* @param data source byte array
|
| 241 |
+
* @param offset starting offset in the byte array
|
| 242 |
+
* @return the value read
|
| 243 |
+
*/
|
| 244 |
+
public static float readSwappedFloat(final byte[] data, final int offset) {
|
| 245 |
+
return Float.intBitsToFloat( readSwappedInteger( data, offset ) );
|
| 246 |
+
}
|
| 247 |
+
|
| 248 |
+
/**
|
| 249 |
+
* Writes a "double" value to a byte array at a given offset. The value is
|
| 250 |
+
* converted to the opposed endian system while writing.
|
| 251 |
+
* @param data target byte array
|
| 252 |
+
* @param offset starting offset in the byte array
|
| 253 |
+
* @param value value to write
|
| 254 |
+
*/
|
| 255 |
+
public static void writeSwappedDouble(final byte[] data, final int offset, final double value) {
|
| 256 |
+
writeSwappedLong( data, offset, Double.doubleToLongBits( value ) );
|
| 257 |
+
}
|
| 258 |
+
|
| 259 |
+
/**
|
| 260 |
+
* Reads a "double" value from a byte array at a given offset. The value is
|
| 261 |
+
* converted to the opposed endian system while reading.
|
| 262 |
+
* @param data source byte array
|
| 263 |
+
* @param offset starting offset in the byte array
|
| 264 |
+
* @return the value read
|
| 265 |
+
*/
|
| 266 |
+
public static double readSwappedDouble(final byte[] data, final int offset) {
|
| 267 |
+
return Double.longBitsToDouble( readSwappedLong( data, offset ) );
|
| 268 |
+
}
|
| 269 |
+
|
| 270 |
+
/**
|
| 271 |
+
* Writes a "short" value to an OutputStream. The value is
|
| 272 |
+
* converted to the opposed endian system while writing.
|
| 273 |
+
* @param output target OutputStream
|
| 274 |
+
* @param value value to write
|
| 275 |
+
* @throws IOException in case of an I/O problem
|
| 276 |
+
*/
|
| 277 |
+
public static void writeSwappedShort(final OutputStream output, final short value)
|
| 278 |
+
throws IOException
|
| 279 |
+
{
|
| 280 |
+
output.write( (byte)( ( value >> 0 ) & 0xff ) );
|
| 281 |
+
output.write( (byte)( ( value >> 8 ) & 0xff ) );
|
| 282 |
+
}
|
| 283 |
+
|
| 284 |
+
/**
|
| 285 |
+
* Reads a "short" value from an InputStream. The value is
|
| 286 |
+
* converted to the opposed endian system while reading.
|
| 287 |
+
* @param input source InputStream
|
| 288 |
+
* @return the value just read
|
| 289 |
+
* @throws IOException in case of an I/O problem
|
| 290 |
+
*/
|
| 291 |
+
public static short readSwappedShort(final InputStream input)
|
| 292 |
+
throws IOException
|
| 293 |
+
{
|
| 294 |
+
return (short)( ( ( read( input ) & 0xff ) << 0 ) +
|
| 295 |
+
( ( read( input ) & 0xff ) << 8 ) );
|
| 296 |
+
}
|
| 297 |
+
|
| 298 |
+
/**
|
| 299 |
+
* Reads a unsigned short (16-bit) from an InputStream. The value is
|
| 300 |
+
* converted to the opposed endian system while reading.
|
| 301 |
+
* @param input source InputStream
|
| 302 |
+
* @return the value just read
|
| 303 |
+
* @throws IOException in case of an I/O problem
|
| 304 |
+
*/
|
| 305 |
+
public static int readSwappedUnsignedShort(final InputStream input)
|
| 306 |
+
throws IOException
|
| 307 |
+
{
|
| 308 |
+
final int value1 = read( input );
|
| 309 |
+
final int value2 = read( input );
|
| 310 |
+
|
| 311 |
+
return ( ( ( value1 & 0xff ) << 0 ) +
|
| 312 |
+
( ( value2 & 0xff ) << 8 ) );
|
| 313 |
+
}
|
| 314 |
+
|
| 315 |
+
/**
|
| 316 |
+
* Writes a "int" value to an OutputStream. The value is
|
| 317 |
+
* converted to the opposed endian system while writing.
|
| 318 |
+
* @param output target OutputStream
|
| 319 |
+
* @param value value to write
|
| 320 |
+
* @throws IOException in case of an I/O problem
|
| 321 |
+
*/
|
| 322 |
+
public static void writeSwappedInteger(final OutputStream output, final int value)
|
| 323 |
+
throws IOException
|
| 324 |
+
{
|
| 325 |
+
output.write( (byte)( ( value >> 0 ) & 0xff ) );
|
| 326 |
+
output.write( (byte)( ( value >> 8 ) & 0xff ) );
|
| 327 |
+
output.write( (byte)( ( value >> 16 ) & 0xff ) );
|
| 328 |
+
output.write( (byte)( ( value >> 24 ) & 0xff ) );
|
| 329 |
+
}
|
| 330 |
+
|
| 331 |
+
/**
|
| 332 |
+
* Reads a "int" value from an InputStream. The value is
|
| 333 |
+
* converted to the opposed endian system while reading.
|
| 334 |
+
* @param input source InputStream
|
| 335 |
+
* @return the value just read
|
| 336 |
+
* @throws IOException in case of an I/O problem
|
| 337 |
+
*/
|
| 338 |
+
public static int readSwappedInteger(final InputStream input)
|
| 339 |
+
throws IOException
|
| 340 |
+
{
|
| 341 |
+
final int value1 = read( input );
|
| 342 |
+
final int value2 = read( input );
|
| 343 |
+
final int value3 = read( input );
|
| 344 |
+
final int value4 = read( input );
|
| 345 |
+
|
| 346 |
+
return ( ( value1 & 0xff ) << 0 ) +
|
| 347 |
+
( ( value2 & 0xff ) << 8 ) +
|
| 348 |
+
( ( value3 & 0xff ) << 16 ) +
|
| 349 |
+
( ( value4 & 0xff ) << 24 );
|
| 350 |
+
}
|
| 351 |
+
|
| 352 |
+
/**
|
| 353 |
+
* Reads a unsigned integer (32-bit) from an InputStream. The value is
|
| 354 |
+
* converted to the opposed endian system while reading.
|
| 355 |
+
* @param input source InputStream
|
| 356 |
+
* @return the value just read
|
| 357 |
+
* @throws IOException in case of an I/O problem
|
| 358 |
+
*/
|
| 359 |
+
public static long readSwappedUnsignedInteger(final InputStream input)
|
| 360 |
+
throws IOException
|
| 361 |
+
{
|
| 362 |
+
final int value1 = read( input );
|
| 363 |
+
final int value2 = read( input );
|
| 364 |
+
final int value3 = read( input );
|
| 365 |
+
final int value4 = read( input );
|
| 366 |
+
|
| 367 |
+
final long low = ( ( ( value1 & 0xff ) << 0 ) +
|
| 368 |
+
( ( value2 & 0xff ) << 8 ) +
|
| 369 |
+
( ( value3 & 0xff ) << 16 ) );
|
| 370 |
+
|
| 371 |
+
final long high = value4 & 0xff;
|
| 372 |
+
|
| 373 |
+
return (high << 24) + (0xffffffffL & low);
|
| 374 |
+
}
|
| 375 |
+
|
| 376 |
+
/**
|
| 377 |
+
* Writes a "long" value to an OutputStream. The value is
|
| 378 |
+
* converted to the opposed endian system while writing.
|
| 379 |
+
* @param output target OutputStream
|
| 380 |
+
* @param value value to write
|
| 381 |
+
* @throws IOException in case of an I/O problem
|
| 382 |
+
*/
|
| 383 |
+
public static void writeSwappedLong(final OutputStream output, final long value)
|
| 384 |
+
throws IOException
|
| 385 |
+
{
|
| 386 |
+
output.write( (byte)( ( value >> 0 ) & 0xff ) );
|
| 387 |
+
output.write( (byte)( ( value >> 8 ) & 0xff ) );
|
| 388 |
+
output.write( (byte)( ( value >> 16 ) & 0xff ) );
|
| 389 |
+
output.write( (byte)( ( value >> 24 ) & 0xff ) );
|
| 390 |
+
output.write( (byte)( ( value >> 32 ) & 0xff ) );
|
| 391 |
+
output.write( (byte)( ( value >> 40 ) & 0xff ) );
|
| 392 |
+
output.write( (byte)( ( value >> 48 ) & 0xff ) );
|
| 393 |
+
output.write( (byte)( ( value >> 56 ) & 0xff ) );
|
| 394 |
+
}
|
| 395 |
+
|
| 396 |
+
/**
|
| 397 |
+
* Reads a "long" value from an InputStream. The value is
|
| 398 |
+
* converted to the opposed endian system while reading.
|
| 399 |
+
* @param input source InputStream
|
| 400 |
+
* @return the value just read
|
| 401 |
+
* @throws IOException in case of an I/O problem
|
| 402 |
+
*/
|
| 403 |
+
public static long readSwappedLong(final InputStream input)
|
| 404 |
+
throws IOException
|
| 405 |
+
{
|
| 406 |
+
final byte[] bytes = new byte[8];
|
| 407 |
+
for ( int i=0; i<8; i++ ) {
|
| 408 |
+
bytes[i] = (byte) read( input );
|
| 409 |
+
}
|
| 410 |
+
return readSwappedLong( bytes, 0 );
|
| 411 |
+
}
|
| 412 |
+
|
| 413 |
+
/**
|
| 414 |
+
* Writes a "float" value to an OutputStream. The value is
|
| 415 |
+
* converted to the opposed endian system while writing.
|
| 416 |
+
* @param output target OutputStream
|
| 417 |
+
* @param value value to write
|
| 418 |
+
* @throws IOException in case of an I/O problem
|
| 419 |
+
*/
|
| 420 |
+
public static void writeSwappedFloat(final OutputStream output, final float value)
|
| 421 |
+
throws IOException
|
| 422 |
+
{
|
| 423 |
+
writeSwappedInteger( output, Float.floatToIntBits( value ) );
|
| 424 |
+
}
|
| 425 |
+
|
| 426 |
+
/**
|
| 427 |
+
* Reads a "float" value from an InputStream. The value is
|
| 428 |
+
* converted to the opposed endian system while reading.
|
| 429 |
+
* @param input source InputStream
|
| 430 |
+
* @return the value just read
|
| 431 |
+
* @throws IOException in case of an I/O problem
|
| 432 |
+
*/
|
| 433 |
+
public static float readSwappedFloat(final InputStream input)
|
| 434 |
+
throws IOException
|
| 435 |
+
{
|
| 436 |
+
return Float.intBitsToFloat( readSwappedInteger( input ) );
|
| 437 |
+
}
|
| 438 |
+
|
| 439 |
+
/**
|
| 440 |
+
* Writes a "double" value to an OutputStream. The value is
|
| 441 |
+
* converted to the opposed endian system while writing.
|
| 442 |
+
* @param output target OutputStream
|
| 443 |
+
* @param value value to write
|
| 444 |
+
* @throws IOException in case of an I/O problem
|
| 445 |
+
*/
|
| 446 |
+
public static void writeSwappedDouble(final OutputStream output, final double value)
|
| 447 |
+
throws IOException
|
| 448 |
+
{
|
| 449 |
+
writeSwappedLong( output, Double.doubleToLongBits( value ) );
|
| 450 |
+
}
|
| 451 |
+
|
| 452 |
+
/**
|
| 453 |
+
* Reads a "double" value from an InputStream. The value is
|
| 454 |
+
* converted to the opposed endian system while reading.
|
| 455 |
+
* @param input source InputStream
|
| 456 |
+
* @return the value just read
|
| 457 |
+
* @throws IOException in case of an I/O problem
|
| 458 |
+
*/
|
| 459 |
+
public static double readSwappedDouble(final InputStream input)
|
| 460 |
+
throws IOException
|
| 461 |
+
{
|
| 462 |
+
return Double.longBitsToDouble( readSwappedLong( input ) );
|
| 463 |
+
}
|
| 464 |
+
|
| 465 |
+
/**
|
| 466 |
+
* Reads the next byte from the input stream.
|
| 467 |
+
* @param input the stream
|
| 468 |
+
* @return the byte
|
| 469 |
+
* @throws IOException if the end of file is reached
|
| 470 |
+
*/
|
| 471 |
+
private static int read(final InputStream input)
|
| 472 |
+
throws IOException
|
| 473 |
+
{
|
| 474 |
+
final int value = input.read();
|
| 475 |
+
|
| 476 |
+
if( EOF == value ) {
|
| 477 |
+
throw new EOFException( "Unexpected EOF reached" );
|
| 478 |
+
}
|
| 479 |
+
|
| 480 |
+
return value;
|
| 481 |
+
}
|
| 482 |
+
}
|
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/01_课件与电子教材/尚硅谷_第15章_File类与IO流/03-apache-common包/commons-io-2.5-src/src/main/java/org/apache/commons/io/FileCleaner.java
ADDED
|
@@ -0,0 +1,160 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Licensed to the Apache Software Foundation (ASF) under one or more
|
| 3 |
+
* contributor license agreements. See the NOTICE file distributed with
|
| 4 |
+
* this work for additional information regarding copyright ownership.
|
| 5 |
+
* The ASF licenses this file to You under the Apache License, Version 2.0
|
| 6 |
+
* (the "License"); you may not use this file except in compliance with
|
| 7 |
+
* the License. You may obtain a copy of the License at
|
| 8 |
+
*
|
| 9 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
*
|
| 11 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 12 |
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
| 13 |
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 14 |
+
* See the License for the specific language governing permissions and
|
| 15 |
+
* limitations under the License.
|
| 16 |
+
*/
|
| 17 |
+
package org.apache.commons.io;
|
| 18 |
+
|
| 19 |
+
import java.io.File;
|
| 20 |
+
|
| 21 |
+
/**
|
| 22 |
+
* Keeps track of files awaiting deletion, and deletes them when an associated
|
| 23 |
+
* marker object is reclaimed by the garbage collector.
|
| 24 |
+
* <p>
|
| 25 |
+
* This utility creates a background thread to handle file deletion.
|
| 26 |
+
* Each file to be deleted is registered with a handler object.
|
| 27 |
+
* When the handler object is garbage collected, the file is deleted.
|
| 28 |
+
* <p>
|
| 29 |
+
* In an environment with multiple class loaders (a servlet container, for
|
| 30 |
+
* example), you should consider stopping the background thread if it is no
|
| 31 |
+
* longer needed. This is done by invoking the method
|
| 32 |
+
* {@link #exitWhenFinished}, typically in
|
| 33 |
+
* {@code javax.servlet.ServletContextListener.contextDestroyed(javax.servlet.ServletContextEvent)} or similar.
|
| 34 |
+
*
|
| 35 |
+
* @version $Id: FileCleaner.java 1680650 2015-05-20 18:36:40Z britter $
|
| 36 |
+
* @deprecated Use {@link FileCleaningTracker}
|
| 37 |
+
*/
|
| 38 |
+
@Deprecated
|
| 39 |
+
public class FileCleaner {
|
| 40 |
+
/**
|
| 41 |
+
* The instance to use for the deprecated, static methods.
|
| 42 |
+
*/
|
| 43 |
+
static final FileCleaningTracker theInstance = new FileCleaningTracker();
|
| 44 |
+
|
| 45 |
+
//-----------------------------------------------------------------------
|
| 46 |
+
/**
|
| 47 |
+
* Track the specified file, using the provided marker, deleting the file
|
| 48 |
+
* when the marker instance is garbage collected.
|
| 49 |
+
* The {@link FileDeleteStrategy#NORMAL normal} deletion strategy will be used.
|
| 50 |
+
*
|
| 51 |
+
* @param file the file to be tracked, not null
|
| 52 |
+
* @param marker the marker object used to track the file, not null
|
| 53 |
+
* @throws NullPointerException if the file is null
|
| 54 |
+
* @deprecated Use {@link FileCleaningTracker#track(File, Object)}.
|
| 55 |
+
*/
|
| 56 |
+
@Deprecated
|
| 57 |
+
public static void track(final File file, final Object marker) {
|
| 58 |
+
theInstance.track(file, marker);
|
| 59 |
+
}
|
| 60 |
+
|
| 61 |
+
/**
|
| 62 |
+
* Track the specified file, using the provided marker, deleting the file
|
| 63 |
+
* when the marker instance is garbage collected.
|
| 64 |
+
* The speified deletion strategy is used.
|
| 65 |
+
*
|
| 66 |
+
* @param file the file to be tracked, not null
|
| 67 |
+
* @param marker the marker object used to track the file, not null
|
| 68 |
+
* @param deleteStrategy the strategy to delete the file, null means normal
|
| 69 |
+
* @throws NullPointerException if the file is null
|
| 70 |
+
* @deprecated Use {@link FileCleaningTracker#track(File, Object, FileDeleteStrategy)}.
|
| 71 |
+
*/
|
| 72 |
+
@Deprecated
|
| 73 |
+
public static void track(final File file, final Object marker, final FileDeleteStrategy deleteStrategy) {
|
| 74 |
+
theInstance.track(file, marker, deleteStrategy);
|
| 75 |
+
}
|
| 76 |
+
|
| 77 |
+
/**
|
| 78 |
+
* Track the specified file, using the provided marker, deleting the file
|
| 79 |
+
* when the marker instance is garbage collected.
|
| 80 |
+
* The {@link FileDeleteStrategy#NORMAL normal} deletion strategy will be used.
|
| 81 |
+
*
|
| 82 |
+
* @param path the full path to the file to be tracked, not null
|
| 83 |
+
* @param marker the marker object used to track the file, not null
|
| 84 |
+
* @throws NullPointerException if the path is null
|
| 85 |
+
* @deprecated Use {@link FileCleaningTracker#track(String, Object)}.
|
| 86 |
+
*/
|
| 87 |
+
@Deprecated
|
| 88 |
+
public static void track(final String path, final Object marker) {
|
| 89 |
+
theInstance.track(path, marker);
|
| 90 |
+
}
|
| 91 |
+
|
| 92 |
+
/**
|
| 93 |
+
* Track the specified file, using the provided marker, deleting the file
|
| 94 |
+
* when the marker instance is garbage collected.
|
| 95 |
+
* The speified deletion strategy is used.
|
| 96 |
+
*
|
| 97 |
+
* @param path the full path to the file to be tracked, not null
|
| 98 |
+
* @param marker the marker object used to track the file, not null
|
| 99 |
+
* @param deleteStrategy the strategy to delete the file, null means normal
|
| 100 |
+
* @throws NullPointerException if the path is null
|
| 101 |
+
* @deprecated Use {@link FileCleaningTracker#track(String, Object, FileDeleteStrategy)}.
|
| 102 |
+
*/
|
| 103 |
+
@Deprecated
|
| 104 |
+
public static void track(final String path, final Object marker, final FileDeleteStrategy deleteStrategy) {
|
| 105 |
+
theInstance.track(path, marker, deleteStrategy);
|
| 106 |
+
}
|
| 107 |
+
|
| 108 |
+
//-----------------------------------------------------------------------
|
| 109 |
+
/**
|
| 110 |
+
* Retrieve the number of files currently being tracked, and therefore
|
| 111 |
+
* awaiting deletion.
|
| 112 |
+
*
|
| 113 |
+
* @return the number of files being tracked
|
| 114 |
+
* @deprecated Use {@link FileCleaningTracker#getTrackCount()}.
|
| 115 |
+
*/
|
| 116 |
+
@Deprecated
|
| 117 |
+
public static int getTrackCount() {
|
| 118 |
+
return theInstance.getTrackCount();
|
| 119 |
+
}
|
| 120 |
+
|
| 121 |
+
/**
|
| 122 |
+
* Call this method to cause the file cleaner thread to terminate when
|
| 123 |
+
* there are no more objects being tracked for deletion.
|
| 124 |
+
* <p>
|
| 125 |
+
* In a simple environment, you don't need this method as the file cleaner
|
| 126 |
+
* thread will simply exit when the JVM exits. In a more complex environment,
|
| 127 |
+
* with multiple class loaders (such as an application server), you should be
|
| 128 |
+
* aware that the file cleaner thread will continue running even if the class
|
| 129 |
+
* loader it was started from terminates. This can consitute a memory leak.
|
| 130 |
+
* <p>
|
| 131 |
+
* For example, suppose that you have developed a web application, which
|
| 132 |
+
* contains the commons-io jar file in your WEB-INF/lib directory. In other
|
| 133 |
+
* words, the FileCleaner class is loaded through the class loader of your
|
| 134 |
+
* web application. If the web application is terminated, but the servlet
|
| 135 |
+
* container is still running, then the file cleaner thread will still exist,
|
| 136 |
+
* posing a memory leak.
|
| 137 |
+
* <p>
|
| 138 |
+
* This method allows the thread to be terminated. Simply call this method
|
| 139 |
+
* in the resource cleanup code, such as
|
| 140 |
+
* {@code javax.servlet.ServletContextListener.contextDestroyed(javax.servlet.ServletContextEvent)}.
|
| 141 |
+
* One called, no new objects can be tracked by the file cleaner.
|
| 142 |
+
* @deprecated Use {@link FileCleaningTracker#exitWhenFinished()}.
|
| 143 |
+
*/
|
| 144 |
+
@Deprecated
|
| 145 |
+
public static synchronized void exitWhenFinished() {
|
| 146 |
+
theInstance.exitWhenFinished();
|
| 147 |
+
}
|
| 148 |
+
|
| 149 |
+
/**
|
| 150 |
+
* Returns the singleton instance, which is used by the deprecated, static methods.
|
| 151 |
+
* This is mainly useful for code, which wants to support the new
|
| 152 |
+
* {@link FileCleaningTracker} class while maintain compatibility with the
|
| 153 |
+
* deprecated {@link FileCleaner}.
|
| 154 |
+
*
|
| 155 |
+
* @return the singleton instance
|
| 156 |
+
*/
|
| 157 |
+
public static FileCleaningTracker getInstance() {
|
| 158 |
+
return theInstance;
|
| 159 |
+
}
|
| 160 |
+
}
|
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/01_课件与电子教材/尚硅谷_第15章_File类与IO流/03-apache-common包/commons-io-2.5-src/src/main/java/org/apache/commons/io/FileCleaningTracker.java
ADDED
|
@@ -0,0 +1,288 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Licensed to the Apache Software Foundation (ASF) under one or more
|
| 3 |
+
* contributor license agreements. See the NOTICE file distributed with
|
| 4 |
+
* this work for additional information regarding copyright ownership.
|
| 5 |
+
* The ASF licenses this file to You under the Apache License, Version 2.0
|
| 6 |
+
* (the "License"); you may not use this file except in compliance with
|
| 7 |
+
* the License. You may obtain a copy of the License at
|
| 8 |
+
*
|
| 9 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
*
|
| 11 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 12 |
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
| 13 |
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 14 |
+
* See the License for the specific language governing permissions and
|
| 15 |
+
* limitations under the License.
|
| 16 |
+
*/
|
| 17 |
+
package org.apache.commons.io;
|
| 18 |
+
|
| 19 |
+
import java.io.File;
|
| 20 |
+
import java.lang.ref.PhantomReference;
|
| 21 |
+
import java.lang.ref.ReferenceQueue;
|
| 22 |
+
import java.util.ArrayList;
|
| 23 |
+
import java.util.Collection;
|
| 24 |
+
import java.util.Collections;
|
| 25 |
+
import java.util.HashSet;
|
| 26 |
+
import java.util.List;
|
| 27 |
+
|
| 28 |
+
/**
|
| 29 |
+
* Keeps track of files awaiting deletion, and deletes them when an associated
|
| 30 |
+
* marker object is reclaimed by the garbage collector.
|
| 31 |
+
* <p>
|
| 32 |
+
* This utility creates a background thread to handle file deletion.
|
| 33 |
+
* Each file to be deleted is registered with a handler object.
|
| 34 |
+
* When the handler object is garbage collected, the file is deleted.
|
| 35 |
+
* <p>
|
| 36 |
+
* In an environment with multiple class loaders (a servlet container, for
|
| 37 |
+
* example), you should consider stopping the background thread if it is no
|
| 38 |
+
* longer needed. This is done by invoking the method
|
| 39 |
+
* {@link #exitWhenFinished}, typically in
|
| 40 |
+
* {@code javax.servlet.ServletContextListener.contextDestroyed(javax.servlet.ServletContextEvent)} or similar.
|
| 41 |
+
*
|
| 42 |
+
* @version $Id: FileCleaningTracker.java 1686747 2015-06-21 18:44:49Z krosenvold $
|
| 43 |
+
*/
|
| 44 |
+
public class FileCleaningTracker {
|
| 45 |
+
|
| 46 |
+
// Note: fields are package protected to allow use by test cases
|
| 47 |
+
|
| 48 |
+
/**
|
| 49 |
+
* Queue of <code>Tracker</code> instances being watched.
|
| 50 |
+
*/
|
| 51 |
+
ReferenceQueue<Object> q = new ReferenceQueue<Object>();
|
| 52 |
+
/**
|
| 53 |
+
* Collection of <code>Tracker</code> instances in existence.
|
| 54 |
+
*/
|
| 55 |
+
final Collection<Tracker> trackers = Collections.synchronizedSet(new HashSet<Tracker>()); // synchronized
|
| 56 |
+
/**
|
| 57 |
+
* Collection of File paths that failed to delete.
|
| 58 |
+
*/
|
| 59 |
+
final List<String> deleteFailures = Collections.synchronizedList(new ArrayList<String>());
|
| 60 |
+
/**
|
| 61 |
+
* Whether to terminate the thread when the tracking is complete.
|
| 62 |
+
*/
|
| 63 |
+
volatile boolean exitWhenFinished = false;
|
| 64 |
+
/**
|
| 65 |
+
* The thread that will clean up registered files.
|
| 66 |
+
*/
|
| 67 |
+
Thread reaper;
|
| 68 |
+
|
| 69 |
+
//-----------------------------------------------------------------------
|
| 70 |
+
/**
|
| 71 |
+
* Track the specified file, using the provided marker, deleting the file
|
| 72 |
+
* when the marker instance is garbage collected.
|
| 73 |
+
* The {@link FileDeleteStrategy#NORMAL normal} deletion strategy will be used.
|
| 74 |
+
*
|
| 75 |
+
* @param file the file to be tracked, not null
|
| 76 |
+
* @param marker the marker object used to track the file, not null
|
| 77 |
+
* @throws NullPointerException if the file is null
|
| 78 |
+
*/
|
| 79 |
+
public void track(final File file, final Object marker) {
|
| 80 |
+
track(file, marker, null);
|
| 81 |
+
}
|
| 82 |
+
|
| 83 |
+
/**
|
| 84 |
+
* Track the specified file, using the provided marker, deleting the file
|
| 85 |
+
* when the marker instance is garbage collected.
|
| 86 |
+
* The speified deletion strategy is used.
|
| 87 |
+
*
|
| 88 |
+
* @param file the file to be tracked, not null
|
| 89 |
+
* @param marker the marker object used to track the file, not null
|
| 90 |
+
* @param deleteStrategy the strategy to delete the file, null means normal
|
| 91 |
+
* @throws NullPointerException if the file is null
|
| 92 |
+
*/
|
| 93 |
+
public void track(final File file, final Object marker, final FileDeleteStrategy deleteStrategy) {
|
| 94 |
+
if (file == null) {
|
| 95 |
+
throw new NullPointerException("The file must not be null");
|
| 96 |
+
}
|
| 97 |
+
addTracker(file.getPath(), marker, deleteStrategy);
|
| 98 |
+
}
|
| 99 |
+
|
| 100 |
+
/**
|
| 101 |
+
* Track the specified file, using the provided marker, deleting the file
|
| 102 |
+
* when the marker instance is garbage collected.
|
| 103 |
+
* The {@link FileDeleteStrategy#NORMAL normal} deletion strategy will be used.
|
| 104 |
+
*
|
| 105 |
+
* @param path the full path to the file to be tracked, not null
|
| 106 |
+
* @param marker the marker object used to track the file, not null
|
| 107 |
+
* @throws NullPointerException if the path is null
|
| 108 |
+
*/
|
| 109 |
+
public void track(final String path, final Object marker) {
|
| 110 |
+
track(path, marker, null);
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
+
/**
|
| 114 |
+
* Track the specified file, using the provided marker, deleting the file
|
| 115 |
+
* when the marker instance is garbage collected.
|
| 116 |
+
* The speified deletion strategy is used.
|
| 117 |
+
*
|
| 118 |
+
* @param path the full path to the file to be tracked, not null
|
| 119 |
+
* @param marker the marker object used to track the file, not null
|
| 120 |
+
* @param deleteStrategy the strategy to delete the file, null means normal
|
| 121 |
+
* @throws NullPointerException if the path is null
|
| 122 |
+
*/
|
| 123 |
+
public void track(final String path, final Object marker, final FileDeleteStrategy deleteStrategy) {
|
| 124 |
+
if (path == null) {
|
| 125 |
+
throw new NullPointerException("The path must not be null");
|
| 126 |
+
}
|
| 127 |
+
addTracker(path, marker, deleteStrategy);
|
| 128 |
+
}
|
| 129 |
+
|
| 130 |
+
/**
|
| 131 |
+
* Adds a tracker to the list of trackers.
|
| 132 |
+
*
|
| 133 |
+
* @param path the full path to the file to be tracked, not null
|
| 134 |
+
* @param marker the marker object used to track the file, not null
|
| 135 |
+
* @param deleteStrategy the strategy to delete the file, null means normal
|
| 136 |
+
*/
|
| 137 |
+
private synchronized void addTracker(final String path, final Object marker, final FileDeleteStrategy
|
| 138 |
+
deleteStrategy) {
|
| 139 |
+
// synchronized block protects reaper
|
| 140 |
+
if (exitWhenFinished) {
|
| 141 |
+
throw new IllegalStateException("No new trackers can be added once exitWhenFinished() is called");
|
| 142 |
+
}
|
| 143 |
+
if (reaper == null) {
|
| 144 |
+
reaper = new Reaper();
|
| 145 |
+
reaper.start();
|
| 146 |
+
}
|
| 147 |
+
trackers.add(new Tracker(path, deleteStrategy, marker, q));
|
| 148 |
+
}
|
| 149 |
+
|
| 150 |
+
//-----------------------------------------------------------------------
|
| 151 |
+
/**
|
| 152 |
+
* Retrieve the number of files currently being tracked, and therefore
|
| 153 |
+
* awaiting deletion.
|
| 154 |
+
*
|
| 155 |
+
* @return the number of files being tracked
|
| 156 |
+
*/
|
| 157 |
+
public int getTrackCount() {
|
| 158 |
+
return trackers.size();
|
| 159 |
+
}
|
| 160 |
+
|
| 161 |
+
/**
|
| 162 |
+
* Return the file paths that failed to delete.
|
| 163 |
+
*
|
| 164 |
+
* @return the file paths that failed to delete
|
| 165 |
+
* @since 2.0
|
| 166 |
+
*/
|
| 167 |
+
public List<String> getDeleteFailures() {
|
| 168 |
+
return deleteFailures;
|
| 169 |
+
}
|
| 170 |
+
|
| 171 |
+
/**
|
| 172 |
+
* Call this method to cause the file cleaner thread to terminate when
|
| 173 |
+
* there are no more objects being tracked for deletion.
|
| 174 |
+
* <p>
|
| 175 |
+
* In a simple environment, you don't need this method as the file cleaner
|
| 176 |
+
* thread will simply exit when the JVM exits. In a more complex environment,
|
| 177 |
+
* with multiple class loaders (such as an application server), you should be
|
| 178 |
+
* aware that the file cleaner thread will continue running even if the class
|
| 179 |
+
* loader it was started from terminates. This can consitute a memory leak.
|
| 180 |
+
* <p>
|
| 181 |
+
* For example, suppose that you have developed a web application, which
|
| 182 |
+
* contains the commons-io jar file in your WEB-INF/lib directory. In other
|
| 183 |
+
* words, the FileCleaner class is loaded through the class loader of your
|
| 184 |
+
* web application. If the web application is terminated, but the servlet
|
| 185 |
+
* container is still running, then the file cleaner thread will still exist,
|
| 186 |
+
* posing a memory leak.
|
| 187 |
+
* <p>
|
| 188 |
+
* This method allows the thread to be terminated. Simply call this method
|
| 189 |
+
* in the resource cleanup code, such as
|
| 190 |
+
* {@code javax.servlet.ServletContextListener.contextDestroyed(javax.servlet.ServletContextEvent)}.
|
| 191 |
+
* Once called, no new objects can be tracked by the file cleaner.
|
| 192 |
+
*/
|
| 193 |
+
public synchronized void exitWhenFinished() {
|
| 194 |
+
// synchronized block protects reaper
|
| 195 |
+
exitWhenFinished = true;
|
| 196 |
+
if (reaper != null) {
|
| 197 |
+
synchronized (reaper) {
|
| 198 |
+
reaper.interrupt();
|
| 199 |
+
}
|
| 200 |
+
}
|
| 201 |
+
}
|
| 202 |
+
|
| 203 |
+
//-----------------------------------------------------------------------
|
| 204 |
+
/**
|
| 205 |
+
* The reaper thread.
|
| 206 |
+
*/
|
| 207 |
+
private final class Reaper extends Thread {
|
| 208 |
+
/** Construct a new Reaper */
|
| 209 |
+
Reaper() {
|
| 210 |
+
super("File Reaper");
|
| 211 |
+
setPriority(Thread.MAX_PRIORITY);
|
| 212 |
+
setDaemon(true);
|
| 213 |
+
}
|
| 214 |
+
|
| 215 |
+
/**
|
| 216 |
+
* Run the reaper thread that will delete files as their associated
|
| 217 |
+
* marker objects are reclaimed by the garbage collector.
|
| 218 |
+
*/
|
| 219 |
+
@Override
|
| 220 |
+
public void run() {
|
| 221 |
+
// thread exits when exitWhenFinished is true and there are no more tracked objects
|
| 222 |
+
while (exitWhenFinished == false || trackers.size() > 0) {
|
| 223 |
+
try {
|
| 224 |
+
// Wait for a tracker to remove.
|
| 225 |
+
final Tracker tracker = (Tracker) q.remove(); // cannot return null
|
| 226 |
+
trackers.remove(tracker);
|
| 227 |
+
if (!tracker.delete()) {
|
| 228 |
+
deleteFailures.add(tracker.getPath());
|
| 229 |
+
}
|
| 230 |
+
tracker.clear();
|
| 231 |
+
} catch (final InterruptedException e) {
|
| 232 |
+
continue;
|
| 233 |
+
}
|
| 234 |
+
}
|
| 235 |
+
}
|
| 236 |
+
}
|
| 237 |
+
|
| 238 |
+
//-----------------------------------------------------------------------
|
| 239 |
+
/**
|
| 240 |
+
* Inner class which acts as the reference for a file pending deletion.
|
| 241 |
+
*/
|
| 242 |
+
private static final class Tracker extends PhantomReference<Object> {
|
| 243 |
+
|
| 244 |
+
/**
|
| 245 |
+
* The full path to the file being tracked.
|
| 246 |
+
*/
|
| 247 |
+
private final String path;
|
| 248 |
+
/**
|
| 249 |
+
* The strategy for deleting files.
|
| 250 |
+
*/
|
| 251 |
+
private final FileDeleteStrategy deleteStrategy;
|
| 252 |
+
|
| 253 |
+
/**
|
| 254 |
+
* Constructs an instance of this class from the supplied parameters.
|
| 255 |
+
*
|
| 256 |
+
* @param path the full path to the file to be tracked, not null
|
| 257 |
+
* @param deleteStrategy the strategy to delete the file, null means normal
|
| 258 |
+
* @param marker the marker object used to track the file, not null
|
| 259 |
+
* @param queue the queue on to which the tracker will be pushed, not null
|
| 260 |
+
*/
|
| 261 |
+
Tracker(final String path, final FileDeleteStrategy deleteStrategy, final Object marker,
|
| 262 |
+
final ReferenceQueue<? super Object> queue) {
|
| 263 |
+
super(marker, queue);
|
| 264 |
+
this.path = path;
|
| 265 |
+
this.deleteStrategy = deleteStrategy == null ? FileDeleteStrategy.NORMAL : deleteStrategy;
|
| 266 |
+
}
|
| 267 |
+
|
| 268 |
+
/**
|
| 269 |
+
* Return the path.
|
| 270 |
+
*
|
| 271 |
+
* @return the path
|
| 272 |
+
*/
|
| 273 |
+
public String getPath() {
|
| 274 |
+
return path;
|
| 275 |
+
}
|
| 276 |
+
|
| 277 |
+
/**
|
| 278 |
+
* Deletes the file associated with this tracker instance.
|
| 279 |
+
*
|
| 280 |
+
* @return {@code true} if the file was deleted successfully;
|
| 281 |
+
* {@code false} otherwise.
|
| 282 |
+
*/
|
| 283 |
+
public boolean delete() {
|
| 284 |
+
return deleteStrategy.deleteQuietly(new File(path));
|
| 285 |
+
}
|
| 286 |
+
}
|
| 287 |
+
|
| 288 |
+
}
|
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/01_课件与电子教材/尚硅谷_第15章_File类与IO流/03-apache-common包/commons-io-2.5-src/src/main/java/org/apache/commons/io/FileDeleteStrategy.java
ADDED
|
@@ -0,0 +1,157 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Licensed to the Apache Software Foundation (ASF) under one or more
|
| 3 |
+
* contributor license agreements. See the NOTICE file distributed with
|
| 4 |
+
* this work for additional information regarding copyright ownership.
|
| 5 |
+
* The ASF licenses this file to You under the Apache License, Version 2.0
|
| 6 |
+
* (the "License"); you may not use this file except in compliance with
|
| 7 |
+
* the License. You may obtain a copy of the License at
|
| 8 |
+
*
|
| 9 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
*
|
| 11 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 12 |
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
| 13 |
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 14 |
+
* See the License for the specific language governing permissions and
|
| 15 |
+
* limitations under the License.
|
| 16 |
+
*/
|
| 17 |
+
package org.apache.commons.io;
|
| 18 |
+
|
| 19 |
+
import java.io.File;
|
| 20 |
+
import java.io.IOException;
|
| 21 |
+
|
| 22 |
+
/**
|
| 23 |
+
* Strategy for deleting files.
|
| 24 |
+
* <p>
|
| 25 |
+
* There is more than one way to delete a file.
|
| 26 |
+
* You may want to limit access to certain directories, to only delete
|
| 27 |
+
* directories if they are empty, or maybe to force deletion.
|
| 28 |
+
* <p>
|
| 29 |
+
* This class captures the strategy to use and is designed for user subclassing.
|
| 30 |
+
*
|
| 31 |
+
* @version $Id: FileDeleteStrategy.java 1563227 2014-01-31 19:45:30Z ggregory $
|
| 32 |
+
* @since 1.3
|
| 33 |
+
*/
|
| 34 |
+
public class FileDeleteStrategy {
|
| 35 |
+
|
| 36 |
+
/**
|
| 37 |
+
* The singleton instance for normal file deletion, which does not permit
|
| 38 |
+
* the deletion of directories that are not empty.
|
| 39 |
+
*/
|
| 40 |
+
public static final FileDeleteStrategy NORMAL = new FileDeleteStrategy("Normal");
|
| 41 |
+
/**
|
| 42 |
+
* The singleton instance for forced file deletion, which always deletes,
|
| 43 |
+
* even if the file represents a non-empty directory.
|
| 44 |
+
*/
|
| 45 |
+
public static final FileDeleteStrategy FORCE = new ForceFileDeleteStrategy();
|
| 46 |
+
|
| 47 |
+
/** The name of the strategy. */
|
| 48 |
+
private final String name;
|
| 49 |
+
|
| 50 |
+
//-----------------------------------------------------------------------
|
| 51 |
+
/**
|
| 52 |
+
* Restricted constructor.
|
| 53 |
+
*
|
| 54 |
+
* @param name the name by which the strategy is known
|
| 55 |
+
*/
|
| 56 |
+
protected FileDeleteStrategy(final String name) {
|
| 57 |
+
this.name = name;
|
| 58 |
+
}
|
| 59 |
+
|
| 60 |
+
//-----------------------------------------------------------------------
|
| 61 |
+
/**
|
| 62 |
+
* Deletes the file object, which may be a file or a directory.
|
| 63 |
+
* All <code>IOException</code>s are caught and false returned instead.
|
| 64 |
+
* If the file does not exist or is null, true is returned.
|
| 65 |
+
* <p>
|
| 66 |
+
* Subclass writers should override {@link #doDelete(File)}, not this method.
|
| 67 |
+
*
|
| 68 |
+
* @param fileToDelete the file to delete, null returns true
|
| 69 |
+
* @return true if the file was deleted, or there was no such file
|
| 70 |
+
*/
|
| 71 |
+
public boolean deleteQuietly(final File fileToDelete) {
|
| 72 |
+
if (fileToDelete == null || fileToDelete.exists() == false) {
|
| 73 |
+
return true;
|
| 74 |
+
}
|
| 75 |
+
try {
|
| 76 |
+
return doDelete(fileToDelete);
|
| 77 |
+
} catch (final IOException ex) {
|
| 78 |
+
return false;
|
| 79 |
+
}
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
+
/**
|
| 83 |
+
* Deletes the file object, which may be a file or a directory.
|
| 84 |
+
* If the file does not exist, the method just returns.
|
| 85 |
+
* <p>
|
| 86 |
+
* Subclass writers should override {@link #doDelete(File)}, not this method.
|
| 87 |
+
*
|
| 88 |
+
* @param fileToDelete the file to delete, not null
|
| 89 |
+
* @throws NullPointerException if the file is null
|
| 90 |
+
* @throws IOException if an error occurs during file deletion
|
| 91 |
+
*/
|
| 92 |
+
public void delete(final File fileToDelete) throws IOException {
|
| 93 |
+
if (fileToDelete.exists() && doDelete(fileToDelete) == false) {
|
| 94 |
+
throw new IOException("Deletion failed: " + fileToDelete);
|
| 95 |
+
}
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
/**
|
| 99 |
+
* Actually deletes the file object, which may be a file or a directory.
|
| 100 |
+
* <p>
|
| 101 |
+
* This method is designed for subclasses to override.
|
| 102 |
+
* The implementation may return either false or an <code>IOException</code>
|
| 103 |
+
* when deletion fails. The {@link #delete(File)} and {@link #deleteQuietly(File)}
|
| 104 |
+
* methods will handle either response appropriately.
|
| 105 |
+
* A check has been made to ensure that the file will exist.
|
| 106 |
+
* <p>
|
| 107 |
+
* This implementation uses {@link File#delete()}.
|
| 108 |
+
*
|
| 109 |
+
* @param fileToDelete the file to delete, exists, not null
|
| 110 |
+
* @return true if the file was deleteds
|
| 111 |
+
* @throws NullPointerException if the file is null
|
| 112 |
+
* @throws IOException if an error occurs during file deletion
|
| 113 |
+
*/
|
| 114 |
+
protected boolean doDelete(final File fileToDelete) throws IOException {
|
| 115 |
+
return fileToDelete.delete();
|
| 116 |
+
}
|
| 117 |
+
|
| 118 |
+
//-----------------------------------------------------------------------
|
| 119 |
+
/**
|
| 120 |
+
* Gets a string describing the delete strategy.
|
| 121 |
+
*
|
| 122 |
+
* @return a string describing the delete strategy
|
| 123 |
+
*/
|
| 124 |
+
@Override
|
| 125 |
+
public String toString() {
|
| 126 |
+
return "FileDeleteStrategy[" + name + "]";
|
| 127 |
+
}
|
| 128 |
+
|
| 129 |
+
//-----------------------------------------------------------------------
|
| 130 |
+
/**
|
| 131 |
+
* Force file deletion strategy.
|
| 132 |
+
*/
|
| 133 |
+
static class ForceFileDeleteStrategy extends FileDeleteStrategy {
|
| 134 |
+
/** Default Constructor */
|
| 135 |
+
ForceFileDeleteStrategy() {
|
| 136 |
+
super("Force");
|
| 137 |
+
}
|
| 138 |
+
|
| 139 |
+
/**
|
| 140 |
+
* Deletes the file object.
|
| 141 |
+
* <p>
|
| 142 |
+
* This implementation uses <code>FileUtils.forceDelete()</code>
|
| 143 |
+
* if the file exists.
|
| 144 |
+
*
|
| 145 |
+
* @param fileToDelete the file to delete, not null
|
| 146 |
+
* @return Always returns {@code true}
|
| 147 |
+
* @throws NullPointerException if the file is null
|
| 148 |
+
* @throws IOException if an error occurs during file deletion
|
| 149 |
+
*/
|
| 150 |
+
@Override
|
| 151 |
+
protected boolean doDelete(final File fileToDelete) throws IOException {
|
| 152 |
+
FileUtils.forceDelete(fileToDelete);
|
| 153 |
+
return true;
|
| 154 |
+
}
|
| 155 |
+
}
|
| 156 |
+
|
| 157 |
+
}
|
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/01_课件与电子教材/尚硅谷_第15章_File类与IO流/03-apache-common包/commons-io-2.5-src/src/main/java/org/apache/commons/io/FileExistsException.java
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Licensed to the Apache Software Foundation (ASF) under one or more
|
| 3 |
+
* contributor license agreements. See the NOTICE file distributed with
|
| 4 |
+
* this work for additional information regarding copyright ownership.
|
| 5 |
+
* The ASF licenses this file to You under the Apache License, Version 2.0
|
| 6 |
+
* (the "License"); you may not use this file except in compliance with
|
| 7 |
+
* the License. You may obtain a copy of the License at
|
| 8 |
+
*
|
| 9 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
*
|
| 11 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 12 |
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
| 13 |
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 14 |
+
* See the License for the specific language governing permissions and
|
| 15 |
+
* limitations under the License.
|
| 16 |
+
*/
|
| 17 |
+
package org.apache.commons.io;
|
| 18 |
+
|
| 19 |
+
import java.io.File;
|
| 20 |
+
import java.io.IOException;
|
| 21 |
+
|
| 22 |
+
/**
|
| 23 |
+
* Indicates that a file already exists.
|
| 24 |
+
*
|
| 25 |
+
* @version $Id: FileExistsException.java 1415850 2012-11-30 20:51:39Z ggregory $
|
| 26 |
+
* @since 2.0
|
| 27 |
+
*/
|
| 28 |
+
public class FileExistsException extends IOException {
|
| 29 |
+
|
| 30 |
+
/**
|
| 31 |
+
* Defines the serial version UID.
|
| 32 |
+
*/
|
| 33 |
+
private static final long serialVersionUID = 1L;
|
| 34 |
+
|
| 35 |
+
/**
|
| 36 |
+
* Default Constructor.
|
| 37 |
+
*/
|
| 38 |
+
public FileExistsException() {
|
| 39 |
+
super();
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
/**
|
| 43 |
+
* Construct an instance with the specified message.
|
| 44 |
+
*
|
| 45 |
+
* @param message The error message
|
| 46 |
+
*/
|
| 47 |
+
public FileExistsException(final String message) {
|
| 48 |
+
super(message);
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
/**
|
| 52 |
+
* Construct an instance with the specified file.
|
| 53 |
+
*
|
| 54 |
+
* @param file The file that exists
|
| 55 |
+
*/
|
| 56 |
+
public FileExistsException(final File file) {
|
| 57 |
+
super("File " + file + " exists");
|
| 58 |
+
}
|
| 59 |
+
|
| 60 |
+
}
|
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/01_课件与电子教材/尚硅谷_第15章_File类与IO流/03-apache-common包/commons-io-2.5-src/src/main/java/org/apache/commons/io/FileSystemUtils.java
ADDED
|
@@ -0,0 +1,541 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Licensed to the Apache Software Foundation (ASF) under one or more
|
| 3 |
+
* contributor license agreements. See the NOTICE file distributed with
|
| 4 |
+
* this work for additional information regarding copyright ownership.
|
| 5 |
+
* The ASF licenses this file to You under the Apache License, Version 2.0
|
| 6 |
+
* (the "License"); you may not use this file except in compliance with
|
| 7 |
+
* the License. You may obtain a copy of the License at
|
| 8 |
+
*
|
| 9 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
*
|
| 11 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 12 |
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
| 13 |
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 14 |
+
* See the License for the specific language governing permissions and
|
| 15 |
+
* limitations under the License.
|
| 16 |
+
*/
|
| 17 |
+
package org.apache.commons.io;
|
| 18 |
+
|
| 19 |
+
import java.io.BufferedReader;
|
| 20 |
+
import java.io.File;
|
| 21 |
+
import java.io.IOException;
|
| 22 |
+
import java.io.InputStream;
|
| 23 |
+
import java.io.InputStreamReader;
|
| 24 |
+
import java.io.OutputStream;
|
| 25 |
+
import java.nio.charset.Charset;
|
| 26 |
+
import java.util.ArrayList;
|
| 27 |
+
import java.util.Arrays;
|
| 28 |
+
import java.util.List;
|
| 29 |
+
import java.util.Locale;
|
| 30 |
+
import java.util.StringTokenizer;
|
| 31 |
+
|
| 32 |
+
/**
|
| 33 |
+
* General File System utilities.
|
| 34 |
+
* <p>
|
| 35 |
+
* This class provides static utility methods for general file system
|
| 36 |
+
* functions not provided via the JDK {@link java.io.File File} class.
|
| 37 |
+
* <p>
|
| 38 |
+
* The current functions provided are:
|
| 39 |
+
* <ul>
|
| 40 |
+
* <li>Get the free space on a drive
|
| 41 |
+
* </ul>
|
| 42 |
+
*
|
| 43 |
+
* @version $Id: FileSystemUtils.java 1686747 2015-06-21 18:44:49Z krosenvold $
|
| 44 |
+
* @since 1.1
|
| 45 |
+
*/
|
| 46 |
+
public class FileSystemUtils {
|
| 47 |
+
|
| 48 |
+
/** Singleton instance, used mainly for testing. */
|
| 49 |
+
private static final FileSystemUtils INSTANCE = new FileSystemUtils();
|
| 50 |
+
|
| 51 |
+
/** Operating system state flag for error. */
|
| 52 |
+
private static final int INIT_PROBLEM = -1;
|
| 53 |
+
/** Operating system state flag for neither Unix nor Windows. */
|
| 54 |
+
private static final int OTHER = 0;
|
| 55 |
+
/** Operating system state flag for Windows. */
|
| 56 |
+
private static final int WINDOWS = 1;
|
| 57 |
+
/** Operating system state flag for Unix. */
|
| 58 |
+
private static final int UNIX = 2;
|
| 59 |
+
/** Operating system state flag for Posix flavour Unix. */
|
| 60 |
+
private static final int POSIX_UNIX = 3;
|
| 61 |
+
|
| 62 |
+
/** The operating system flag. */
|
| 63 |
+
private static final int OS;
|
| 64 |
+
|
| 65 |
+
/** The path to df */
|
| 66 |
+
private static final String DF;
|
| 67 |
+
|
| 68 |
+
static {
|
| 69 |
+
int os = OTHER;
|
| 70 |
+
String dfPath = "df";
|
| 71 |
+
try {
|
| 72 |
+
String osName = System.getProperty("os.name");
|
| 73 |
+
if (osName == null) {
|
| 74 |
+
throw new IOException("os.name not found");
|
| 75 |
+
}
|
| 76 |
+
osName = osName.toLowerCase(Locale.ENGLISH);
|
| 77 |
+
// match
|
| 78 |
+
if (osName.contains("windows")) {
|
| 79 |
+
os = WINDOWS;
|
| 80 |
+
} else if (osName.contains("linux") ||
|
| 81 |
+
osName.contains("mpe/ix") ||
|
| 82 |
+
osName.contains("freebsd") ||
|
| 83 |
+
osName.contains("irix") ||
|
| 84 |
+
osName.contains("digital unix") ||
|
| 85 |
+
osName.contains("unix") ||
|
| 86 |
+
osName.contains("mac os x")) {
|
| 87 |
+
os = UNIX;
|
| 88 |
+
} else if (osName.contains("sun os") ||
|
| 89 |
+
osName.contains("sunos") ||
|
| 90 |
+
osName.contains("solaris")) {
|
| 91 |
+
os = POSIX_UNIX;
|
| 92 |
+
dfPath = "/usr/xpg4/bin/df";
|
| 93 |
+
} else if (osName.contains("hp-ux") ||
|
| 94 |
+
osName.contains("aix")) {
|
| 95 |
+
os = POSIX_UNIX;
|
| 96 |
+
} else {
|
| 97 |
+
os = OTHER;
|
| 98 |
+
}
|
| 99 |
+
|
| 100 |
+
} catch (final Exception ex) {
|
| 101 |
+
os = INIT_PROBLEM;
|
| 102 |
+
}
|
| 103 |
+
OS = os;
|
| 104 |
+
DF = dfPath;
|
| 105 |
+
}
|
| 106 |
+
|
| 107 |
+
/**
|
| 108 |
+
* Instances should NOT be constructed in standard programming.
|
| 109 |
+
*/
|
| 110 |
+
public FileSystemUtils() {
|
| 111 |
+
super();
|
| 112 |
+
}
|
| 113 |
+
|
| 114 |
+
//-----------------------------------------------------------------------
|
| 115 |
+
/**
|
| 116 |
+
* Returns the free space on a drive or volume by invoking
|
| 117 |
+
* the command line.
|
| 118 |
+
* This method does not normalize the result, and typically returns
|
| 119 |
+
* bytes on Windows, 512 byte units on OS X and kilobytes on Unix.
|
| 120 |
+
* As this is not very useful, this method is deprecated in favour
|
| 121 |
+
* of {@link #freeSpaceKb(String)} which returns a result in kilobytes.
|
| 122 |
+
* <p>
|
| 123 |
+
* Note that some OS's are NOT currently supported, including OS/390,
|
| 124 |
+
* OpenVMS.
|
| 125 |
+
* <pre>
|
| 126 |
+
* FileSystemUtils.freeSpace("C:"); // Windows
|
| 127 |
+
* FileSystemUtils.freeSpace("/volume"); // *nix
|
| 128 |
+
* </pre>
|
| 129 |
+
* The free space is calculated via the command line.
|
| 130 |
+
* It uses 'dir /-c' on Windows and 'df' on *nix.
|
| 131 |
+
*
|
| 132 |
+
* @param path the path to get free space for, not null, not empty on Unix
|
| 133 |
+
* @return the amount of free drive space on the drive or volume
|
| 134 |
+
* @throws IllegalArgumentException if the path is invalid
|
| 135 |
+
* @throws IllegalStateException if an error occurred in initialisation
|
| 136 |
+
* @throws IOException if an error occurs when finding the free space
|
| 137 |
+
* @since 1.1, enhanced OS support in 1.2 and 1.3
|
| 138 |
+
* @deprecated Use freeSpaceKb(String)
|
| 139 |
+
* Deprecated from 1.3, may be removed in 2.0
|
| 140 |
+
*/
|
| 141 |
+
@Deprecated
|
| 142 |
+
public static long freeSpace(final String path) throws IOException {
|
| 143 |
+
return INSTANCE.freeSpaceOS(path, OS, false, -1);
|
| 144 |
+
}
|
| 145 |
+
|
| 146 |
+
//-----------------------------------------------------------------------
|
| 147 |
+
/**
|
| 148 |
+
* Returns the free space on a drive or volume in kilobytes by invoking
|
| 149 |
+
* the command line.
|
| 150 |
+
* <pre>
|
| 151 |
+
* FileSystemUtils.freeSpaceKb("C:"); // Windows
|
| 152 |
+
* FileSystemUtils.freeSpaceKb("/volume"); // *nix
|
| 153 |
+
* </pre>
|
| 154 |
+
* The free space is calculated via the command line.
|
| 155 |
+
* It uses 'dir /-c' on Windows, 'df -kP' on AIX/HP-UX and 'df -k' on other Unix.
|
| 156 |
+
* <p>
|
| 157 |
+
* In order to work, you must be running Windows, or have a implementation of
|
| 158 |
+
* Unix df that supports GNU format when passed -k (or -kP). If you are going
|
| 159 |
+
* to rely on this code, please check that it works on your OS by running
|
| 160 |
+
* some simple tests to compare the command line with the output from this class.
|
| 161 |
+
* If your operating system isn't supported, please raise a JIRA call detailing
|
| 162 |
+
* the exact result from df -k and as much other detail as possible, thanks.
|
| 163 |
+
*
|
| 164 |
+
* @param path the path to get free space for, not null, not empty on Unix
|
| 165 |
+
* @return the amount of free drive space on the drive or volume in kilobytes
|
| 166 |
+
* @throws IllegalArgumentException if the path is invalid
|
| 167 |
+
* @throws IllegalStateException if an error occurred in initialisation
|
| 168 |
+
* @throws IOException if an error occurs when finding the free space
|
| 169 |
+
* @since 1.2, enhanced OS support in 1.3
|
| 170 |
+
*/
|
| 171 |
+
public static long freeSpaceKb(final String path) throws IOException {
|
| 172 |
+
return freeSpaceKb(path, -1);
|
| 173 |
+
}
|
| 174 |
+
/**
|
| 175 |
+
* Returns the free space on a drive or volume in kilobytes by invoking
|
| 176 |
+
* the command line.
|
| 177 |
+
* <pre>
|
| 178 |
+
* FileSystemUtils.freeSpaceKb("C:"); // Windows
|
| 179 |
+
* FileSystemUtils.freeSpaceKb("/volume"); // *nix
|
| 180 |
+
* </pre>
|
| 181 |
+
* The free space is calculated via the command line.
|
| 182 |
+
* It uses 'dir /-c' on Windows, 'df -kP' on AIX/HP-UX and 'df -k' on other Unix.
|
| 183 |
+
* <p>
|
| 184 |
+
* In order to work, you must be running Windows, or have a implementation of
|
| 185 |
+
* Unix df that supports GNU format when passed -k (or -kP). If you are going
|
| 186 |
+
* to rely on this code, please check that it works on your OS by running
|
| 187 |
+
* some simple tests to compare the command line with the output from this class.
|
| 188 |
+
* If your operating system isn't supported, please raise a JIRA call detailing
|
| 189 |
+
* the exact result from df -k and as much other detail as possible, thanks.
|
| 190 |
+
*
|
| 191 |
+
* @param path the path to get free space for, not null, not empty on Unix
|
| 192 |
+
* @param timeout The timeout amount in milliseconds or no timeout if the value
|
| 193 |
+
* is zero or less
|
| 194 |
+
* @return the amount of free drive space on the drive or volume in kilobytes
|
| 195 |
+
* @throws IllegalArgumentException if the path is invalid
|
| 196 |
+
* @throws IllegalStateException if an error occurred in initialisation
|
| 197 |
+
* @throws IOException if an error occurs when finding the free space
|
| 198 |
+
* @since 2.0
|
| 199 |
+
*/
|
| 200 |
+
public static long freeSpaceKb(final String path, final long timeout) throws IOException {
|
| 201 |
+
return INSTANCE.freeSpaceOS(path, OS, true, timeout);
|
| 202 |
+
}
|
| 203 |
+
|
| 204 |
+
/**
|
| 205 |
+
* Returns the disk size of the volume which holds the working directory.
|
| 206 |
+
* <p>
|
| 207 |
+
* Identical to:
|
| 208 |
+
* <pre>
|
| 209 |
+
* freeSpaceKb(new File(".").getAbsolutePath())
|
| 210 |
+
* </pre>
|
| 211 |
+
* @return the amount of free drive space on the drive or volume in kilobytes
|
| 212 |
+
* @throws IllegalStateException if an error occurred in initialisation
|
| 213 |
+
* @throws IOException if an error occurs when finding the free space
|
| 214 |
+
* @since 2.0
|
| 215 |
+
*/
|
| 216 |
+
public static long freeSpaceKb() throws IOException {
|
| 217 |
+
return freeSpaceKb(-1);
|
| 218 |
+
}
|
| 219 |
+
|
| 220 |
+
/**
|
| 221 |
+
* Returns the disk size of the volume which holds the working directory.
|
| 222 |
+
* <p>
|
| 223 |
+
* Identical to:
|
| 224 |
+
* <pre>
|
| 225 |
+
* freeSpaceKb(new File(".").getAbsolutePath())
|
| 226 |
+
* </pre>
|
| 227 |
+
* @param timeout The timeout amount in milliseconds or no timeout if the value
|
| 228 |
+
* is zero or less
|
| 229 |
+
* @return the amount of free drive space on the drive or volume in kilobytes
|
| 230 |
+
* @throws IllegalStateException if an error occurred in initialisation
|
| 231 |
+
* @throws IOException if an error occurs when finding the free space
|
| 232 |
+
* @since 2.0
|
| 233 |
+
*/
|
| 234 |
+
public static long freeSpaceKb(final long timeout) throws IOException {
|
| 235 |
+
return freeSpaceKb(new File(".").getAbsolutePath(), timeout);
|
| 236 |
+
}
|
| 237 |
+
|
| 238 |
+
//-----------------------------------------------------------------------
|
| 239 |
+
/**
|
| 240 |
+
* Returns the free space on a drive or volume in a cross-platform manner.
|
| 241 |
+
* Note that some OS's are NOT currently supported, including OS/390.
|
| 242 |
+
* <pre>
|
| 243 |
+
* FileSystemUtils.freeSpace("C:"); // Windows
|
| 244 |
+
* FileSystemUtils.freeSpace("/volume"); // *nix
|
| 245 |
+
* </pre>
|
| 246 |
+
* The free space is calculated via the command line.
|
| 247 |
+
* It uses 'dir /-c' on Windows and 'df' on *nix.
|
| 248 |
+
*
|
| 249 |
+
* @param path the path to get free space for, not null, not empty on Unix
|
| 250 |
+
* @param os the operating system code
|
| 251 |
+
* @param kb whether to normalize to kilobytes
|
| 252 |
+
* @param timeout The timeout amount in milliseconds or no timeout if the value
|
| 253 |
+
* is zero or less
|
| 254 |
+
* @return the amount of free drive space on the drive or volume
|
| 255 |
+
* @throws IllegalArgumentException if the path is invalid
|
| 256 |
+
* @throws IllegalStateException if an error occurred in initialisation
|
| 257 |
+
* @throws IOException if an error occurs when finding the free space
|
| 258 |
+
*/
|
| 259 |
+
long freeSpaceOS(final String path, final int os, final boolean kb, final long timeout) throws IOException {
|
| 260 |
+
if (path == null) {
|
| 261 |
+
throw new IllegalArgumentException("Path must not be null");
|
| 262 |
+
}
|
| 263 |
+
switch (os) {
|
| 264 |
+
case WINDOWS:
|
| 265 |
+
return kb ? freeSpaceWindows(path, timeout) / FileUtils.ONE_KB : freeSpaceWindows(path, timeout);
|
| 266 |
+
case UNIX:
|
| 267 |
+
return freeSpaceUnix(path, kb, false, timeout);
|
| 268 |
+
case POSIX_UNIX:
|
| 269 |
+
return freeSpaceUnix(path, kb, true, timeout);
|
| 270 |
+
case OTHER:
|
| 271 |
+
throw new IllegalStateException("Unsupported operating system");
|
| 272 |
+
default:
|
| 273 |
+
throw new IllegalStateException(
|
| 274 |
+
"Exception caught when determining operating system");
|
| 275 |
+
}
|
| 276 |
+
}
|
| 277 |
+
|
| 278 |
+
//-----------------------------------------------------------------------
|
| 279 |
+
/**
|
| 280 |
+
* Find free space on the Windows platform using the 'dir' command.
|
| 281 |
+
*
|
| 282 |
+
* @param path the path to get free space for, including the colon
|
| 283 |
+
* @param timeout The timeout amount in milliseconds or no timeout if the value
|
| 284 |
+
* is zero or less
|
| 285 |
+
* @return the amount of free drive space on the drive
|
| 286 |
+
* @throws IOException if an error occurs
|
| 287 |
+
*/
|
| 288 |
+
long freeSpaceWindows(String path, final long timeout) throws IOException {
|
| 289 |
+
path = FilenameUtils.normalize(path, false);
|
| 290 |
+
if (path.length() > 0 && path.charAt(0) != '"') {
|
| 291 |
+
path = "\"" + path + "\"";
|
| 292 |
+
}
|
| 293 |
+
|
| 294 |
+
// build and run the 'dir' command
|
| 295 |
+
final String[] cmdAttribs = new String[] {"cmd.exe", "/C", "dir /a /-c " + path};
|
| 296 |
+
|
| 297 |
+
// read in the output of the command to an ArrayList
|
| 298 |
+
final List<String> lines = performCommand(cmdAttribs, Integer.MAX_VALUE, timeout);
|
| 299 |
+
|
| 300 |
+
// now iterate over the lines we just read and find the LAST
|
| 301 |
+
// non-empty line (the free space bytes should be in the last element
|
| 302 |
+
// of the ArrayList anyway, but this will ensure it works even if it's
|
| 303 |
+
// not, still assuming it is on the last non-blank line)
|
| 304 |
+
for (int i = lines.size() - 1; i >= 0; i--) {
|
| 305 |
+
final String line = lines.get(i);
|
| 306 |
+
if (line.length() > 0) {
|
| 307 |
+
return parseDir(line, path);
|
| 308 |
+
}
|
| 309 |
+
}
|
| 310 |
+
// all lines are blank
|
| 311 |
+
throw new IOException(
|
| 312 |
+
"Command line 'dir /-c' did not return any info " +
|
| 313 |
+
"for path '" + path + "'");
|
| 314 |
+
}
|
| 315 |
+
|
| 316 |
+
/**
|
| 317 |
+
* Parses the Windows dir response last line
|
| 318 |
+
*
|
| 319 |
+
* @param line the line to parse
|
| 320 |
+
* @param path the path that was sent
|
| 321 |
+
* @return the number of bytes
|
| 322 |
+
* @throws IOException if an error occurs
|
| 323 |
+
*/
|
| 324 |
+
long parseDir(final String line, final String path) throws IOException {
|
| 325 |
+
// read from the end of the line to find the last numeric
|
| 326 |
+
// character on the line, then continue until we find the first
|
| 327 |
+
// non-numeric character, and everything between that and the last
|
| 328 |
+
// numeric character inclusive is our free space bytes count
|
| 329 |
+
int bytesStart = 0;
|
| 330 |
+
int bytesEnd = 0;
|
| 331 |
+
int j = line.length() - 1;
|
| 332 |
+
innerLoop1: while (j >= 0) {
|
| 333 |
+
final char c = line.charAt(j);
|
| 334 |
+
if (Character.isDigit(c)) {
|
| 335 |
+
// found the last numeric character, this is the end of
|
| 336 |
+
// the free space bytes count
|
| 337 |
+
bytesEnd = j + 1;
|
| 338 |
+
break innerLoop1;
|
| 339 |
+
}
|
| 340 |
+
j--;
|
| 341 |
+
}
|
| 342 |
+
innerLoop2: while (j >= 0) {
|
| 343 |
+
final char c = line.charAt(j);
|
| 344 |
+
if (!Character.isDigit(c) && c != ',' && c != '.') {
|
| 345 |
+
// found the next non-numeric character, this is the
|
| 346 |
+
// beginning of the free space bytes count
|
| 347 |
+
bytesStart = j + 1;
|
| 348 |
+
break innerLoop2;
|
| 349 |
+
}
|
| 350 |
+
j--;
|
| 351 |
+
}
|
| 352 |
+
if (j < 0) {
|
| 353 |
+
throw new IOException(
|
| 354 |
+
"Command line 'dir /-c' did not return valid info " +
|
| 355 |
+
"for path '" + path + "'");
|
| 356 |
+
}
|
| 357 |
+
|
| 358 |
+
// remove commas and dots in the bytes count
|
| 359 |
+
final StringBuilder buf = new StringBuilder(line.substring(bytesStart, bytesEnd));
|
| 360 |
+
for (int k = 0; k < buf.length(); k++) {
|
| 361 |
+
if (buf.charAt(k) == ',' || buf.charAt(k) == '.') {
|
| 362 |
+
buf.deleteCharAt(k--);
|
| 363 |
+
}
|
| 364 |
+
}
|
| 365 |
+
return parseBytes(buf.toString(), path);
|
| 366 |
+
}
|
| 367 |
+
|
| 368 |
+
//-----------------------------------------------------------------------
|
| 369 |
+
/**
|
| 370 |
+
* Find free space on the *nix platform using the 'df' command.
|
| 371 |
+
*
|
| 372 |
+
* @param path the path to get free space for
|
| 373 |
+
* @param kb whether to normalize to kilobytes
|
| 374 |
+
* @param posix whether to use the POSIX standard format flag
|
| 375 |
+
* @param timeout The timeout amount in milliseconds or no timeout if the value
|
| 376 |
+
* is zero or less
|
| 377 |
+
* @return the amount of free drive space on the volume
|
| 378 |
+
* @throws IOException if an error occurs
|
| 379 |
+
*/
|
| 380 |
+
long freeSpaceUnix(final String path, final boolean kb, final boolean posix, final long timeout)
|
| 381 |
+
throws IOException {
|
| 382 |
+
if (path.isEmpty()) {
|
| 383 |
+
throw new IllegalArgumentException("Path must not be empty");
|
| 384 |
+
}
|
| 385 |
+
|
| 386 |
+
// build and run the 'dir' command
|
| 387 |
+
String flags = "-";
|
| 388 |
+
if (kb) {
|
| 389 |
+
flags += "k";
|
| 390 |
+
}
|
| 391 |
+
if (posix) {
|
| 392 |
+
flags += "P";
|
| 393 |
+
}
|
| 394 |
+
final String[] cmdAttribs =
|
| 395 |
+
flags.length() > 1 ? new String[] {DF, flags, path} : new String[] {DF, path};
|
| 396 |
+
|
| 397 |
+
// perform the command, asking for up to 3 lines (header, interesting, overflow)
|
| 398 |
+
final List<String> lines = performCommand(cmdAttribs, 3, timeout);
|
| 399 |
+
if (lines.size() < 2) {
|
| 400 |
+
// unknown problem, throw exception
|
| 401 |
+
throw new IOException(
|
| 402 |
+
"Command line '" + DF + "' did not return info as expected " +
|
| 403 |
+
"for path '" + path + "'- response was " + lines);
|
| 404 |
+
}
|
| 405 |
+
final String line2 = lines.get(1); // the line we're interested in
|
| 406 |
+
|
| 407 |
+
// Now, we tokenize the string. The fourth element is what we want.
|
| 408 |
+
StringTokenizer tok = new StringTokenizer(line2, " ");
|
| 409 |
+
if (tok.countTokens() < 4) {
|
| 410 |
+
// could be long Filesystem, thus data on third line
|
| 411 |
+
if (tok.countTokens() == 1 && lines.size() >= 3) {
|
| 412 |
+
final String line3 = lines.get(2); // the line may be interested in
|
| 413 |
+
tok = new StringTokenizer(line3, " ");
|
| 414 |
+
} else {
|
| 415 |
+
throw new IOException(
|
| 416 |
+
"Command line '" + DF + "' did not return data as expected " +
|
| 417 |
+
"for path '" + path + "'- check path is valid");
|
| 418 |
+
}
|
| 419 |
+
} else {
|
| 420 |
+
tok.nextToken(); // Ignore Filesystem
|
| 421 |
+
}
|
| 422 |
+
tok.nextToken(); // Ignore 1K-blocks
|
| 423 |
+
tok.nextToken(); // Ignore Used
|
| 424 |
+
final String freeSpace = tok.nextToken();
|
| 425 |
+
return parseBytes(freeSpace, path);
|
| 426 |
+
}
|
| 427 |
+
|
| 428 |
+
//-----------------------------------------------------------------------
|
| 429 |
+
/**
|
| 430 |
+
* Parses the bytes from a string.
|
| 431 |
+
*
|
| 432 |
+
* @param freeSpace the free space string
|
| 433 |
+
* @param path the path
|
| 434 |
+
* @return the number of bytes
|
| 435 |
+
* @throws IOException if an error occurs
|
| 436 |
+
*/
|
| 437 |
+
long parseBytes(final String freeSpace, final String path) throws IOException {
|
| 438 |
+
try {
|
| 439 |
+
final long bytes = Long.parseLong(freeSpace);
|
| 440 |
+
if (bytes < 0) {
|
| 441 |
+
throw new IOException(
|
| 442 |
+
"Command line '" + DF + "' did not find free space in response " +
|
| 443 |
+
"for path '" + path + "'- check path is valid");
|
| 444 |
+
}
|
| 445 |
+
return bytes;
|
| 446 |
+
|
| 447 |
+
} catch (final NumberFormatException ex) {
|
| 448 |
+
throw new IOException(
|
| 449 |
+
"Command line '" + DF + "' did not return numeric data as expected " +
|
| 450 |
+
"for path '" + path + "'- check path is valid", ex);
|
| 451 |
+
}
|
| 452 |
+
}
|
| 453 |
+
|
| 454 |
+
//-----------------------------------------------------------------------
|
| 455 |
+
/**
|
| 456 |
+
* Performs the os command.
|
| 457 |
+
*
|
| 458 |
+
* @param cmdAttribs the command line parameters
|
| 459 |
+
* @param max The maximum limit for the lines returned
|
| 460 |
+
* @param timeout The timeout amount in milliseconds or no timeout if the value
|
| 461 |
+
* is zero or less
|
| 462 |
+
* @return the lines returned by the command, converted to lower-case
|
| 463 |
+
* @throws IOException if an error occurs
|
| 464 |
+
*/
|
| 465 |
+
List<String> performCommand(final String[] cmdAttribs, final int max, final long timeout) throws IOException {
|
| 466 |
+
// this method does what it can to avoid the 'Too many open files' error
|
| 467 |
+
// based on trial and error and these links:
|
| 468 |
+
// http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4784692
|
| 469 |
+
// http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4801027
|
| 470 |
+
// http://forum.java.sun.com/thread.jspa?threadID=533029&messageID=2572018
|
| 471 |
+
// however, its still not perfect as the JDK support is so poor
|
| 472 |
+
// (see commons-exec or Ant for a better multi-threaded multi-os solution)
|
| 473 |
+
|
| 474 |
+
final List<String> lines = new ArrayList<String>(20);
|
| 475 |
+
Process proc = null;
|
| 476 |
+
InputStream in = null;
|
| 477 |
+
OutputStream out = null;
|
| 478 |
+
InputStream err = null;
|
| 479 |
+
BufferedReader inr = null;
|
| 480 |
+
try {
|
| 481 |
+
|
| 482 |
+
final Thread monitor = ThreadMonitor.start(timeout);
|
| 483 |
+
|
| 484 |
+
proc = openProcess(cmdAttribs);
|
| 485 |
+
in = proc.getInputStream();
|
| 486 |
+
out = proc.getOutputStream();
|
| 487 |
+
err = proc.getErrorStream();
|
| 488 |
+
// default charset is most likely appropriate here
|
| 489 |
+
inr = new BufferedReader(new InputStreamReader(in, Charset.defaultCharset()));
|
| 490 |
+
String line = inr.readLine();
|
| 491 |
+
while (line != null && lines.size() < max) {
|
| 492 |
+
line = line.toLowerCase(Locale.ENGLISH).trim();
|
| 493 |
+
lines.add(line);
|
| 494 |
+
line = inr.readLine();
|
| 495 |
+
}
|
| 496 |
+
|
| 497 |
+
proc.waitFor();
|
| 498 |
+
|
| 499 |
+
ThreadMonitor.stop(monitor);
|
| 500 |
+
|
| 501 |
+
if (proc.exitValue() != 0) {
|
| 502 |
+
// os command problem, throw exception
|
| 503 |
+
throw new IOException(
|
| 504 |
+
"Command line returned OS error code '" + proc.exitValue() +
|
| 505 |
+
"' for command " + Arrays.asList(cmdAttribs));
|
| 506 |
+
}
|
| 507 |
+
if (lines.isEmpty()) {
|
| 508 |
+
// unknown problem, throw exception
|
| 509 |
+
throw new IOException(
|
| 510 |
+
"Command line did not return any info " +
|
| 511 |
+
"for command " + Arrays.asList(cmdAttribs));
|
| 512 |
+
}
|
| 513 |
+
return lines;
|
| 514 |
+
|
| 515 |
+
} catch (final InterruptedException ex) {
|
| 516 |
+
throw new IOException(
|
| 517 |
+
"Command line threw an InterruptedException " +
|
| 518 |
+
"for command " + Arrays.asList(cmdAttribs) + " timeout=" + timeout, ex);
|
| 519 |
+
} finally {
|
| 520 |
+
IOUtils.closeQuietly(in);
|
| 521 |
+
IOUtils.closeQuietly(out);
|
| 522 |
+
IOUtils.closeQuietly(err);
|
| 523 |
+
IOUtils.closeQuietly(inr);
|
| 524 |
+
if (proc != null) {
|
| 525 |
+
proc.destroy();
|
| 526 |
+
}
|
| 527 |
+
}
|
| 528 |
+
}
|
| 529 |
+
|
| 530 |
+
/**
|
| 531 |
+
* Opens the process to the operating system.
|
| 532 |
+
*
|
| 533 |
+
* @param cmdAttribs the command line parameters
|
| 534 |
+
* @return the process
|
| 535 |
+
* @throws IOException if an error occurs
|
| 536 |
+
*/
|
| 537 |
+
Process openProcess(final String[] cmdAttribs) throws IOException {
|
| 538 |
+
return Runtime.getRuntime().exec(cmdAttribs);
|
| 539 |
+
}
|
| 540 |
+
|
| 541 |
+
}
|
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/01_课件与电子教材/尚硅谷_第15章_File类与IO流/03-apache-common包/commons-io-2.5-src/src/main/java/org/apache/commons/io/FileUtils.java
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/01_课件与电子教材/尚硅谷_第15章_File类与IO流/03-apache-common包/commons-io-2.5-src/src/main/java/org/apache/commons/io/FilenameUtils.java
ADDED
|
@@ -0,0 +1,1452 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Licensed to the Apache Software Foundation (ASF) under one or more
|
| 3 |
+
* contributor license agreements. See the NOTICE file distributed with
|
| 4 |
+
* this work for additional information regarding copyright ownership.
|
| 5 |
+
* The ASF licenses this file to You under the Apache License, Version 2.0
|
| 6 |
+
* (the "License"); you may not use this file except in compliance with
|
| 7 |
+
* the License. You may obtain a copy of the License at
|
| 8 |
+
*
|
| 9 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
*
|
| 11 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 12 |
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
| 13 |
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 14 |
+
* See the License for the specific language governing permissions and
|
| 15 |
+
* limitations under the License.
|
| 16 |
+
*/
|
| 17 |
+
package org.apache.commons.io;
|
| 18 |
+
|
| 19 |
+
import java.io.File;
|
| 20 |
+
import java.io.IOException;
|
| 21 |
+
import java.util.ArrayList;
|
| 22 |
+
import java.util.Collection;
|
| 23 |
+
import java.util.Stack;
|
| 24 |
+
|
| 25 |
+
/**
|
| 26 |
+
* General filename and filepath manipulation utilities.
|
| 27 |
+
* <p>
|
| 28 |
+
* When dealing with filenames you can hit problems when moving from a Windows
|
| 29 |
+
* based development machine to a Unix based production machine.
|
| 30 |
+
* This class aims to help avoid those problems.
|
| 31 |
+
* <p>
|
| 32 |
+
* <b>NOTE</b>: You may be able to avoid using this class entirely simply by
|
| 33 |
+
* using JDK {@link java.io.File File} objects and the two argument constructor
|
| 34 |
+
* {@link java.io.File#File(java.io.File, java.lang.String) File(File,String)}.
|
| 35 |
+
* <p>
|
| 36 |
+
* Most methods on this class are designed to work the same on both Unix and Windows.
|
| 37 |
+
* Those that don't include 'System', 'Unix' or 'Windows' in their name.
|
| 38 |
+
* <p>
|
| 39 |
+
* Most methods recognise both separators (forward and back), and both
|
| 40 |
+
* sets of prefixes. See the javadoc of each method for details.
|
| 41 |
+
* <p>
|
| 42 |
+
* This class defines six components within a filename
|
| 43 |
+
* (example C:\dev\project\file.txt):
|
| 44 |
+
* <ul>
|
| 45 |
+
* <li>the prefix - C:\</li>
|
| 46 |
+
* <li>the path - dev\project\</li>
|
| 47 |
+
* <li>the full path - C:\dev\project\</li>
|
| 48 |
+
* <li>the name - file.txt</li>
|
| 49 |
+
* <li>the base name - file</li>
|
| 50 |
+
* <li>the extension - txt</li>
|
| 51 |
+
* </ul>
|
| 52 |
+
* Note that this class works best if directory filenames end with a separator.
|
| 53 |
+
* If you omit the last separator, it is impossible to determine if the filename
|
| 54 |
+
* corresponds to a file or a directory. As a result, we have chosen to say
|
| 55 |
+
* it corresponds to a file.
|
| 56 |
+
* <p>
|
| 57 |
+
* This class only supports Unix and Windows style names.
|
| 58 |
+
* Prefixes are matched as follows:
|
| 59 |
+
* <pre>
|
| 60 |
+
* Windows:
|
| 61 |
+
* a\b\c.txt --> "" --> relative
|
| 62 |
+
* \a\b\c.txt --> "\" --> current drive absolute
|
| 63 |
+
* C:a\b\c.txt --> "C:" --> drive relative
|
| 64 |
+
* C:\a\b\c.txt --> "C:\" --> absolute
|
| 65 |
+
* \\server\a\b\c.txt --> "\\server\" --> UNC
|
| 66 |
+
*
|
| 67 |
+
* Unix:
|
| 68 |
+
* a/b/c.txt --> "" --> relative
|
| 69 |
+
* /a/b/c.txt --> "/" --> absolute
|
| 70 |
+
* ~/a/b/c.txt --> "~/" --> current user
|
| 71 |
+
* ~ --> "~/" --> current user (slash added)
|
| 72 |
+
* ~user/a/b/c.txt --> "~user/" --> named user
|
| 73 |
+
* ~user --> "~user/" --> named user (slash added)
|
| 74 |
+
* </pre>
|
| 75 |
+
* Both prefix styles are matched always, irrespective of the machine that you are
|
| 76 |
+
* currently running on.
|
| 77 |
+
* <p>
|
| 78 |
+
* Origin of code: Excalibur, Alexandria, Tomcat, Commons-Utils.
|
| 79 |
+
*
|
| 80 |
+
* @version $Id: FilenameUtils.java 1702170 2015-09-10 06:35:02Z krosenvold $
|
| 81 |
+
* @since 1.1
|
| 82 |
+
*/
|
| 83 |
+
public class FilenameUtils {
|
| 84 |
+
|
| 85 |
+
private static final int NOT_FOUND = -1;
|
| 86 |
+
|
| 87 |
+
/**
|
| 88 |
+
* The extension separator character.
|
| 89 |
+
* @since 1.4
|
| 90 |
+
*/
|
| 91 |
+
public static final char EXTENSION_SEPARATOR = '.';
|
| 92 |
+
|
| 93 |
+
/**
|
| 94 |
+
* The extension separator String.
|
| 95 |
+
* @since 1.4
|
| 96 |
+
*/
|
| 97 |
+
public static final String EXTENSION_SEPARATOR_STR = Character.toString(EXTENSION_SEPARATOR);
|
| 98 |
+
|
| 99 |
+
/**
|
| 100 |
+
* The Unix separator character.
|
| 101 |
+
*/
|
| 102 |
+
private static final char UNIX_SEPARATOR = '/';
|
| 103 |
+
|
| 104 |
+
/**
|
| 105 |
+
* The Windows separator character.
|
| 106 |
+
*/
|
| 107 |
+
private static final char WINDOWS_SEPARATOR = '\\';
|
| 108 |
+
|
| 109 |
+
/**
|
| 110 |
+
* The system separator character.
|
| 111 |
+
*/
|
| 112 |
+
private static final char SYSTEM_SEPARATOR = File.separatorChar;
|
| 113 |
+
|
| 114 |
+
/**
|
| 115 |
+
* The separator character that is the opposite of the system separator.
|
| 116 |
+
*/
|
| 117 |
+
private static final char OTHER_SEPARATOR;
|
| 118 |
+
static {
|
| 119 |
+
if (isSystemWindows()) {
|
| 120 |
+
OTHER_SEPARATOR = UNIX_SEPARATOR;
|
| 121 |
+
} else {
|
| 122 |
+
OTHER_SEPARATOR = WINDOWS_SEPARATOR;
|
| 123 |
+
}
|
| 124 |
+
}
|
| 125 |
+
|
| 126 |
+
/**
|
| 127 |
+
* Instances should NOT be constructed in standard programming.
|
| 128 |
+
*/
|
| 129 |
+
public FilenameUtils() {
|
| 130 |
+
super();
|
| 131 |
+
}
|
| 132 |
+
|
| 133 |
+
//-----------------------------------------------------------------------
|
| 134 |
+
/**
|
| 135 |
+
* Determines if Windows file system is in use.
|
| 136 |
+
*
|
| 137 |
+
* @return true if the system is Windows
|
| 138 |
+
*/
|
| 139 |
+
static boolean isSystemWindows() {
|
| 140 |
+
return SYSTEM_SEPARATOR == WINDOWS_SEPARATOR;
|
| 141 |
+
}
|
| 142 |
+
|
| 143 |
+
//-----------------------------------------------------------------------
|
| 144 |
+
/**
|
| 145 |
+
* Checks if the character is a separator.
|
| 146 |
+
*
|
| 147 |
+
* @param ch the character to check
|
| 148 |
+
* @return true if it is a separator character
|
| 149 |
+
*/
|
| 150 |
+
private static boolean isSeparator(final char ch) {
|
| 151 |
+
return ch == UNIX_SEPARATOR || ch == WINDOWS_SEPARATOR;
|
| 152 |
+
}
|
| 153 |
+
|
| 154 |
+
//-----------------------------------------------------------------------
|
| 155 |
+
/**
|
| 156 |
+
* Normalizes a path, removing double and single dot path steps.
|
| 157 |
+
* <p>
|
| 158 |
+
* This method normalizes a path to a standard format.
|
| 159 |
+
* The input may contain separators in either Unix or Windows format.
|
| 160 |
+
* The output will contain separators in the format of the system.
|
| 161 |
+
* <p>
|
| 162 |
+
* A trailing slash will be retained.
|
| 163 |
+
* A double slash will be merged to a single slash (but UNC names are handled).
|
| 164 |
+
* A single dot path segment will be removed.
|
| 165 |
+
* A double dot will cause that path segment and the one before to be removed.
|
| 166 |
+
* If the double dot has no parent path segment to work with, {@code null}
|
| 167 |
+
* is returned.
|
| 168 |
+
* <p>
|
| 169 |
+
* The output will be the same on both Unix and Windows except
|
| 170 |
+
* for the separator character.
|
| 171 |
+
* <pre>
|
| 172 |
+
* /foo// --> /foo/
|
| 173 |
+
* /foo/./ --> /foo/
|
| 174 |
+
* /foo/../bar --> /bar
|
| 175 |
+
* /foo/../bar/ --> /bar/
|
| 176 |
+
* /foo/../bar/../baz --> /baz
|
| 177 |
+
* //foo//./bar --> /foo/bar
|
| 178 |
+
* /../ --> null
|
| 179 |
+
* ../foo --> null
|
| 180 |
+
* foo/bar/.. --> foo/
|
| 181 |
+
* foo/../../bar --> null
|
| 182 |
+
* foo/../bar --> bar
|
| 183 |
+
* //server/foo/../bar --> //server/bar
|
| 184 |
+
* //server/../bar --> null
|
| 185 |
+
* C:\foo\..\bar --> C:\bar
|
| 186 |
+
* C:\..\bar --> null
|
| 187 |
+
* ~/foo/../bar/ --> ~/bar/
|
| 188 |
+
* ~/../bar --> null
|
| 189 |
+
* </pre>
|
| 190 |
+
* (Note the file separator returned will be correct for Windows/Unix)
|
| 191 |
+
*
|
| 192 |
+
* @param filename the filename to normalize, null returns null
|
| 193 |
+
* @return the normalized filename, or null if invalid. Null bytes inside string will be removed
|
| 194 |
+
*/
|
| 195 |
+
public static String normalize(final String filename) {
|
| 196 |
+
return doNormalize(filename, SYSTEM_SEPARATOR, true);
|
| 197 |
+
}
|
| 198 |
+
/**
|
| 199 |
+
* Normalizes a path, removing double and single dot path steps.
|
| 200 |
+
* <p>
|
| 201 |
+
* This method normalizes a path to a standard format.
|
| 202 |
+
* The input may contain separators in either Unix or Windows format.
|
| 203 |
+
* The output will contain separators in the format specified.
|
| 204 |
+
* <p>
|
| 205 |
+
* A trailing slash will be retained.
|
| 206 |
+
* A double slash will be merged to a single slash (but UNC names are handled).
|
| 207 |
+
* A single dot path segment will be removed.
|
| 208 |
+
* A double dot will cause that path segment and the one before to be removed.
|
| 209 |
+
* If the double dot has no parent path segment to work with, {@code null}
|
| 210 |
+
* is returned.
|
| 211 |
+
* <p>
|
| 212 |
+
* The output will be the same on both Unix and Windows except
|
| 213 |
+
* for the separator character.
|
| 214 |
+
* <pre>
|
| 215 |
+
* /foo// --> /foo/
|
| 216 |
+
* /foo/./ --> /foo/
|
| 217 |
+
* /foo/../bar --> /bar
|
| 218 |
+
* /foo/../bar/ --> /bar/
|
| 219 |
+
* /foo/../bar/../baz --> /baz
|
| 220 |
+
* //foo//./bar --> /foo/bar
|
| 221 |
+
* /../ --> null
|
| 222 |
+
* ../foo --> null
|
| 223 |
+
* foo/bar/.. --> foo/
|
| 224 |
+
* foo/../../bar --> null
|
| 225 |
+
* foo/../bar --> bar
|
| 226 |
+
* //server/foo/../bar --> //server/bar
|
| 227 |
+
* //server/../bar --> null
|
| 228 |
+
* C:\foo\..\bar --> C:\bar
|
| 229 |
+
* C:\..\bar --> null
|
| 230 |
+
* ~/foo/../bar/ --> ~/bar/
|
| 231 |
+
* ~/../bar --> null
|
| 232 |
+
* </pre>
|
| 233 |
+
* The output will be the same on both Unix and Windows including
|
| 234 |
+
* the separator character.
|
| 235 |
+
*
|
| 236 |
+
* @param filename the filename to normalize, null returns null
|
| 237 |
+
* @param unixSeparator {@code true} if a unix separator should
|
| 238 |
+
* be used or {@code false} if a windows separator should be used.
|
| 239 |
+
* @return the normalized filename, or null if invalid. Null bytes inside string will be removed
|
| 240 |
+
* @since 2.0
|
| 241 |
+
*/
|
| 242 |
+
public static String normalize(final String filename, final boolean unixSeparator) {
|
| 243 |
+
final char separator = unixSeparator ? UNIX_SEPARATOR : WINDOWS_SEPARATOR;
|
| 244 |
+
return doNormalize(filename, separator, true);
|
| 245 |
+
}
|
| 246 |
+
|
| 247 |
+
//-----------------------------------------------------------------------
|
| 248 |
+
/**
|
| 249 |
+
* Normalizes a path, removing double and single dot path steps,
|
| 250 |
+
* and removing any final directory separator.
|
| 251 |
+
* <p>
|
| 252 |
+
* This method normalizes a path to a standard format.
|
| 253 |
+
* The input may contain separators in either Unix or Windows format.
|
| 254 |
+
* The output will contain separators in the format of the system.
|
| 255 |
+
* <p>
|
| 256 |
+
* A trailing slash will be removed.
|
| 257 |
+
* A double slash will be merged to a single slash (but UNC names are handled).
|
| 258 |
+
* A single dot path segment will be removed.
|
| 259 |
+
* A double dot will cause that path segment and the one before to be removed.
|
| 260 |
+
* If the double dot has no parent path segment to work with, {@code null}
|
| 261 |
+
* is returned.
|
| 262 |
+
* <p>
|
| 263 |
+
* The output will be the same on both Unix and Windows except
|
| 264 |
+
* for the separator character.
|
| 265 |
+
* <pre>
|
| 266 |
+
* /foo// --> /foo
|
| 267 |
+
* /foo/./ --> /foo
|
| 268 |
+
* /foo/../bar --> /bar
|
| 269 |
+
* /foo/../bar/ --> /bar
|
| 270 |
+
* /foo/../bar/../baz --> /baz
|
| 271 |
+
* //foo//./bar --> /foo/bar
|
| 272 |
+
* /../ --> null
|
| 273 |
+
* ../foo --> null
|
| 274 |
+
* foo/bar/.. --> foo
|
| 275 |
+
* foo/../../bar --> null
|
| 276 |
+
* foo/../bar --> bar
|
| 277 |
+
* //server/foo/../bar --> //server/bar
|
| 278 |
+
* //server/../bar --> null
|
| 279 |
+
* C:\foo\..\bar --> C:\bar
|
| 280 |
+
* C:\..\bar --> null
|
| 281 |
+
* ~/foo/../bar/ --> ~/bar
|
| 282 |
+
* ~/../bar --> null
|
| 283 |
+
* </pre>
|
| 284 |
+
* (Note the file separator returned will be correct for Windows/Unix)
|
| 285 |
+
*
|
| 286 |
+
* @param filename the filename to normalize, null returns null
|
| 287 |
+
* @return the normalized filename, or null if invalid. Null bytes inside string will be removed
|
| 288 |
+
*/
|
| 289 |
+
public static String normalizeNoEndSeparator(final String filename) {
|
| 290 |
+
return doNormalize(filename, SYSTEM_SEPARATOR, false);
|
| 291 |
+
}
|
| 292 |
+
|
| 293 |
+
/**
|
| 294 |
+
* Normalizes a path, removing double and single dot path steps,
|
| 295 |
+
* and removing any final directory separator.
|
| 296 |
+
* <p>
|
| 297 |
+
* This method normalizes a path to a standard format.
|
| 298 |
+
* The input may contain separators in either Unix or Windows format.
|
| 299 |
+
* The output will contain separators in the format specified.
|
| 300 |
+
* <p>
|
| 301 |
+
* A trailing slash will be removed.
|
| 302 |
+
* A double slash will be merged to a single slash (but UNC names are handled).
|
| 303 |
+
* A single dot path segment will be removed.
|
| 304 |
+
* A double dot will cause that path segment and the one before to be removed.
|
| 305 |
+
* If the double dot has no parent path segment to work with, {@code null}
|
| 306 |
+
* is returned.
|
| 307 |
+
* <p>
|
| 308 |
+
* The output will be the same on both Unix and Windows including
|
| 309 |
+
* the separator character.
|
| 310 |
+
* <pre>
|
| 311 |
+
* /foo// --> /foo
|
| 312 |
+
* /foo/./ --> /foo
|
| 313 |
+
* /foo/../bar --> /bar
|
| 314 |
+
* /foo/../bar/ --> /bar
|
| 315 |
+
* /foo/../bar/../baz --> /baz
|
| 316 |
+
* //foo//./bar --> /foo/bar
|
| 317 |
+
* /../ --> null
|
| 318 |
+
* ../foo --> null
|
| 319 |
+
* foo/bar/.. --> foo
|
| 320 |
+
* foo/../../bar --> null
|
| 321 |
+
* foo/../bar --> bar
|
| 322 |
+
* //server/foo/../bar --> //server/bar
|
| 323 |
+
* //server/../bar --> null
|
| 324 |
+
* C:\foo\..\bar --> C:\bar
|
| 325 |
+
* C:\..\bar --> null
|
| 326 |
+
* ~/foo/../bar/ --> ~/bar
|
| 327 |
+
* ~/../bar --> null
|
| 328 |
+
* </pre>
|
| 329 |
+
*
|
| 330 |
+
* @param filename the filename to normalize, null returns null
|
| 331 |
+
* @param unixSeparator {@code true} if a unix separator should
|
| 332 |
+
* be used or {@code false} if a windows separtor should be used.
|
| 333 |
+
* @return the normalized filename, or null if invalid. Null bytes inside string will be removed
|
| 334 |
+
* @since 2.0
|
| 335 |
+
*/
|
| 336 |
+
public static String normalizeNoEndSeparator(final String filename, final boolean unixSeparator) {
|
| 337 |
+
final char separator = unixSeparator ? UNIX_SEPARATOR : WINDOWS_SEPARATOR;
|
| 338 |
+
return doNormalize(filename, separator, false);
|
| 339 |
+
}
|
| 340 |
+
|
| 341 |
+
/**
|
| 342 |
+
* Internal method to perform the normalization.
|
| 343 |
+
*
|
| 344 |
+
* @param filename the filename
|
| 345 |
+
* @param separator The separator character to use
|
| 346 |
+
* @param keepSeparator true to keep the final separator
|
| 347 |
+
* @return the normalized filename. Null bytes inside string will be removed.
|
| 348 |
+
*/
|
| 349 |
+
private static String doNormalize(final String filename, final char separator, final boolean keepSeparator) {
|
| 350 |
+
if (filename == null) {
|
| 351 |
+
return null;
|
| 352 |
+
}
|
| 353 |
+
|
| 354 |
+
failIfNullBytePresent(filename);
|
| 355 |
+
|
| 356 |
+
int size = filename.length();
|
| 357 |
+
if (size == 0) {
|
| 358 |
+
return filename;
|
| 359 |
+
}
|
| 360 |
+
final int prefix = getPrefixLength(filename);
|
| 361 |
+
if (prefix < 0) {
|
| 362 |
+
return null;
|
| 363 |
+
}
|
| 364 |
+
|
| 365 |
+
final char[] array = new char[size + 2]; // +1 for possible extra slash, +2 for arraycopy
|
| 366 |
+
filename.getChars(0, filename.length(), array, 0);
|
| 367 |
+
|
| 368 |
+
// fix separators throughout
|
| 369 |
+
final char otherSeparator = separator == SYSTEM_SEPARATOR ? OTHER_SEPARATOR : SYSTEM_SEPARATOR;
|
| 370 |
+
for (int i = 0; i < array.length; i++) {
|
| 371 |
+
if (array[i] == otherSeparator) {
|
| 372 |
+
array[i] = separator;
|
| 373 |
+
}
|
| 374 |
+
}
|
| 375 |
+
|
| 376 |
+
// add extra separator on the end to simplify code below
|
| 377 |
+
boolean lastIsDirectory = true;
|
| 378 |
+
if (array[size - 1] != separator) {
|
| 379 |
+
array[size++] = separator;
|
| 380 |
+
lastIsDirectory = false;
|
| 381 |
+
}
|
| 382 |
+
|
| 383 |
+
// adjoining slashes
|
| 384 |
+
for (int i = prefix + 1; i < size; i++) {
|
| 385 |
+
if (array[i] == separator && array[i - 1] == separator) {
|
| 386 |
+
System.arraycopy(array, i, array, i - 1, size - i);
|
| 387 |
+
size--;
|
| 388 |
+
i--;
|
| 389 |
+
}
|
| 390 |
+
}
|
| 391 |
+
|
| 392 |
+
// dot slash
|
| 393 |
+
for (int i = prefix + 1; i < size; i++) {
|
| 394 |
+
if (array[i] == separator && array[i - 1] == '.' &&
|
| 395 |
+
(i == prefix + 1 || array[i - 2] == separator)) {
|
| 396 |
+
if (i == size - 1) {
|
| 397 |
+
lastIsDirectory = true;
|
| 398 |
+
}
|
| 399 |
+
System.arraycopy(array, i + 1, array, i - 1, size - i);
|
| 400 |
+
size -=2;
|
| 401 |
+
i--;
|
| 402 |
+
}
|
| 403 |
+
}
|
| 404 |
+
|
| 405 |
+
// double dot slash
|
| 406 |
+
outer:
|
| 407 |
+
for (int i = prefix + 2; i < size; i++) {
|
| 408 |
+
if (array[i] == separator && array[i - 1] == '.' && array[i - 2] == '.' &&
|
| 409 |
+
(i == prefix + 2 || array[i - 3] == separator)) {
|
| 410 |
+
if (i == prefix + 2) {
|
| 411 |
+
return null;
|
| 412 |
+
}
|
| 413 |
+
if (i == size - 1) {
|
| 414 |
+
lastIsDirectory = true;
|
| 415 |
+
}
|
| 416 |
+
int j;
|
| 417 |
+
for (j = i - 4 ; j >= prefix; j--) {
|
| 418 |
+
if (array[j] == separator) {
|
| 419 |
+
// remove b/../ from a/b/../c
|
| 420 |
+
System.arraycopy(array, i + 1, array, j + 1, size - i);
|
| 421 |
+
size -= i - j;
|
| 422 |
+
i = j + 1;
|
| 423 |
+
continue outer;
|
| 424 |
+
}
|
| 425 |
+
}
|
| 426 |
+
// remove a/../ from a/../c
|
| 427 |
+
System.arraycopy(array, i + 1, array, prefix, size - i);
|
| 428 |
+
size -= i + 1 - prefix;
|
| 429 |
+
i = prefix + 1;
|
| 430 |
+
}
|
| 431 |
+
}
|
| 432 |
+
|
| 433 |
+
if (size <= 0) { // should never be less than 0
|
| 434 |
+
return "";
|
| 435 |
+
}
|
| 436 |
+
if (size <= prefix) { // should never be less than prefix
|
| 437 |
+
return new String(array, 0, size);
|
| 438 |
+
}
|
| 439 |
+
if (lastIsDirectory && keepSeparator) {
|
| 440 |
+
return new String(array, 0, size); // keep trailing separator
|
| 441 |
+
}
|
| 442 |
+
return new String(array, 0, size - 1); // lose trailing separator
|
| 443 |
+
}
|
| 444 |
+
|
| 445 |
+
//-----------------------------------------------------------------------
|
| 446 |
+
/**
|
| 447 |
+
* Concatenates a filename to a base path using normal command line style rules.
|
| 448 |
+
* <p>
|
| 449 |
+
* The effect is equivalent to resultant directory after changing
|
| 450 |
+
* directory to the first argument, followed by changing directory to
|
| 451 |
+
* the second argument.
|
| 452 |
+
* <p>
|
| 453 |
+
* The first argument is the base path, the second is the path to concatenate.
|
| 454 |
+
* The returned path is always normalized via {@link #normalize(String)},
|
| 455 |
+
* thus <code>..</code> is handled.
|
| 456 |
+
* <p>
|
| 457 |
+
* If <code>pathToAdd</code> is absolute (has an absolute prefix), then
|
| 458 |
+
* it will be normalized and returned.
|
| 459 |
+
* Otherwise, the paths will be joined, normalized and returned.
|
| 460 |
+
* <p>
|
| 461 |
+
* The output will be the same on both Unix and Windows except
|
| 462 |
+
* for the separator character.
|
| 463 |
+
* <pre>
|
| 464 |
+
* /foo/ + bar --> /foo/bar
|
| 465 |
+
* /foo + bar --> /foo/bar
|
| 466 |
+
* /foo + /bar --> /bar
|
| 467 |
+
* /foo + C:/bar --> C:/bar
|
| 468 |
+
* /foo + C:bar --> C:bar (*)
|
| 469 |
+
* /foo/a/ + ../bar --> foo/bar
|
| 470 |
+
* /foo/ + ../../bar --> null
|
| 471 |
+
* /foo/ + /bar --> /bar
|
| 472 |
+
* /foo/.. + /bar --> /bar
|
| 473 |
+
* /foo + bar/c.txt --> /foo/bar/c.txt
|
| 474 |
+
* /foo/c.txt + bar --> /foo/c.txt/bar (!)
|
| 475 |
+
* </pre>
|
| 476 |
+
* (*) Note that the Windows relative drive prefix is unreliable when
|
| 477 |
+
* used with this method.
|
| 478 |
+
* (!) Note that the first parameter must be a path. If it ends with a name, then
|
| 479 |
+
* the name will be built into the concatenated path. If this might be a problem,
|
| 480 |
+
* use {@link #getFullPath(String)} on the base path argument.
|
| 481 |
+
*
|
| 482 |
+
* @param basePath the base path to attach to, always treated as a path
|
| 483 |
+
* @param fullFilenameToAdd the filename (or path) to attach to the base
|
| 484 |
+
* @return the concatenated path, or null if invalid. Null bytes inside string will be removed
|
| 485 |
+
*/
|
| 486 |
+
public static String concat(final String basePath, final String fullFilenameToAdd) {
|
| 487 |
+
final int prefix = getPrefixLength(fullFilenameToAdd);
|
| 488 |
+
if (prefix < 0) {
|
| 489 |
+
return null;
|
| 490 |
+
}
|
| 491 |
+
if (prefix > 0) {
|
| 492 |
+
return normalize(fullFilenameToAdd);
|
| 493 |
+
}
|
| 494 |
+
if (basePath == null) {
|
| 495 |
+
return null;
|
| 496 |
+
}
|
| 497 |
+
final int len = basePath.length();
|
| 498 |
+
if (len == 0) {
|
| 499 |
+
return normalize(fullFilenameToAdd);
|
| 500 |
+
}
|
| 501 |
+
final char ch = basePath.charAt(len - 1);
|
| 502 |
+
if (isSeparator(ch)) {
|
| 503 |
+
return normalize(basePath + fullFilenameToAdd);
|
| 504 |
+
} else {
|
| 505 |
+
return normalize(basePath + '/' + fullFilenameToAdd);
|
| 506 |
+
}
|
| 507 |
+
}
|
| 508 |
+
|
| 509 |
+
/**
|
| 510 |
+
* Determines whether the {@code parent} directory contains the {@code child} element (a file or directory).
|
| 511 |
+
* <p>
|
| 512 |
+
* The files names are expected to be normalized.
|
| 513 |
+
* </p>
|
| 514 |
+
*
|
| 515 |
+
* Edge cases:
|
| 516 |
+
* <ul>
|
| 517 |
+
* <li>A {@code directory} must not be null: if null, throw IllegalArgumentException</li>
|
| 518 |
+
* <li>A directory does not contain itself: return false</li>
|
| 519 |
+
* <li>A null child file is not contained in any parent: return false</li>
|
| 520 |
+
* </ul>
|
| 521 |
+
*
|
| 522 |
+
* @param canonicalParent
|
| 523 |
+
* the file to consider as the parent.
|
| 524 |
+
* @param canonicalChild
|
| 525 |
+
* the file to consider as the child.
|
| 526 |
+
* @return true is the candidate leaf is under by the specified composite. False otherwise.
|
| 527 |
+
* @throws IOException
|
| 528 |
+
* if an IO error occurs while checking the files.
|
| 529 |
+
* @since 2.2
|
| 530 |
+
* @see FileUtils#directoryContains(File, File)
|
| 531 |
+
*/
|
| 532 |
+
public static boolean directoryContains(final String canonicalParent, final String canonicalChild)
|
| 533 |
+
throws IOException {
|
| 534 |
+
|
| 535 |
+
// Fail fast against NullPointerException
|
| 536 |
+
if (canonicalParent == null) {
|
| 537 |
+
throw new IllegalArgumentException("Directory must not be null");
|
| 538 |
+
}
|
| 539 |
+
|
| 540 |
+
if (canonicalChild == null) {
|
| 541 |
+
return false;
|
| 542 |
+
}
|
| 543 |
+
|
| 544 |
+
if (IOCase.SYSTEM.checkEquals(canonicalParent, canonicalChild)) {
|
| 545 |
+
return false;
|
| 546 |
+
}
|
| 547 |
+
|
| 548 |
+
return IOCase.SYSTEM.checkStartsWith(canonicalChild, canonicalParent);
|
| 549 |
+
}
|
| 550 |
+
|
| 551 |
+
//-----------------------------------------------------------------------
|
| 552 |
+
/**
|
| 553 |
+
* Converts all separators to the Unix separator of forward slash.
|
| 554 |
+
*
|
| 555 |
+
* @param path the path to be changed, null ignored
|
| 556 |
+
* @return the updated path
|
| 557 |
+
*/
|
| 558 |
+
public static String separatorsToUnix(final String path) {
|
| 559 |
+
if (path == null || path.indexOf(WINDOWS_SEPARATOR) == NOT_FOUND) {
|
| 560 |
+
return path;
|
| 561 |
+
}
|
| 562 |
+
return path.replace(WINDOWS_SEPARATOR, UNIX_SEPARATOR);
|
| 563 |
+
}
|
| 564 |
+
|
| 565 |
+
/**
|
| 566 |
+
* Converts all separators to the Windows separator of backslash.
|
| 567 |
+
*
|
| 568 |
+
* @param path the path to be changed, null ignored
|
| 569 |
+
* @return the updated path
|
| 570 |
+
*/
|
| 571 |
+
public static String separatorsToWindows(final String path) {
|
| 572 |
+
if (path == null || path.indexOf(UNIX_SEPARATOR) == NOT_FOUND) {
|
| 573 |
+
return path;
|
| 574 |
+
}
|
| 575 |
+
return path.replace(UNIX_SEPARATOR, WINDOWS_SEPARATOR);
|
| 576 |
+
}
|
| 577 |
+
|
| 578 |
+
/**
|
| 579 |
+
* Converts all separators to the system separator.
|
| 580 |
+
*
|
| 581 |
+
* @param path the path to be changed, null ignored
|
| 582 |
+
* @return the updated path
|
| 583 |
+
*/
|
| 584 |
+
public static String separatorsToSystem(final String path) {
|
| 585 |
+
if (path == null) {
|
| 586 |
+
return null;
|
| 587 |
+
}
|
| 588 |
+
if (isSystemWindows()) {
|
| 589 |
+
return separatorsToWindows(path);
|
| 590 |
+
} else {
|
| 591 |
+
return separatorsToUnix(path);
|
| 592 |
+
}
|
| 593 |
+
}
|
| 594 |
+
|
| 595 |
+
//-----------------------------------------------------------------------
|
| 596 |
+
/**
|
| 597 |
+
* Returns the length of the filename prefix, such as <code>C:/</code> or <code>~/</code>.
|
| 598 |
+
* <p>
|
| 599 |
+
* This method will handle a file in either Unix or Windows format.
|
| 600 |
+
* <p>
|
| 601 |
+
* The prefix length includes the first slash in the full filename
|
| 602 |
+
* if applicable. Thus, it is possible that the length returned is greater
|
| 603 |
+
* than the length of the input string.
|
| 604 |
+
* <pre>
|
| 605 |
+
* Windows:
|
| 606 |
+
* a\b\c.txt --> "" --> relative
|
| 607 |
+
* \a\b\c.txt --> "\" --> current drive absolute
|
| 608 |
+
* C:a\b\c.txt --> "C:" --> drive relative
|
| 609 |
+
* C:\a\b\c.txt --> "C:\" --> absolute
|
| 610 |
+
* \\server\a\b\c.txt --> "\\server\" --> UNC
|
| 611 |
+
* \\\a\b\c.txt --> error, length = -1
|
| 612 |
+
*
|
| 613 |
+
* Unix:
|
| 614 |
+
* a/b/c.txt --> "" --> relative
|
| 615 |
+
* /a/b/c.txt --> "/" --> absolute
|
| 616 |
+
* ~/a/b/c.txt --> "~/" --> current user
|
| 617 |
+
* ~ --> "~/" --> current user (slash added)
|
| 618 |
+
* ~user/a/b/c.txt --> "~user/" --> named user
|
| 619 |
+
* ~user --> "~user/" --> named user (slash added)
|
| 620 |
+
* //server/a/b/c.txt --> "//server/"
|
| 621 |
+
* ///a/b/c.txt --> error, length = -1
|
| 622 |
+
* </pre>
|
| 623 |
+
* <p>
|
| 624 |
+
* The output will be the same irrespective of the machine that the code is running on.
|
| 625 |
+
* ie. both Unix and Windows prefixes are matched regardless.
|
| 626 |
+
*
|
| 627 |
+
* Note that a leading // (or \\) is used to indicate a UNC name on Windows.
|
| 628 |
+
* These must be followed by a server name, so double-slashes are not collapsed
|
| 629 |
+
* to a single slash at the start of the filename.
|
| 630 |
+
*
|
| 631 |
+
* @param filename the filename to find the prefix in, null returns -1
|
| 632 |
+
* @return the length of the prefix, -1 if invalid or null
|
| 633 |
+
*/
|
| 634 |
+
public static int getPrefixLength(final String filename) {
|
| 635 |
+
if (filename == null) {
|
| 636 |
+
return NOT_FOUND;
|
| 637 |
+
}
|
| 638 |
+
final int len = filename.length();
|
| 639 |
+
if (len == 0) {
|
| 640 |
+
return 0;
|
| 641 |
+
}
|
| 642 |
+
char ch0 = filename.charAt(0);
|
| 643 |
+
if (ch0 == ':') {
|
| 644 |
+
return NOT_FOUND;
|
| 645 |
+
}
|
| 646 |
+
if (len == 1) {
|
| 647 |
+
if (ch0 == '~') {
|
| 648 |
+
return 2; // return a length greater than the input
|
| 649 |
+
}
|
| 650 |
+
return isSeparator(ch0) ? 1 : 0;
|
| 651 |
+
} else {
|
| 652 |
+
if (ch0 == '~') {
|
| 653 |
+
int posUnix = filename.indexOf(UNIX_SEPARATOR, 1);
|
| 654 |
+
int posWin = filename.indexOf(WINDOWS_SEPARATOR, 1);
|
| 655 |
+
if (posUnix == NOT_FOUND && posWin == NOT_FOUND) {
|
| 656 |
+
return len + 1; // return a length greater than the input
|
| 657 |
+
}
|
| 658 |
+
posUnix = posUnix == NOT_FOUND ? posWin : posUnix;
|
| 659 |
+
posWin = posWin == NOT_FOUND ? posUnix : posWin;
|
| 660 |
+
return Math.min(posUnix, posWin) + 1;
|
| 661 |
+
}
|
| 662 |
+
final char ch1 = filename.charAt(1);
|
| 663 |
+
if (ch1 == ':') {
|
| 664 |
+
ch0 = Character.toUpperCase(ch0);
|
| 665 |
+
if (ch0 >= 'A' && ch0 <= 'Z') {
|
| 666 |
+
if (len == 2 || isSeparator(filename.charAt(2)) == false) {
|
| 667 |
+
return 2;
|
| 668 |
+
}
|
| 669 |
+
return 3;
|
| 670 |
+
}
|
| 671 |
+
return NOT_FOUND;
|
| 672 |
+
|
| 673 |
+
} else if (isSeparator(ch0) && isSeparator(ch1)) {
|
| 674 |
+
int posUnix = filename.indexOf(UNIX_SEPARATOR, 2);
|
| 675 |
+
int posWin = filename.indexOf(WINDOWS_SEPARATOR, 2);
|
| 676 |
+
if (posUnix == NOT_FOUND && posWin == NOT_FOUND || posUnix == 2 || posWin == 2) {
|
| 677 |
+
return NOT_FOUND;
|
| 678 |
+
}
|
| 679 |
+
posUnix = posUnix == NOT_FOUND ? posWin : posUnix;
|
| 680 |
+
posWin = posWin == NOT_FOUND ? posUnix : posWin;
|
| 681 |
+
return Math.min(posUnix, posWin) + 1;
|
| 682 |
+
} else {
|
| 683 |
+
return isSeparator(ch0) ? 1 : 0;
|
| 684 |
+
}
|
| 685 |
+
}
|
| 686 |
+
}
|
| 687 |
+
|
| 688 |
+
/**
|
| 689 |
+
* Returns the index of the last directory separator character.
|
| 690 |
+
* <p>
|
| 691 |
+
* This method will handle a file in either Unix or Windows format.
|
| 692 |
+
* The position of the last forward or backslash is returned.
|
| 693 |
+
* <p>
|
| 694 |
+
* The output will be the same irrespective of the machine that the code is running on.
|
| 695 |
+
*
|
| 696 |
+
* @param filename the filename to find the last path separator in, null returns -1
|
| 697 |
+
* @return the index of the last separator character, or -1 if there
|
| 698 |
+
* is no such character
|
| 699 |
+
*/
|
| 700 |
+
public static int indexOfLastSeparator(final String filename) {
|
| 701 |
+
if (filename == null) {
|
| 702 |
+
return NOT_FOUND;
|
| 703 |
+
}
|
| 704 |
+
final int lastUnixPos = filename.lastIndexOf(UNIX_SEPARATOR);
|
| 705 |
+
final int lastWindowsPos = filename.lastIndexOf(WINDOWS_SEPARATOR);
|
| 706 |
+
return Math.max(lastUnixPos, lastWindowsPos);
|
| 707 |
+
}
|
| 708 |
+
|
| 709 |
+
/**
|
| 710 |
+
* Returns the index of the last extension separator character, which is a dot.
|
| 711 |
+
* <p>
|
| 712 |
+
* This method also checks that there is no directory separator after the last dot. To do this it uses
|
| 713 |
+
* {@link #indexOfLastSeparator(String)} which will handle a file in either Unix or Windows format.
|
| 714 |
+
* </p>
|
| 715 |
+
* <p>
|
| 716 |
+
* The output will be the same irrespective of the machine that the code is running on.
|
| 717 |
+
* </p>
|
| 718 |
+
*
|
| 719 |
+
* @param filename
|
| 720 |
+
* the filename to find the last extension separator in, null returns -1
|
| 721 |
+
* @return the index of the last extension separator character, or -1 if there is no such character
|
| 722 |
+
*/
|
| 723 |
+
public static int indexOfExtension(final String filename) {
|
| 724 |
+
if (filename == null) {
|
| 725 |
+
return NOT_FOUND;
|
| 726 |
+
}
|
| 727 |
+
final int extensionPos = filename.lastIndexOf(EXTENSION_SEPARATOR);
|
| 728 |
+
final int lastSeparator = indexOfLastSeparator(filename);
|
| 729 |
+
return lastSeparator > extensionPos ? NOT_FOUND : extensionPos;
|
| 730 |
+
}
|
| 731 |
+
|
| 732 |
+
//-----------------------------------------------------------------------
|
| 733 |
+
/**
|
| 734 |
+
* Gets the prefix from a full filename, such as <code>C:/</code>
|
| 735 |
+
* or <code>~/</code>.
|
| 736 |
+
* <p>
|
| 737 |
+
* This method will handle a file in either Unix or Windows format.
|
| 738 |
+
* The prefix includes the first slash in the full filename where applicable.
|
| 739 |
+
* <pre>
|
| 740 |
+
* Windows:
|
| 741 |
+
* a\b\c.txt --> "" --> relative
|
| 742 |
+
* \a\b\c.txt --> "\" --> current drive absolute
|
| 743 |
+
* C:a\b\c.txt --> "C:" --> drive relative
|
| 744 |
+
* C:\a\b\c.txt --> "C:\" --> absolute
|
| 745 |
+
* \\server\a\b\c.txt --> "\\server\" --> UNC
|
| 746 |
+
*
|
| 747 |
+
* Unix:
|
| 748 |
+
* a/b/c.txt --> "" --> relative
|
| 749 |
+
* /a/b/c.txt --> "/" --> absolute
|
| 750 |
+
* ~/a/b/c.txt --> "~/" --> current user
|
| 751 |
+
* ~ --> "~/" --> current user (slash added)
|
| 752 |
+
* ~user/a/b/c.txt --> "~user/" --> named user
|
| 753 |
+
* ~user --> "~user/" --> named user (slash added)
|
| 754 |
+
* </pre>
|
| 755 |
+
* <p>
|
| 756 |
+
* The output will be the same irrespective of the machine that the code is running on.
|
| 757 |
+
* ie. both Unix and Windows prefixes are matched regardless.
|
| 758 |
+
*
|
| 759 |
+
* @param filename the filename to query, null returns null
|
| 760 |
+
* @return the prefix of the file, null if invalid. Null bytes inside string will be removed
|
| 761 |
+
*/
|
| 762 |
+
public static String getPrefix(final String filename) {
|
| 763 |
+
if (filename == null) {
|
| 764 |
+
return null;
|
| 765 |
+
}
|
| 766 |
+
final int len = getPrefixLength(filename);
|
| 767 |
+
if (len < 0) {
|
| 768 |
+
return null;
|
| 769 |
+
}
|
| 770 |
+
if (len > filename.length()) {
|
| 771 |
+
failIfNullBytePresent(filename + UNIX_SEPARATOR);
|
| 772 |
+
return filename + UNIX_SEPARATOR;
|
| 773 |
+
}
|
| 774 |
+
String path = filename.substring(0, len);
|
| 775 |
+
failIfNullBytePresent(path);
|
| 776 |
+
return path;
|
| 777 |
+
}
|
| 778 |
+
|
| 779 |
+
/**
|
| 780 |
+
* Gets the path from a full filename, which excludes the prefix.
|
| 781 |
+
* <p>
|
| 782 |
+
* This method will handle a file in either Unix or Windows format.
|
| 783 |
+
* The method is entirely text based, and returns the text before and
|
| 784 |
+
* including the last forward or backslash.
|
| 785 |
+
* <pre>
|
| 786 |
+
* C:\a\b\c.txt --> a\b\
|
| 787 |
+
* ~/a/b/c.txt --> a/b/
|
| 788 |
+
* a.txt --> ""
|
| 789 |
+
* a/b/c --> a/b/
|
| 790 |
+
* a/b/c/ --> a/b/c/
|
| 791 |
+
* </pre>
|
| 792 |
+
* <p>
|
| 793 |
+
* The output will be the same irrespective of the machine that the code is running on.
|
| 794 |
+
* <p>
|
| 795 |
+
* This method drops the prefix from the result.
|
| 796 |
+
* See {@link #getFullPath(String)} for the method that retains the prefix.
|
| 797 |
+
*
|
| 798 |
+
* @param filename the filename to query, null returns null
|
| 799 |
+
* @return the path of the file, an empty string if none exists, null if invalid.
|
| 800 |
+
* Null bytes inside string will be removed
|
| 801 |
+
*/
|
| 802 |
+
public static String getPath(final String filename) {
|
| 803 |
+
return doGetPath(filename, 1);
|
| 804 |
+
}
|
| 805 |
+
|
| 806 |
+
/**
|
| 807 |
+
* Gets the path from a full filename, which excludes the prefix, and
|
| 808 |
+
* also excluding the final directory separator.
|
| 809 |
+
* <p>
|
| 810 |
+
* This method will handle a file in either Unix or Windows format.
|
| 811 |
+
* The method is entirely text based, and returns the text before the
|
| 812 |
+
* last forward or backslash.
|
| 813 |
+
* <pre>
|
| 814 |
+
* C:\a\b\c.txt --> a\b
|
| 815 |
+
* ~/a/b/c.txt --> a/b
|
| 816 |
+
* a.txt --> ""
|
| 817 |
+
* a/b/c --> a/b
|
| 818 |
+
* a/b/c/ --> a/b/c
|
| 819 |
+
* </pre>
|
| 820 |
+
* <p>
|
| 821 |
+
* The output will be the same irrespective of the machine that the code is running on.
|
| 822 |
+
* <p>
|
| 823 |
+
* This method drops the prefix from the result.
|
| 824 |
+
* See {@link #getFullPathNoEndSeparator(String)} for the method that retains the prefix.
|
| 825 |
+
*
|
| 826 |
+
* @param filename the filename to query, null returns null
|
| 827 |
+
* @return the path of the file, an empty string if none exists, null if invalid.
|
| 828 |
+
* Null bytes inside string will be removed
|
| 829 |
+
*/
|
| 830 |
+
public static String getPathNoEndSeparator(final String filename) {
|
| 831 |
+
return doGetPath(filename, 0);
|
| 832 |
+
}
|
| 833 |
+
|
| 834 |
+
/**
|
| 835 |
+
* Does the work of getting the path.
|
| 836 |
+
*
|
| 837 |
+
* @param filename the filename
|
| 838 |
+
* @param separatorAdd 0 to omit the end separator, 1 to return it
|
| 839 |
+
* @return the path. Null bytes inside string will be removed
|
| 840 |
+
*/
|
| 841 |
+
private static String doGetPath(final String filename, final int separatorAdd) {
|
| 842 |
+
if (filename == null) {
|
| 843 |
+
return null;
|
| 844 |
+
}
|
| 845 |
+
final int prefix = getPrefixLength(filename);
|
| 846 |
+
if (prefix < 0) {
|
| 847 |
+
return null;
|
| 848 |
+
}
|
| 849 |
+
final int index = indexOfLastSeparator(filename);
|
| 850 |
+
final int endIndex = index+separatorAdd;
|
| 851 |
+
if (prefix >= filename.length() || index < 0 || prefix >= endIndex) {
|
| 852 |
+
return "";
|
| 853 |
+
}
|
| 854 |
+
String path = filename.substring(prefix, endIndex);
|
| 855 |
+
failIfNullBytePresent(path);
|
| 856 |
+
return path;
|
| 857 |
+
}
|
| 858 |
+
|
| 859 |
+
/**
|
| 860 |
+
* Gets the full path from a full filename, which is the prefix + path.
|
| 861 |
+
* <p>
|
| 862 |
+
* This method will handle a file in either Unix or Windows format.
|
| 863 |
+
* The method is entirely text based, and returns the text before and
|
| 864 |
+
* including the last forward or backslash.
|
| 865 |
+
* <pre>
|
| 866 |
+
* C:\a\b\c.txt --> C:\a\b\
|
| 867 |
+
* ~/a/b/c.txt --> ~/a/b/
|
| 868 |
+
* a.txt --> ""
|
| 869 |
+
* a/b/c --> a/b/
|
| 870 |
+
* a/b/c/ --> a/b/c/
|
| 871 |
+
* C: --> C:
|
| 872 |
+
* C:\ --> C:\
|
| 873 |
+
* ~ --> ~/
|
| 874 |
+
* ~/ --> ~/
|
| 875 |
+
* ~user --> ~user/
|
| 876 |
+
* ~user/ --> ~user/
|
| 877 |
+
* </pre>
|
| 878 |
+
* <p>
|
| 879 |
+
* The output will be the same irrespective of the machine that the code is running on.
|
| 880 |
+
*
|
| 881 |
+
* @param filename the filename to query, null returns null
|
| 882 |
+
* @return the path of the file, an empty string if none exists, null if invalid
|
| 883 |
+
*/
|
| 884 |
+
public static String getFullPath(final String filename) {
|
| 885 |
+
return doGetFullPath(filename, true);
|
| 886 |
+
}
|
| 887 |
+
|
| 888 |
+
/**
|
| 889 |
+
* Gets the full path from a full filename, which is the prefix + path,
|
| 890 |
+
* and also excluding the final directory separator.
|
| 891 |
+
* <p>
|
| 892 |
+
* This method will handle a file in either Unix or Windows format.
|
| 893 |
+
* The method is entirely text based, and returns the text before the
|
| 894 |
+
* last forward or backslash.
|
| 895 |
+
* <pre>
|
| 896 |
+
* C:\a\b\c.txt --> C:\a\b
|
| 897 |
+
* ~/a/b/c.txt --> ~/a/b
|
| 898 |
+
* a.txt --> ""
|
| 899 |
+
* a/b/c --> a/b
|
| 900 |
+
* a/b/c/ --> a/b/c
|
| 901 |
+
* C: --> C:
|
| 902 |
+
* C:\ --> C:\
|
| 903 |
+
* ~ --> ~
|
| 904 |
+
* ~/ --> ~
|
| 905 |
+
* ~user --> ~user
|
| 906 |
+
* ~user/ --> ~user
|
| 907 |
+
* </pre>
|
| 908 |
+
* <p>
|
| 909 |
+
* The output will be the same irrespective of the machine that the code is running on.
|
| 910 |
+
*
|
| 911 |
+
* @param filename the filename to query, null returns null
|
| 912 |
+
* @return the path of the file, an empty string if none exists, null if invalid
|
| 913 |
+
*/
|
| 914 |
+
public static String getFullPathNoEndSeparator(final String filename) {
|
| 915 |
+
return doGetFullPath(filename, false);
|
| 916 |
+
}
|
| 917 |
+
|
| 918 |
+
/**
|
| 919 |
+
* Does the work of getting the path.
|
| 920 |
+
*
|
| 921 |
+
* @param filename the filename
|
| 922 |
+
* @param includeSeparator true to include the end separator
|
| 923 |
+
* @return the path
|
| 924 |
+
*/
|
| 925 |
+
private static String doGetFullPath(final String filename, final boolean includeSeparator) {
|
| 926 |
+
if (filename == null) {
|
| 927 |
+
return null;
|
| 928 |
+
}
|
| 929 |
+
final int prefix = getPrefixLength(filename);
|
| 930 |
+
if (prefix < 0) {
|
| 931 |
+
return null;
|
| 932 |
+
}
|
| 933 |
+
if (prefix >= filename.length()) {
|
| 934 |
+
if (includeSeparator) {
|
| 935 |
+
return getPrefix(filename); // add end slash if necessary
|
| 936 |
+
} else {
|
| 937 |
+
return filename;
|
| 938 |
+
}
|
| 939 |
+
}
|
| 940 |
+
final int index = indexOfLastSeparator(filename);
|
| 941 |
+
if (index < 0) {
|
| 942 |
+
return filename.substring(0, prefix);
|
| 943 |
+
}
|
| 944 |
+
int end = index + (includeSeparator ? 1 : 0);
|
| 945 |
+
if (end == 0) {
|
| 946 |
+
end++;
|
| 947 |
+
}
|
| 948 |
+
return filename.substring(0, end);
|
| 949 |
+
}
|
| 950 |
+
|
| 951 |
+
/**
|
| 952 |
+
* Gets the name minus the path from a full filename.
|
| 953 |
+
* <p>
|
| 954 |
+
* This method will handle a file in either Unix or Windows format.
|
| 955 |
+
* The text after the last forward or backslash is returned.
|
| 956 |
+
* <pre>
|
| 957 |
+
* a/b/c.txt --> c.txt
|
| 958 |
+
* a.txt --> a.txt
|
| 959 |
+
* a/b/c --> c
|
| 960 |
+
* a/b/c/ --> ""
|
| 961 |
+
* </pre>
|
| 962 |
+
* <p>
|
| 963 |
+
* The output will be the same irrespective of the machine that the code is running on.
|
| 964 |
+
*
|
| 965 |
+
* @param filename the filename to query, null returns null
|
| 966 |
+
* @return the name of the file without the path, or an empty string if none exists.
|
| 967 |
+
* Null bytes inside string will be removed
|
| 968 |
+
*/
|
| 969 |
+
public static String getName(final String filename) {
|
| 970 |
+
if (filename == null) {
|
| 971 |
+
return null;
|
| 972 |
+
}
|
| 973 |
+
failIfNullBytePresent(filename);
|
| 974 |
+
final int index = indexOfLastSeparator(filename);
|
| 975 |
+
return filename.substring(index + 1);
|
| 976 |
+
}
|
| 977 |
+
|
| 978 |
+
/**
|
| 979 |
+
* Check the input for null bytes, a sign of unsanitized data being passed to to file level functions.
|
| 980 |
+
*
|
| 981 |
+
* This may be used for poison byte attacks.
|
| 982 |
+
* @param path the path to check
|
| 983 |
+
*/
|
| 984 |
+
private static void failIfNullBytePresent(String path) {
|
| 985 |
+
int len = path.length();
|
| 986 |
+
for (int i = 0; i < len; i++) {
|
| 987 |
+
if (path.charAt(i) == 0) {
|
| 988 |
+
throw new IllegalArgumentException("Null byte present in file/path name. There are no " +
|
| 989 |
+
"known legitimate use cases for such data, but several injection attacks may use it");
|
| 990 |
+
}
|
| 991 |
+
}
|
| 992 |
+
}
|
| 993 |
+
|
| 994 |
+
/**
|
| 995 |
+
* Gets the base name, minus the full path and extension, from a full filename.
|
| 996 |
+
* <p>
|
| 997 |
+
* This method will handle a file in either Unix or Windows format.
|
| 998 |
+
* The text after the last forward or backslash and before the last dot is returned.
|
| 999 |
+
* <pre>
|
| 1000 |
+
* a/b/c.txt --> c
|
| 1001 |
+
* a.txt --> a
|
| 1002 |
+
* a/b/c --> c
|
| 1003 |
+
* a/b/c/ --> ""
|
| 1004 |
+
* </pre>
|
| 1005 |
+
* <p>
|
| 1006 |
+
* The output will be the same irrespective of the machine that the code is running on.
|
| 1007 |
+
*
|
| 1008 |
+
* @param filename the filename to query, null returns null
|
| 1009 |
+
* @return the name of the file without the path, or an empty string if none exists. Null bytes inside string
|
| 1010 |
+
* will be removed
|
| 1011 |
+
*/
|
| 1012 |
+
public static String getBaseName(final String filename) {
|
| 1013 |
+
return removeExtension(getName(filename));
|
| 1014 |
+
}
|
| 1015 |
+
|
| 1016 |
+
/**
|
| 1017 |
+
* Gets the extension of a filename.
|
| 1018 |
+
* <p>
|
| 1019 |
+
* This method returns the textual part of the filename after the last dot.
|
| 1020 |
+
* There must be no directory separator after the dot.
|
| 1021 |
+
* <pre>
|
| 1022 |
+
* foo.txt --> "txt"
|
| 1023 |
+
* a/b/c.jpg --> "jpg"
|
| 1024 |
+
* a/b.txt/c --> ""
|
| 1025 |
+
* a/b/c --> ""
|
| 1026 |
+
* </pre>
|
| 1027 |
+
* <p>
|
| 1028 |
+
* The output will be the same irrespective of the machine that the code is running on.
|
| 1029 |
+
*
|
| 1030 |
+
* @param filename the filename to retrieve the extension of.
|
| 1031 |
+
* @return the extension of the file or an empty string if none exists or {@code null}
|
| 1032 |
+
* if the filename is {@code null}.
|
| 1033 |
+
*/
|
| 1034 |
+
public static String getExtension(final String filename) {
|
| 1035 |
+
if (filename == null) {
|
| 1036 |
+
return null;
|
| 1037 |
+
}
|
| 1038 |
+
final int index = indexOfExtension(filename);
|
| 1039 |
+
if (index == NOT_FOUND) {
|
| 1040 |
+
return "";
|
| 1041 |
+
} else {
|
| 1042 |
+
return filename.substring(index + 1);
|
| 1043 |
+
}
|
| 1044 |
+
}
|
| 1045 |
+
|
| 1046 |
+
//-----------------------------------------------------------------------
|
| 1047 |
+
/**
|
| 1048 |
+
* Removes the extension from a filename.
|
| 1049 |
+
* <p>
|
| 1050 |
+
* This method returns the textual part of the filename before the last dot.
|
| 1051 |
+
* There must be no directory separator after the dot.
|
| 1052 |
+
* <pre>
|
| 1053 |
+
* foo.txt --> foo
|
| 1054 |
+
* a\b\c.jpg --> a\b\c
|
| 1055 |
+
* a\b\c --> a\b\c
|
| 1056 |
+
* a.b\c --> a.b\c
|
| 1057 |
+
* </pre>
|
| 1058 |
+
* <p>
|
| 1059 |
+
* The output will be the same irrespective of the machine that the code is running on.
|
| 1060 |
+
*
|
| 1061 |
+
* @param filename the filename to query, null returns null
|
| 1062 |
+
* @return the filename minus the extension
|
| 1063 |
+
*/
|
| 1064 |
+
public static String removeExtension(final String filename) {
|
| 1065 |
+
if (filename == null) {
|
| 1066 |
+
return null;
|
| 1067 |
+
}
|
| 1068 |
+
failIfNullBytePresent(filename);
|
| 1069 |
+
|
| 1070 |
+
final int index = indexOfExtension(filename);
|
| 1071 |
+
if (index == NOT_FOUND) {
|
| 1072 |
+
return filename;
|
| 1073 |
+
} else {
|
| 1074 |
+
return filename.substring(0, index);
|
| 1075 |
+
}
|
| 1076 |
+
}
|
| 1077 |
+
|
| 1078 |
+
//-----------------------------------------------------------------------
|
| 1079 |
+
/**
|
| 1080 |
+
* Checks whether two filenames are equal exactly.
|
| 1081 |
+
* <p>
|
| 1082 |
+
* No processing is performed on the filenames other than comparison,
|
| 1083 |
+
* thus this is merely a null-safe case-sensitive equals.
|
| 1084 |
+
*
|
| 1085 |
+
* @param filename1 the first filename to query, may be null
|
| 1086 |
+
* @param filename2 the second filename to query, may be null
|
| 1087 |
+
* @return true if the filenames are equal, null equals null
|
| 1088 |
+
* @see IOCase#SENSITIVE
|
| 1089 |
+
*/
|
| 1090 |
+
public static boolean equals(final String filename1, final String filename2) {
|
| 1091 |
+
return equals(filename1, filename2, false, IOCase.SENSITIVE);
|
| 1092 |
+
}
|
| 1093 |
+
|
| 1094 |
+
/**
|
| 1095 |
+
* Checks whether two filenames are equal using the case rules of the system.
|
| 1096 |
+
* <p>
|
| 1097 |
+
* No processing is performed on the filenames other than comparison.
|
| 1098 |
+
* The check is case-sensitive on Unix and case-insensitive on Windows.
|
| 1099 |
+
*
|
| 1100 |
+
* @param filename1 the first filename to query, may be null
|
| 1101 |
+
* @param filename2 the second filename to query, may be null
|
| 1102 |
+
* @return true if the filenames are equal, null equals null
|
| 1103 |
+
* @see IOCase#SYSTEM
|
| 1104 |
+
*/
|
| 1105 |
+
public static boolean equalsOnSystem(final String filename1, final String filename2) {
|
| 1106 |
+
return equals(filename1, filename2, false, IOCase.SYSTEM);
|
| 1107 |
+
}
|
| 1108 |
+
|
| 1109 |
+
//-----------------------------------------------------------------------
|
| 1110 |
+
/**
|
| 1111 |
+
* Checks whether two filenames are equal after both have been normalized.
|
| 1112 |
+
* <p>
|
| 1113 |
+
* Both filenames are first passed to {@link #normalize(String)}.
|
| 1114 |
+
* The check is then performed in a case-sensitive manner.
|
| 1115 |
+
*
|
| 1116 |
+
* @param filename1 the first filename to query, may be null
|
| 1117 |
+
* @param filename2 the second filename to query, may be null
|
| 1118 |
+
* @return true if the filenames are equal, null equals null
|
| 1119 |
+
* @see IOCase#SENSITIVE
|
| 1120 |
+
*/
|
| 1121 |
+
public static boolean equalsNormalized(final String filename1, final String filename2) {
|
| 1122 |
+
return equals(filename1, filename2, true, IOCase.SENSITIVE);
|
| 1123 |
+
}
|
| 1124 |
+
|
| 1125 |
+
/**
|
| 1126 |
+
* Checks whether two filenames are equal after both have been normalized
|
| 1127 |
+
* and using the case rules of the system.
|
| 1128 |
+
* <p>
|
| 1129 |
+
* Both filenames are first passed to {@link #normalize(String)}.
|
| 1130 |
+
* The check is then performed case-sensitive on Unix and
|
| 1131 |
+
* case-insensitive on Windows.
|
| 1132 |
+
*
|
| 1133 |
+
* @param filename1 the first filename to query, may be null
|
| 1134 |
+
* @param filename2 the second filename to query, may be null
|
| 1135 |
+
* @return true if the filenames are equal, null equals null
|
| 1136 |
+
* @see IOCase#SYSTEM
|
| 1137 |
+
*/
|
| 1138 |
+
public static boolean equalsNormalizedOnSystem(final String filename1, final String filename2) {
|
| 1139 |
+
return equals(filename1, filename2, true, IOCase.SYSTEM);
|
| 1140 |
+
}
|
| 1141 |
+
|
| 1142 |
+
/**
|
| 1143 |
+
* Checks whether two filenames are equal, optionally normalizing and providing
|
| 1144 |
+
* control over the case-sensitivity.
|
| 1145 |
+
*
|
| 1146 |
+
* @param filename1 the first filename to query, may be null
|
| 1147 |
+
* @param filename2 the second filename to query, may be null
|
| 1148 |
+
* @param normalized whether to normalize the filenames
|
| 1149 |
+
* @param caseSensitivity what case sensitivity rule to use, null means case-sensitive
|
| 1150 |
+
* @return true if the filenames are equal, null equals null
|
| 1151 |
+
* @since 1.3
|
| 1152 |
+
*/
|
| 1153 |
+
public static boolean equals(
|
| 1154 |
+
String filename1, String filename2,
|
| 1155 |
+
final boolean normalized, IOCase caseSensitivity) {
|
| 1156 |
+
|
| 1157 |
+
if (filename1 == null || filename2 == null) {
|
| 1158 |
+
return filename1 == null && filename2 == null;
|
| 1159 |
+
}
|
| 1160 |
+
if (normalized) {
|
| 1161 |
+
filename1 = normalize(filename1);
|
| 1162 |
+
filename2 = normalize(filename2);
|
| 1163 |
+
if (filename1 == null || filename2 == null) {
|
| 1164 |
+
throw new NullPointerException(
|
| 1165 |
+
"Error normalizing one or both of the file names");
|
| 1166 |
+
}
|
| 1167 |
+
}
|
| 1168 |
+
if (caseSensitivity == null) {
|
| 1169 |
+
caseSensitivity = IOCase.SENSITIVE;
|
| 1170 |
+
}
|
| 1171 |
+
return caseSensitivity.checkEquals(filename1, filename2);
|
| 1172 |
+
}
|
| 1173 |
+
|
| 1174 |
+
//-----------------------------------------------------------------------
|
| 1175 |
+
/**
|
| 1176 |
+
* Checks whether the extension of the filename is that specified.
|
| 1177 |
+
* <p>
|
| 1178 |
+
* This method obtains the extension as the textual part of the filename
|
| 1179 |
+
* after the last dot. There must be no directory separator after the dot.
|
| 1180 |
+
* The extension check is case-sensitive on all platforms.
|
| 1181 |
+
*
|
| 1182 |
+
* @param filename the filename to query, null returns false
|
| 1183 |
+
* @param extension the extension to check for, null or empty checks for no extension
|
| 1184 |
+
* @return true if the filename has the specified extension
|
| 1185 |
+
* @throws java.lang.IllegalArgumentException if the supplied filename contains null bytes
|
| 1186 |
+
*/
|
| 1187 |
+
public static boolean isExtension(final String filename, final String extension) {
|
| 1188 |
+
if (filename == null) {
|
| 1189 |
+
return false;
|
| 1190 |
+
}
|
| 1191 |
+
failIfNullBytePresent(filename);
|
| 1192 |
+
|
| 1193 |
+
if (extension == null || extension.isEmpty()) {
|
| 1194 |
+
return indexOfExtension(filename) == NOT_FOUND;
|
| 1195 |
+
}
|
| 1196 |
+
final String fileExt = getExtension(filename);
|
| 1197 |
+
return fileExt.equals(extension);
|
| 1198 |
+
}
|
| 1199 |
+
|
| 1200 |
+
/**
|
| 1201 |
+
* Checks whether the extension of the filename is one of those specified.
|
| 1202 |
+
* <p>
|
| 1203 |
+
* This method obtains the extension as the textual part of the filename
|
| 1204 |
+
* after the last dot. There must be no directory separator after the dot.
|
| 1205 |
+
* The extension check is case-sensitive on all platforms.
|
| 1206 |
+
*
|
| 1207 |
+
* @param filename the filename to query, null returns false
|
| 1208 |
+
* @param extensions the extensions to check for, null checks for no extension
|
| 1209 |
+
* @return true if the filename is one of the extensions
|
| 1210 |
+
* @throws java.lang.IllegalArgumentException if the supplied filename contains null bytes
|
| 1211 |
+
*/
|
| 1212 |
+
public static boolean isExtension(final String filename, final String[] extensions) {
|
| 1213 |
+
if (filename == null) {
|
| 1214 |
+
return false;
|
| 1215 |
+
}
|
| 1216 |
+
failIfNullBytePresent(filename);
|
| 1217 |
+
|
| 1218 |
+
if (extensions == null || extensions.length == 0) {
|
| 1219 |
+
return indexOfExtension(filename) == NOT_FOUND;
|
| 1220 |
+
}
|
| 1221 |
+
final String fileExt = getExtension(filename);
|
| 1222 |
+
for (final String extension : extensions) {
|
| 1223 |
+
if (fileExt.equals(extension)) {
|
| 1224 |
+
return true;
|
| 1225 |
+
}
|
| 1226 |
+
}
|
| 1227 |
+
return false;
|
| 1228 |
+
}
|
| 1229 |
+
|
| 1230 |
+
/**
|
| 1231 |
+
* Checks whether the extension of the filename is one of those specified.
|
| 1232 |
+
* <p>
|
| 1233 |
+
* This method obtains the extension as the textual part of the filename
|
| 1234 |
+
* after the last dot. There must be no directory separator after the dot.
|
| 1235 |
+
* The extension check is case-sensitive on all platforms.
|
| 1236 |
+
*
|
| 1237 |
+
* @param filename the filename to query, null returns false
|
| 1238 |
+
* @param extensions the extensions to check for, null checks for no extension
|
| 1239 |
+
* @return true if the filename is one of the extensions
|
| 1240 |
+
* @throws java.lang.IllegalArgumentException if the supplied filename contains null bytes
|
| 1241 |
+
*/
|
| 1242 |
+
public static boolean isExtension(final String filename, final Collection<String> extensions) {
|
| 1243 |
+
if (filename == null) {
|
| 1244 |
+
return false;
|
| 1245 |
+
}
|
| 1246 |
+
failIfNullBytePresent(filename);
|
| 1247 |
+
|
| 1248 |
+
if (extensions == null || extensions.isEmpty()) {
|
| 1249 |
+
return indexOfExtension(filename) == NOT_FOUND;
|
| 1250 |
+
}
|
| 1251 |
+
final String fileExt = getExtension(filename);
|
| 1252 |
+
for (final String extension : extensions) {
|
| 1253 |
+
if (fileExt.equals(extension)) {
|
| 1254 |
+
return true;
|
| 1255 |
+
}
|
| 1256 |
+
}
|
| 1257 |
+
return false;
|
| 1258 |
+
}
|
| 1259 |
+
|
| 1260 |
+
//-----------------------------------------------------------------------
|
| 1261 |
+
/**
|
| 1262 |
+
* Checks a filename to see if it matches the specified wildcard matcher,
|
| 1263 |
+
* always testing case-sensitive.
|
| 1264 |
+
* <p>
|
| 1265 |
+
* The wildcard matcher uses the characters '?' and '*' to represent a
|
| 1266 |
+
* single or multiple (zero or more) wildcard characters.
|
| 1267 |
+
* This is the same as often found on Dos/Unix command lines.
|
| 1268 |
+
* The check is case-sensitive always.
|
| 1269 |
+
* <pre>
|
| 1270 |
+
* wildcardMatch("c.txt", "*.txt") --> true
|
| 1271 |
+
* wildcardMatch("c.txt", "*.jpg") --> false
|
| 1272 |
+
* wildcardMatch("a/b/c.txt", "a/b/*") --> true
|
| 1273 |
+
* wildcardMatch("c.txt", "*.???") --> true
|
| 1274 |
+
* wildcardMatch("c.txt", "*.????") --> false
|
| 1275 |
+
* </pre>
|
| 1276 |
+
* N.B. the sequence "*?" does not work properly at present in match strings.
|
| 1277 |
+
*
|
| 1278 |
+
* @param filename the filename to match on
|
| 1279 |
+
* @param wildcardMatcher the wildcard string to match against
|
| 1280 |
+
* @return true if the filename matches the wilcard string
|
| 1281 |
+
* @see IOCase#SENSITIVE
|
| 1282 |
+
*/
|
| 1283 |
+
public static boolean wildcardMatch(final String filename, final String wildcardMatcher) {
|
| 1284 |
+
return wildcardMatch(filename, wildcardMatcher, IOCase.SENSITIVE);
|
| 1285 |
+
}
|
| 1286 |
+
|
| 1287 |
+
/**
|
| 1288 |
+
* Checks a filename to see if it matches the specified wildcard matcher
|
| 1289 |
+
* using the case rules of the system.
|
| 1290 |
+
* <p>
|
| 1291 |
+
* The wildcard matcher uses the characters '?' and '*' to represent a
|
| 1292 |
+
* single or multiple (zero or more) wildcard characters.
|
| 1293 |
+
* This is the same as often found on Dos/Unix command lines.
|
| 1294 |
+
* The check is case-sensitive on Unix and case-insensitive on Windows.
|
| 1295 |
+
* <pre>
|
| 1296 |
+
* wildcardMatch("c.txt", "*.txt") --> true
|
| 1297 |
+
* wildcardMatch("c.txt", "*.jpg") --> false
|
| 1298 |
+
* wildcardMatch("a/b/c.txt", "a/b/*") --> true
|
| 1299 |
+
* wildcardMatch("c.txt", "*.???") --> true
|
| 1300 |
+
* wildcardMatch("c.txt", "*.????") --> false
|
| 1301 |
+
* </pre>
|
| 1302 |
+
* N.B. the sequence "*?" does not work properly at present in match strings.
|
| 1303 |
+
*
|
| 1304 |
+
* @param filename the filename to match on
|
| 1305 |
+
* @param wildcardMatcher the wildcard string to match against
|
| 1306 |
+
* @return true if the filename matches the wilcard string
|
| 1307 |
+
* @see IOCase#SYSTEM
|
| 1308 |
+
*/
|
| 1309 |
+
public static boolean wildcardMatchOnSystem(final String filename, final String wildcardMatcher) {
|
| 1310 |
+
return wildcardMatch(filename, wildcardMatcher, IOCase.SYSTEM);
|
| 1311 |
+
}
|
| 1312 |
+
|
| 1313 |
+
/**
|
| 1314 |
+
* Checks a filename to see if it matches the specified wildcard matcher
|
| 1315 |
+
* allowing control over case-sensitivity.
|
| 1316 |
+
* <p>
|
| 1317 |
+
* The wildcard matcher uses the characters '?' and '*' to represent a
|
| 1318 |
+
* single or multiple (zero or more) wildcard characters.
|
| 1319 |
+
* N.B. the sequence "*?" does not work properly at present in match strings.
|
| 1320 |
+
*
|
| 1321 |
+
* @param filename the filename to match on
|
| 1322 |
+
* @param wildcardMatcher the wildcard string to match against
|
| 1323 |
+
* @param caseSensitivity what case sensitivity rule to use, null means case-sensitive
|
| 1324 |
+
* @return true if the filename matches the wilcard string
|
| 1325 |
+
* @since 1.3
|
| 1326 |
+
*/
|
| 1327 |
+
public static boolean wildcardMatch(final String filename, final String wildcardMatcher, IOCase caseSensitivity) {
|
| 1328 |
+
if (filename == null && wildcardMatcher == null) {
|
| 1329 |
+
return true;
|
| 1330 |
+
}
|
| 1331 |
+
if (filename == null || wildcardMatcher == null) {
|
| 1332 |
+
return false;
|
| 1333 |
+
}
|
| 1334 |
+
if (caseSensitivity == null) {
|
| 1335 |
+
caseSensitivity = IOCase.SENSITIVE;
|
| 1336 |
+
}
|
| 1337 |
+
final String[] wcs = splitOnTokens(wildcardMatcher);
|
| 1338 |
+
boolean anyChars = false;
|
| 1339 |
+
int textIdx = 0;
|
| 1340 |
+
int wcsIdx = 0;
|
| 1341 |
+
final Stack<int[]> backtrack = new Stack<int[]>();
|
| 1342 |
+
|
| 1343 |
+
// loop around a backtrack stack, to handle complex * matching
|
| 1344 |
+
do {
|
| 1345 |
+
if (backtrack.size() > 0) {
|
| 1346 |
+
final int[] array = backtrack.pop();
|
| 1347 |
+
wcsIdx = array[0];
|
| 1348 |
+
textIdx = array[1];
|
| 1349 |
+
anyChars = true;
|
| 1350 |
+
}
|
| 1351 |
+
|
| 1352 |
+
// loop whilst tokens and text left to process
|
| 1353 |
+
while (wcsIdx < wcs.length) {
|
| 1354 |
+
|
| 1355 |
+
if (wcs[wcsIdx].equals("?")) {
|
| 1356 |
+
// ? so move to next text char
|
| 1357 |
+
textIdx++;
|
| 1358 |
+
if (textIdx > filename.length()) {
|
| 1359 |
+
break;
|
| 1360 |
+
}
|
| 1361 |
+
anyChars = false;
|
| 1362 |
+
|
| 1363 |
+
} else if (wcs[wcsIdx].equals("*")) {
|
| 1364 |
+
// set any chars status
|
| 1365 |
+
anyChars = true;
|
| 1366 |
+
if (wcsIdx == wcs.length - 1) {
|
| 1367 |
+
textIdx = filename.length();
|
| 1368 |
+
}
|
| 1369 |
+
|
| 1370 |
+
} else {
|
| 1371 |
+
// matching text token
|
| 1372 |
+
if (anyChars) {
|
| 1373 |
+
// any chars then try to locate text token
|
| 1374 |
+
textIdx = caseSensitivity.checkIndexOf(filename, textIdx, wcs[wcsIdx]);
|
| 1375 |
+
if (textIdx == NOT_FOUND) {
|
| 1376 |
+
// token not found
|
| 1377 |
+
break;
|
| 1378 |
+
}
|
| 1379 |
+
final int repeat = caseSensitivity.checkIndexOf(filename, textIdx + 1, wcs[wcsIdx]);
|
| 1380 |
+
if (repeat >= 0) {
|
| 1381 |
+
backtrack.push(new int[] {wcsIdx, repeat});
|
| 1382 |
+
}
|
| 1383 |
+
} else {
|
| 1384 |
+
// matching from current position
|
| 1385 |
+
if (!caseSensitivity.checkRegionMatches(filename, textIdx, wcs[wcsIdx])) {
|
| 1386 |
+
// couldnt match token
|
| 1387 |
+
break;
|
| 1388 |
+
}
|
| 1389 |
+
}
|
| 1390 |
+
|
| 1391 |
+
// matched text token, move text index to end of matched token
|
| 1392 |
+
textIdx += wcs[wcsIdx].length();
|
| 1393 |
+
anyChars = false;
|
| 1394 |
+
}
|
| 1395 |
+
|
| 1396 |
+
wcsIdx++;
|
| 1397 |
+
}
|
| 1398 |
+
|
| 1399 |
+
// full match
|
| 1400 |
+
if (wcsIdx == wcs.length && textIdx == filename.length()) {
|
| 1401 |
+
return true;
|
| 1402 |
+
}
|
| 1403 |
+
|
| 1404 |
+
} while (backtrack.size() > 0);
|
| 1405 |
+
|
| 1406 |
+
return false;
|
| 1407 |
+
}
|
| 1408 |
+
|
| 1409 |
+
/**
|
| 1410 |
+
* Splits a string into a number of tokens.
|
| 1411 |
+
* The text is split by '?' and '*'.
|
| 1412 |
+
* Where multiple '*' occur consecutively they are collapsed into a single '*'.
|
| 1413 |
+
*
|
| 1414 |
+
* @param text the text to split
|
| 1415 |
+
* @return the array of tokens, never null
|
| 1416 |
+
*/
|
| 1417 |
+
static String[] splitOnTokens(final String text) {
|
| 1418 |
+
// used by wildcardMatch
|
| 1419 |
+
// package level so a unit test may run on this
|
| 1420 |
+
|
| 1421 |
+
if (text.indexOf('?') == NOT_FOUND && text.indexOf('*') == NOT_FOUND) {
|
| 1422 |
+
return new String[] { text };
|
| 1423 |
+
}
|
| 1424 |
+
|
| 1425 |
+
final char[] array = text.toCharArray();
|
| 1426 |
+
final ArrayList<String> list = new ArrayList<String>();
|
| 1427 |
+
final StringBuilder buffer = new StringBuilder();
|
| 1428 |
+
char prevChar = 0;
|
| 1429 |
+
for (final char ch : array) {
|
| 1430 |
+
if (ch == '?' || ch == '*') {
|
| 1431 |
+
if (buffer.length() != 0) {
|
| 1432 |
+
list.add(buffer.toString());
|
| 1433 |
+
buffer.setLength(0);
|
| 1434 |
+
}
|
| 1435 |
+
if (ch == '?') {
|
| 1436 |
+
list.add("?");
|
| 1437 |
+
} else if (prevChar != '*') {// ch == '*' here; check if previous char was '*'
|
| 1438 |
+
list.add("*");
|
| 1439 |
+
}
|
| 1440 |
+
} else {
|
| 1441 |
+
buffer.append(ch);
|
| 1442 |
+
}
|
| 1443 |
+
prevChar = ch;
|
| 1444 |
+
}
|
| 1445 |
+
if (buffer.length() != 0) {
|
| 1446 |
+
list.add(buffer.toString());
|
| 1447 |
+
}
|
| 1448 |
+
|
| 1449 |
+
return list.toArray( new String[ list.size() ] );
|
| 1450 |
+
}
|
| 1451 |
+
|
| 1452 |
+
}
|
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/01_课件与电子教材/尚硅谷_第15章_File类与IO流/03-apache-common包/commons-io-2.5-src/src/main/java/org/apache/commons/io/HexDump.java
ADDED
|
@@ -0,0 +1,163 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Licensed to the Apache Software Foundation (ASF) under one or more
|
| 3 |
+
* contributor license agreements. See the NOTICE file distributed with
|
| 4 |
+
* this work for additional information regarding copyright ownership.
|
| 5 |
+
* The ASF licenses this file to You under the Apache License, Version 2.0
|
| 6 |
+
* (the "License"); you may not use this file except in compliance with
|
| 7 |
+
* the License. You may obtain a copy of the License at
|
| 8 |
+
*
|
| 9 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
*
|
| 11 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 12 |
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
| 13 |
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 14 |
+
* See the License for the specific language governing permissions and
|
| 15 |
+
* limitations under the License.
|
| 16 |
+
*/
|
| 17 |
+
package org.apache.commons.io;
|
| 18 |
+
|
| 19 |
+
import java.io.IOException;
|
| 20 |
+
import java.io.OutputStream;
|
| 21 |
+
import java.nio.charset.Charset;
|
| 22 |
+
|
| 23 |
+
/**
|
| 24 |
+
* Dumps data in hexadecimal format.
|
| 25 |
+
* <p>
|
| 26 |
+
* Provides a single function to take an array of bytes and display it
|
| 27 |
+
* in hexadecimal form.
|
| 28 |
+
* <p>
|
| 29 |
+
* Origin of code: POI.
|
| 30 |
+
*
|
| 31 |
+
* @version $Id: HexDump.java 1471767 2013-04-24 23:24:19Z sebb $
|
| 32 |
+
*/
|
| 33 |
+
public class HexDump {
|
| 34 |
+
|
| 35 |
+
/**
|
| 36 |
+
* Instances should NOT be constructed in standard programming.
|
| 37 |
+
*/
|
| 38 |
+
public HexDump() {
|
| 39 |
+
super();
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
/**
|
| 43 |
+
* Dump an array of bytes to an OutputStream. The output is formatted
|
| 44 |
+
* for human inspection, with a hexadecimal offset followed by the
|
| 45 |
+
* hexadecimal values of the next 16 bytes of data and the printable ASCII
|
| 46 |
+
* characters (if any) that those bytes represent printed per each line
|
| 47 |
+
* of output.
|
| 48 |
+
* <p>
|
| 49 |
+
* The offset argument specifies the start offset of the data array
|
| 50 |
+
* within a larger entity like a file or an incoming stream. For example,
|
| 51 |
+
* if the data array contains the third kibibyte of a file, then the
|
| 52 |
+
* offset argument should be set to 2048. The offset value printed
|
| 53 |
+
* at the beginning of each line indicates where in that larger entity
|
| 54 |
+
* the first byte on that line is located.
|
| 55 |
+
* <p>
|
| 56 |
+
* All bytes between the given index (inclusive) and the end of the
|
| 57 |
+
* data array are dumped.
|
| 58 |
+
*
|
| 59 |
+
* @param data the byte array to be dumped
|
| 60 |
+
* @param offset offset of the byte array within a larger entity
|
| 61 |
+
* @param stream the OutputStream to which the data is to be
|
| 62 |
+
* written
|
| 63 |
+
* @param index initial index into the byte array
|
| 64 |
+
*
|
| 65 |
+
* @throws IOException is thrown if anything goes wrong writing
|
| 66 |
+
* the data to stream
|
| 67 |
+
* @throws ArrayIndexOutOfBoundsException if the index is
|
| 68 |
+
* outside the data array's bounds
|
| 69 |
+
* @throws IllegalArgumentException if the output stream is null
|
| 70 |
+
*/
|
| 71 |
+
|
| 72 |
+
public static void dump(final byte[] data, final long offset,
|
| 73 |
+
final OutputStream stream, final int index)
|
| 74 |
+
throws IOException, ArrayIndexOutOfBoundsException,
|
| 75 |
+
IllegalArgumentException {
|
| 76 |
+
|
| 77 |
+
if (index < 0 || index >= data.length) {
|
| 78 |
+
throw new ArrayIndexOutOfBoundsException(
|
| 79 |
+
"illegal index: " + index + " into array of length "
|
| 80 |
+
+ data.length);
|
| 81 |
+
}
|
| 82 |
+
if (stream == null) {
|
| 83 |
+
throw new IllegalArgumentException("cannot write to nullstream");
|
| 84 |
+
}
|
| 85 |
+
long display_offset = offset + index;
|
| 86 |
+
final StringBuilder buffer = new StringBuilder(74);
|
| 87 |
+
|
| 88 |
+
for (int j = index; j < data.length; j += 16) {
|
| 89 |
+
int chars_read = data.length - j;
|
| 90 |
+
|
| 91 |
+
if (chars_read > 16) {
|
| 92 |
+
chars_read = 16;
|
| 93 |
+
}
|
| 94 |
+
dump(buffer, display_offset).append(' ');
|
| 95 |
+
for (int k = 0; k < 16; k++) {
|
| 96 |
+
if (k < chars_read) {
|
| 97 |
+
dump(buffer, data[k + j]);
|
| 98 |
+
} else {
|
| 99 |
+
buffer.append(" ");
|
| 100 |
+
}
|
| 101 |
+
buffer.append(' ');
|
| 102 |
+
}
|
| 103 |
+
for (int k = 0; k < chars_read; k++) {
|
| 104 |
+
if (data[k + j] >= ' ' && data[k + j] < 127) {
|
| 105 |
+
buffer.append((char) data[k + j]);
|
| 106 |
+
} else {
|
| 107 |
+
buffer.append('.');
|
| 108 |
+
}
|
| 109 |
+
}
|
| 110 |
+
buffer.append(EOL);
|
| 111 |
+
// make explicit the dependency on the default encoding
|
| 112 |
+
stream.write(buffer.toString().getBytes(Charset.defaultCharset()));
|
| 113 |
+
stream.flush();
|
| 114 |
+
buffer.setLength(0);
|
| 115 |
+
display_offset += chars_read;
|
| 116 |
+
}
|
| 117 |
+
}
|
| 118 |
+
|
| 119 |
+
/**
|
| 120 |
+
* The line-separator (initializes to "line.separator" system property.
|
| 121 |
+
*/
|
| 122 |
+
public static final String EOL =
|
| 123 |
+
System.getProperty("line.separator");
|
| 124 |
+
private static final char[] _hexcodes =
|
| 125 |
+
{
|
| 126 |
+
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
|
| 127 |
+
'A', 'B', 'C', 'D', 'E', 'F'
|
| 128 |
+
};
|
| 129 |
+
private static final int[] _shifts =
|
| 130 |
+
{
|
| 131 |
+
28, 24, 20, 16, 12, 8, 4, 0
|
| 132 |
+
};
|
| 133 |
+
|
| 134 |
+
/**
|
| 135 |
+
* Dump a long value into a StringBuilder.
|
| 136 |
+
*
|
| 137 |
+
* @param _lbuffer the StringBuilder to dump the value in
|
| 138 |
+
* @param value the long value to be dumped
|
| 139 |
+
* @return StringBuilder containing the dumped value.
|
| 140 |
+
*/
|
| 141 |
+
private static StringBuilder dump(final StringBuilder _lbuffer, final long value) {
|
| 142 |
+
for (int j = 0; j < 8; j++) {
|
| 143 |
+
_lbuffer
|
| 144 |
+
.append(_hexcodes[(int) (value >> _shifts[j]) & 15]);
|
| 145 |
+
}
|
| 146 |
+
return _lbuffer;
|
| 147 |
+
}
|
| 148 |
+
|
| 149 |
+
/**
|
| 150 |
+
* Dump a byte value into a StringBuilder.
|
| 151 |
+
*
|
| 152 |
+
* @param _cbuffer the StringBuilder to dump the value in
|
| 153 |
+
* @param value the byte value to be dumped
|
| 154 |
+
* @return StringBuilder containing the dumped value.
|
| 155 |
+
*/
|
| 156 |
+
private static StringBuilder dump(final StringBuilder _cbuffer, final byte value) {
|
| 157 |
+
for (int j = 0; j < 2; j++) {
|
| 158 |
+
_cbuffer.append(_hexcodes[value >> _shifts[j + 6] & 15]);
|
| 159 |
+
}
|
| 160 |
+
return _cbuffer;
|
| 161 |
+
}
|
| 162 |
+
|
| 163 |
+
}
|
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/01_课件与电子教材/尚硅谷_第15章_File类与IO流/03-apache-common包/commons-io-2.5-src/src/main/java/org/apache/commons/io/IOCase.java
ADDED
|
@@ -0,0 +1,254 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Licensed to the Apache Software Foundation (ASF) under one or more
|
| 3 |
+
* contributor license agreements. See the NOTICE file distributed with
|
| 4 |
+
* this work for additional information regarding copyright ownership.
|
| 5 |
+
* The ASF licenses this file to You under the Apache License, Version 2.0
|
| 6 |
+
* (the "License"); you may not use this file except in compliance with
|
| 7 |
+
* the License. You may obtain a copy of the License at
|
| 8 |
+
*
|
| 9 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
*
|
| 11 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 12 |
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
| 13 |
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 14 |
+
* See the License for the specific language governing permissions and
|
| 15 |
+
* limitations under the License.
|
| 16 |
+
*/
|
| 17 |
+
package org.apache.commons.io;
|
| 18 |
+
|
| 19 |
+
import java.io.Serializable;
|
| 20 |
+
|
| 21 |
+
/**
|
| 22 |
+
* Enumeration of IO case sensitivity.
|
| 23 |
+
* <p>
|
| 24 |
+
* Different filing systems have different rules for case-sensitivity.
|
| 25 |
+
* Windows is case-insensitive, Unix is case-sensitive.
|
| 26 |
+
* <p>
|
| 27 |
+
* This class captures that difference, providing an enumeration to
|
| 28 |
+
* control how filename comparisons should be performed. It also provides
|
| 29 |
+
* methods that use the enumeration to perform comparisons.
|
| 30 |
+
* <p>
|
| 31 |
+
* Wherever possible, you should use the <code>check</code> methods in this
|
| 32 |
+
* class to compare filenames.
|
| 33 |
+
*
|
| 34 |
+
* @version $Id: IOCase.java 1483915 2013-05-17 17:02:35Z sebb $
|
| 35 |
+
* @since 1.3
|
| 36 |
+
*/
|
| 37 |
+
public enum IOCase implements Serializable {
|
| 38 |
+
|
| 39 |
+
/**
|
| 40 |
+
* The constant for case sensitive regardless of operating system.
|
| 41 |
+
*/
|
| 42 |
+
SENSITIVE ("Sensitive", true),
|
| 43 |
+
|
| 44 |
+
/**
|
| 45 |
+
* The constant for case insensitive regardless of operating system.
|
| 46 |
+
*/
|
| 47 |
+
INSENSITIVE ("Insensitive", false),
|
| 48 |
+
|
| 49 |
+
/**
|
| 50 |
+
* The constant for case sensitivity determined by the current operating system.
|
| 51 |
+
* Windows is case-insensitive when comparing filenames, Unix is case-sensitive.
|
| 52 |
+
* <p>
|
| 53 |
+
* <strong>Note:</strong> This only caters for Windows and Unix. Other operating
|
| 54 |
+
* systems (e.g. OSX and OpenVMS) are treated as case sensitive if they use the
|
| 55 |
+
* Unix file separator and case-insensitive if they use the Windows file separator
|
| 56 |
+
* (see {@link java.io.File#separatorChar}).
|
| 57 |
+
* <p>
|
| 58 |
+
* If you derialize this constant of Windows, and deserialize on Unix, or vice
|
| 59 |
+
* versa, then the value of the case-sensitivity flag will change.
|
| 60 |
+
*/
|
| 61 |
+
SYSTEM ("System", !FilenameUtils.isSystemWindows());
|
| 62 |
+
|
| 63 |
+
/** Serialization version. */
|
| 64 |
+
private static final long serialVersionUID = -6343169151696340687L;
|
| 65 |
+
|
| 66 |
+
/** The enumeration name. */
|
| 67 |
+
private final String name;
|
| 68 |
+
|
| 69 |
+
/** The sensitivity flag. */
|
| 70 |
+
private final transient boolean sensitive;
|
| 71 |
+
|
| 72 |
+
//-----------------------------------------------------------------------
|
| 73 |
+
/**
|
| 74 |
+
* Factory method to create an IOCase from a name.
|
| 75 |
+
*
|
| 76 |
+
* @param name the name to find
|
| 77 |
+
* @return the IOCase object
|
| 78 |
+
* @throws IllegalArgumentException if the name is invalid
|
| 79 |
+
*/
|
| 80 |
+
public static IOCase forName(final String name) {
|
| 81 |
+
for (IOCase ioCase : IOCase.values())
|
| 82 |
+
{
|
| 83 |
+
if (ioCase.getName().equals(name))
|
| 84 |
+
{
|
| 85 |
+
return ioCase;
|
| 86 |
+
}
|
| 87 |
+
}
|
| 88 |
+
throw new IllegalArgumentException("Invalid IOCase name: " + name);
|
| 89 |
+
}
|
| 90 |
+
|
| 91 |
+
//-----------------------------------------------------------------------
|
| 92 |
+
/**
|
| 93 |
+
* Private constructor.
|
| 94 |
+
*
|
| 95 |
+
* @param name the name
|
| 96 |
+
* @param sensitive the sensitivity
|
| 97 |
+
*/
|
| 98 |
+
private IOCase(final String name, final boolean sensitive) {
|
| 99 |
+
this.name = name;
|
| 100 |
+
this.sensitive = sensitive;
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
+
/**
|
| 104 |
+
* Replaces the enumeration from the stream with a real one.
|
| 105 |
+
* This ensures that the correct flag is set for SYSTEM.
|
| 106 |
+
*
|
| 107 |
+
* @return the resolved object
|
| 108 |
+
*/
|
| 109 |
+
private Object readResolve() {
|
| 110 |
+
return forName(name);
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
+
//-----------------------------------------------------------------------
|
| 114 |
+
/**
|
| 115 |
+
* Gets the name of the constant.
|
| 116 |
+
*
|
| 117 |
+
* @return the name of the constant
|
| 118 |
+
*/
|
| 119 |
+
public String getName() {
|
| 120 |
+
return name;
|
| 121 |
+
}
|
| 122 |
+
|
| 123 |
+
/**
|
| 124 |
+
* Does the object represent case sensitive comparison.
|
| 125 |
+
*
|
| 126 |
+
* @return true if case sensitive
|
| 127 |
+
*/
|
| 128 |
+
public boolean isCaseSensitive() {
|
| 129 |
+
return sensitive;
|
| 130 |
+
}
|
| 131 |
+
|
| 132 |
+
//-----------------------------------------------------------------------
|
| 133 |
+
/**
|
| 134 |
+
* Compares two strings using the case-sensitivity rule.
|
| 135 |
+
* <p>
|
| 136 |
+
* This method mimics {@link String#compareTo} but takes case-sensitivity
|
| 137 |
+
* into account.
|
| 138 |
+
*
|
| 139 |
+
* @param str1 the first string to compare, not null
|
| 140 |
+
* @param str2 the second string to compare, not null
|
| 141 |
+
* @return true if equal using the case rules
|
| 142 |
+
* @throws NullPointerException if either string is null
|
| 143 |
+
*/
|
| 144 |
+
public int checkCompareTo(final String str1, final String str2) {
|
| 145 |
+
if (str1 == null || str2 == null) {
|
| 146 |
+
throw new NullPointerException("The strings must not be null");
|
| 147 |
+
}
|
| 148 |
+
return sensitive ? str1.compareTo(str2) : str1.compareToIgnoreCase(str2);
|
| 149 |
+
}
|
| 150 |
+
|
| 151 |
+
/**
|
| 152 |
+
* Compares two strings using the case-sensitivity rule.
|
| 153 |
+
* <p>
|
| 154 |
+
* This method mimics {@link String#equals} but takes case-sensitivity
|
| 155 |
+
* into account.
|
| 156 |
+
*
|
| 157 |
+
* @param str1 the first string to compare, not null
|
| 158 |
+
* @param str2 the second string to compare, not null
|
| 159 |
+
* @return true if equal using the case rules
|
| 160 |
+
* @throws NullPointerException if either string is null
|
| 161 |
+
*/
|
| 162 |
+
public boolean checkEquals(final String str1, final String str2) {
|
| 163 |
+
if (str1 == null || str2 == null) {
|
| 164 |
+
throw new NullPointerException("The strings must not be null");
|
| 165 |
+
}
|
| 166 |
+
return sensitive ? str1.equals(str2) : str1.equalsIgnoreCase(str2);
|
| 167 |
+
}
|
| 168 |
+
|
| 169 |
+
/**
|
| 170 |
+
* Checks if one string starts with another using the case-sensitivity rule.
|
| 171 |
+
* <p>
|
| 172 |
+
* This method mimics {@link String#startsWith(String)} but takes case-sensitivity
|
| 173 |
+
* into account.
|
| 174 |
+
*
|
| 175 |
+
* @param str the string to check, not null
|
| 176 |
+
* @param start the start to compare against, not null
|
| 177 |
+
* @return true if equal using the case rules
|
| 178 |
+
* @throws NullPointerException if either string is null
|
| 179 |
+
*/
|
| 180 |
+
public boolean checkStartsWith(final String str, final String start) {
|
| 181 |
+
return str.regionMatches(!sensitive, 0, start, 0, start.length());
|
| 182 |
+
}
|
| 183 |
+
|
| 184 |
+
/**
|
| 185 |
+
* Checks if one string ends with another using the case-sensitivity rule.
|
| 186 |
+
* <p>
|
| 187 |
+
* This method mimics {@link String#endsWith} but takes case-sensitivity
|
| 188 |
+
* into account.
|
| 189 |
+
*
|
| 190 |
+
* @param str the string to check, not null
|
| 191 |
+
* @param end the end to compare against, not null
|
| 192 |
+
* @return true if equal using the case rules
|
| 193 |
+
* @throws NullPointerException if either string is null
|
| 194 |
+
*/
|
| 195 |
+
public boolean checkEndsWith(final String str, final String end) {
|
| 196 |
+
final int endLen = end.length();
|
| 197 |
+
return str.regionMatches(!sensitive, str.length() - endLen, end, 0, endLen);
|
| 198 |
+
}
|
| 199 |
+
|
| 200 |
+
/**
|
| 201 |
+
* Checks if one string contains another starting at a specific index using the
|
| 202 |
+
* case-sensitivity rule.
|
| 203 |
+
* <p>
|
| 204 |
+
* This method mimics parts of {@link String#indexOf(String, int)}
|
| 205 |
+
* but takes case-sensitivity into account.
|
| 206 |
+
*
|
| 207 |
+
* @param str the string to check, not null
|
| 208 |
+
* @param strStartIndex the index to start at in str
|
| 209 |
+
* @param search the start to search for, not null
|
| 210 |
+
* @return the first index of the search String,
|
| 211 |
+
* -1 if no match or {@code null} string input
|
| 212 |
+
* @throws NullPointerException if either string is null
|
| 213 |
+
* @since 2.0
|
| 214 |
+
*/
|
| 215 |
+
public int checkIndexOf(final String str, final int strStartIndex, final String search) {
|
| 216 |
+
final int endIndex = str.length() - search.length();
|
| 217 |
+
if (endIndex >= strStartIndex) {
|
| 218 |
+
for (int i = strStartIndex; i <= endIndex; i++) {
|
| 219 |
+
if (checkRegionMatches(str, i, search)) {
|
| 220 |
+
return i;
|
| 221 |
+
}
|
| 222 |
+
}
|
| 223 |
+
}
|
| 224 |
+
return -1;
|
| 225 |
+
}
|
| 226 |
+
|
| 227 |
+
/**
|
| 228 |
+
* Checks if one string contains another at a specific index using the case-sensitivity rule.
|
| 229 |
+
* <p>
|
| 230 |
+
* This method mimics parts of {@link String#regionMatches(boolean, int, String, int, int)}
|
| 231 |
+
* but takes case-sensitivity into account.
|
| 232 |
+
*
|
| 233 |
+
* @param str the string to check, not null
|
| 234 |
+
* @param strStartIndex the index to start at in str
|
| 235 |
+
* @param search the start to search for, not null
|
| 236 |
+
* @return true if equal using the case rules
|
| 237 |
+
* @throws NullPointerException if either string is null
|
| 238 |
+
*/
|
| 239 |
+
public boolean checkRegionMatches(final String str, final int strStartIndex, final String search) {
|
| 240 |
+
return str.regionMatches(!sensitive, strStartIndex, search, 0, search.length());
|
| 241 |
+
}
|
| 242 |
+
|
| 243 |
+
//-----------------------------------------------------------------------
|
| 244 |
+
/**
|
| 245 |
+
* Gets a string describing the sensitivity.
|
| 246 |
+
*
|
| 247 |
+
* @return a string describing the sensitivity
|
| 248 |
+
*/
|
| 249 |
+
@Override
|
| 250 |
+
public String toString() {
|
| 251 |
+
return name;
|
| 252 |
+
}
|
| 253 |
+
|
| 254 |
+
}
|
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/01_课件与电子教材/尚硅谷_第15章_File类与IO流/03-apache-common包/commons-io-2.5-src/src/main/java/org/apache/commons/io/IOExceptionWithCause.java
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Licensed to the Apache Software Foundation (ASF) under one or more
|
| 3 |
+
* contributor license agreements. See the NOTICE file distributed with
|
| 4 |
+
* this work for additional information regarding copyright ownership.
|
| 5 |
+
* The ASF licenses this file to You under the Apache License, Version 2.0
|
| 6 |
+
* (the "License"); you may not use this file except in compliance with
|
| 7 |
+
* the License. You may obtain a copy of the License at
|
| 8 |
+
*
|
| 9 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
*
|
| 11 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 12 |
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
| 13 |
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 14 |
+
* See the License for the specific language governing permissions and
|
| 15 |
+
* limitations under the License.
|
| 16 |
+
*/
|
| 17 |
+
|
| 18 |
+
package org.apache.commons.io;
|
| 19 |
+
|
| 20 |
+
import java.io.IOException;
|
| 21 |
+
|
| 22 |
+
/**
|
| 23 |
+
* Subclasses IOException with the {@link Throwable} constructors missing before Java 6.
|
| 24 |
+
*
|
| 25 |
+
* @version $Id: IOExceptionWithCause.java 1643107 2014-12-03 13:05:23Z sebb $
|
| 26 |
+
* @since 1.4
|
| 27 |
+
* @deprecated (since 2.5) use {@link IOException} instead
|
| 28 |
+
*/
|
| 29 |
+
@Deprecated
|
| 30 |
+
public class IOExceptionWithCause extends IOException {
|
| 31 |
+
|
| 32 |
+
/**
|
| 33 |
+
* Defines the serial version UID.
|
| 34 |
+
*/
|
| 35 |
+
private static final long serialVersionUID = 1L;
|
| 36 |
+
|
| 37 |
+
/**
|
| 38 |
+
* Constructs a new instance with the given message and cause.
|
| 39 |
+
* <p>
|
| 40 |
+
* As specified in {@link Throwable}, the message in the given <code>cause</code> is not used in this instance's
|
| 41 |
+
* message.
|
| 42 |
+
* </p>
|
| 43 |
+
*
|
| 44 |
+
* @param message
|
| 45 |
+
* the message (see {@link #getMessage()})
|
| 46 |
+
* @param cause
|
| 47 |
+
* the cause (see {@link #getCause()}). A {@code null} value is allowed.
|
| 48 |
+
*/
|
| 49 |
+
public IOExceptionWithCause(final String message, final Throwable cause) {
|
| 50 |
+
super(message, cause);
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
/**
|
| 54 |
+
* Constructs a new instance with the given cause.
|
| 55 |
+
* <p>
|
| 56 |
+
* The message is set to <code>cause==null ? null : cause.toString()</code>, which by default contains the class
|
| 57 |
+
* and message of <code>cause</code>. This constructor is useful for call sites that just wrap another throwable.
|
| 58 |
+
* </p>
|
| 59 |
+
*
|
| 60 |
+
* @param cause
|
| 61 |
+
* the cause (see {@link #getCause()}). A {@code null} value is allowed.
|
| 62 |
+
*/
|
| 63 |
+
public IOExceptionWithCause(final Throwable cause) {
|
| 64 |
+
super(cause);
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
}
|
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/01_课件与电子教材/尚硅谷_第15章_File类与IO流/03-apache-common包/commons-io-2.5-src/src/main/java/org/apache/commons/io/IOUtils.java
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/01_课件与电子教材/尚硅谷_第15章_File类与IO流/03-apache-common包/commons-io-2.5-src/src/main/java/org/apache/commons/io/Java7Support.java
ADDED
|
@@ -0,0 +1,190 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
package org.apache.commons.io;
|
| 2 |
+
|
| 3 |
+
/*
|
| 4 |
+
* Licensed to the Apache Software Foundation (ASF) under one
|
| 5 |
+
* or more contributor license agreements. See the NOTICE file
|
| 6 |
+
* distributed with this work for additional information
|
| 7 |
+
* regarding copyright ownership. The ASF licenses this file
|
| 8 |
+
* to you under the Apache License, Version 2.0 (the
|
| 9 |
+
* "License"); you may not use this file except in compliance
|
| 10 |
+
* with the License. You may obtain a copy of the License at
|
| 11 |
+
*
|
| 12 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 13 |
+
*
|
| 14 |
+
* Unless required by applicable law or agreed to in writing,
|
| 15 |
+
* software distributed under the License is distributed on an
|
| 16 |
+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
| 17 |
+
* KIND, either express or implied. See the License for the
|
| 18 |
+
* specific language governing permissions and limitations
|
| 19 |
+
* under the License.
|
| 20 |
+
*/
|
| 21 |
+
|
| 22 |
+
import java.io.File;
|
| 23 |
+
import java.io.IOException;
|
| 24 |
+
import java.lang.reflect.Array;
|
| 25 |
+
import java.lang.reflect.InvocationTargetException;
|
| 26 |
+
import java.lang.reflect.Method;
|
| 27 |
+
|
| 28 |
+
/**
|
| 29 |
+
* Java7 feature detection and reflection based feature access.
|
| 30 |
+
* <p/>
|
| 31 |
+
* Taken from maven-shared-utils, only for private usage until we go full java7
|
| 32 |
+
*/
|
| 33 |
+
class Java7Support {
|
| 34 |
+
|
| 35 |
+
private static final boolean IS_JAVA7;
|
| 36 |
+
|
| 37 |
+
private static Method isSymbolicLink;
|
| 38 |
+
|
| 39 |
+
private static Method delete;
|
| 40 |
+
|
| 41 |
+
private static Method toPath;
|
| 42 |
+
|
| 43 |
+
private static Method exists;
|
| 44 |
+
|
| 45 |
+
private static Method toFile;
|
| 46 |
+
|
| 47 |
+
private static Method readSymlink;
|
| 48 |
+
|
| 49 |
+
private static Method createSymlink;
|
| 50 |
+
|
| 51 |
+
private static Object emptyLinkOpts;
|
| 52 |
+
|
| 53 |
+
private static Object emptyFileAttributes;
|
| 54 |
+
|
| 55 |
+
static {
|
| 56 |
+
boolean isJava7x = true;
|
| 57 |
+
try {
|
| 58 |
+
ClassLoader cl = Thread.currentThread().getContextClassLoader();
|
| 59 |
+
Class<?> files = cl.loadClass("java.nio.file.Files");
|
| 60 |
+
Class<?> path = cl.loadClass("java.nio.file.Path");
|
| 61 |
+
Class<?> fa = cl.loadClass("java.nio.file.attribute.FileAttribute");
|
| 62 |
+
Class<?> linkOption = cl.loadClass("java.nio.file.LinkOption");
|
| 63 |
+
isSymbolicLink = files.getMethod("isSymbolicLink", path);
|
| 64 |
+
delete = files.getMethod("delete", path);
|
| 65 |
+
readSymlink = files.getMethod("readSymbolicLink", path);
|
| 66 |
+
|
| 67 |
+
emptyFileAttributes = Array.newInstance(fa, 0);
|
| 68 |
+
createSymlink = files.getMethod("createSymbolicLink", path, path, emptyFileAttributes.getClass());
|
| 69 |
+
emptyLinkOpts = Array.newInstance(linkOption, 0);
|
| 70 |
+
exists = files.getMethod("exists", path, emptyLinkOpts.getClass());
|
| 71 |
+
toPath = File.class.getMethod("toPath");
|
| 72 |
+
toFile = path.getMethod("toFile");
|
| 73 |
+
} catch (ClassNotFoundException e) {
|
| 74 |
+
isJava7x = false;
|
| 75 |
+
} catch (NoSuchMethodException e) {
|
| 76 |
+
isJava7x = false;
|
| 77 |
+
}
|
| 78 |
+
IS_JAVA7 = isJava7x;
|
| 79 |
+
}
|
| 80 |
+
|
| 81 |
+
/**
|
| 82 |
+
* Invokes java7 isSymbolicLink
|
| 83 |
+
* @param file The file to check
|
| 84 |
+
* @return true if the file is a symbolic link
|
| 85 |
+
*/
|
| 86 |
+
public static boolean isSymLink(File file) {
|
| 87 |
+
try {
|
| 88 |
+
Object path = toPath.invoke(file);
|
| 89 |
+
Boolean result = (Boolean) isSymbolicLink.invoke(null, path);
|
| 90 |
+
return result.booleanValue();
|
| 91 |
+
} catch (IllegalAccessException e) {
|
| 92 |
+
throw new RuntimeException(e);
|
| 93 |
+
} catch (InvocationTargetException e) {
|
| 94 |
+
throw new RuntimeException(e);
|
| 95 |
+
}
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
/**
|
| 99 |
+
* Reads the target of a symbolic link
|
| 100 |
+
* @param symlink The symlink to read
|
| 101 |
+
* @return The location the symlink is pointing to
|
| 102 |
+
* @throws IOException Upon failure
|
| 103 |
+
*/
|
| 104 |
+
|
| 105 |
+
public static File readSymbolicLink(File symlink)
|
| 106 |
+
throws IOException {
|
| 107 |
+
try {
|
| 108 |
+
Object path = toPath.invoke(symlink);
|
| 109 |
+
Object resultPath = readSymlink.invoke(null, path);
|
| 110 |
+
return (File) toFile.invoke(resultPath);
|
| 111 |
+
} catch (IllegalAccessException e) {
|
| 112 |
+
throw new RuntimeException(e);
|
| 113 |
+
} catch (InvocationTargetException e) {
|
| 114 |
+
throw new RuntimeException(e);
|
| 115 |
+
}
|
| 116 |
+
}
|
| 117 |
+
|
| 118 |
+
|
| 119 |
+
/**
|
| 120 |
+
* Indicates if a symlunk target exists
|
| 121 |
+
* @param file The symlink file
|
| 122 |
+
* @return true if the target exists
|
| 123 |
+
* @throws IOException upon error
|
| 124 |
+
*/
|
| 125 |
+
private static boolean exists(File file)
|
| 126 |
+
throws IOException {
|
| 127 |
+
try {
|
| 128 |
+
Object path = toPath.invoke(file);
|
| 129 |
+
final Boolean result = (Boolean) exists.invoke(null, path, emptyLinkOpts);
|
| 130 |
+
return result.booleanValue();
|
| 131 |
+
} catch (IllegalAccessException e) {
|
| 132 |
+
throw new RuntimeException(e);
|
| 133 |
+
} catch (InvocationTargetException e) {
|
| 134 |
+
throw (RuntimeException) e.getTargetException();
|
| 135 |
+
}
|
| 136 |
+
|
| 137 |
+
}
|
| 138 |
+
|
| 139 |
+
/**
|
| 140 |
+
* Creates a symbolic link
|
| 141 |
+
* @param symlink The symlink to create
|
| 142 |
+
* @param target Where it should point
|
| 143 |
+
* @return The newly created symlink
|
| 144 |
+
* @throws IOException upon error
|
| 145 |
+
*/
|
| 146 |
+
public static File createSymbolicLink(File symlink, File target)
|
| 147 |
+
throws IOException {
|
| 148 |
+
try {
|
| 149 |
+
if (!exists(symlink)) {
|
| 150 |
+
Object link = toPath.invoke(symlink);
|
| 151 |
+
Object path = createSymlink.invoke(null, link, toPath.invoke(target), emptyFileAttributes);
|
| 152 |
+
return (File) toFile.invoke(path);
|
| 153 |
+
}
|
| 154 |
+
return symlink;
|
| 155 |
+
} catch (IllegalAccessException e) {
|
| 156 |
+
throw new RuntimeException(e);
|
| 157 |
+
} catch (InvocationTargetException e) {
|
| 158 |
+
final Throwable targetException = e.getTargetException();
|
| 159 |
+
throw (IOException) targetException;
|
| 160 |
+
}
|
| 161 |
+
|
| 162 |
+
}
|
| 163 |
+
|
| 164 |
+
/**
|
| 165 |
+
* Performs a nio delete
|
| 166 |
+
*
|
| 167 |
+
* @param file the file to delete
|
| 168 |
+
* @throws IOException Upon error
|
| 169 |
+
*/
|
| 170 |
+
public static void delete(File file)
|
| 171 |
+
throws IOException {
|
| 172 |
+
try {
|
| 173 |
+
Object path = toPath.invoke(file);
|
| 174 |
+
delete.invoke(null, path);
|
| 175 |
+
} catch (IllegalAccessException e) {
|
| 176 |
+
throw new RuntimeException(e);
|
| 177 |
+
} catch (InvocationTargetException e) {
|
| 178 |
+
throw (IOException) e.getTargetException();
|
| 179 |
+
}
|
| 180 |
+
}
|
| 181 |
+
|
| 182 |
+
/**
|
| 183 |
+
* Indicates if the current vm has java7 lubrary support
|
| 184 |
+
* @return true if java7 library support
|
| 185 |
+
*/
|
| 186 |
+
public static boolean isAtLeastJava7() {
|
| 187 |
+
return IS_JAVA7;
|
| 188 |
+
}
|
| 189 |
+
|
| 190 |
+
}
|
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/01_课件与电子教材/尚硅谷_第15章_File类与IO流/03-apache-common包/commons-io-2.5-src/src/main/java/org/apache/commons/io/LineIterator.java
ADDED
|
@@ -0,0 +1,180 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Licensed to the Apache Software Foundation (ASF) under one or more
|
| 3 |
+
* contributor license agreements. See the NOTICE file distributed with
|
| 4 |
+
* this work for additional information regarding copyright ownership.
|
| 5 |
+
* The ASF licenses this file to You under the Apache License, Version 2.0
|
| 6 |
+
* (the "License"); you may not use this file except in compliance with
|
| 7 |
+
* the License. You may obtain a copy of the License at
|
| 8 |
+
*
|
| 9 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
*
|
| 11 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 12 |
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
| 13 |
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 14 |
+
* See the License for the specific language governing permissions and
|
| 15 |
+
* limitations under the License.
|
| 16 |
+
*/
|
| 17 |
+
package org.apache.commons.io;
|
| 18 |
+
|
| 19 |
+
import java.io.BufferedReader;
|
| 20 |
+
import java.io.IOException;
|
| 21 |
+
import java.io.Reader;
|
| 22 |
+
import java.util.Iterator;
|
| 23 |
+
import java.util.NoSuchElementException;
|
| 24 |
+
|
| 25 |
+
/**
|
| 26 |
+
* An Iterator over the lines in a <code>Reader</code>.
|
| 27 |
+
* <p>
|
| 28 |
+
* <code>LineIterator</code> holds a reference to an open <code>Reader</code>.
|
| 29 |
+
* When you have finished with the iterator you should close the reader
|
| 30 |
+
* to free internal resources. This can be done by closing the reader directly,
|
| 31 |
+
* or by calling the {@link #close()} or {@link #closeQuietly(LineIterator)}
|
| 32 |
+
* method on the iterator.
|
| 33 |
+
* <p>
|
| 34 |
+
* The recommended usage pattern is:
|
| 35 |
+
* <pre>
|
| 36 |
+
* LineIterator it = FileUtils.lineIterator(file, "UTF-8");
|
| 37 |
+
* try {
|
| 38 |
+
* while (it.hasNext()) {
|
| 39 |
+
* String line = it.nextLine();
|
| 40 |
+
* // do something with line
|
| 41 |
+
* }
|
| 42 |
+
* } finally {
|
| 43 |
+
* it.close();
|
| 44 |
+
* }
|
| 45 |
+
* </pre>
|
| 46 |
+
*
|
| 47 |
+
* @version $Id: LineIterator.java 1471767 2013-04-24 23:24:19Z sebb $
|
| 48 |
+
* @since 1.2
|
| 49 |
+
*/
|
| 50 |
+
public class LineIterator implements Iterator<String> {
|
| 51 |
+
|
| 52 |
+
// N.B. This class deliberately does not implement Iterable, see https://issues.apache.org/jira/browse/IO-181
|
| 53 |
+
|
| 54 |
+
/** The reader that is being read. */
|
| 55 |
+
private final BufferedReader bufferedReader;
|
| 56 |
+
/** The current line. */
|
| 57 |
+
private String cachedLine;
|
| 58 |
+
/** A flag indicating if the iterator has been fully read. */
|
| 59 |
+
private boolean finished = false;
|
| 60 |
+
|
| 61 |
+
/**
|
| 62 |
+
* Constructs an iterator of the lines for a <code>Reader</code>.
|
| 63 |
+
*
|
| 64 |
+
* @param reader the <code>Reader</code> to read from, not null
|
| 65 |
+
* @throws IllegalArgumentException if the reader is null
|
| 66 |
+
*/
|
| 67 |
+
public LineIterator(final Reader reader) throws IllegalArgumentException {
|
| 68 |
+
if (reader == null) {
|
| 69 |
+
throw new IllegalArgumentException("Reader must not be null");
|
| 70 |
+
}
|
| 71 |
+
if (reader instanceof BufferedReader) {
|
| 72 |
+
bufferedReader = (BufferedReader) reader;
|
| 73 |
+
} else {
|
| 74 |
+
bufferedReader = new BufferedReader(reader);
|
| 75 |
+
}
|
| 76 |
+
}
|
| 77 |
+
|
| 78 |
+
//-----------------------------------------------------------------------
|
| 79 |
+
/**
|
| 80 |
+
* Indicates whether the <code>Reader</code> has more lines.
|
| 81 |
+
* If there is an <code>IOException</code> then {@link #close()} will
|
| 82 |
+
* be called on this instance.
|
| 83 |
+
*
|
| 84 |
+
* @return {@code true} if the Reader has more lines
|
| 85 |
+
* @throws IllegalStateException if an IO exception occurs
|
| 86 |
+
*/
|
| 87 |
+
public boolean hasNext() {
|
| 88 |
+
if (cachedLine != null) {
|
| 89 |
+
return true;
|
| 90 |
+
} else if (finished) {
|
| 91 |
+
return false;
|
| 92 |
+
} else {
|
| 93 |
+
try {
|
| 94 |
+
while (true) {
|
| 95 |
+
final String line = bufferedReader.readLine();
|
| 96 |
+
if (line == null) {
|
| 97 |
+
finished = true;
|
| 98 |
+
return false;
|
| 99 |
+
} else if (isValidLine(line)) {
|
| 100 |
+
cachedLine = line;
|
| 101 |
+
return true;
|
| 102 |
+
}
|
| 103 |
+
}
|
| 104 |
+
} catch(final IOException ioe) {
|
| 105 |
+
close();
|
| 106 |
+
throw new IllegalStateException(ioe);
|
| 107 |
+
}
|
| 108 |
+
}
|
| 109 |
+
}
|
| 110 |
+
|
| 111 |
+
/**
|
| 112 |
+
* Overridable method to validate each line that is returned.
|
| 113 |
+
* This implementation always returns true.
|
| 114 |
+
* @param line the line that is to be validated
|
| 115 |
+
* @return true if valid, false to remove from the iterator
|
| 116 |
+
*/
|
| 117 |
+
protected boolean isValidLine(final String line) {
|
| 118 |
+
return true;
|
| 119 |
+
}
|
| 120 |
+
|
| 121 |
+
/**
|
| 122 |
+
* Returns the next line in the wrapped <code>Reader</code>.
|
| 123 |
+
*
|
| 124 |
+
* @return the next line from the input
|
| 125 |
+
* @throws NoSuchElementException if there is no line to return
|
| 126 |
+
*/
|
| 127 |
+
public String next() {
|
| 128 |
+
return nextLine();
|
| 129 |
+
}
|
| 130 |
+
|
| 131 |
+
/**
|
| 132 |
+
* Returns the next line in the wrapped <code>Reader</code>.
|
| 133 |
+
*
|
| 134 |
+
* @return the next line from the input
|
| 135 |
+
* @throws NoSuchElementException if there is no line to return
|
| 136 |
+
*/
|
| 137 |
+
public String nextLine() {
|
| 138 |
+
if (!hasNext()) {
|
| 139 |
+
throw new NoSuchElementException("No more lines");
|
| 140 |
+
}
|
| 141 |
+
final String currentLine = cachedLine;
|
| 142 |
+
cachedLine = null;
|
| 143 |
+
return currentLine;
|
| 144 |
+
}
|
| 145 |
+
|
| 146 |
+
/**
|
| 147 |
+
* Closes the underlying <code>Reader</code> quietly.
|
| 148 |
+
* This method is useful if you only want to process the first few
|
| 149 |
+
* lines of a larger file. If you do not close the iterator
|
| 150 |
+
* then the <code>Reader</code> remains open.
|
| 151 |
+
* This method can safely be called multiple times.
|
| 152 |
+
*/
|
| 153 |
+
public void close() {
|
| 154 |
+
finished = true;
|
| 155 |
+
IOUtils.closeQuietly(bufferedReader);
|
| 156 |
+
cachedLine = null;
|
| 157 |
+
}
|
| 158 |
+
|
| 159 |
+
/**
|
| 160 |
+
* Unsupported.
|
| 161 |
+
*
|
| 162 |
+
* @throws UnsupportedOperationException always
|
| 163 |
+
*/
|
| 164 |
+
public void remove() {
|
| 165 |
+
throw new UnsupportedOperationException("Remove unsupported on LineIterator");
|
| 166 |
+
}
|
| 167 |
+
|
| 168 |
+
//-----------------------------------------------------------------------
|
| 169 |
+
/**
|
| 170 |
+
* Closes the iterator, handling null and ignoring exceptions.
|
| 171 |
+
*
|
| 172 |
+
* @param iterator the iterator to close
|
| 173 |
+
*/
|
| 174 |
+
public static void closeQuietly(final LineIterator iterator) {
|
| 175 |
+
if (iterator != null) {
|
| 176 |
+
iterator.close();
|
| 177 |
+
}
|
| 178 |
+
}
|
| 179 |
+
|
| 180 |
+
}
|
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/01_课件与电子教材/尚硅谷_第15章_File类与IO流/03-apache-common包/commons-io-2.5-src/src/main/java/org/apache/commons/io/TaggedIOException.java
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Licensed to the Apache Software Foundation (ASF) under one or more
|
| 3 |
+
* contributor license agreements. See the NOTICE file distributed with
|
| 4 |
+
* this work for additional information regarding copyright ownership.
|
| 5 |
+
* The ASF licenses this file to You under the Apache License, Version 2.0
|
| 6 |
+
* (the "License"); you may not use this file except in compliance with
|
| 7 |
+
* the License. You may obtain a copy of the License at
|
| 8 |
+
*
|
| 9 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
*
|
| 11 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 12 |
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
| 13 |
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 14 |
+
* See the License for the specific language governing permissions and
|
| 15 |
+
* limitations under the License.
|
| 16 |
+
*/
|
| 17 |
+
package org.apache.commons.io;
|
| 18 |
+
|
| 19 |
+
import java.io.IOException;
|
| 20 |
+
import java.io.Serializable;
|
| 21 |
+
|
| 22 |
+
/**
|
| 23 |
+
* An {@link IOException} decorator that adds a serializable tag to the
|
| 24 |
+
* wrapped exception. Both the tag and the original exception can be used
|
| 25 |
+
* to determine further processing when this exception is caught.
|
| 26 |
+
*
|
| 27 |
+
* @since 2.0
|
| 28 |
+
*/
|
| 29 |
+
@SuppressWarnings("deprecation") // needs to extend deprecated IOExceptionWithCause to preserve binary compatibility
|
| 30 |
+
public class TaggedIOException extends IOExceptionWithCause {
|
| 31 |
+
|
| 32 |
+
/**
|
| 33 |
+
* Generated serial version UID.
|
| 34 |
+
*/
|
| 35 |
+
private static final long serialVersionUID = -6994123481142850163L;
|
| 36 |
+
|
| 37 |
+
/**
|
| 38 |
+
* Checks whether the given throwable is tagged with the given tag.
|
| 39 |
+
* <p>
|
| 40 |
+
* This check can only succeed if the throwable is a
|
| 41 |
+
* {@link TaggedIOException} and the tag is {@link Serializable}, but
|
| 42 |
+
* the argument types are intentionally more generic to make it easier
|
| 43 |
+
* to use this method without type casts.
|
| 44 |
+
* <p>
|
| 45 |
+
* A typical use for this method is in a <code>catch</code> block to
|
| 46 |
+
* determine how a caught exception should be handled:
|
| 47 |
+
* <pre>
|
| 48 |
+
* Serializable tag = ...;
|
| 49 |
+
* try {
|
| 50 |
+
* ...;
|
| 51 |
+
* } catch (Throwable t) {
|
| 52 |
+
* if (TaggedIOExcepton.isTaggedWith(t, tag)) {
|
| 53 |
+
* // special processing for tagged exception
|
| 54 |
+
* } else {
|
| 55 |
+
* // handling of other kinds of exceptions
|
| 56 |
+
* }
|
| 57 |
+
* }
|
| 58 |
+
* </pre>
|
| 59 |
+
*
|
| 60 |
+
* @param throwable The Throwable object to check
|
| 61 |
+
* @param tag tag object
|
| 62 |
+
* @return {@code true} if the throwable has the specified tag,
|
| 63 |
+
* otherwise {@code false}
|
| 64 |
+
*/
|
| 65 |
+
public static boolean isTaggedWith(final Throwable throwable, final Object tag) {
|
| 66 |
+
return tag != null
|
| 67 |
+
&& throwable instanceof TaggedIOException
|
| 68 |
+
&& tag.equals(((TaggedIOException) throwable).tag);
|
| 69 |
+
}
|
| 70 |
+
|
| 71 |
+
/**
|
| 72 |
+
* Throws the original {@link IOException} if the given throwable is
|
| 73 |
+
* a {@link TaggedIOException} decorator the given tag. Does nothing
|
| 74 |
+
* if the given throwable is of a different type or if it is tagged
|
| 75 |
+
* with some other tag.
|
| 76 |
+
* <p>
|
| 77 |
+
* This method is typically used in a <code>catch</code> block to
|
| 78 |
+
* selectively rethrow tagged exceptions.
|
| 79 |
+
* <pre>
|
| 80 |
+
* Serializable tag = ...;
|
| 81 |
+
* try {
|
| 82 |
+
* ...;
|
| 83 |
+
* } catch (Throwable t) {
|
| 84 |
+
* TaggedIOExcepton.throwCauseIfTagged(t, tag);
|
| 85 |
+
* // handle other kinds of exceptions
|
| 86 |
+
* }
|
| 87 |
+
* </pre>
|
| 88 |
+
*
|
| 89 |
+
* @param throwable an exception
|
| 90 |
+
* @param tag tag object
|
| 91 |
+
* @throws IOException original exception from the tagged decorator, if any
|
| 92 |
+
*/
|
| 93 |
+
public static void throwCauseIfTaggedWith(final Throwable throwable, final Object tag)
|
| 94 |
+
throws IOException {
|
| 95 |
+
if (isTaggedWith(throwable, tag)) {
|
| 96 |
+
throw ((TaggedIOException) throwable).getCause();
|
| 97 |
+
}
|
| 98 |
+
}
|
| 99 |
+
|
| 100 |
+
/**
|
| 101 |
+
* The tag of this exception.
|
| 102 |
+
*/
|
| 103 |
+
private final Serializable tag;
|
| 104 |
+
|
| 105 |
+
/**
|
| 106 |
+
* Creates a tagged wrapper for the given exception.
|
| 107 |
+
*
|
| 108 |
+
* @param original the exception to be tagged
|
| 109 |
+
* @param tag tag of this exception
|
| 110 |
+
*/
|
| 111 |
+
public TaggedIOException(final IOException original, final Serializable tag) {
|
| 112 |
+
super(original.getMessage(), original);
|
| 113 |
+
this.tag = tag;
|
| 114 |
+
}
|
| 115 |
+
|
| 116 |
+
/**
|
| 117 |
+
* Returns the serializable tag object.
|
| 118 |
+
*
|
| 119 |
+
* @return tag object
|
| 120 |
+
*/
|
| 121 |
+
public Serializable getTag() {
|
| 122 |
+
return tag;
|
| 123 |
+
}
|
| 124 |
+
|
| 125 |
+
/**
|
| 126 |
+
* Returns the wrapped exception. The only difference to the overridden
|
| 127 |
+
* {@link Throwable#getCause()} method is the narrower return type.
|
| 128 |
+
*
|
| 129 |
+
* @return wrapped exception
|
| 130 |
+
*/
|
| 131 |
+
@Override
|
| 132 |
+
public IOException getCause() {
|
| 133 |
+
return (IOException) super.getCause();
|
| 134 |
+
}
|
| 135 |
+
|
| 136 |
+
}
|
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/01_课件与电子教材/尚硅谷_第15章_File类与IO流/03-apache-common包/commons-io-2.5-src/src/main/java/org/apache/commons/io/ThreadMonitor.java
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Licensed to the Apache Software Foundation (ASF) under one or more
|
| 3 |
+
* contributor license agreements. See the NOTICE file distributed with
|
| 4 |
+
* this work for additional information regarding copyright ownership.
|
| 5 |
+
* The ASF licenses this file to You under the Apache License, Version 2.0
|
| 6 |
+
* (the "License"); you may not use this file except in compliance with
|
| 7 |
+
* the License. You may obtain a copy of the License at
|
| 8 |
+
*
|
| 9 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
*
|
| 11 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 12 |
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
| 13 |
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 14 |
+
* See the License for the specific language governing permissions and
|
| 15 |
+
* limitations under the License.
|
| 16 |
+
*/
|
| 17 |
+
package org.apache.commons.io;
|
| 18 |
+
|
| 19 |
+
/**
|
| 20 |
+
* Monitors a thread, interrupting it if it reaches the specified timeout.
|
| 21 |
+
* <p>
|
| 22 |
+
* This works by sleeping until the specified timeout amount and then
|
| 23 |
+
* interrupting the thread being monitored. If the thread being monitored
|
| 24 |
+
* completes its work before being interrupted, it should <code>interrupt()</code>
|
| 25 |
+
* the <i>monitor</i> thread.
|
| 26 |
+
* </p>
|
| 27 |
+
*
|
| 28 |
+
* <pre>
|
| 29 |
+
* long timeoutInMillis = 1000;
|
| 30 |
+
* try {
|
| 31 |
+
* Thread monitor = ThreadMonitor.start(timeoutInMillis);
|
| 32 |
+
* // do some work here
|
| 33 |
+
* ThreadMonitor.stop(monitor);
|
| 34 |
+
* } catch (InterruptedException e) {
|
| 35 |
+
* // timed amount was reached
|
| 36 |
+
* }
|
| 37 |
+
* </pre>
|
| 38 |
+
*
|
| 39 |
+
* @version $Id: ThreadMonitor.java 1718945 2015-12-09 19:51:14Z krosenvold $
|
| 40 |
+
*/
|
| 41 |
+
class ThreadMonitor implements Runnable {
|
| 42 |
+
|
| 43 |
+
private final Thread thread;
|
| 44 |
+
private final long timeout;
|
| 45 |
+
|
| 46 |
+
/**
|
| 47 |
+
* Start monitoring the current thread.
|
| 48 |
+
*
|
| 49 |
+
* @param timeout The timeout amount in milliseconds
|
| 50 |
+
* or no timeout if the value is zero or less
|
| 51 |
+
* @return The monitor thread or {@code null}
|
| 52 |
+
* if the timeout amount is not greater than zero
|
| 53 |
+
*/
|
| 54 |
+
public static Thread start(final long timeout) {
|
| 55 |
+
return start(Thread.currentThread(), timeout);
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
/**
|
| 59 |
+
* Start monitoring the specified thread.
|
| 60 |
+
*
|
| 61 |
+
* @param thread The thread The thread to monitor
|
| 62 |
+
* @param timeout The timeout amount in milliseconds
|
| 63 |
+
* or no timeout if the value is zero or less
|
| 64 |
+
* @return The monitor thread or {@code null}
|
| 65 |
+
* if the timeout amount is not greater than zero
|
| 66 |
+
*/
|
| 67 |
+
public static Thread start(final Thread thread, final long timeout) {
|
| 68 |
+
Thread monitor = null;
|
| 69 |
+
if (timeout > 0) {
|
| 70 |
+
final ThreadMonitor timout = new ThreadMonitor(thread, timeout);
|
| 71 |
+
monitor = new Thread(timout, ThreadMonitor.class.getSimpleName());
|
| 72 |
+
monitor.setDaemon(true);
|
| 73 |
+
monitor.start();
|
| 74 |
+
}
|
| 75 |
+
return monitor;
|
| 76 |
+
}
|
| 77 |
+
|
| 78 |
+
/**
|
| 79 |
+
* Stop monitoring the specified thread.
|
| 80 |
+
*
|
| 81 |
+
* @param thread The monitor thread, may be {@code null}
|
| 82 |
+
*/
|
| 83 |
+
public static void stop(final Thread thread) {
|
| 84 |
+
if (thread != null) {
|
| 85 |
+
thread.interrupt();
|
| 86 |
+
}
|
| 87 |
+
}
|
| 88 |
+
|
| 89 |
+
/**
|
| 90 |
+
* Construct and new monitor.
|
| 91 |
+
*
|
| 92 |
+
* @param thread The thread to monitor
|
| 93 |
+
* @param timeout The timeout amount in milliseconds
|
| 94 |
+
*/
|
| 95 |
+
private ThreadMonitor(final Thread thread, final long timeout) {
|
| 96 |
+
this.thread = thread;
|
| 97 |
+
this.timeout = timeout;
|
| 98 |
+
}
|
| 99 |
+
|
| 100 |
+
/**
|
| 101 |
+
* Sleep until the specified timeout amount and then
|
| 102 |
+
* interrupt the thread being monitored.
|
| 103 |
+
*
|
| 104 |
+
* @see Runnable#run()
|
| 105 |
+
*/
|
| 106 |
+
public void run() {
|
| 107 |
+
try {
|
| 108 |
+
sleep(timeout);
|
| 109 |
+
thread.interrupt();
|
| 110 |
+
} catch (final InterruptedException e) {
|
| 111 |
+
// timeout not reached
|
| 112 |
+
}
|
| 113 |
+
}
|
| 114 |
+
|
| 115 |
+
/**
|
| 116 |
+
* Sleep for a guaranteed minimum number of milliseconds unless interrupted.
|
| 117 |
+
*
|
| 118 |
+
* This method exists because Thread.sleep(100) can sleep for 0, 70, 100 or 200ms or anything else
|
| 119 |
+
* it deems appropriate. Read the docs on Thread.sleep for further interesting details.
|
| 120 |
+
* @
|
| 121 |
+
* @param ms the number of milliseconds to sleep for
|
| 122 |
+
* @throws InterruptedException if interrupted
|
| 123 |
+
*/
|
| 124 |
+
private static void sleep(long ms) throws InterruptedException {
|
| 125 |
+
long finishAt = System.currentTimeMillis() + ms;
|
| 126 |
+
long remaining = ms;
|
| 127 |
+
do {
|
| 128 |
+
Thread.sleep(remaining);
|
| 129 |
+
remaining = finishAt - System.currentTimeMillis();
|
| 130 |
+
} while (remaining > 0);
|
| 131 |
+
}
|
| 132 |
+
|
| 133 |
+
|
| 134 |
+
}
|
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/01_课件与电子教材/尚硅谷_第15章_File类与IO流/03-apache-common包/commons-io-2.5-src/src/main/java/org/apache/commons/io/comparator/AbstractFileComparator.java
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Licensed to the Apache Software Foundation (ASF) under one or more
|
| 3 |
+
* contributor license agreements. See the NOTICE file distributed with
|
| 4 |
+
* this work for additional information regarding copyright ownership.
|
| 5 |
+
* The ASF licenses this file to You under the Apache License, Version 2.0
|
| 6 |
+
* (the "License"); you may not use this file except in compliance with
|
| 7 |
+
* the License. You may obtain a copy of the License at
|
| 8 |
+
*
|
| 9 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
*
|
| 11 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 12 |
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
| 13 |
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 14 |
+
* See the License for the specific language governing permissions and
|
| 15 |
+
* limitations under the License.
|
| 16 |
+
*/
|
| 17 |
+
package org.apache.commons.io.comparator;
|
| 18 |
+
|
| 19 |
+
import java.io.File;
|
| 20 |
+
import java.util.Arrays;
|
| 21 |
+
import java.util.Collections;
|
| 22 |
+
import java.util.Comparator;
|
| 23 |
+
import java.util.List;
|
| 24 |
+
|
| 25 |
+
/**
|
| 26 |
+
* Abstract file {@link Comparator} which provides sorting for file arrays and lists.
|
| 27 |
+
*
|
| 28 |
+
* @version $Id: AbstractFileComparator.java 1415850 2012-11-30 20:51:39Z ggregory $
|
| 29 |
+
* @since 2.0
|
| 30 |
+
*/
|
| 31 |
+
abstract class AbstractFileComparator implements Comparator<File> {
|
| 32 |
+
|
| 33 |
+
/**
|
| 34 |
+
* Sort an array of files.
|
| 35 |
+
* <p>
|
| 36 |
+
* This method uses {@link Arrays#sort(Object[], Comparator)}
|
| 37 |
+
* and returns the original array.
|
| 38 |
+
*
|
| 39 |
+
* @param files The files to sort, may be null
|
| 40 |
+
* @return The sorted array
|
| 41 |
+
* @since 2.0
|
| 42 |
+
*/
|
| 43 |
+
public File[] sort(final File... files) {
|
| 44 |
+
if (files != null) {
|
| 45 |
+
Arrays.sort(files, this);
|
| 46 |
+
}
|
| 47 |
+
return files;
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
/**
|
| 51 |
+
* Sort a List of files.
|
| 52 |
+
* <p>
|
| 53 |
+
* This method uses {@link Collections#sort(List, Comparator)}
|
| 54 |
+
* and returns the original list.
|
| 55 |
+
*
|
| 56 |
+
* @param files The files to sort, may be null
|
| 57 |
+
* @return The sorted list
|
| 58 |
+
* @since 2.0
|
| 59 |
+
*/
|
| 60 |
+
public List<File> sort(final List<File> files) {
|
| 61 |
+
if (files != null) {
|
| 62 |
+
Collections.sort(files, this);
|
| 63 |
+
}
|
| 64 |
+
return files;
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
/**
|
| 68 |
+
* String representation of this file comparator.
|
| 69 |
+
*
|
| 70 |
+
* @return String representation of this file comparator
|
| 71 |
+
*/
|
| 72 |
+
@Override
|
| 73 |
+
public String toString() {
|
| 74 |
+
return getClass().getSimpleName();
|
| 75 |
+
}
|
| 76 |
+
}
|
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/01_课件与电子教材/尚硅谷_第15章_File类与IO流/03-apache-common包/commons-io-2.5-src/src/main/java/org/apache/commons/io/comparator/CompositeFileComparator.java
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Licensed to the Apache Software Foundation (ASF) under one or more
|
| 3 |
+
* contributor license agreements. See the NOTICE file distributed with
|
| 4 |
+
* this work for additional information regarding copyright ownership.
|
| 5 |
+
* The ASF licenses this file to You under the Apache License, Version 2.0
|
| 6 |
+
* (the "License"); you may not use this file except in compliance with
|
| 7 |
+
* the License. You may obtain a copy of the License at
|
| 8 |
+
*
|
| 9 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
*
|
| 11 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 12 |
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
| 13 |
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 14 |
+
* See the License for the specific language governing permissions and
|
| 15 |
+
* limitations under the License.
|
| 16 |
+
*/
|
| 17 |
+
package org.apache.commons.io.comparator;
|
| 18 |
+
|
| 19 |
+
import java.io.File;
|
| 20 |
+
import java.io.Serializable;
|
| 21 |
+
import java.util.ArrayList;
|
| 22 |
+
import java.util.Comparator;
|
| 23 |
+
import java.util.List;
|
| 24 |
+
|
| 25 |
+
/**
|
| 26 |
+
* Compare two files using a set of delegate file {@link Comparator}.
|
| 27 |
+
* <p>
|
| 28 |
+
* This comparator can be used to sort lists or arrays of files
|
| 29 |
+
* by combining a number other comparators.
|
| 30 |
+
* <p>
|
| 31 |
+
* Example of sorting a list of files by type (i.e. directory or file)
|
| 32 |
+
* and then by name:
|
| 33 |
+
* <pre>
|
| 34 |
+
* CompositeFileComparator comparator =
|
| 35 |
+
* new CompositeFileComparator(
|
| 36 |
+
* (AbstractFileComparator) DirectoryFileComparator.DIRECTORY_COMPARATOR,
|
| 37 |
+
* (AbstractFileComparator) NameFileComparator.NAME_COMPARATOR);
|
| 38 |
+
* List<File> list = ...
|
| 39 |
+
* comparator.sort(list);
|
| 40 |
+
* </pre>
|
| 41 |
+
*
|
| 42 |
+
* @version $Id: CompositeFileComparator.java 1642757 2014-12-01 21:09:30Z sebb $
|
| 43 |
+
* @since 2.0
|
| 44 |
+
*/
|
| 45 |
+
public class CompositeFileComparator extends AbstractFileComparator implements Serializable {
|
| 46 |
+
|
| 47 |
+
private static final long serialVersionUID = -2224170307287243428L;
|
| 48 |
+
private static final Comparator<?>[] NO_COMPARATORS = {};
|
| 49 |
+
private final Comparator<File>[] delegates;
|
| 50 |
+
|
| 51 |
+
/**
|
| 52 |
+
* Create a composite comparator for the set of delegate comparators.
|
| 53 |
+
*
|
| 54 |
+
* @param delegates The delegate file comparators
|
| 55 |
+
*/
|
| 56 |
+
@SuppressWarnings("unchecked") // casts 1 & 2 must be OK because types are already correct
|
| 57 |
+
public CompositeFileComparator(final Comparator<File>... delegates) {
|
| 58 |
+
if (delegates == null) {
|
| 59 |
+
this.delegates = (Comparator<File>[]) NO_COMPARATORS;//1
|
| 60 |
+
} else {
|
| 61 |
+
this.delegates = (Comparator<File>[]) new Comparator<?>[delegates.length];//2
|
| 62 |
+
System.arraycopy(delegates, 0, this.delegates, 0, delegates.length);
|
| 63 |
+
}
|
| 64 |
+
}
|
| 65 |
+
|
| 66 |
+
/**
|
| 67 |
+
* Create a composite comparator for the set of delegate comparators.
|
| 68 |
+
*
|
| 69 |
+
* @param delegates The delegate file comparators
|
| 70 |
+
*/
|
| 71 |
+
@SuppressWarnings("unchecked") // casts 1 & 2 must be OK because types are already correct
|
| 72 |
+
public CompositeFileComparator(final Iterable<Comparator<File>> delegates) {
|
| 73 |
+
if (delegates == null) {
|
| 74 |
+
this.delegates = (Comparator<File>[]) NO_COMPARATORS; //1
|
| 75 |
+
} else {
|
| 76 |
+
final List<Comparator<File>> list = new ArrayList<Comparator<File>>();
|
| 77 |
+
for (final Comparator<File> comparator : delegates) {
|
| 78 |
+
list.add(comparator);
|
| 79 |
+
}
|
| 80 |
+
this.delegates = (Comparator<File>[]) list.toArray(new Comparator<?>[list.size()]); //2
|
| 81 |
+
}
|
| 82 |
+
}
|
| 83 |
+
|
| 84 |
+
/**
|
| 85 |
+
* Compare the two files using delegate comparators.
|
| 86 |
+
*
|
| 87 |
+
* @param file1 The first file to compare
|
| 88 |
+
* @param file2 The second file to compare
|
| 89 |
+
* @return the first non-zero result returned from
|
| 90 |
+
* the delegate comparators or zero.
|
| 91 |
+
*/
|
| 92 |
+
public int compare(final File file1, final File file2) {
|
| 93 |
+
int result = 0;
|
| 94 |
+
for (final Comparator<File> delegate : delegates) {
|
| 95 |
+
result = delegate.compare(file1, file2);
|
| 96 |
+
if (result != 0) {
|
| 97 |
+
break;
|
| 98 |
+
}
|
| 99 |
+
}
|
| 100 |
+
return result;
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
+
/**
|
| 104 |
+
* String representation of this file comparator.
|
| 105 |
+
*
|
| 106 |
+
* @return String representation of this file comparator
|
| 107 |
+
*/
|
| 108 |
+
@Override
|
| 109 |
+
public String toString() {
|
| 110 |
+
final StringBuilder builder = new StringBuilder();
|
| 111 |
+
builder.append(super.toString());
|
| 112 |
+
builder.append('{');
|
| 113 |
+
for (int i = 0; i < delegates.length; i++) {
|
| 114 |
+
if (i > 0) {
|
| 115 |
+
builder.append(',');
|
| 116 |
+
}
|
| 117 |
+
builder.append(delegates[i]);
|
| 118 |
+
}
|
| 119 |
+
builder.append('}');
|
| 120 |
+
return builder.toString();
|
| 121 |
+
}
|
| 122 |
+
}
|
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/01_课件与电子教材/尚硅谷_第15章_File类与IO流/03-apache-common包/commons-io-2.5-src/src/main/java/org/apache/commons/io/comparator/DefaultFileComparator.java
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Licensed to the Apache Software Foundation (ASF) under one or more
|
| 3 |
+
* contributor license agreements. See the NOTICE file distributed with
|
| 4 |
+
* this work for additional information regarding copyright ownership.
|
| 5 |
+
* The ASF licenses this file to You under the Apache License, Version 2.0
|
| 6 |
+
* (the "License"); you may not use this file except in compliance with
|
| 7 |
+
* the License. You may obtain a copy of the License at
|
| 8 |
+
*
|
| 9 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
*
|
| 11 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 12 |
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
| 13 |
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 14 |
+
* See the License for the specific language governing permissions and
|
| 15 |
+
* limitations under the License.
|
| 16 |
+
*/
|
| 17 |
+
package org.apache.commons.io.comparator;
|
| 18 |
+
|
| 19 |
+
import java.io.File;
|
| 20 |
+
import java.io.Serializable;
|
| 21 |
+
import java.util.Comparator;
|
| 22 |
+
|
| 23 |
+
/**
|
| 24 |
+
* Compare two files using the <b>default</b> {@link File#compareTo(File)} method.
|
| 25 |
+
* <p>
|
| 26 |
+
* This comparator can be used to sort lists or arrays of files
|
| 27 |
+
* by using the default file comparison.
|
| 28 |
+
* <p>
|
| 29 |
+
* Example of sorting a list of files using the
|
| 30 |
+
* {@link #DEFAULT_COMPARATOR} singleton instance:
|
| 31 |
+
* <pre>
|
| 32 |
+
* List<File> list = ...
|
| 33 |
+
* ((AbstractFileComparator) DefaultFileComparator.DEFAULT_COMPARATOR).sort(list);
|
| 34 |
+
* </pre>
|
| 35 |
+
* <p>
|
| 36 |
+
* Example of doing a <i>reverse</i> sort of an array of files using the
|
| 37 |
+
* {@link #DEFAULT_REVERSE} singleton instance:
|
| 38 |
+
* <pre>
|
| 39 |
+
* File[] array = ...
|
| 40 |
+
* ((AbstractFileComparator) DefaultFileComparator.DEFAULT_REVERSE).sort(array);
|
| 41 |
+
* </pre>
|
| 42 |
+
* <p>
|
| 43 |
+
*
|
| 44 |
+
* @version $Id: DefaultFileComparator.java 1642757 2014-12-01 21:09:30Z sebb $
|
| 45 |
+
* @since 1.4
|
| 46 |
+
*/
|
| 47 |
+
public class DefaultFileComparator extends AbstractFileComparator implements Serializable {
|
| 48 |
+
|
| 49 |
+
private static final long serialVersionUID = 3260141861365313518L;
|
| 50 |
+
|
| 51 |
+
/** Singleton default comparator instance */
|
| 52 |
+
public static final Comparator<File> DEFAULT_COMPARATOR = new DefaultFileComparator();
|
| 53 |
+
|
| 54 |
+
/** Singleton reverse default comparator instance */
|
| 55 |
+
public static final Comparator<File> DEFAULT_REVERSE = new ReverseComparator(DEFAULT_COMPARATOR);
|
| 56 |
+
|
| 57 |
+
/**
|
| 58 |
+
* Compare the two files using the {@link File#compareTo(File)} method.
|
| 59 |
+
*
|
| 60 |
+
* @param file1 The first file to compare
|
| 61 |
+
* @param file2 The second file to compare
|
| 62 |
+
* @return the result of calling file1's
|
| 63 |
+
* {@link File#compareTo(File)} with file2 as the parameter.
|
| 64 |
+
*/
|
| 65 |
+
public int compare(final File file1, final File file2) {
|
| 66 |
+
return file1.compareTo(file2);
|
| 67 |
+
}
|
| 68 |
+
}
|
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/01_课件与电子教材/尚硅谷_第15章_File类与IO流/03-apache-common包/commons-io-2.5-src/src/main/java/org/apache/commons/io/comparator/DirectoryFileComparator.java
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Licensed to the Apache Software Foundation (ASF) under one or more
|
| 3 |
+
* contributor license agreements. See the NOTICE file distributed with
|
| 4 |
+
* this work for additional information regarding copyright ownership.
|
| 5 |
+
* The ASF licenses this file to You under the Apache License, Version 2.0
|
| 6 |
+
* (the "License"); you may not use this file except in compliance with
|
| 7 |
+
* the License. You may obtain a copy of the License at
|
| 8 |
+
*
|
| 9 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
*
|
| 11 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 12 |
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
| 13 |
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 14 |
+
* See the License for the specific language governing permissions and
|
| 15 |
+
* limitations under the License.
|
| 16 |
+
*/
|
| 17 |
+
package org.apache.commons.io.comparator;
|
| 18 |
+
|
| 19 |
+
import java.io.File;
|
| 20 |
+
import java.io.Serializable;
|
| 21 |
+
import java.util.Comparator;
|
| 22 |
+
|
| 23 |
+
/**
|
| 24 |
+
* Compare two files using the {@link File#isDirectory()} method.
|
| 25 |
+
* <p>
|
| 26 |
+
* This comparator can be used to sort lists or arrays by directories and files.
|
| 27 |
+
* <p>
|
| 28 |
+
* Example of sorting a list of files/directories using the
|
| 29 |
+
* {@link #DIRECTORY_COMPARATOR} singleton instance:
|
| 30 |
+
* <pre>
|
| 31 |
+
* List<File> list = ...
|
| 32 |
+
* ((AbstractFileComparator) DirectoryFileComparator.DIRECTORY_COMPARATOR).sort(list);
|
| 33 |
+
* </pre>
|
| 34 |
+
* <p>
|
| 35 |
+
* Example of doing a <i>reverse</i> sort of an array of files/directories using the
|
| 36 |
+
* {@link #DIRECTORY_REVERSE} singleton instance:
|
| 37 |
+
* <pre>
|
| 38 |
+
* File[] array = ...
|
| 39 |
+
* ((AbstractFileComparator) DirectoryFileComparator.DIRECTORY_REVERSE).sort(array);
|
| 40 |
+
* </pre>
|
| 41 |
+
* <p>
|
| 42 |
+
*
|
| 43 |
+
* @version $Id: DirectoryFileComparator.java 1642757 2014-12-01 21:09:30Z sebb $
|
| 44 |
+
* @since 2.0
|
| 45 |
+
*/
|
| 46 |
+
public class DirectoryFileComparator extends AbstractFileComparator implements Serializable {
|
| 47 |
+
|
| 48 |
+
private static final long serialVersionUID = 296132640160964395L;
|
| 49 |
+
|
| 50 |
+
/** Singleton default comparator instance */
|
| 51 |
+
public static final Comparator<File> DIRECTORY_COMPARATOR = new DirectoryFileComparator();
|
| 52 |
+
|
| 53 |
+
/** Singleton reverse default comparator instance */
|
| 54 |
+
public static final Comparator<File> DIRECTORY_REVERSE = new ReverseComparator(DIRECTORY_COMPARATOR);
|
| 55 |
+
|
| 56 |
+
/**
|
| 57 |
+
* Compare the two files using the {@link File#isDirectory()} method.
|
| 58 |
+
*
|
| 59 |
+
* @param file1 The first file to compare
|
| 60 |
+
* @param file2 The second file to compare
|
| 61 |
+
* @return the result of calling file1's
|
| 62 |
+
* {@link File#compareTo(File)} with file2 as the parameter.
|
| 63 |
+
*/
|
| 64 |
+
public int compare(final File file1, final File file2) {
|
| 65 |
+
return getType(file1) - getType(file2);
|
| 66 |
+
}
|
| 67 |
+
|
| 68 |
+
/**
|
| 69 |
+
* Convert type to numeric value.
|
| 70 |
+
*
|
| 71 |
+
* @param file The file
|
| 72 |
+
* @return 1 for directories and 2 for files
|
| 73 |
+
*/
|
| 74 |
+
private int getType(final File file) {
|
| 75 |
+
if (file.isDirectory()) {
|
| 76 |
+
return 1;
|
| 77 |
+
} else {
|
| 78 |
+
return 2;
|
| 79 |
+
}
|
| 80 |
+
}
|
| 81 |
+
}
|
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/01_课件与电子教材/尚硅谷_第15章_File类与IO流/03-apache-common包/commons-io-2.5-src/src/main/java/org/apache/commons/io/comparator/ExtensionFileComparator.java
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Licensed to the Apache Software Foundation (ASF) under one or more
|
| 3 |
+
* contributor license agreements. See the NOTICE file distributed with
|
| 4 |
+
* this work for additional information regarding copyright ownership.
|
| 5 |
+
* The ASF licenses this file to You under the Apache License, Version 2.0
|
| 6 |
+
* (the "License"); you may not use this file except in compliance with
|
| 7 |
+
* the License. You may obtain a copy of the License at
|
| 8 |
+
*
|
| 9 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
*
|
| 11 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 12 |
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
| 13 |
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 14 |
+
* See the License for the specific language governing permissions and
|
| 15 |
+
* limitations under the License.
|
| 16 |
+
*/
|
| 17 |
+
package org.apache.commons.io.comparator;
|
| 18 |
+
|
| 19 |
+
import java.io.File;
|
| 20 |
+
import java.io.Serializable;
|
| 21 |
+
import java.util.Comparator;
|
| 22 |
+
|
| 23 |
+
import org.apache.commons.io.FilenameUtils;
|
| 24 |
+
import org.apache.commons.io.IOCase;
|
| 25 |
+
|
| 26 |
+
/**
|
| 27 |
+
* Compare the file name <b>extensions</b> for order
|
| 28 |
+
* (see {@link FilenameUtils#getExtension(String)}).
|
| 29 |
+
* <p>
|
| 30 |
+
* This comparator can be used to sort lists or arrays of files
|
| 31 |
+
* by their file extension either in a case-sensitive, case-insensitive or
|
| 32 |
+
* system dependent case sensitive way. A number of singleton instances
|
| 33 |
+
* are provided for the various case sensitivity options (using {@link IOCase})
|
| 34 |
+
* and the reverse of those options.
|
| 35 |
+
* <p>
|
| 36 |
+
* Example of a <i>case-sensitive</i> file extension sort using the
|
| 37 |
+
* {@link #EXTENSION_COMPARATOR} singleton instance:
|
| 38 |
+
* <pre>
|
| 39 |
+
* List<File> list = ...
|
| 40 |
+
* ((AbstractFileComparator) ExtensionFileComparator.EXTENSION_COMPARATOR).sort(list);
|
| 41 |
+
* </pre>
|
| 42 |
+
* <p>
|
| 43 |
+
* Example of a <i>reverse case-insensitive</i> file extension sort using the
|
| 44 |
+
* {@link #EXTENSION_INSENSITIVE_REVERSE} singleton instance:
|
| 45 |
+
* <pre>
|
| 46 |
+
* File[] array = ...
|
| 47 |
+
* ((AbstractFileComparator) ExtensionFileComparator.EXTENSION_INSENSITIVE_REVERSE).sort(array);
|
| 48 |
+
* </pre>
|
| 49 |
+
* <p>
|
| 50 |
+
*
|
| 51 |
+
* @version $Id: ExtensionFileComparator.java 1642757 2014-12-01 21:09:30Z sebb $
|
| 52 |
+
* @since 1.4
|
| 53 |
+
*/
|
| 54 |
+
public class ExtensionFileComparator extends AbstractFileComparator implements Serializable {
|
| 55 |
+
|
| 56 |
+
private static final long serialVersionUID = 1928235200184222815L;
|
| 57 |
+
|
| 58 |
+
/** Case-sensitive extension comparator instance (see {@link IOCase#SENSITIVE}) */
|
| 59 |
+
public static final Comparator<File> EXTENSION_COMPARATOR = new ExtensionFileComparator();
|
| 60 |
+
|
| 61 |
+
/** Reverse case-sensitive extension comparator instance (see {@link IOCase#SENSITIVE}) */
|
| 62 |
+
public static final Comparator<File> EXTENSION_REVERSE = new ReverseComparator(EXTENSION_COMPARATOR);
|
| 63 |
+
|
| 64 |
+
/** Case-insensitive extension comparator instance (see {@link IOCase#INSENSITIVE}) */
|
| 65 |
+
public static final Comparator<File> EXTENSION_INSENSITIVE_COMPARATOR
|
| 66 |
+
= new ExtensionFileComparator(IOCase.INSENSITIVE);
|
| 67 |
+
|
| 68 |
+
/** Reverse case-insensitive extension comparator instance (see {@link IOCase#INSENSITIVE}) */
|
| 69 |
+
public static final Comparator<File> EXTENSION_INSENSITIVE_REVERSE
|
| 70 |
+
= new ReverseComparator(EXTENSION_INSENSITIVE_COMPARATOR);
|
| 71 |
+
|
| 72 |
+
/** System sensitive extension comparator instance (see {@link IOCase#SYSTEM}) */
|
| 73 |
+
public static final Comparator<File> EXTENSION_SYSTEM_COMPARATOR = new ExtensionFileComparator(IOCase.SYSTEM);
|
| 74 |
+
|
| 75 |
+
/** Reverse system sensitive path comparator instance (see {@link IOCase#SYSTEM}) */
|
| 76 |
+
public static final Comparator<File> EXTENSION_SYSTEM_REVERSE = new ReverseComparator(EXTENSION_SYSTEM_COMPARATOR);
|
| 77 |
+
|
| 78 |
+
/** Whether the comparison is case sensitive. */
|
| 79 |
+
private final IOCase caseSensitivity;
|
| 80 |
+
|
| 81 |
+
/**
|
| 82 |
+
* Construct a case sensitive file extension comparator instance.
|
| 83 |
+
*/
|
| 84 |
+
public ExtensionFileComparator() {
|
| 85 |
+
this.caseSensitivity = IOCase.SENSITIVE;
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
/**
|
| 89 |
+
* Construct a file extension comparator instance with the specified case-sensitivity.
|
| 90 |
+
*
|
| 91 |
+
* @param caseSensitivity how to handle case sensitivity, null means case-sensitive
|
| 92 |
+
*/
|
| 93 |
+
public ExtensionFileComparator(final IOCase caseSensitivity) {
|
| 94 |
+
this.caseSensitivity = caseSensitivity == null ? IOCase.SENSITIVE : caseSensitivity;
|
| 95 |
+
}
|
| 96 |
+
|
| 97 |
+
/**
|
| 98 |
+
* Compare the extensions of two files the specified case sensitivity.
|
| 99 |
+
*
|
| 100 |
+
* @param file1 The first file to compare
|
| 101 |
+
* @param file2 The second file to compare
|
| 102 |
+
* @return a negative value if the first file's extension
|
| 103 |
+
* is less than the second, zero if the extensions are the
|
| 104 |
+
* same and a positive value if the first files extension
|
| 105 |
+
* is greater than the second file.
|
| 106 |
+
*
|
| 107 |
+
*/
|
| 108 |
+
public int compare(final File file1, final File file2) {
|
| 109 |
+
final String suffix1 = FilenameUtils.getExtension(file1.getName());
|
| 110 |
+
final String suffix2 = FilenameUtils.getExtension(file2.getName());
|
| 111 |
+
return caseSensitivity.checkCompareTo(suffix1, suffix2);
|
| 112 |
+
}
|
| 113 |
+
|
| 114 |
+
/**
|
| 115 |
+
* String representation of this file comparator.
|
| 116 |
+
*
|
| 117 |
+
* @return String representation of this file comparator
|
| 118 |
+
*/
|
| 119 |
+
@Override
|
| 120 |
+
public String toString() {
|
| 121 |
+
return super.toString() + "[caseSensitivity=" + caseSensitivity + "]";
|
| 122 |
+
}
|
| 123 |
+
}
|
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/01_课件与电子教材/尚硅谷_第15章_File类与IO流/03-apache-common包/commons-io-2.5-src/src/main/java/org/apache/commons/io/comparator/LastModifiedFileComparator.java
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Licensed to the Apache Software Foundation (ASF) under one or more
|
| 3 |
+
* contributor license agreements. See the NOTICE file distributed with
|
| 4 |
+
* this work for additional information regarding copyright ownership.
|
| 5 |
+
* The ASF licenses this file to You under the Apache License, Version 2.0
|
| 6 |
+
* (the "License"); you may not use this file except in compliance with
|
| 7 |
+
* the License. You may obtain a copy of the License at
|
| 8 |
+
*
|
| 9 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
*
|
| 11 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 12 |
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
| 13 |
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 14 |
+
* See the License for the specific language governing permissions and
|
| 15 |
+
* limitations under the License.
|
| 16 |
+
*/
|
| 17 |
+
package org.apache.commons.io.comparator;
|
| 18 |
+
|
| 19 |
+
import java.io.File;
|
| 20 |
+
import java.io.Serializable;
|
| 21 |
+
import java.util.Comparator;
|
| 22 |
+
|
| 23 |
+
/**
|
| 24 |
+
* Compare the <b>last modified date/time</b> of two files for order
|
| 25 |
+
* (see {@link File#lastModified()}).
|
| 26 |
+
* <p>
|
| 27 |
+
* This comparator can be used to sort lists or arrays of files
|
| 28 |
+
* by their last modified date/time.
|
| 29 |
+
* <p>
|
| 30 |
+
* Example of sorting a list of files using the
|
| 31 |
+
* {@link #LASTMODIFIED_COMPARATOR} singleton instance:
|
| 32 |
+
* <pre>
|
| 33 |
+
* List<File> list = ...
|
| 34 |
+
* ((AbstractFileComparator) LastModifiedFileComparator.LASTMODIFIED_COMPARATOR).sort(list);
|
| 35 |
+
* </pre>
|
| 36 |
+
* <p>
|
| 37 |
+
* Example of doing a <i>reverse</i> sort of an array of files using the
|
| 38 |
+
* {@link #LASTMODIFIED_REVERSE} singleton instance:
|
| 39 |
+
* <pre>
|
| 40 |
+
* File[] array = ...
|
| 41 |
+
* ((AbstractFileComparator) LastModifiedFileComparator.LASTMODIFIED_REVERSE).sort(array);
|
| 42 |
+
* </pre>
|
| 43 |
+
* <p>
|
| 44 |
+
*
|
| 45 |
+
* @version $Id: LastModifiedFileComparator.java 1642757 2014-12-01 21:09:30Z sebb $
|
| 46 |
+
* @since 1.4
|
| 47 |
+
*/
|
| 48 |
+
public class LastModifiedFileComparator extends AbstractFileComparator implements Serializable {
|
| 49 |
+
|
| 50 |
+
private static final long serialVersionUID = 7372168004395734046L;
|
| 51 |
+
|
| 52 |
+
/** Last modified comparator instance */
|
| 53 |
+
public static final Comparator<File> LASTMODIFIED_COMPARATOR = new LastModifiedFileComparator();
|
| 54 |
+
|
| 55 |
+
/** Reverse last modified comparator instance */
|
| 56 |
+
public static final Comparator<File> LASTMODIFIED_REVERSE = new ReverseComparator(LASTMODIFIED_COMPARATOR);
|
| 57 |
+
|
| 58 |
+
/**
|
| 59 |
+
* Compare the last the last modified date/time of two files.
|
| 60 |
+
*
|
| 61 |
+
* @param file1 The first file to compare
|
| 62 |
+
* @param file2 The second file to compare
|
| 63 |
+
* @return a negative value if the first file's lastmodified date/time
|
| 64 |
+
* is less than the second, zero if the lastmodified date/time are the
|
| 65 |
+
* same and a positive value if the first files lastmodified date/time
|
| 66 |
+
* is greater than the second file.
|
| 67 |
+
*
|
| 68 |
+
*/
|
| 69 |
+
public int compare(final File file1, final File file2) {
|
| 70 |
+
final long result = file1.lastModified() - file2.lastModified();
|
| 71 |
+
if (result < 0) {
|
| 72 |
+
return -1;
|
| 73 |
+
} else if (result > 0) {
|
| 74 |
+
return 1;
|
| 75 |
+
} else {
|
| 76 |
+
return 0;
|
| 77 |
+
}
|
| 78 |
+
}
|
| 79 |
+
}
|
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/01_课件与电子教材/尚硅谷_第15章_File类与IO流/03-apache-common包/commons-io-2.5-src/src/main/java/org/apache/commons/io/comparator/NameFileComparator.java
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Licensed to the Apache Software Foundation (ASF) under one or more
|
| 3 |
+
* contributor license agreements. See the NOTICE file distributed with
|
| 4 |
+
* this work for additional information regarding copyright ownership.
|
| 5 |
+
* The ASF licenses this file to You under the Apache License, Version 2.0
|
| 6 |
+
* (the "License"); you may not use this file except in compliance with
|
| 7 |
+
* the License. You may obtain a copy of the License at
|
| 8 |
+
*
|
| 9 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
*
|
| 11 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 12 |
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
| 13 |
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 14 |
+
* See the License for the specific language governing permissions and
|
| 15 |
+
* limitations under the License.
|
| 16 |
+
*/
|
| 17 |
+
package org.apache.commons.io.comparator;
|
| 18 |
+
|
| 19 |
+
import java.io.File;
|
| 20 |
+
import java.io.Serializable;
|
| 21 |
+
import java.util.Comparator;
|
| 22 |
+
|
| 23 |
+
import org.apache.commons.io.IOCase;
|
| 24 |
+
|
| 25 |
+
/**
|
| 26 |
+
* Compare the <b>names</b> of two files for order (see {@link File#getName()}).
|
| 27 |
+
* <p>
|
| 28 |
+
* This comparator can be used to sort lists or arrays of files
|
| 29 |
+
* by their name either in a case-sensitive, case-insensitive or
|
| 30 |
+
* system dependent case sensitive way. A number of singleton instances
|
| 31 |
+
* are provided for the various case sensitivity options (using {@link IOCase})
|
| 32 |
+
* and the reverse of those options.
|
| 33 |
+
* <p>
|
| 34 |
+
* Example of a <i>case-sensitive</i> file name sort using the
|
| 35 |
+
* {@link #NAME_COMPARATOR} singleton instance:
|
| 36 |
+
* <pre>
|
| 37 |
+
* List<File> list = ...
|
| 38 |
+
* ((AbstractFileComparator) NameFileComparator.NAME_COMPARATOR).sort(list);
|
| 39 |
+
* </pre>
|
| 40 |
+
* <p>
|
| 41 |
+
* Example of a <i>reverse case-insensitive</i> file name sort using the
|
| 42 |
+
* {@link #NAME_INSENSITIVE_REVERSE} singleton instance:
|
| 43 |
+
* <pre>
|
| 44 |
+
* File[] array = ...
|
| 45 |
+
* ((AbstractFileComparator) NameFileComparator.NAME_INSENSITIVE_REVERSE).sort(array);
|
| 46 |
+
* </pre>
|
| 47 |
+
* <p>
|
| 48 |
+
*
|
| 49 |
+
* @version $Id: NameFileComparator.java 1642757 2014-12-01 21:09:30Z sebb $
|
| 50 |
+
* @since 1.4
|
| 51 |
+
*/
|
| 52 |
+
public class NameFileComparator extends AbstractFileComparator implements Serializable {
|
| 53 |
+
|
| 54 |
+
private static final long serialVersionUID = 8397947749814525798L;
|
| 55 |
+
|
| 56 |
+
/** Case-sensitive name comparator instance (see {@link IOCase#SENSITIVE}) */
|
| 57 |
+
public static final Comparator<File> NAME_COMPARATOR = new NameFileComparator();
|
| 58 |
+
|
| 59 |
+
/** Reverse case-sensitive name comparator instance (see {@link IOCase#SENSITIVE}) */
|
| 60 |
+
public static final Comparator<File> NAME_REVERSE = new ReverseComparator(NAME_COMPARATOR);
|
| 61 |
+
|
| 62 |
+
/** Case-insensitive name comparator instance (see {@link IOCase#INSENSITIVE}) */
|
| 63 |
+
public static final Comparator<File> NAME_INSENSITIVE_COMPARATOR = new NameFileComparator(IOCase.INSENSITIVE);
|
| 64 |
+
|
| 65 |
+
/** Reverse case-insensitive name comparator instance (see {@link IOCase#INSENSITIVE}) */
|
| 66 |
+
public static final Comparator<File> NAME_INSENSITIVE_REVERSE = new ReverseComparator(NAME_INSENSITIVE_COMPARATOR);
|
| 67 |
+
|
| 68 |
+
/** System sensitive name comparator instance (see {@link IOCase#SYSTEM}) */
|
| 69 |
+
public static final Comparator<File> NAME_SYSTEM_COMPARATOR = new NameFileComparator(IOCase.SYSTEM);
|
| 70 |
+
|
| 71 |
+
/** Reverse system sensitive name comparator instance (see {@link IOCase#SYSTEM}) */
|
| 72 |
+
public static final Comparator<File> NAME_SYSTEM_REVERSE = new ReverseComparator(NAME_SYSTEM_COMPARATOR);
|
| 73 |
+
|
| 74 |
+
/** Whether the comparison is case sensitive. */
|
| 75 |
+
private final IOCase caseSensitivity;
|
| 76 |
+
|
| 77 |
+
/**
|
| 78 |
+
* Construct a case sensitive file name comparator instance.
|
| 79 |
+
*/
|
| 80 |
+
public NameFileComparator() {
|
| 81 |
+
this.caseSensitivity = IOCase.SENSITIVE;
|
| 82 |
+
}
|
| 83 |
+
|
| 84 |
+
/**
|
| 85 |
+
* Construct a file name comparator instance with the specified case-sensitivity.
|
| 86 |
+
*
|
| 87 |
+
* @param caseSensitivity how to handle case sensitivity, null means case-sensitive
|
| 88 |
+
*/
|
| 89 |
+
public NameFileComparator(final IOCase caseSensitivity) {
|
| 90 |
+
this.caseSensitivity = caseSensitivity == null ? IOCase.SENSITIVE : caseSensitivity;
|
| 91 |
+
}
|
| 92 |
+
|
| 93 |
+
/**
|
| 94 |
+
* Compare the names of two files with the specified case sensitivity.
|
| 95 |
+
*
|
| 96 |
+
* @param file1 The first file to compare
|
| 97 |
+
* @param file2 The second file to compare
|
| 98 |
+
* @return a negative value if the first file's name
|
| 99 |
+
* is less than the second, zero if the names are the
|
| 100 |
+
* same and a positive value if the first files name
|
| 101 |
+
* is greater than the second file.
|
| 102 |
+
*/
|
| 103 |
+
public int compare(final File file1, final File file2) {
|
| 104 |
+
return caseSensitivity.checkCompareTo(file1.getName(), file2.getName());
|
| 105 |
+
}
|
| 106 |
+
|
| 107 |
+
/**
|
| 108 |
+
* String representation of this file comparator.
|
| 109 |
+
*
|
| 110 |
+
* @return String representation of this file comparator
|
| 111 |
+
*/
|
| 112 |
+
@Override
|
| 113 |
+
public String toString() {
|
| 114 |
+
return super.toString() + "[caseSensitivity=" + caseSensitivity + "]";
|
| 115 |
+
}
|
| 116 |
+
}
|
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/01_课件与电子教材/尚硅谷_第15章_File类与IO流/03-apache-common包/commons-io-2.5-src/src/main/java/org/apache/commons/io/comparator/PathFileComparator.java
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Licensed to the Apache Software Foundation (ASF) under one or more
|
| 3 |
+
* contributor license agreements. See the NOTICE file distributed with
|
| 4 |
+
* this work for additional information regarding copyright ownership.
|
| 5 |
+
* The ASF licenses this file to You under the Apache License, Version 2.0
|
| 6 |
+
* (the "License"); you may not use this file except in compliance with
|
| 7 |
+
* the License. You may obtain a copy of the License at
|
| 8 |
+
*
|
| 9 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
*
|
| 11 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 12 |
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
| 13 |
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 14 |
+
* See the License for the specific language governing permissions and
|
| 15 |
+
* limitations under the License.
|
| 16 |
+
*/
|
| 17 |
+
package org.apache.commons.io.comparator;
|
| 18 |
+
|
| 19 |
+
import java.io.File;
|
| 20 |
+
import java.io.Serializable;
|
| 21 |
+
import java.util.Comparator;
|
| 22 |
+
|
| 23 |
+
import org.apache.commons.io.IOCase;
|
| 24 |
+
|
| 25 |
+
/**
|
| 26 |
+
* Compare the <b>path</b> of two files for order (see {@link File#getPath()}).
|
| 27 |
+
* <p>
|
| 28 |
+
* This comparator can be used to sort lists or arrays of files
|
| 29 |
+
* by their path either in a case-sensitive, case-insensitive or
|
| 30 |
+
* system dependent case sensitive way. A number of singleton instances
|
| 31 |
+
* are provided for the various case sensitivity options (using {@link IOCase})
|
| 32 |
+
* and the reverse of those options.
|
| 33 |
+
* <p>
|
| 34 |
+
* Example of a <i>case-sensitive</i> file path sort using the
|
| 35 |
+
* {@link #PATH_COMPARATOR} singleton instance:
|
| 36 |
+
* <pre>
|
| 37 |
+
* List<File> list = ...
|
| 38 |
+
* ((AbstractFileComparator) PathFileComparator.PATH_COMPARATOR).sort(list);
|
| 39 |
+
* </pre>
|
| 40 |
+
* <p>
|
| 41 |
+
* Example of a <i>reverse case-insensitive</i> file path sort using the
|
| 42 |
+
* {@link #PATH_INSENSITIVE_REVERSE} singleton instance:
|
| 43 |
+
* <pre>
|
| 44 |
+
* File[] array = ...
|
| 45 |
+
* ((AbstractFileComparator) PathFileComparator.PATH_INSENSITIVE_REVERSE).sort(array);
|
| 46 |
+
* </pre>
|
| 47 |
+
* <p>
|
| 48 |
+
*
|
| 49 |
+
* @version $Id: PathFileComparator.java 1642757 2014-12-01 21:09:30Z sebb $
|
| 50 |
+
* @since 1.4
|
| 51 |
+
*/
|
| 52 |
+
public class PathFileComparator extends AbstractFileComparator implements Serializable {
|
| 53 |
+
|
| 54 |
+
private static final long serialVersionUID = 6527501707585768673L;
|
| 55 |
+
|
| 56 |
+
/** Case-sensitive path comparator instance (see {@link IOCase#SENSITIVE}) */
|
| 57 |
+
public static final Comparator<File> PATH_COMPARATOR = new PathFileComparator();
|
| 58 |
+
|
| 59 |
+
/** Reverse case-sensitive path comparator instance (see {@link IOCase#SENSITIVE}) */
|
| 60 |
+
public static final Comparator<File> PATH_REVERSE = new ReverseComparator(PATH_COMPARATOR);
|
| 61 |
+
|
| 62 |
+
/** Case-insensitive path comparator instance (see {@link IOCase#INSENSITIVE}) */
|
| 63 |
+
public static final Comparator<File> PATH_INSENSITIVE_COMPARATOR = new PathFileComparator(IOCase.INSENSITIVE);
|
| 64 |
+
|
| 65 |
+
/** Reverse case-insensitive path comparator instance (see {@link IOCase#INSENSITIVE}) */
|
| 66 |
+
public static final Comparator<File> PATH_INSENSITIVE_REVERSE = new ReverseComparator(PATH_INSENSITIVE_COMPARATOR);
|
| 67 |
+
|
| 68 |
+
/** System sensitive path comparator instance (see {@link IOCase#SYSTEM}) */
|
| 69 |
+
public static final Comparator<File> PATH_SYSTEM_COMPARATOR = new PathFileComparator(IOCase.SYSTEM);
|
| 70 |
+
|
| 71 |
+
/** Reverse system sensitive path comparator instance (see {@link IOCase#SYSTEM}) */
|
| 72 |
+
public static final Comparator<File> PATH_SYSTEM_REVERSE = new ReverseComparator(PATH_SYSTEM_COMPARATOR);
|
| 73 |
+
|
| 74 |
+
/** Whether the comparison is case sensitive. */
|
| 75 |
+
private final IOCase caseSensitivity;
|
| 76 |
+
|
| 77 |
+
/**
|
| 78 |
+
* Construct a case sensitive file path comparator instance.
|
| 79 |
+
*/
|
| 80 |
+
public PathFileComparator() {
|
| 81 |
+
this.caseSensitivity = IOCase.SENSITIVE;
|
| 82 |
+
}
|
| 83 |
+
|
| 84 |
+
/**
|
| 85 |
+
* Construct a file path comparator instance with the specified case-sensitivity.
|
| 86 |
+
*
|
| 87 |
+
* @param caseSensitivity how to handle case sensitivity, null means case-sensitive
|
| 88 |
+
*/
|
| 89 |
+
public PathFileComparator(final IOCase caseSensitivity) {
|
| 90 |
+
this.caseSensitivity = caseSensitivity == null ? IOCase.SENSITIVE : caseSensitivity;
|
| 91 |
+
}
|
| 92 |
+
|
| 93 |
+
/**
|
| 94 |
+
* Compare the paths of two files the specified case sensitivity.
|
| 95 |
+
*
|
| 96 |
+
* @param file1 The first file to compare
|
| 97 |
+
* @param file2 The second file to compare
|
| 98 |
+
* @return a negative value if the first file's path
|
| 99 |
+
* is less than the second, zero if the paths are the
|
| 100 |
+
* same and a positive value if the first files path
|
| 101 |
+
* is greater than the second file.
|
| 102 |
+
*
|
| 103 |
+
*/
|
| 104 |
+
public int compare(final File file1, final File file2) {
|
| 105 |
+
return caseSensitivity.checkCompareTo(file1.getPath(), file2.getPath());
|
| 106 |
+
}
|
| 107 |
+
|
| 108 |
+
/**
|
| 109 |
+
* String representation of this file comparator.
|
| 110 |
+
*
|
| 111 |
+
* @return String representation of this file comparator
|
| 112 |
+
*/
|
| 113 |
+
@Override
|
| 114 |
+
public String toString() {
|
| 115 |
+
return super.toString() + "[caseSensitivity=" + caseSensitivity + "]";
|
| 116 |
+
}
|
| 117 |
+
}
|
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/01_课件与电子教材/尚硅谷_第15章_File类与IO流/03-apache-common包/commons-io-2.5-src/src/main/java/org/apache/commons/io/comparator/ReverseComparator.java
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Licensed to the Apache Software Foundation (ASF) under one or more
|
| 3 |
+
* contributor license agreements. See the NOTICE file distributed with
|
| 4 |
+
* this work for additional information regarding copyright ownership.
|
| 5 |
+
* The ASF licenses this file to You under the Apache License, Version 2.0
|
| 6 |
+
* (the "License"); you may not use this file except in compliance with
|
| 7 |
+
* the License. You may obtain a copy of the License at
|
| 8 |
+
*
|
| 9 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
*
|
| 11 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 12 |
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
| 13 |
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 14 |
+
* See the License for the specific language governing permissions and
|
| 15 |
+
* limitations under the License.
|
| 16 |
+
*/
|
| 17 |
+
package org.apache.commons.io.comparator;
|
| 18 |
+
|
| 19 |
+
import java.io.File;
|
| 20 |
+
import java.io.Serializable;
|
| 21 |
+
import java.util.Comparator;
|
| 22 |
+
|
| 23 |
+
/**
|
| 24 |
+
* Reverses the result of comparing two objects using
|
| 25 |
+
* the delegate {@link Comparator}.
|
| 26 |
+
*
|
| 27 |
+
* @version $Id: ReverseComparator.java 1642757 2014-12-01 21:09:30Z sebb $
|
| 28 |
+
* @since 1.4
|
| 29 |
+
*/
|
| 30 |
+
class ReverseComparator extends AbstractFileComparator implements Serializable {
|
| 31 |
+
|
| 32 |
+
private static final long serialVersionUID = -4808255005272229056L;
|
| 33 |
+
private final Comparator<File> delegate;
|
| 34 |
+
|
| 35 |
+
/**
|
| 36 |
+
* Construct an instance with the sepecified delegate {@link Comparator}.
|
| 37 |
+
*
|
| 38 |
+
* @param delegate The comparator to delegate to
|
| 39 |
+
*/
|
| 40 |
+
public ReverseComparator(final Comparator<File> delegate) {
|
| 41 |
+
if (delegate == null) {
|
| 42 |
+
throw new IllegalArgumentException("Delegate comparator is missing");
|
| 43 |
+
}
|
| 44 |
+
this.delegate = delegate;
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
/**
|
| 48 |
+
* Compare using the delegate Comparator, but reversing the result.
|
| 49 |
+
*
|
| 50 |
+
* @param file1 The first file to compare
|
| 51 |
+
* @param file2 The second file to compare
|
| 52 |
+
* @return the result from the delegate {@link Comparator#compare(Object, Object)}
|
| 53 |
+
* reversing the value (i.e. positive becomes negative and vice versa)
|
| 54 |
+
*/
|
| 55 |
+
public int compare(final File file1, final File file2) {
|
| 56 |
+
return delegate.compare(file2, file1); // parameters switched round
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
/**
|
| 60 |
+
* String representation of this file comparator.
|
| 61 |
+
*
|
| 62 |
+
* @return String representation of this file comparator
|
| 63 |
+
*/
|
| 64 |
+
@Override
|
| 65 |
+
public String toString() {
|
| 66 |
+
return super.toString() + "[" + delegate.toString() + "]";
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
}
|
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/01_课件与电子教材/尚硅谷_第15章_File类与IO流/03-apache-common包/commons-io-2.5-src/src/main/java/org/apache/commons/io/comparator/SizeFileComparator.java
ADDED
|
@@ -0,0 +1,142 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Licensed to the Apache Software Foundation (ASF) under one or more
|
| 3 |
+
* contributor license agreements. See the NOTICE file distributed with
|
| 4 |
+
* this work for additional information regarding copyright ownership.
|
| 5 |
+
* The ASF licenses this file to You under the Apache License, Version 2.0
|
| 6 |
+
* (the "License"); you may not use this file except in compliance with
|
| 7 |
+
* the License. You may obtain a copy of the License at
|
| 8 |
+
*
|
| 9 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
*
|
| 11 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 12 |
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
| 13 |
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 14 |
+
* See the License for the specific language governing permissions and
|
| 15 |
+
* limitations under the License.
|
| 16 |
+
*/
|
| 17 |
+
package org.apache.commons.io.comparator;
|
| 18 |
+
|
| 19 |
+
import java.io.File;
|
| 20 |
+
import java.io.Serializable;
|
| 21 |
+
import java.util.Comparator;
|
| 22 |
+
|
| 23 |
+
import org.apache.commons.io.FileUtils;
|
| 24 |
+
|
| 25 |
+
/**
|
| 26 |
+
* Compare the <b>length/size</b> of two files for order (see
|
| 27 |
+
* {@link File#length()} and {@link FileUtils#sizeOfDirectory(File)}).
|
| 28 |
+
* <p>
|
| 29 |
+
* This comparator can be used to sort lists or arrays of files
|
| 30 |
+
* by their length/size.
|
| 31 |
+
* <p>
|
| 32 |
+
* Example of sorting a list of files using the
|
| 33 |
+
* {@link #SIZE_COMPARATOR} singleton instance:
|
| 34 |
+
* <pre>
|
| 35 |
+
* List<File> list = ...
|
| 36 |
+
* ((AbstractFileComparator) SizeFileComparator.SIZE_COMPARATOR).sort(list);
|
| 37 |
+
* </pre>
|
| 38 |
+
* <p>
|
| 39 |
+
* Example of doing a <i>reverse</i> sort of an array of files using the
|
| 40 |
+
* {@link #SIZE_REVERSE} singleton instance:
|
| 41 |
+
* <pre>
|
| 42 |
+
* File[] array = ...
|
| 43 |
+
* ((AbstractFileComparator) SizeFileComparator.SIZE_REVERSE).sort(array);
|
| 44 |
+
* </pre>
|
| 45 |
+
* <p>
|
| 46 |
+
* <strong>N.B.</strong> Directories are treated as <b>zero size</b> unless
|
| 47 |
+
* <code>sumDirectoryContents</code> is {@code true}.
|
| 48 |
+
*
|
| 49 |
+
* @version $Id: SizeFileComparator.java 1642757 2014-12-01 21:09:30Z sebb $
|
| 50 |
+
* @since 1.4
|
| 51 |
+
*/
|
| 52 |
+
public class SizeFileComparator extends AbstractFileComparator implements Serializable {
|
| 53 |
+
|
| 54 |
+
private static final long serialVersionUID = -1201561106411416190L;
|
| 55 |
+
|
| 56 |
+
/** Size comparator instance - directories are treated as zero size */
|
| 57 |
+
public static final Comparator<File> SIZE_COMPARATOR = new SizeFileComparator();
|
| 58 |
+
|
| 59 |
+
/** Reverse size comparator instance - directories are treated as zero size */
|
| 60 |
+
public static final Comparator<File> SIZE_REVERSE = new ReverseComparator(SIZE_COMPARATOR);
|
| 61 |
+
|
| 62 |
+
/**
|
| 63 |
+
* Size comparator instance which sums the size of a directory's contents
|
| 64 |
+
* using {@link FileUtils#sizeOfDirectory(File)}
|
| 65 |
+
*/
|
| 66 |
+
public static final Comparator<File> SIZE_SUMDIR_COMPARATOR = new SizeFileComparator(true);
|
| 67 |
+
|
| 68 |
+
/**
|
| 69 |
+
* Reverse size comparator instance which sums the size of a directory's contents
|
| 70 |
+
* using {@link FileUtils#sizeOfDirectory(File)}
|
| 71 |
+
*/
|
| 72 |
+
public static final Comparator<File> SIZE_SUMDIR_REVERSE = new ReverseComparator(SIZE_SUMDIR_COMPARATOR);
|
| 73 |
+
|
| 74 |
+
/** Whether the sum of the directory's contents should be calculated. */
|
| 75 |
+
private final boolean sumDirectoryContents;
|
| 76 |
+
|
| 77 |
+
/**
|
| 78 |
+
* Construct a file size comparator instance (directories treated as zero size).
|
| 79 |
+
*/
|
| 80 |
+
public SizeFileComparator() {
|
| 81 |
+
this.sumDirectoryContents = false;
|
| 82 |
+
}
|
| 83 |
+
|
| 84 |
+
/**
|
| 85 |
+
* Construct a file size comparator instance specifying whether the size of
|
| 86 |
+
* the directory contents should be aggregated.
|
| 87 |
+
* <p>
|
| 88 |
+
* If the <code>sumDirectoryContents</code> is {@code true} The size of
|
| 89 |
+
* directories is calculated using {@link FileUtils#sizeOfDirectory(File)}.
|
| 90 |
+
*
|
| 91 |
+
* @param sumDirectoryContents {@code true} if the sum of the directoryies contents
|
| 92 |
+
* should be calculated, otherwise {@code false} if directories should be treated
|
| 93 |
+
* as size zero (see {@link FileUtils#sizeOfDirectory(File)}).
|
| 94 |
+
*/
|
| 95 |
+
public SizeFileComparator(final boolean sumDirectoryContents) {
|
| 96 |
+
this.sumDirectoryContents = sumDirectoryContents;
|
| 97 |
+
}
|
| 98 |
+
|
| 99 |
+
/**
|
| 100 |
+
* Compare the length of two files.
|
| 101 |
+
*
|
| 102 |
+
* @param file1 The first file to compare
|
| 103 |
+
* @param file2 The second file to compare
|
| 104 |
+
* @return a negative value if the first file's length
|
| 105 |
+
* is less than the second, zero if the lengths are the
|
| 106 |
+
* same and a positive value if the first files length
|
| 107 |
+
* is greater than the second file.
|
| 108 |
+
*
|
| 109 |
+
*/
|
| 110 |
+
public int compare(final File file1, final File file2) {
|
| 111 |
+
long size1 = 0;
|
| 112 |
+
if (file1.isDirectory()) {
|
| 113 |
+
size1 = sumDirectoryContents && file1.exists() ? FileUtils.sizeOfDirectory(file1) : 0;
|
| 114 |
+
} else {
|
| 115 |
+
size1 = file1.length();
|
| 116 |
+
}
|
| 117 |
+
long size2 = 0;
|
| 118 |
+
if (file2.isDirectory()) {
|
| 119 |
+
size2 = sumDirectoryContents && file2.exists() ? FileUtils.sizeOfDirectory(file2) : 0;
|
| 120 |
+
} else {
|
| 121 |
+
size2 = file2.length();
|
| 122 |
+
}
|
| 123 |
+
final long result = size1 - size2;
|
| 124 |
+
if (result < 0) {
|
| 125 |
+
return -1;
|
| 126 |
+
} else if (result > 0) {
|
| 127 |
+
return 1;
|
| 128 |
+
} else {
|
| 129 |
+
return 0;
|
| 130 |
+
}
|
| 131 |
+
}
|
| 132 |
+
|
| 133 |
+
/**
|
| 134 |
+
* String representation of this file comparator.
|
| 135 |
+
*
|
| 136 |
+
* @return String representation of this file comparator
|
| 137 |
+
*/
|
| 138 |
+
@Override
|
| 139 |
+
public String toString() {
|
| 140 |
+
return super.toString() + "[sumDirectoryContents=" + sumDirectoryContents + "]";
|
| 141 |
+
}
|
| 142 |
+
}
|
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/01_课件与电子教材/尚硅谷_第15章_File类与IO流/03-apache-common包/commons-io-2.5-src/src/main/java/org/apache/commons/io/comparator/package.html
ADDED
|
@@ -0,0 +1,188 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
| 2 |
+
<!--
|
| 3 |
+
Licensed to the Apache Software Foundation (ASF) under one or more
|
| 4 |
+
contributor license agreements. See the NOTICE file distributed with
|
| 5 |
+
this work for additional information regarding copyright ownership.
|
| 6 |
+
The ASF licenses this file to You under the Apache License, Version 2.0
|
| 7 |
+
(the "License"); you may not use this file except in compliance with
|
| 8 |
+
the License. You may obtain a copy of the License at
|
| 9 |
+
|
| 10 |
+
http://www.apache.org/licenses/LICENSE-2.0
|
| 11 |
+
|
| 12 |
+
Unless required by applicable law or agreed to in writing, software
|
| 13 |
+
distributed under the License is distributed on an "AS IS" BASIS,
|
| 14 |
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 15 |
+
See the License for the specific language governing permissions and
|
| 16 |
+
limitations under the License.
|
| 17 |
+
-->
|
| 18 |
+
<html>
|
| 19 |
+
<body>
|
| 20 |
+
<p>This package provides various {@link java.util.Comparator} implementations
|
| 21 |
+
for {@link java.io.File}s.
|
| 22 |
+
</p>
|
| 23 |
+
<h3>Sorting</h3>
|
| 24 |
+
<p>
|
| 25 |
+
All the compartors include <i>convenience</i> utility <code>sort(File...)</code> and
|
| 26 |
+
<code>sort(List)</code> methods.
|
| 27 |
+
</p>
|
| 28 |
+
<p>
|
| 29 |
+
For example, to sort the files in a directory by name:
|
| 30 |
+
</p>
|
| 31 |
+
<pre>
|
| 32 |
+
File[] files = dir.listFiles();
|
| 33 |
+
NameFileComparator.NAME_COMPARATOR.sort(files);
|
| 34 |
+
</pre>
|
| 35 |
+
<p>
|
| 36 |
+
...alternatively you can do this in one line:
|
| 37 |
+
</p>
|
| 38 |
+
<p>
|
| 39 |
+
<pre>
|
| 40 |
+
File[] files = NameFileComparator.NAME_COMPARATOR.sort(dir.listFiles());
|
| 41 |
+
</pre>
|
| 42 |
+
</p>
|
| 43 |
+
|
| 44 |
+
<h3>Composite Comparator</h3>
|
| 45 |
+
<p>
|
| 46 |
+
The <a href="CompositeFileComparator.html">CompositeFileComparator</a> can be used
|
| 47 |
+
to compare (and sort lists or arrays of files) by combining a number other comparators.
|
| 48 |
+
</p>
|
| 49 |
+
<p>
|
| 50 |
+
For example, to sort an array of files by type (i.e. directory or file)
|
| 51 |
+
and then by name:
|
| 52 |
+
</p>
|
| 53 |
+
<p>
|
| 54 |
+
<pre>
|
| 55 |
+
CompositeFileComparator comparator =
|
| 56 |
+
new CompositeFileComparator(
|
| 57 |
+
DirectoryFileComparator.DIRECTORY_COMPARATOR,
|
| 58 |
+
NameFileComparator.NAME_COMPARATOR);
|
| 59 |
+
File[] files = dir.listFiles();
|
| 60 |
+
comparator.sort(files);
|
| 61 |
+
</pre>
|
| 62 |
+
</p>
|
| 63 |
+
|
| 64 |
+
<h3>Singleton Instances (thread-safe)</h3>
|
| 65 |
+
<p>
|
| 66 |
+
The {@link java.util.Comparator} implementations have some <i>convenience</i>
|
| 67 |
+
singleton(<i>thread-safe</i>) instances ready to use:
|
| 68 |
+
<ul>
|
| 69 |
+
<li><a href="DefaultFileComparator.html">DefaultFileComparator</a> - default file compare:
|
| 70 |
+
<ul>
|
| 71 |
+
<li><a href="DefaultFileComparator.html#DEFAULT_COMPARATOR">DEFAULT_COMPARATOR</a>
|
| 72 |
+
- Compare using <code>File.compareTo(File)</code> method.
|
| 73 |
+
</li>
|
| 74 |
+
<li><a href="DefaultFileComparator.html#DEFAULT_REVERSE">DEFAULT_REVERSE</a>
|
| 75 |
+
- Reverse compare of <code>File.compareTo(File)</code> method.
|
| 76 |
+
</li>
|
| 77 |
+
</ul>
|
| 78 |
+
</li>
|
| 79 |
+
<li><a href="DirectoryFileComparator.html">DirectoryFileComparator</a> - compare by type (directory or file):
|
| 80 |
+
<ul>
|
| 81 |
+
<li><a href="DirectoryFileComparator.html#DIRECTORY_COMPARATOR">DIRECTORY_COMPARATOR</a>
|
| 82 |
+
- Compare using <code>File.isDirectory()</code> method (directories < files).
|
| 83 |
+
</li>
|
| 84 |
+
<li><a href="DirectoryFileComparator.html#DIRECTORY_REVERSE">DIRECTORY_REVERSE</a>
|
| 85 |
+
- Reverse compare of <code>File.isDirectory()</code> method (directories > files).
|
| 86 |
+
</li>
|
| 87 |
+
</ul>
|
| 88 |
+
</li>
|
| 89 |
+
<li><a href="ExtensionFileComparator.html">ExtensionFileComparator</a> - compare file extenstions:
|
| 90 |
+
<ul>
|
| 91 |
+
<li><a href="ExtensionFileComparator.html#EXTENSION_COMPARATOR">EXTENSION_COMPARATOR</a>
|
| 92 |
+
- Compare using <code>FilenameUtils.getExtension(String)</code> method.
|
| 93 |
+
</li>
|
| 94 |
+
<li><a href="ExtensionFileComparator.html#EXTENSION_REVERSE">EXTENSION_REVERSE</a>
|
| 95 |
+
- Reverse compare of <code>FilenameUtils.getExtension(String)</code> method.
|
| 96 |
+
</li>
|
| 97 |
+
<li><a href="ExtensionFileComparator.html#EXTENSION_INSENSITIVE_COMPARATOR">EXTENSION_INSENSITIVE_COMPARATOR</a>
|
| 98 |
+
- Case-insensitive compare using <code>FilenameUtils.getExtension(String)</code> method.
|
| 99 |
+
</li>
|
| 100 |
+
<li><a href="ExtensionFileComparator.html#EXTENSION_INSENSITIVE_REVERSE">EXTENSION_INSENSITIVE_REVERSE</a>
|
| 101 |
+
- Reverse case-insensitive compare of <code>FilenameUtils.getExtension(String)</code> method.
|
| 102 |
+
</li>
|
| 103 |
+
<li><a href="ExtensionFileComparator.html#EXTENSION_SYSTEM_COMPARATOR">EXTENSION_SYSTEM_COMPARATOR</a>
|
| 104 |
+
- System sensitive compare using <code>FilenameUtils.getExtension(String)</code> method.
|
| 105 |
+
</li>
|
| 106 |
+
<li><a href="ExtensionFileComparator.html#EXTENSION_SYSTEM_REVERSE">EXTENSION_SYSTEM_REVERSE</a>
|
| 107 |
+
- Reverse system sensitive compare of <code>FilenameUtils.getExtension(String)</code> method.
|
| 108 |
+
</li>
|
| 109 |
+
</ul>
|
| 110 |
+
</li>
|
| 111 |
+
<li><a href="LastModifiedFileComparator.html">LastModifiedFileComparator</a>
|
| 112 |
+
- compare the file's last modified date/time:
|
| 113 |
+
<ul>
|
| 114 |
+
<li><a href="LastModifiedFileComparator.html#LASTMODIFIED_COMPARATOR">LASTMODIFIED_COMPARATOR</a>
|
| 115 |
+
- Compare using <code>File.lastModified()</code> method.
|
| 116 |
+
</li>
|
| 117 |
+
<li><a href="LastModifiedFileComparator.html#LASTMODIFIED_REVERSE">LASTMODIFIED_REVERSE</a>
|
| 118 |
+
- Reverse compare of <code>File.lastModified()</code> method.
|
| 119 |
+
</li>
|
| 120 |
+
</ul>
|
| 121 |
+
</li>
|
| 122 |
+
<li><a href="NameFileComparator.html">NameFileComparator</a> - compare file names:
|
| 123 |
+
<ul>
|
| 124 |
+
<li><a href="NameFileComparator.html#NAME_COMPARATOR">NAME_COMPARATOR</a>
|
| 125 |
+
- Compare using <code>File.getName()</code> method.
|
| 126 |
+
</li>
|
| 127 |
+
<li><a href="NameFileComparator.html#NAME_REVERSE">NAME_REVERSE</a>
|
| 128 |
+
- Reverse compare of <code>File.getName()</code> method.
|
| 129 |
+
</li>
|
| 130 |
+
<li><a href="NameFileComparator.html#NAME_INSENSITIVE_COMPARATOR">NAME_INSENSITIVE_COMPARATOR</a>
|
| 131 |
+
- Case-insensitive compare using <code>File.getName()</code> method.
|
| 132 |
+
</li>
|
| 133 |
+
<li><a href="NameFileComparator.html#NAME_INSENSITIVE_REVERSE">NAME_INSENSITIVE_REVERSE</a>
|
| 134 |
+
- Reverse case-insensitive compare of <code>File.getName()</code> method.
|
| 135 |
+
</li>
|
| 136 |
+
<li><a href="NameFileComparator.html#NAME_SYSTEM_COMPARATOR">NAME_SYSTEM_COMPARATOR</a>
|
| 137 |
+
- System sensitive compare using <code>File.getName()</code> method.
|
| 138 |
+
</li>
|
| 139 |
+
<li><a href="NameFileComparator.html#NAME_SYSTEM_REVERSE">NAME_SYSTEM_REVERSE</a>
|
| 140 |
+
- Reverse system sensitive compare of <code>File.getName()</code> method.
|
| 141 |
+
</li>
|
| 142 |
+
</ul>
|
| 143 |
+
</li>
|
| 144 |
+
<li><a href="PathFileComparator.html">PathFileComparator</a> - compare file paths:
|
| 145 |
+
<ul>
|
| 146 |
+
<li><a href="PathFileComparator.html#PATH_COMPARATOR">PATH_COMPARATOR</a>
|
| 147 |
+
- Compare using <code>File.getPath()</code> method.
|
| 148 |
+
</li>
|
| 149 |
+
<li><a href="PathFileComparator.html#PATH_REVERSE">PATH_REVERSE</a>
|
| 150 |
+
- Reverse compare of <code>File.getPath()</code> method.
|
| 151 |
+
</li>
|
| 152 |
+
<li><a href="PathFileComparator.html#PATH_INSENSITIVE_COMPARATOR">PATH_INSENSITIVE_COMPARATOR</a>
|
| 153 |
+
- Case-insensitive compare using <code>File.getPath()</code> method.
|
| 154 |
+
</li>
|
| 155 |
+
<li><a href="PathFileComparator.html#PATH_INSENSITIVE_REVERSE">PATH_INSENSITIVE_REVERSE</a>
|
| 156 |
+
- Reverse case-insensitive compare of <code>File.getPath()</code> method.
|
| 157 |
+
</li>
|
| 158 |
+
<li><a href="PathFileComparator.html#PATH_SYSTEM_COMPARATOR">PATH_SYSTEM_COMPARATOR</a>
|
| 159 |
+
- System sensitive compare using <code>File.getPath()</code> method.
|
| 160 |
+
</li>
|
| 161 |
+
<li><a href="PathFileComparator.html#PATH_SYSTEM_REVERSE">PATH_SYSTEM_REVERSE</a>
|
| 162 |
+
- Reverse system sensitive compare of <code>File.getPath()</code> method.
|
| 163 |
+
</li>
|
| 164 |
+
</ul>
|
| 165 |
+
</li>
|
| 166 |
+
<li><a href="SizeFileComparator.html">SizeFileComparator</a> - compare the file's size:
|
| 167 |
+
<ul>
|
| 168 |
+
<li><a href="SizeFileComparator.html#SIZE_COMPARATOR">SIZE_COMPARATOR</a>
|
| 169 |
+
- Compare using <code>File.length()</code> method (directories treated as zero length).
|
| 170 |
+
</li>
|
| 171 |
+
<li><a href="SizeFileComparator.html#SIZE_REVERSE">LASTMODIFIED_REVERSE</a>
|
| 172 |
+
- Reverse compare of <code>File.length()</code> method (directories treated as zero length).
|
| 173 |
+
</li>
|
| 174 |
+
<li><a href="SizeFileComparator.html#SIZE_SUMDIR_COMPARATOR">SIZE_SUMDIR_COMPARATOR</a>
|
| 175 |
+
- Compare using <code>FileUtils.sizeOfDirectory(File)</code> method
|
| 176 |
+
(sums the size of a directory's contents).
|
| 177 |
+
</li>
|
| 178 |
+
<li><a href="SizeFileComparator.html#SIZE_SUMDIR_REVERSE">SIZE_SUMDIR_REVERSE</a>
|
| 179 |
+
- Reverse compare of <code>FileUtils.sizeOfDirectory(File)</code> method
|
| 180 |
+
(sums the size of a directory's contents).
|
| 181 |
+
</li>
|
| 182 |
+
</ul>
|
| 183 |
+
</li>
|
| 184 |
+
</ul>
|
| 185 |
+
</p>
|
| 186 |
+
|
| 187 |
+
</body>
|
| 188 |
+
</html>
|
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/01_课件与电子教材/尚硅谷_第15章_File类与IO流/03-apache-common包/commons-io-2.5-src/src/main/java/org/apache/commons/io/filefilter/AbstractFileFilter.java
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Licensed to the Apache Software Foundation (ASF) under one or more
|
| 3 |
+
* contributor license agreements. See the NOTICE file distributed with
|
| 4 |
+
* this work for additional information regarding copyright ownership.
|
| 5 |
+
* The ASF licenses this file to You under the Apache License, Version 2.0
|
| 6 |
+
* (the "License"); you may not use this file except in compliance with
|
| 7 |
+
* the License. You may obtain a copy of the License at
|
| 8 |
+
*
|
| 9 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
*
|
| 11 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 12 |
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
| 13 |
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 14 |
+
* See the License for the specific language governing permissions and
|
| 15 |
+
* limitations under the License.
|
| 16 |
+
*/
|
| 17 |
+
package org.apache.commons.io.filefilter;
|
| 18 |
+
|
| 19 |
+
import java.io.File;
|
| 20 |
+
|
| 21 |
+
/**
|
| 22 |
+
* An abstract class which implements the Java FileFilter and FilenameFilter
|
| 23 |
+
* interfaces via the IOFileFilter interface.
|
| 24 |
+
* <p>
|
| 25 |
+
* Note that a subclass <b>must</b> override one of the accept methods,
|
| 26 |
+
* otherwise your class will infinitely loop.
|
| 27 |
+
*
|
| 28 |
+
* @since 1.0
|
| 29 |
+
* @version $Id: AbstractFileFilter.java 1415850 2012-11-30 20:51:39Z ggregory $
|
| 30 |
+
*/
|
| 31 |
+
public abstract class AbstractFileFilter implements IOFileFilter {
|
| 32 |
+
|
| 33 |
+
/**
|
| 34 |
+
* Checks to see if the File should be accepted by this filter.
|
| 35 |
+
*
|
| 36 |
+
* @param file the File to check
|
| 37 |
+
* @return true if this file matches the test
|
| 38 |
+
*/
|
| 39 |
+
public boolean accept(final File file) {
|
| 40 |
+
return accept(file.getParentFile(), file.getName());
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
/**
|
| 44 |
+
* Checks to see if the File should be accepted by this filter.
|
| 45 |
+
*
|
| 46 |
+
* @param dir the directory File to check
|
| 47 |
+
* @param name the filename within the directory to check
|
| 48 |
+
* @return true if this file matches the test
|
| 49 |
+
*/
|
| 50 |
+
public boolean accept(final File dir, final String name) {
|
| 51 |
+
return accept(new File(dir, name));
|
| 52 |
+
}
|
| 53 |
+
|
| 54 |
+
/**
|
| 55 |
+
* Provide a String representaion of this file filter.
|
| 56 |
+
*
|
| 57 |
+
* @return a String representaion
|
| 58 |
+
*/
|
| 59 |
+
@Override
|
| 60 |
+
public String toString() {
|
| 61 |
+
return getClass().getSimpleName();
|
| 62 |
+
}
|
| 63 |
+
|
| 64 |
+
}
|
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/01_课件与电子教材/尚硅谷_第15章_File类与IO流/03-apache-common包/commons-io-2.5-src/src/main/java/org/apache/commons/io/filefilter/AgeFileFilter.java
ADDED
|
@@ -0,0 +1,159 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Licensed to the Apache Software Foundation (ASF) under one or more
|
| 3 |
+
* contributor license agreements. See the NOTICE file distributed with
|
| 4 |
+
* this work for additional information regarding copyright ownership.
|
| 5 |
+
* The ASF licenses this file to You under the Apache License, Version 2.0
|
| 6 |
+
* (the "License"); you may not use this file except in compliance with
|
| 7 |
+
* the License. You may obtain a copy of the License at
|
| 8 |
+
*
|
| 9 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
*
|
| 11 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 12 |
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
| 13 |
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 14 |
+
* See the License for the specific language governing permissions and
|
| 15 |
+
* limitations under the License.
|
| 16 |
+
*/
|
| 17 |
+
package org.apache.commons.io.filefilter;
|
| 18 |
+
|
| 19 |
+
import java.io.File;
|
| 20 |
+
import java.io.Serializable;
|
| 21 |
+
import java.util.Date;
|
| 22 |
+
|
| 23 |
+
import org.apache.commons.io.FileUtils;
|
| 24 |
+
|
| 25 |
+
/**
|
| 26 |
+
* Filters files based on a cutoff time, can filter either newer
|
| 27 |
+
* files or files equal to or older.
|
| 28 |
+
* <p>
|
| 29 |
+
* For example, to print all files and directories in the
|
| 30 |
+
* current directory older than one day:
|
| 31 |
+
*
|
| 32 |
+
* <pre>
|
| 33 |
+
* File dir = new File(".");
|
| 34 |
+
* // We are interested in files older than one day
|
| 35 |
+
* long cutoff = System.currentTimeMillis() - (24 * 60 * 60 * 1000);
|
| 36 |
+
* String[] files = dir.list( new AgeFileFilter(cutoff) );
|
| 37 |
+
* for ( int i = 0; i < files.length; i++ ) {
|
| 38 |
+
* System.out.println(files[i]);
|
| 39 |
+
* }
|
| 40 |
+
* </pre>
|
| 41 |
+
*
|
| 42 |
+
* @version $Id: AgeFileFilter.java 1642757 2014-12-01 21:09:30Z sebb $
|
| 43 |
+
* @see FileFilterUtils#ageFileFilter(Date)
|
| 44 |
+
* @see FileFilterUtils#ageFileFilter(File)
|
| 45 |
+
* @see FileFilterUtils#ageFileFilter(long)
|
| 46 |
+
* @see FileFilterUtils#ageFileFilter(Date, boolean)
|
| 47 |
+
* @see FileFilterUtils#ageFileFilter(File, boolean)
|
| 48 |
+
* @see FileFilterUtils#ageFileFilter(long, boolean)
|
| 49 |
+
* @since 1.2
|
| 50 |
+
*/
|
| 51 |
+
public class AgeFileFilter extends AbstractFileFilter implements Serializable {
|
| 52 |
+
|
| 53 |
+
private static final long serialVersionUID = -2132740084016138541L;
|
| 54 |
+
|
| 55 |
+
/** The cutoff time threshold. */
|
| 56 |
+
private final long cutoff;
|
| 57 |
+
/** Whether the files accepted will be older or newer. */
|
| 58 |
+
private final boolean acceptOlder;
|
| 59 |
+
|
| 60 |
+
/**
|
| 61 |
+
* Constructs a new age file filter for files equal to or older than
|
| 62 |
+
* a certain cutoff
|
| 63 |
+
*
|
| 64 |
+
* @param cutoff the threshold age of the files
|
| 65 |
+
*/
|
| 66 |
+
public AgeFileFilter(final long cutoff) {
|
| 67 |
+
this(cutoff, true);
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
+
/**
|
| 71 |
+
* Constructs a new age file filter for files on any one side
|
| 72 |
+
* of a certain cutoff.
|
| 73 |
+
*
|
| 74 |
+
* @param cutoff the threshold age of the files
|
| 75 |
+
* @param acceptOlder if true, older files (at or before the cutoff)
|
| 76 |
+
* are accepted, else newer ones (after the cutoff).
|
| 77 |
+
*/
|
| 78 |
+
public AgeFileFilter(final long cutoff, final boolean acceptOlder) {
|
| 79 |
+
this.acceptOlder = acceptOlder;
|
| 80 |
+
this.cutoff = cutoff;
|
| 81 |
+
}
|
| 82 |
+
|
| 83 |
+
/**
|
| 84 |
+
* Constructs a new age file filter for files older than (at or before)
|
| 85 |
+
* a certain cutoff date.
|
| 86 |
+
*
|
| 87 |
+
* @param cutoffDate the threshold age of the files
|
| 88 |
+
*/
|
| 89 |
+
public AgeFileFilter(final Date cutoffDate) {
|
| 90 |
+
this(cutoffDate, true);
|
| 91 |
+
}
|
| 92 |
+
|
| 93 |
+
/**
|
| 94 |
+
* Constructs a new age file filter for files on any one side
|
| 95 |
+
* of a certain cutoff date.
|
| 96 |
+
*
|
| 97 |
+
* @param cutoffDate the threshold age of the files
|
| 98 |
+
* @param acceptOlder if true, older files (at or before the cutoff)
|
| 99 |
+
* are accepted, else newer ones (after the cutoff).
|
| 100 |
+
*/
|
| 101 |
+
public AgeFileFilter(final Date cutoffDate, final boolean acceptOlder) {
|
| 102 |
+
this(cutoffDate.getTime(), acceptOlder);
|
| 103 |
+
}
|
| 104 |
+
|
| 105 |
+
/**
|
| 106 |
+
* Constructs a new age file filter for files older than (at or before)
|
| 107 |
+
* a certain File (whose last modification time will be used as reference).
|
| 108 |
+
*
|
| 109 |
+
* @param cutoffReference the file whose last modification
|
| 110 |
+
* time is usesd as the threshold age of the files
|
| 111 |
+
*/
|
| 112 |
+
public AgeFileFilter(final File cutoffReference) {
|
| 113 |
+
this(cutoffReference, true);
|
| 114 |
+
}
|
| 115 |
+
|
| 116 |
+
/**
|
| 117 |
+
* Constructs a new age file filter for files on any one side
|
| 118 |
+
* of a certain File (whose last modification time will be used as
|
| 119 |
+
* reference).
|
| 120 |
+
*
|
| 121 |
+
* @param cutoffReference the file whose last modification
|
| 122 |
+
* time is usesd as the threshold age of the files
|
| 123 |
+
* @param acceptOlder if true, older files (at or before the cutoff)
|
| 124 |
+
* are accepted, else newer ones (after the cutoff).
|
| 125 |
+
*/
|
| 126 |
+
public AgeFileFilter(final File cutoffReference, final boolean acceptOlder) {
|
| 127 |
+
this(cutoffReference.lastModified(), acceptOlder);
|
| 128 |
+
}
|
| 129 |
+
|
| 130 |
+
//-----------------------------------------------------------------------
|
| 131 |
+
/**
|
| 132 |
+
* Checks to see if the last modification of the file matches cutoff
|
| 133 |
+
* favorably.
|
| 134 |
+
* <p>
|
| 135 |
+
* If last modification time equals cutoff and newer files are required,
|
| 136 |
+
* file <b>IS NOT</b> selected.
|
| 137 |
+
* If last modification time equals cutoff and older files are required,
|
| 138 |
+
* file <b>IS</b> selected.
|
| 139 |
+
*
|
| 140 |
+
* @param file the File to check
|
| 141 |
+
* @return true if the filename matches
|
| 142 |
+
*/
|
| 143 |
+
@Override
|
| 144 |
+
public boolean accept(final File file) {
|
| 145 |
+
final boolean newer = FileUtils.isFileNewer(file, cutoff);
|
| 146 |
+
return acceptOlder ? !newer : newer;
|
| 147 |
+
}
|
| 148 |
+
|
| 149 |
+
/**
|
| 150 |
+
* Provide a String representaion of this file filter.
|
| 151 |
+
*
|
| 152 |
+
* @return a String representaion
|
| 153 |
+
*/
|
| 154 |
+
@Override
|
| 155 |
+
public String toString() {
|
| 156 |
+
final String condition = acceptOlder ? "<=" : ">";
|
| 157 |
+
return super.toString() + "(" + condition + cutoff + ")";
|
| 158 |
+
}
|
| 159 |
+
}
|
尚硅谷Java入门教程,java电子书+Java面试真题(2023新版)/01_课件与电子教材/尚硅谷_第15章_File类与IO流/03-apache-common包/commons-io-2.5-src/src/main/java/org/apache/commons/io/filefilter/AndFileFilter.java
ADDED
|
@@ -0,0 +1,170 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Licensed to the Apache Software Foundation (ASF) under one or more
|
| 3 |
+
* contributor license agreements. See the NOTICE file distributed with
|
| 4 |
+
* this work for additional information regarding copyright ownership.
|
| 5 |
+
* The ASF licenses this file to You under the Apache License, Version 2.0
|
| 6 |
+
* (the "License"); you may not use this file except in compliance with
|
| 7 |
+
* the License. You may obtain a copy of the License at
|
| 8 |
+
*
|
| 9 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
*
|
| 11 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 12 |
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
| 13 |
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 14 |
+
* See the License for the specific language governing permissions and
|
| 15 |
+
* limitations under the License.
|
| 16 |
+
*/
|
| 17 |
+
package org.apache.commons.io.filefilter;
|
| 18 |
+
|
| 19 |
+
import java.io.File;
|
| 20 |
+
import java.io.Serializable;
|
| 21 |
+
import java.util.ArrayList;
|
| 22 |
+
import java.util.Collections;
|
| 23 |
+
import java.util.List;
|
| 24 |
+
|
| 25 |
+
/**
|
| 26 |
+
* A {@link java.io.FileFilter} providing conditional AND logic across a list of
|
| 27 |
+
* file filters. This filter returns {@code true} if all filters in the
|
| 28 |
+
* list return {@code true}. Otherwise, it returns {@code false}.
|
| 29 |
+
* Checking of the file filter list stops when the first filter returns
|
| 30 |
+
* {@code false}.
|
| 31 |
+
*
|
| 32 |
+
* @since 1.0
|
| 33 |
+
* @version $Id: AndFileFilter.java 1642757 2014-12-01 21:09:30Z sebb $
|
| 34 |
+
*
|
| 35 |
+
* @see FileFilterUtils#and(IOFileFilter...)
|
| 36 |
+
*/
|
| 37 |
+
public class AndFileFilter
|
| 38 |
+
extends AbstractFileFilter
|
| 39 |
+
implements ConditionalFileFilter, Serializable {
|
| 40 |
+
|
| 41 |
+
private static final long serialVersionUID = 7215974688563965257L;
|
| 42 |
+
|
| 43 |
+
/** The list of file filters. */
|
| 44 |
+
private final List<IOFileFilter> fileFilters;
|
| 45 |
+
|
| 46 |
+
/**
|
| 47 |
+
* Constructs a new instance of <code>AndFileFilter</code>.
|
| 48 |
+
*
|
| 49 |
+
* @since 1.1
|
| 50 |
+
*/
|
| 51 |
+
public AndFileFilter() {
|
| 52 |
+
this.fileFilters = new ArrayList<IOFileFilter>();
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
/**
|
| 56 |
+
* Constructs a new instance of <code>AndFileFilter</code>
|
| 57 |
+
* with the specified list of filters.
|
| 58 |
+
*
|
| 59 |
+
* @param fileFilters a List of IOFileFilter instances, copied, null ignored
|
| 60 |
+
* @since 1.1
|
| 61 |
+
*/
|
| 62 |
+
public AndFileFilter(final List<IOFileFilter> fileFilters) {
|
| 63 |
+
if (fileFilters == null) {
|
| 64 |
+
this.fileFilters = new ArrayList<IOFileFilter>();
|
| 65 |
+
} else {
|
| 66 |
+
this.fileFilters = new ArrayList<IOFileFilter>(fileFilters);
|
| 67 |
+
}
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
+
/**
|
| 71 |
+
* Constructs a new file filter that ANDs the result of two other filters.
|
| 72 |
+
*
|
| 73 |
+
* @param filter1 the first filter, must not be null
|
| 74 |
+
* @param filter2 the second filter, must not be null
|
| 75 |
+
* @throws IllegalArgumentException if either filter is null
|
| 76 |
+
*/
|
| 77 |
+
public AndFileFilter(final IOFileFilter filter1, final IOFileFilter filter2) {
|
| 78 |
+
if (filter1 == null || filter2 == null) {
|
| 79 |
+
throw new IllegalArgumentException("The filters must not be null");
|
| 80 |
+
}
|
| 81 |
+
this.fileFilters = new ArrayList<IOFileFilter>(2);
|
| 82 |
+
addFileFilter(filter1);
|
| 83 |
+
addFileFilter(filter2);
|
| 84 |
+
}
|
| 85 |
+
|
| 86 |
+
/**
|
| 87 |
+
* {@inheritDoc}
|
| 88 |
+
*/
|
| 89 |
+
public void addFileFilter(final IOFileFilter ioFileFilter) {
|
| 90 |
+
this.fileFilters.add(ioFileFilter);
|
| 91 |
+
}
|
| 92 |
+
|
| 93 |
+
/**
|
| 94 |
+
* {@inheritDoc}
|
| 95 |
+
*/
|
| 96 |
+
public List<IOFileFilter> getFileFilters() {
|
| 97 |
+
return Collections.unmodifiableList(this.fileFilters);
|
| 98 |
+
}
|
| 99 |
+
|
| 100 |
+
/**
|
| 101 |
+
* {@inheritDoc}
|
| 102 |
+
*/
|
| 103 |
+
public boolean removeFileFilter(final IOFileFilter ioFileFilter) {
|
| 104 |
+
return this.fileFilters.remove(ioFileFilter);
|
| 105 |
+
}
|
| 106 |
+
|
| 107 |
+
/**
|
| 108 |
+
* {@inheritDoc}
|
| 109 |
+
*/
|
| 110 |
+
public void setFileFilters(final List<IOFileFilter> fileFilters) {
|
| 111 |
+
this.fileFilters.clear();
|
| 112 |
+
this.fileFilters.addAll(fileFilters);
|
| 113 |
+
}
|
| 114 |
+
|
| 115 |
+
/**
|
| 116 |
+
* {@inheritDoc}
|
| 117 |
+
*/
|
| 118 |
+
@Override
|
| 119 |
+
public boolean accept(final File file) {
|
| 120 |
+
if (this.fileFilters.isEmpty()) {
|
| 121 |
+
return false;
|
| 122 |
+
}
|
| 123 |
+
for (final IOFileFilter fileFilter : fileFilters) {
|
| 124 |
+
if (!fileFilter.accept(file)) {
|
| 125 |
+
return false;
|
| 126 |
+
}
|
| 127 |
+
}
|
| 128 |
+
return true;
|
| 129 |
+
}
|
| 130 |
+
|
| 131 |
+
/**
|
| 132 |
+
* {@inheritDoc}
|
| 133 |
+
*/
|
| 134 |
+
@Override
|
| 135 |
+
public boolean accept(final File file, final String name) {
|
| 136 |
+
if (this.fileFilters.isEmpty()) {
|
| 137 |
+
return false;
|
| 138 |
+
}
|
| 139 |
+
for (final IOFileFilter fileFilter : fileFilters) {
|
| 140 |
+
if (!fileFilter.accept(file, name)) {
|
| 141 |
+
return false;
|
| 142 |
+
}
|
| 143 |
+
}
|
| 144 |
+
return true;
|
| 145 |
+
}
|
| 146 |
+
|
| 147 |
+
/**
|
| 148 |
+
* Provide a String representaion of this file filter.
|
| 149 |
+
*
|
| 150 |
+
* @return a String representaion
|
| 151 |
+
*/
|
| 152 |
+
@Override
|
| 153 |
+
public String toString() {
|
| 154 |
+
final StringBuilder buffer = new StringBuilder();
|
| 155 |
+
buffer.append(super.toString());
|
| 156 |
+
buffer.append("(");
|
| 157 |
+
if (fileFilters != null) {
|
| 158 |
+
for (int i = 0; i < fileFilters.size(); i++) {
|
| 159 |
+
if (i > 0) {
|
| 160 |
+
buffer.append(",");
|
| 161 |
+
}
|
| 162 |
+
final Object filter = fileFilters.get(i);
|
| 163 |
+
buffer.append(filter == null ? "null" : filter.toString());
|
| 164 |
+
}
|
| 165 |
+
}
|
| 166 |
+
buffer.append(")");
|
| 167 |
+
return buffer.toString();
|
| 168 |
+
}
|
| 169 |
+
|
| 170 |
+
}
|