add ListPeer and ListPeers commands and replies
[jSite2.git] / src / net / pterodactylus / util / fcp / FcpUtils.java
index 9892610..a492f2e 100644 (file)
@@ -3,6 +3,7 @@
  */
 package net.pterodactylus.util.fcp;
 
+import java.util.StringTokenizer;
 import java.util.concurrent.atomic.AtomicLong;
 
 /**
@@ -25,4 +26,24 @@ public class FcpUtils {
                return new StringBuilder().append(System.currentTimeMillis()).append('-').append(counter.getAndIncrement()).toString();
        }
 
+       /**
+        * Parses an integer field, separated by ‘;’ and returns the parsed values.
+        * 
+        * @param field
+        *            The field to parse
+        * @return An array with the parsed values
+        * @throws NumberFormatException
+        *             if a value can not be converted to a number
+        */
+       public static int[] parseMultiIntegerField(String field) throws NumberFormatException {
+               StringTokenizer fieldTokens = new StringTokenizer(field, ";");
+               int[] result = new int[fieldTokens.countTokens()];
+               int counter = 0;
+               while (fieldTokens.hasMoreTokens()) {
+                       String fieldToken = fieldTokens.nextToken();
+                       result[counter++] = Integer.valueOf(fieldToken);
+               }
+               return result;
+       }
+
 }