apache-commons

Genericized commons collection

Hi, I'm astonished that the Apache Commons Collections project still hasn't got around to making their library generics-aware. I really like the features provided by this library, but the lack of support for generics is a big turn-off. There is a Lavalabs fork of Commons Collections which does support generics, which seems to claim back...

How can I read other parameters in a multipart form with Apache Commons

I have a file upload form that is being posted back to a servlet (using multipart/form-data encoding). In the servlet, I am trying to use Apache Commons to handle the upload. However, I also have some other fields in the form that are just plain fields. How can I read those parameters from the request? For example, in my servlet, I ...

Logging Commons and Mapped Diagnostic Context

What have others done to get around the fact that the Commons Logging project (for both .NET and Java) do not support Mapped or Nested Diagnostic Contexts as far as I know? ...

How do I represent an XML file as a Java object using commons-digester?

Following on from my recent question regarding parsing XML files in Java I have decided to use the commons-digester library. I am now familiar with this process and now want to create a Java class representing the XML file, so that when a user instantiates a new object of that class, all of the data from the XML file will be available. ...

Posting contents of a file using HttpClient ?

I want to send the contents of a file as part of a http request using Apache HttpClient and I could not figure out how to pass on the file contents in the request body. ...

Logging using SL4J, Jakarta Commons logging, log4j for third party libraries and my own code

I have some questions about logging, more specifically about setting it up and making sure it works. The project I'm doing will use Wicket, Spring and Hibernate. I know that Wicket and Hibernate uses Simple Logging Facade for Java (SL4J) and that Spring is using the logging component from Apache Commons. Will they co-exist happily? I t...

Find a way in the java logging frameworks scene.

Hey to all Java has a lot of frameworks / APIs that help you do logging in your application: The Java API has java.util.logging package. Apache's Log4j. Apache's Commons Logging. SLF4J (logging Facade). jLo. and many many more... I've always used the log4j library, i found it sufficient most of the time, and extensible when i needed...

Locking a file while copying using Commons IO

I am using the Apache Commons IO: FileUtils.copyFileToDirectory(srcFile, destDir) How do I make Windows lock the destination file during copy? Windows locks the file correctly if I use: Runtime.getRuntime().exec( "cmd /c copy /Y \"" + srcFile.getCanonicalPath() + "\" \"" + destDir.getCanonicalPath() + "\"")...

Problem with FTPClient class in java

I'm using org.apache.commons.net.ftp.FTPClient and seeing behavior that is, well... perplexing. The method beneath intends to go through an FTPFile list, read them in and then do something with the contents. That's all working. What is not (really) working is that the FTPClient object does the following... 1) Properly retrieves and st...

printing meaningful errors with apache commons configuration

I'm using HierarchicalConfiguration for use with XML configuration files. Works great. But now I need to report meaningful information as an error. I would like to print the offending fragment of XML (or at least report line #), but I can't seem to get hold of an XML object or string from a HierarchicalConfiguration object. Help! What ...

Apache Commons HttpClient PostMethod support?

I am curios about how one can set the request properties for a PostMethod in Apache Commons HttpClient? I am refactoring some code written using HttpURLConnection class to post which looks like the following: conn1.setRequestProperty( "Content-Type", "multipart/related; type=\"application/xml\"; boundary=" + boundary); conn1.s...

Why did I get "FileUploadException: Stream ended unexpectedly" with Apache Commons FileUpload?

What is the reason for encountering this Exception: org.apache.commons.fileupload.FileUploadException: Processing of multipart/form-data request failed. Stream ended unexpectedly ...

Apache commons PredicatedList with no IllegalArgumentException

Is there a way in Apache Commons Collections to have a PredicatedList (or similar) which does not throw an IllegalArgumentException if the thing you are trying to add doesn't match the predicate? If it does not match, it would just ignore the request to add the item to the list. So for example, if I do this: List predicatedList = List...

How to send java.util.logging to log4j?

I have an existing application which does all of its logging against log4j. We use a number of other libraries that either also use log4j, or log against Commons Logging, which ends up using log4j under the covers in our environment. One of our dependencies even logs against slf4j, which also works fine since it eventually delegates to l...

Recursively finding only directories with FileUtils.listFiles

I want to collect a list of all files under a directory, in particular including subdirectories. I like not doing things myself, so I'm using FileUtils.listFiles from Apache Commons IO. So I have something like: import java.io.File; import java.util.Collection; import org.apache.commons.io.FileUtils; import org.apache.commons.io.filefi...

Sorting an collecton of java beans by field

Hi, I have an collection of java beans that populate a JSF DataTable I'm trying to implement column sorting. I'd like to sort the array/collection depending on the field selected. I have using Reflection in the past for this, but wanted to find a neater way of doing it, using Commons BeanUtils and/or Collections but can't seem to find...

Capturing large amounts of output from Apache Commons-Exec

I am writing a video application in Java by executing ffmpeg and capturing its output to standard output. I decided to use Apache Commons-Exec instead of Java's Runtime, because it seems better. However, I am have a difficult time capturing all of the output. I thought using pipes would be the way to go, because it is a standard way o...

Is there a way to get apache-digester to intern strings for certain attributes?

I am a big fan of using apache-digester to load XML files into my object model. I am dealing with large files that contain many duplicates (event logs), and would therefore like to String.intern() the strings for specific attributes (the ones that frequently repeat). Since Apache-Digester reads the whole file before relinquishing contr...

using DirectoryWalker

I am trying to figure out how to use apache commons io DirectoryWalker. It's pretty easy to understand how to subclass DirectoryWalker. But how do you start executing it on a particular directory? ...

Using FTP Proxy with apache commons-net

I want to set up an FTP connection using a proxy server with Apache's commons-net. But looking at this Does FTPClient support FTP connections through an FTP proxy server? has me worried. I have to meddle with the system properties and the Sun docs state that "If socksProxyHost is specified then all TCP sockets will use the SOCKS proxy ...