Return-Path: X-Original-To: apmail-zookeeper-commits-archive@www.apache.org Delivered-To: apmail-zookeeper-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 9B512DB45 for ; Fri, 25 Jan 2013 06:54:41 +0000 (UTC) Received: (qmail 54544 invoked by uid 500); 25 Jan 2013 06:54:41 -0000 Delivered-To: apmail-zookeeper-commits-archive@zookeeper.apache.org Received: (qmail 54458 invoked by uid 500); 25 Jan 2013 06:54:41 -0000 Mailing-List: contact commits-help@zookeeper.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@ Delivered-To: mailing list commits@zookeeper.apache.org Received: (qmail 54433 invoked by uid 99); 25 Jan 2013 06:54:40 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 25 Jan 2013 06:54:40 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 25 Jan 2013 06:54:39 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 26DD42388A38; Fri, 25 Jan 2013 06:54:20 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1438351 - in /zookeeper/trunk: CHANGES.txt src/java/main/org/apache/zookeeper/client/ConnectStringParser.java src/java/main/org/apache/zookeeper/common/StringUtils.java src/java/test/org/apache/zookeeper/test/StringUtilTest.java Date: Fri, 25 Jan 2013 06:54:19 -0000 To: commits@zookeeper.apache.org From: phunt@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20130125065420.26DD42388A38@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: phunt Date: Fri Jan 25 06:54:19 2013 New Revision: 1438351 URL: http://svn.apache.org/viewvc?rev=1438351&view=rev Log: ZOOKEEPER-1619. Allow spaces in URL (Edward Ribeiro via phunt) Added: zookeeper/trunk/src/java/main/org/apache/zookeeper/common/StringUtils.java zookeeper/trunk/src/java/test/org/apache/zookeeper/test/StringUtilTest.java Modified: zookeeper/trunk/CHANGES.txt zookeeper/trunk/src/java/main/org/apache/zookeeper/client/ConnectStringParser.java Modified: zookeeper/trunk/CHANGES.txt URL: http://svn.apache.org/viewvc/zookeeper/trunk/CHANGES.txt?rev=1438351&r1=1438350&r2=1438351&view=diff ============================================================================== --- zookeeper/trunk/CHANGES.txt (original) +++ zookeeper/trunk/CHANGES.txt Fri Jan 25 06:54:19 2013 @@ -471,6 +471,9 @@ IMPROVEMENTS: ZOOKEEPER-1535. ZK Shell/Cli re-executes last command on exit (Edward Ribeiro via camille) + ZOOKEEPER-1619. Allow spaces in URL (Edward Ribeiro via phunt) + + Release 3.4.0 - Non-backward compatible changes: Modified: zookeeper/trunk/src/java/main/org/apache/zookeeper/client/ConnectStringParser.java URL: http://svn.apache.org/viewvc/zookeeper/trunk/src/java/main/org/apache/zookeeper/client/ConnectStringParser.java?rev=1438351&r1=1438350&r2=1438351&view=diff ============================================================================== --- zookeeper/trunk/src/java/main/org/apache/zookeeper/client/ConnectStringParser.java (original) +++ zookeeper/trunk/src/java/main/org/apache/zookeeper/client/ConnectStringParser.java Fri Jan 25 06:54:19 2013 @@ -18,10 +18,13 @@ package org.apache.zookeeper.client; +import org.apache.zookeeper.common.PathUtils; + import java.net.InetSocketAddress; import java.util.ArrayList; +import java.util.List; -import org.apache.zookeeper.common.PathUtils; +import static org.apache.zookeeper.common.StringUtils.split; /** * A parser for ZooKeeper Client connect strings. @@ -62,7 +65,7 @@ public final class ConnectStringParser { this.chrootPath = null; } - String hostsList[] = connectString.split(","); + List hostsList = split(connectString,","); for (String host : hostsList) { int port = DEFAULT_PORT; int pidx = host.lastIndexOf(':'); @@ -84,4 +87,4 @@ public final class ConnectStringParser { public ArrayList getServerAddresses() { return serverAddresses; } -} \ No newline at end of file +} Added: zookeeper/trunk/src/java/main/org/apache/zookeeper/common/StringUtils.java URL: http://svn.apache.org/viewvc/zookeeper/trunk/src/java/main/org/apache/zookeeper/common/StringUtils.java?rev=1438351&view=auto ============================================================================== --- zookeeper/trunk/src/java/main/org/apache/zookeeper/common/StringUtils.java (added) +++ zookeeper/trunk/src/java/main/org/apache/zookeeper/common/StringUtils.java Fri Jan 25 06:54:19 2013 @@ -0,0 +1,44 @@ +/* Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.zookeeper.common; +import java.util.ArrayList; +import java.util.List; +import java.util.Collections; + +public class StringUtils { + + private StringUtils() {/** non instantiable and non inheritable **/} + + /** + * This method returns an immutable List, but different from String's split() + * it trims the results in the input String, and removes any empty string from + * the resulting List. + * + */ + public static List split(String value, String separator) { + String[] splits = value.split(separator); + List results = new ArrayList(); + for (int i = 0; i < splits.length; i++) { + splits[i] = splits[i].trim(); + if (splits[i].length() > 0) { + results.add(splits[i]); + } + } + return Collections.unmodifiableList(results); + } +} Added: zookeeper/trunk/src/java/test/org/apache/zookeeper/test/StringUtilTest.java URL: http://svn.apache.org/viewvc/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/StringUtilTest.java?rev=1438351&view=auto ============================================================================== --- zookeeper/trunk/src/java/test/org/apache/zookeeper/test/StringUtilTest.java (added) +++ zookeeper/trunk/src/java/test/org/apache/zookeeper/test/StringUtilTest.java Fri Jan 25 06:54:19 2013 @@ -0,0 +1,43 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.zookeeper.test; + + +import org.apache.zookeeper.common.StringUtils; +import org.junit.Test; + +import java.util.Arrays; + +import static junit.framework.Assert.assertEquals; + +public class StringUtilTest { + + @Test + public void testStrings() { + + String s1 = " a , b , "; + assertEquals("[a, b]", StringUtils.split(s1, ",").toString()); + + String s2 = ""; + assertEquals(0, StringUtils.split(s2, ",").size()); + + String s3 = "1, , 2"; + assertEquals("[1, 2]", StringUtils.split(s3, ",").toString()); + + } +}