The Artima Developer Community
Sponsored Link

Java Community News
Apache Releases New Version of Commons IO

3 replies on 1 page. Most recent reply: Feb 23, 2007 1:38 PM by Max Lybbert

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 3 replies on 1 page
Frank Sommers

Posts: 2642
Nickname: fsommers
Registered: Jan, 2002

Apache Releases New Version of Commons IO Posted: Feb 21, 2007 1:17 PM
Reply to this message Reply
Summary
The Apache Commons IO project is a Java library that simplifies working with all things related to streams, files, and even the local file system. In some cases, Commons IO brings Ruby-like simplicity to working with Java IO objects.
Advertisement

While some developers looking at dynamic languages bemoan Java's comparative verbosity, others seem busily at work bringing similar conciseness to Java code.

One example is the Apache Commons IO project, which recently released the 1.3.1 version of its Java library. Commons IO makes working with streams and files easier, often requiring just a fraction of code compared with the standard Java IO APIs. The project's documentation shows how dramatically Commons IO can reduce the amount of code required for reading from an input stream, for example:

Without commons IO:

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();
 }

With Commons IO:

 InputStream in = new URL( "http://jakarta.apache.org" ).openStream();
 try {
   System.out.println( IOUtils.toString( in ) );
 } finally {
   IOUtils.closeQuietly(in);
 }

Reading lines of a file becomes similarly easy:

File file = new File("/commons/io/project.properties");
List lines = FileUtils.readLines(file, "UTF-8");

Such code is clearly on par with the sort of simplicity that dynamic languages, such as Ruby, are known for. Do you believe that APIs, such as Commons IO, can solve Java's verbosity problems in a way the language can't?


Aliaksandr Radzivanovich

Posts: 1
Nickname: ara
Registered: Nov, 2005

Re: Apache Releases New Version of Commons IO Posted: Feb 22, 2007 2:28 AM
Reply to this message Reply
> One example is the Apache Commons
> IO project, which recently released the 3.1.3 version
> of its Java library.

The current version must be 1.1.3.

> <pre>
> InputStream in = new URL( "http://jakarta.apache.org"
> " ).openStream();
> try {
> System.out.println( IOUtils.toString( in ) );
> } finally {
> IOUtils.closeQuietly(in);
> }
> </pre>

It seems like one has to read the entire stream into memory just to print it to console ;)

Tim

Posts: 4
Nickname: timmorrow
Registered: Mar, 2003

Re: Apache Releases New Version of Commons IO Posted: Feb 22, 2007 1:23 PM
Reply to this message Reply
Maybe just a poor example. Try

IOUtils.copy(in, System.out);


I mostly use it for IOUtils.copy()

Max Lybbert

Posts: 314
Nickname: mlybbert
Registered: Apr, 2005

Re: Apache Releases New Version of Commons IO Posted: Feb 23, 2007 1:38 PM
Reply to this message Reply
/* Do you believe that APIs, such as Commons IO, can solve Java's verbosity problems in a way the language can't?
*/

Only if you accept the idea that some programmers are meant to create libraries (and suffer from the verbosity) and other programmers are meant to write applications (and benefit from the library programmer who took one for the team). Otherwise, Java's going to need some better abstraction mechanisms.

Flat View: This topic has 3 replies on 1 page
Topic: Flip for Flapjax Previous Topic   Next Topic Topic: Atlassian Releases Bamboo, a Continuous Integration Server

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use