FAQ Database Discussion Community
java,apache-commons,apache-commons-math,bernoulli-probability
A Bernoulli distribution is equivalent to a binomial distribution with only 1 trial i.e. BinomialDistribution(1,p) from the Apache Commons Math library. A Bernoulli distribution is obviously a much simpler thing than the general binomial distribution. If performance matters, should I roll my own BernoulliDistribution(p) by subclassing AbstractIntegerDistribution, or would I...
java,validation,apache-commons
I have an API in which I am doing my own validation for certain input parameters. For example - public Builder(int clientId) { TestUtils.assertNonNegative(clientId, "ClientId"); this.clientId = clientId; } public Builder setUserId(String userid) { TestUtils.assertNotNull(userid, "UserId"); this.userid = userid; return this; } And my assertNonNegative and assertNotNull method in TestUtils...
java,apache-commons
I have a list of commmons Pair that stores words and their frequency like the following private List<Pair<String, Integer>> words = new ArrayList<Pair<String, Integer>(); I am trying to sort it so that when I iterate over it to print the words, I want the words with the highest frequency to...
android,ftp,apache-commons
I am using the apache commons library in an android app that we have developed. This is legacy code, and for some reason, it is not writing to the device. This is happening on multiple devices, so it's not device specific. We are using Nexus 7 devices running Android 4.4....
java,arrays,apache-commons
org.apache.commons.lang3.ArrayUtils provides methods to check if Array is empty, but for example for String array which has empty String elementsmeaning character "" it returns true for that isNotEmpty() method, which is correct as that method check only for null and length == 0. Is there any other method or implementation...
java,apache-commons,properties-file
I am currently using the Apache commons configuration library to write and read data from a file. I am able to save the key value pair colors=hello to the user..properties file, but when i try to read the value is get the below exception. Exception in thread "main" java.lang.IllegalArgumentException: 'hello'...
java,xml,xml-parsing,apache-commons
I am using Apache Commons Configuration for reading configuration in xml file - standalone-full-ha.xml in Wildfly 8 application server. <?xml version="1.0" ?> <server xmlns="urn:jboss:domain:2.2"> ... ... <profile> ... ... <subsystem xmlns="urn:jboss:domain:datasources:2.0"> <datasources> <datasource jta="true" jndi-name="java:/TestDB" pool-name="TestDB" enabled="true" use-java-context="true" spy="false" use-ccm="true"> <connection-url>jdbc:sybase:Tds:ip:port/db-name</connection-url> ......
java,file,url,apache-commons,fileutils
I am using the following method to download a file off the internet: try { URL url = new URL("http://search.maven.org/remotecontent?filepath=com/cedarsoftware/json-io/4.0.0/json-io-4.0.0.jar"); FileUtils.copyURLToFile(url, new File(jsonerFolder.getParent() + "\\mods\\json-io-4.0.0.jar")); } catch (Exception e1) { logger.error("Downloading json-io failed with an exception"); e1.printStackTrace(); } But the downloaded file is not a jar, rather, it is an...
java,nullpointerexception,guava,apache-commons,preconditions
Do you know some nice alternative to Apache Commons Validate or Guava Preconditions that would throw IllegalArgumentException instead of NullPointerException when checking if object is not null (except Spring Assert)? I'm aware that Javadocs say: Applications should throw instances of this class [NullPointerException] to indicate other illegal uses of the...
java,hash,apache-commons,hash-collision,apache-commons-lang
I am getting collision with using Apache Commons Lang HashCodeBuilder using release 3.4. I am hashing a Route object, which contains two Cell objects, start and end. At the end I am providing an example when collision occurs. Both classes override hashCode and equals method. First the Cell class: import...
google-app-engine,apache-commons
I am trying to upload a word doc file in MySQL database in a Google app engine application. I am using org.apache.commons.upload to upload file.i have tried so many variations in my code but it every time it gives me same error. Error: Server Error The server encountered an error...
java,slf4j,apache-commons
I have a string such as following: Filed Id is invalid, value = {} and valid ranges = '{},{},{}' and I want replace {} by custom value in runtime. I see this pattern in SLF4J and real question is : Is there a third party utility for support this requirement...
java,file-upload,apache-commons
For my current solution, I'm using apache commons FileUpload library to process incoming multi-part requests. I'm able to send the files appropriately then read the stream on the server end using the streaming api code here. If you look at the format of multipart requests listed here, there is a...
java,apache,apache-commons,pool
I'm using the Apache Commons Pool 2 implementation to have object pool mechanism for my application. As of now, I have set the default value of maxTotal() and maxIdle() as 10 in my code. But I am not able to understand what is the difference between them ? What if...
java,guava,apache-commons
I need to get the hostname of the machine where the code is running. I have a method like this: private static final String getHostName() { try { return InetAddress.getLocalHost().getCanonicalHostName().toLowerCase(); } catch (UnknownHostException ex) { logger.logError("error = ", ex); } // this looks pretty odd to me, are there any...
java,apache-commons,notify
I have created a class FolderObserver which observes a folder in my project for changes (file created/file deleted). My class is implementing the Runnable interface (I'm using the classes FileAlterationObserver, FileAlterationMonitor, FileAlterationListener from apache commons). In my main class I start a thread with my FolderObserver object as an argument....
java,utf-8,apache-commons,utf-16,document-conversion
I’m using Java 6. I have an XML template, which begins like so <?xml version="1.0" encoding="UTF-8"?> However, I notice when I parse and output it with the following code (using Apache Commons-io 2.4) … Document doc = null; InputStream in = this.getClass().getClassLoader().getResourceAsStream(“my-template.xml”); try { byte[] data = org.apache.commons.io.IOUtils.toByteArray( in );...
java,xml,groovy,apache-commons,apache-commons-config
I am trying to use Apache Commons Configuration in groovy script to read values from a simple properties file and fill an XML template with these values from that file. The goal of this example is to be able to launch multiple instances of Tomcat with settings defined in properties...
grails,apache-commons
I am developing a module in which some file need to be uploaded on a ftp server for that I have added the "commons-net-3.3.jar" in my grails app & while using it import org.apache.commons.net.ftp.FTP import org.apache.commons.net.ftp.FTPClient import org.apache.commons.net.ftp.FTPClientConfig import org.apache.commons.net.ftp.FTPFile import org.apache.commons.net.ftp.FTPReply It is throwing the error unable to resolve...
java,xml,xml-parsing,apache-commons
I am using apache commons configuration 1.10 to manage xml configurations. This is a configuration file in xml format. <?xml version="1.0" encoding="ISO-8859-1" ?> <config> <mainServerHostname>MainServer</mainServerHostname> <failoverServers> <server> <ipAddress>192.168.0.5</ipAddress> <priority>1</priority> </server> <server> <ipAddress>192.168.0.6</ipAddress> <priority>2</priority> </server> </failoverServers>...
java,linux,import,apache-commons
I´ve made a Java Project on Windows and now I want to use it under Linux. Since I am working with Files, I "need" the org.apache.commons.io.FilenameUtils package. Under Windows I am working with IntelliJ, so it manages everything for me. I am sharing the Directory of the Project via VirtualBox...
java,javamail,apache-commons,apache-commons-email
I'm using version 1.3.3 Apache Commons Mail for sending out emails. I've tried changing the Apache mail version using telnet smtp.gmail.com 587 to test for connectivity (it works, so its not about the firewall) trying out with different ports setting SSL/ TSL and tried other bunch of methods configured my...
java,apache-commons
This question already has an answer here: Setting multiple jars in java classpath 20 answers I am trying to use a feature from the Apache Commons called StringUtils. However this requires you download the libary and add it so I can use the code import org.apache.commons.lang3.StringUtils;. My problem is...
apache,apache-commons,apache-commons-httpclient
Hi all I use apache's httpclient to make restcalls, everything is working fine, When multiple thread are using this method my app crashes. What is the implementation for this class that is MultithreadSafe. Here is my code. httpClient = new HttpClient(); HttpMethod method = null; method = new GetMethod(); ......