Skip to content

Commit f06d0e5

Browse files
author
Stephen Colebourne
committed
Fix source code formatting
git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/io/trunk@385119 13f79535-47bb-0310-9956-ffa450edef68
1 parent f38ef9b commit f06d0e5

2 files changed

Lines changed: 57 additions & 57 deletions

File tree

xdocs/bestpractices.xml

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,14 @@ limitations under the License.
5757
Let's look at an example.
5858
</p>
5959
<source>
60-
public static String getExtension(String filename) {
61-
int index = filename.lastIndexOf('.');
62-
if (index == -1) {
63-
return "";
64-
} else {
65-
return filename.substring(index + 1);
66-
}
67-
}</source>
60+
public static String getExtension(String filename) {
61+
int index = filename.lastIndexOf('.');
62+
if (index == -1) {
63+
return "";
64+
} else {
65+
return filename.substring(index + 1);
66+
}
67+
}</source>
6868
<p>
6969
Easy enough? Right, but what happens if someone passes in a full path
7070
instead of only a filename? Consider the following, perfectly legal path:
@@ -82,16 +82,16 @@ limitations under the License.
8282
Instead of:
8383
</p>
8484
<source>
85-
String tmpdir = "/var/tmp";
86-
String tmpfile = tmpdir + System.getProperty("file.separator") + "test.tmp";
87-
InputStream in = new java.io.FileInputStream(tmpfile);</source>
85+
String tmpdir = "/var/tmp";
86+
String tmpfile = tmpdir + System.getProperty("file.separator") + "test.tmp";
87+
InputStream in = new java.io.FileInputStream(tmpfile);</source>
8888
<p>
8989
...write:
9090
</p>
9191
<source>
92-
File tmpdir = new File("/var/tmp");
93-
File tmpfile = new File(tmpdir, "test.tmp");
94-
InputStream in = new java.io.FileInputStream(tmpfile);</source>
92+
File tmpdir = new File("/var/tmp");
93+
File tmpfile = new File(tmpdir, "test.tmp");
94+
InputStream in = new java.io.FileInputStream(tmpfile);</source>
9595

9696
</section>
9797

@@ -109,15 +109,14 @@ limitations under the License.
109109
FileInputStream with a BufferedInputStream:
110110
</p>
111111
<source>
112-
InputStream in = new java.io.FileInputStream(myfile);
113-
try {
114-
in = new java.io.BufferedInputStream(in);
115-
116-
in.read(.....
117-
} finally {
118-
IOUtils.closeQuietly(in);
119-
}
120-
</source>
112+
InputStream in = new java.io.FileInputStream(myfile);
113+
try {
114+
in = new java.io.BufferedInputStream(in);
115+
116+
in.read(.....
117+
} finally {
118+
IOUtils.closeQuietly(in);
119+
}</source>
121120
<p>
122121
Pay attention that you're not buffering an already buffered stream. Some
123122
components like XML parsers may do their own buffering so decorating

xdocs/description.xml

Lines changed: 35 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0"?>
22
<!--
3-
Copyright 2002-2005 The Apache Software Foundation.
3+
Copyright 2002-2006 The Apache Software Foundation.
44
55
Licensed under the Apache License, Version 2.0 (the "License");
66
you may not use this file except in compliance with the License.
@@ -26,6 +26,7 @@ limitations under the License.
2626
Commons-IO contains
2727
<a href="#Utility classes">utility classes</a>,
2828
<a href="#Endian classes">endian classes</a>,
29+
<a href="#Line iterator">line iterator</a>,
2930
<a href="#File filters">file filters</a> and
3031
<a href="#Streams">stream implementations</a>.
3132
</p>
@@ -49,29 +50,29 @@ limitations under the License.
4950
</p>
5051

5152
<source>
52-
InputStream in = new URL( "http://jakarta.apache.org" ).openStream();
53-
try {
54-
InputStreamReader inR = new InputStreamReader( in );
55-
BufferedReader buf = new BufferedReader( inR );
56-
String line;
57-
while ( ( line = buf.readLine() ) != null ) {
58-
System.out.println( line );
59-
}
60-
} finally {
61-
in.close();
62-
}</source>
53+
InputStream in = new URL( "http://jakarta.apache.org" ).openStream();
54+
try {
55+
InputStreamReader inR = new InputStreamReader( in );
56+
BufferedReader buf = new BufferedReader( inR );
57+
String line;
58+
while ( ( line = buf.readLine() ) != null ) {
59+
System.out.println( line );
60+
}
61+
} finally {
62+
in.close();
63+
}</source>
6364

6465
<p>
6566
With the IOUtils class, that could be done with:
6667
</p>
6768

6869
<source>
69-
InputStream in = new URL( "http://jakarta.apache.org" ).openStream();
70-
try {
71-
System.out.println( IOUtils.toString( in ) );
72-
} finally {
73-
IOUtils.closeQuietly(in);
74-
}</source>
70+
InputStream in = new URL( "http://jakarta.apache.org" ).openStream();
71+
try {
72+
System.out.println( IOUtils.toString( in ) );
73+
} finally {
74+
IOUtils.closeQuietly(in);
75+
}</source>
7576

7677
<p>
7778
In certain application domains, such IO operations are
@@ -97,8 +98,8 @@ limitations under the License.
9798
For example to read an entire file line by line you could use:
9899
</p>
99100
<source>
100-
File file = new File("/commons/io/project.properties");
101-
List lines = FileUtils.readLines(file, "UTF-8");</source>
101+
File file = new File("/commons/io/project.properties");
102+
List lines = FileUtils.readLines(file, "UTF-8");</source>
102103
</subsection>
103104

104105
<subsection name="FilenameUtils">
@@ -113,9 +114,9 @@ limitations under the License.
113114
For example to normalize a filename removing double dot segments:
114115
</p>
115116
<source>
116-
String filename = "C:/commons/io/../lang/project.xml";
117-
String normalized = FilenameUtils.normalize(filename);
118-
// result is "C:/commons/lang/project.xml"</source>
117+
String filename = "C:/commons/io/../lang/project.xml";
118+
String normalized = FilenameUtils.normalize(filename);
119+
// result is "C:/commons/lang/project.xml"</source>
119120
</subsection>
120121

121122
<subsection name="FileSystemUtils">
@@ -131,7 +132,7 @@ limitations under the License.
131132
For example to find the free space on a drive:
132133
</p>
133134
<source>
134-
long freeSpace = FileSystemUtils.freeSpace("C:/");</source>
135+
long freeSpace = FileSystemUtils.freeSpace("C:/");</source>
135136
</subsection>
136137

137138
</section>
@@ -180,16 +181,16 @@ limitations under the License.
180181
<code>FileUtils</code> or <code>IOUtils</code>.
181182
The recommended usage pattern is:
182183
</p>
183-
<pre>
184-
LineIterator it = FileUtils.lineIterator(file, "UTF-8");
185-
try {
186-
while (it.hasNext()) {
187-
String line = it.nextLine();
188-
/// do something with line
189-
}
190-
} finally {
191-
LineIterator.closeQuietly(iterator);
192-
}</pre>
184+
<source>
185+
LineIterator it = FileUtils.lineIterator(file, "UTF-8");
186+
try {
187+
while (it.hasNext()) {
188+
String line = it.nextLine();
189+
/// do something with line
190+
}
191+
} finally {
192+
LineIterator.closeQuietly(iterator);
193+
}</source>
193194
</section>
194195

195196
<section name="File filters">

0 commit comments

Comments
 (0)