1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
|
<?xml version="1.0"?>
<!--
Main index
$Id: index.xml,v 1.8 2004/04/24 23:53:01 bayard Exp $
-->
<document>
<properties>
<title>Commons IO</title>
<author email="commons-dev@jakarta.apache.org">Commons Documentation Team</author>
</properties>
<body>
<section name="Commons IO">
<p>
Commons-IO contains <a href="#Utility classes">utility classes</a>,
stream implementations, <a href="#File filters">file filters</a>, and
<a href="#Endian classes">endian classes</a>.
</p>
<p>
For a more detailed descriptions, take a look at the
<a href="apidocs/index.html">JavaDocs</a>.
</p>
</section>
<section name="Utility classes">
<subsection name="CopyUtils and IOUtils">
<p>
<code>org.apache.commons.io.CopyUtils</code>
contains a comprehensive set of static methods for copying
from String, byte[], InputStream, Reader
to OutputStream, Writer.
</p>
<p>
<code>org.apache.commons.io.IOUtils</code>
contains additional IO-related tools for safely closing streams
and creating Strings and byte arrays from streams and Readers.
</p>
<p>
As an example, consider the task of reading bytes
from a URL, and printing them. This would typically done like this:
</p>
<source>
InputStream in = new URL( "http://jakarta.apache.org" ).openStream();
try {
InputStreamReader inR = new InputStreamReader( in );
BufferedReader buf = new BufferedReader( inR );
String line;
while ( ( line = buf.readLine() ) != null ) {
System.out.println( line );
}
} finally {
in.close();
}
</source>
<p>
With the IOUtils class, that could be done with:
</p>
<source>
InputStream in = new URL( "http://jakarta.apache.org" ).openStream();
try {
System.out.println( IOUtils.toString( in ) );
} finally {
IOUtils.closeQuietly(in);
}
</source>
<p>
In certain application domains, such IO operations are
common, and this class can save a great deal of time. And you can
rely on well-tested code.
For utility code such as this, flexibility and speed are of primary importance.
</p>
</subsection>
<subsection name="FileUtils">
<p>
The <code>org.apache.commons.io.FileUtils</code>
class contains methods for retrieving different components of a file path
(directory name, file base name, file extension), methods
for copying files to other files and directories, and methods
for querying, deleting and cleaning directories. For more information,
see the class description.
</p>
</subsection>
</section>
<section name="File filters">
<p>
The <code>org.apache.commons.io.filefilter</code>
package defines an interface (<code>IOFileFilter</code>) that
combines both <code>java.io.FileFilter</code> and
<code>java.io.FilenameFilter</code>. Besides
that the package offers a series of ready-to-use
implementations of the <code>IOFileFilter</code>
interface including
implementation that allow you to combine other such filters.
These filter can be used to list files or in FileDialog, for example.
</p>
</section>
<section name="Endian classes">
<p>
Different computer architectures adopt different
conventions for byte ordering. In so-called
"Little Endian" architectures (eg Intel), the low-order
byte is stored in memory at the lowest address, and
subsequent bytes at higher addresses. For "Big Endian"
architectures (eg Motorola), the situation is reversed.
</p>
<p>
There are two classes in this package of relevance:
</p>
<ul>
<li>
The <code>org.apache.commons.io.EndianUtils</code>
class contains static methods for swapping the Endian-ness
of Java primitives and streams.
</li>
<li>
The <code>org.apache.commons.io.input.SwappedDataInputStream</code>
class is an implementation of the <code>DataInput</code> interface. With
this, one can read data from files of non-native Endian-ness.
</li>
</ul>
<p>
For more information, see
<a
href="http://www.cs.umass.edu/~verts/cs32/endian.html">http://www.cs.umass.edu/~verts/cs32/endian.html</a>
</p>
</section>
</body>
</document>
|