summaryrefslogtreecommitdiffstats
path: root/tools/runner/java/vogar/Strings.java
diff options
context:
space:
mode:
Diffstat (limited to 'tools/runner/java/vogar/Strings.java')
-rw-r--r--tools/runner/java/vogar/Strings.java77
1 files changed, 77 insertions, 0 deletions
diff --git a/tools/runner/java/vogar/Strings.java b/tools/runner/java/vogar/Strings.java
new file mode 100644
index 0000000..d46d860
--- /dev/null
+++ b/tools/runner/java/vogar/Strings.java
@@ -0,0 +1,77 @@
+/*
+ * Copyright (C) 2009 The Android Open Source Project
+ *
+ * Licensed 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 vogar;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Iterator;
+
+/**
+ * Utility methods for strings.
+ */
+public class Strings {
+
+ public static String readFile(File f) throws IOException {
+ StringBuilder result = new StringBuilder();
+ BufferedReader in =
+ new BufferedReader(new InputStreamReader(new FileInputStream(f), "UTF-8"));
+ String line;
+ while ((line = in.readLine()) != null) {
+ result.append(line);
+ result.append('\n');
+ }
+ in.close();
+ return result.toString();
+ }
+
+ public static String join(Object[] objects, String delimiter) {
+ return join(Arrays.asList(objects), delimiter);
+ }
+
+ public static String join(Iterable<?> objects, String delimiter) {
+ Iterator<?> i = objects.iterator();
+ if (!i.hasNext()) {
+ return "";
+ }
+
+ StringBuilder result = new StringBuilder();
+ result.append(i.next());
+ while(i.hasNext()) {
+ result.append(delimiter).append(i.next());
+ }
+ return result.toString();
+ }
+
+ public static String[] objectsToStrings(Object[] objects) {
+ String[] result = new String[objects.length];
+ int i = 0;
+ for (Object o : objects) {
+ result[i++] = o.toString();
+ }
+ return result;
+ }
+
+ public static String[] objectsToStrings(Collection<?> objects) {
+ return objectsToStrings(objects.toArray());
+ }
+}