views:

293

answers:

10

Community wiki'ed already, folks.

What part of Apache Commons saves you the most time?

I'm curious to get together a list of these to browse and see what I don't know about, or what I should be using more often than not.

+2  A: 

IOUtils, specifically FileUtils and IOUtils; it feels like the way that files + streams should have been done. The repetitive work is handled for me, and the code is both quicker to write and clearer to read.

Dean J
It's a bit too easy, though - ignoring IOExceptions thrown inside `closeQuietly` really isn't a good idea.
skaffman
In some cases, if you know you'll do nothing about it anyway, ignoring them is a good way to go...
Valentin Rocher
@skaffman: Ignoring the need for a second try/catch block to close the stream is where I love it. Also, copying a file to a String becomes one method instead of a block of code.
Dean J
+2  A: 

I'm a huge fan of Apache Digester. I like persisting stuff to XML, and I love its rule based XML parser which just gives me the object without effort.

Uri
+1  A: 

DateUtils. It is so much simpler to use than Java's built in Date and Calendar classes. I don't know what I would do without it!

Rachel
Have you tried http://joda-time.sourceforge.net/ I find that the best Date utility library for Java.
Shervin
I have tried it an it is also an excellent library. I find that I use DateUtil more because Apache Commons already included in the projects at work and usually covers the functionality that we need.
Rachel
+2  A: 

commons-configuration is quite useful when writing configurable code.

Riduidel
+1  A: 

Apache Commons - provides various reusable components. I frequently use - Collections, IO, Digester, BeanUtils and EXEC.

HonorGod
+1  A: 

FileUpload definitely. The remnant is either relatively easy to homegrow (which thus implies that it doesn't save that much time) or has better alternatives.

BalusC
I don't really agree with the "easy to homegrow" point of view. You could easily hack together classes doing the same things, but why reinventing the wheel ? Generally, Apache Commons implementations are pretty simple, and well-tested.
Valentin Rocher
@Valentin: I don't argue that and I wasn't insinuating that :) Truly, it's better to pick commons than reinventing the wheel, but the question literally states "Which saves you the most time?". Try reinventing FileUpload yourself without looking at its source/javadocs and tell how much time you wasted before getting it as rock solid as FileUpload.
BalusC
+5  A: 

StringUtils.isBlank(String string)

raticulin
... which is equal to `"".equals(string.trim())`. BTW - it's part of commons-lang.
Andreas_D
don't you need a not null test too?
raticulin
@Andreas : more exactly, it tests if the string is null, empty, or full of whitespaces.
Valentin Rocher
Because it takes SOOO much time to write a simple utility class that does the same thing without introducing a whole set of dependencies...
GreenieMeanie
@GreenieMeanie yeah sure, like I only use this method from the whole commons-lang...Anyway, if it is in commons-lang already, YES, it is too much OF MY time to write something that does the same thing. Nevemind the dependency
raticulin
@GreenieMeanie; arguably, you could rewrite all of J2EE with only the J2SE libraries, but that'd be dumb. Commons are a single-layer deep of dependencies, so it's not any worse than any other library.
Dean J
@raticulin, @Valentin - Ouch, you're right, if string is null, the string.trim() expression throws a NPE. Stupid mistake ;-) - yes, we need a null test, so it is: `(string == null || "".equals(string.trim()))`
Andreas_D
+5  A: 

commons-lang

Since StringUtils has got a lot of static methods, I like to use them using Expression Language (EL) in seam, mapping StringUtils as a component

#{stringutils.left(r.map.job_error, 9)}

In components.xml:

<component name="stringutils" class="org.apache.commons.lang.StringUtils" scope="stateless"/>
volothamp
+4  A: 

commons-codec - the Base64 and Hex classes at least.

Bozho
+1  A: 

ArrayUtils: For my app development this helped the most.

javatechi