commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From scolebou...@apache.org
Subject svn commit: r385119 - in /jakarta/commons/proper/io/trunk/xdocs: bestpractices.xml description.xml
Date Sat, 11 Mar 2006 18:22:17 GMT
Author: scolebourne
Date: Sat Mar 11 10:22:15 2006
New Revision: 385119

URL: http://svn.apache.org/viewcvs?rev=385119&view=rev
Log:
Fix source code formatting

Modified:
    jakarta/commons/proper/io/trunk/xdocs/bestpractices.xml
    jakarta/commons/proper/io/trunk/xdocs/description.xml

Modified: jakarta/commons/proper/io/trunk/xdocs/bestpractices.xml
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/io/trunk/xdocs/bestpractices.xml?rev=385119&r1=385118&r2=385119&view=diff
==============================================================================
--- jakarta/commons/proper/io/trunk/xdocs/bestpractices.xml (original)
+++ jakarta/commons/proper/io/trunk/xdocs/bestpractices.xml Sat Mar 11 10:22:15 2006
@@ -57,14 +57,14 @@
             Let's look at an example.
         </p>
         <source>
-    public static String getExtension(String filename) {
-        int index = filename.lastIndexOf('.');
-        if (index == -1) {
-            return "";
-        } else {
-            return filename.substring(index + 1);
-        }
-    }</source>
+ public static String getExtension(String filename) {
+   int index = filename.lastIndexOf('.');
+   if (index == -1) {
+     return "";
+   } else {
+     return filename.substring(index + 1);
+   }
+ }</source>
         <p>
             Easy enough? Right, but what happens if someone passes in a full path 
             instead of only a filename? Consider the following, perfectly legal path:
@@ -82,16 +82,16 @@
             Instead of:
         </p>
         <source>
-    String tmpdir = "/var/tmp";
-    String tmpfile = tmpdir + System.getProperty("file.separator") + "test.tmp";
-    InputStream in = new java.io.FileInputStream(tmpfile);</source>
+ String tmpdir = "/var/tmp";
+ String tmpfile = tmpdir + System.getProperty("file.separator") + "test.tmp";
+ InputStream in = new java.io.FileInputStream(tmpfile);</source>
         <p>
             ...write:
         </p>
         <source>
-    File tmpdir = new File("/var/tmp");
-    File tmpfile = new File(tmpdir, "test.tmp");
-    InputStream in = new java.io.FileInputStream(tmpfile);</source>
+ File tmpdir = new File("/var/tmp");
+ File tmpfile = new File(tmpdir, "test.tmp");
+ InputStream in = new java.io.FileInputStream(tmpfile);</source>
 
     </section>
     
@@ -109,15 +109,14 @@
             FileInputStream with a BufferedInputStream:
         </p>
         <source>
-            InputStream in = new java.io.FileInputStream(myfile);
-            try {
-                in = new java.io.BufferedInputStream(in);
-                
-                in.read(.....
-            } finally {
-                IOUtils.closeQuietly(in);
-            }
-        </source>
+ InputStream in = new java.io.FileInputStream(myfile);
+ try {
+   in = new java.io.BufferedInputStream(in);
+   
+   in.read(.....
+ } finally {
+   IOUtils.closeQuietly(in);
+ }</source>
         <p>
             Pay attention that you're not buffering an already buffered stream. Some
             components like XML parsers may do their own buffering so decorating

Modified: jakarta/commons/proper/io/trunk/xdocs/description.xml
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/io/trunk/xdocs/description.xml?rev=385119&r1=385118&r2=385119&view=diff
==============================================================================
--- jakarta/commons/proper/io/trunk/xdocs/description.xml (original)
+++ jakarta/commons/proper/io/trunk/xdocs/description.xml Sat Mar 11 10:22:15 2006
@@ -1,6 +1,6 @@
 <?xml version="1.0"?>
 <!--
-Copyright 2002-2005 The Apache Software Foundation.
+Copyright 2002-2006 The Apache Software Foundation.
  
 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
@@ -26,6 +26,7 @@
             Commons-IO contains
             <a href="#Utility classes">utility classes</a>,
             <a href="#Endian classes">endian classes</a>,
+            <a href="#Line iterator">line iterator</a>,
             <a href="#File filters">file filters</a> and
             <a href="#Streams">stream implementations</a>.
         </p>
@@ -49,29 +50,29 @@
             </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>
+ 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>
+ 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
@@ -97,8 +98,8 @@
                 For example to read an entire file line by line you could use:
             </p>
             <source>
-  File file = new File("/commons/io/project.properties");
-  List lines = FileUtils.readLines(file, "UTF-8");</source>
+ File file = new File("/commons/io/project.properties");
+ List lines = FileUtils.readLines(file, "UTF-8");</source>
         </subsection>
 
         <subsection name="FilenameUtils">
@@ -113,9 +114,9 @@
                 For example to normalize a filename removing double dot segments:
             </p>
             <source>
-  String filename = "C:/commons/io/../lang/project.xml";
-  String normalized = FilenameUtils.normalize(filename);
-  // result is "C:/commons/lang/project.xml"</source>
+ String filename = "C:/commons/io/../lang/project.xml";
+ String normalized = FilenameUtils.normalize(filename);
+ // result is "C:/commons/lang/project.xml"</source>
         </subsection>
 
         <subsection name="FileSystemUtils">
@@ -131,7 +132,7 @@
                 For example to find the free space on a drive:
             </p>
             <source>
-  long freeSpace = FileSystemUtils.freeSpace("C:/");</source>
+ long freeSpace = FileSystemUtils.freeSpace("C:/");</source>
         </subsection>
 
     </section>
@@ -180,16 +181,16 @@
 			<code>FileUtils</code> or <code>IOUtils</code>.
 			The recommended usage pattern is:
         </p>
-        <pre>
-  LineIterator it = FileUtils.lineIterator(file, "UTF-8");
-  try {
-    while (it.hasNext()) {
-      String line = it.nextLine();
-      /// do something with line
-    }
-  } finally {
-    LineIterator.closeQuietly(iterator);
-  }</pre>
+        <source>
+ LineIterator it = FileUtils.lineIterator(file, "UTF-8");
+ try {
+   while (it.hasNext()) {
+     String line = it.nextLine();
+     /// do something with line
+   }
+ } finally {
+   LineIterator.closeQuietly(iterator);
+ }</source>
     </section>
 
     <section name="File filters">



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message