summaryrefslogtreecommitdiff
path: root/src/de/danoeh/antennapod/util
diff options
context:
space:
mode:
authordaniel oeh <daniel.oeh@gmail.com>2012-10-31 16:56:23 +0100
committerdaniel oeh <daniel.oeh@gmail.com>2012-10-31 16:56:23 +0100
commit1c0874dabedee1eac0174c6e99885be92843f161 (patch)
treeb2ba44d63c31f580ca26d818010bd8cb5f97e548 /src/de/danoeh/antennapod/util
parent8c541fb82d2470b9c97eb12b5d121e3c283e0ab1 (diff)
downloadAntennaPod-1c0874dabedee1eac0174c6e99885be92843f161.zip
Created FileNameGenerator class
Diffstat (limited to 'src/de/danoeh/antennapod/util')
-rw-r--r--src/de/danoeh/antennapod/util/FileNameGenerator.java36
-rw-r--r--src/de/danoeh/antennapod/util/NumberGenerator.java21
2 files changed, 36 insertions, 21 deletions
diff --git a/src/de/danoeh/antennapod/util/FileNameGenerator.java b/src/de/danoeh/antennapod/util/FileNameGenerator.java
new file mode 100644
index 000000000..3bc193080
--- /dev/null
+++ b/src/de/danoeh/antennapod/util/FileNameGenerator.java
@@ -0,0 +1,36 @@
+package de.danoeh.antennapod.util;
+
+import java.util.Arrays;
+
+/** Generates valid filenames for a given string. */
+public class FileNameGenerator {
+
+ private static final char[] ILLEGAL_CHARACTERS = { '/', '\\', '?', '%',
+ '*', ':', '|', '"', '<', '>' };
+ static {
+ Arrays.sort(ILLEGAL_CHARACTERS);
+ }
+
+ private FileNameGenerator() {
+
+ }
+
+ /**
+ * This method will return a new string that doesn't contain any illegal
+ * characters of the given string.
+ */
+ public static String generateFileName(String string) {
+ StringBuilder builder = new StringBuilder();
+ for (int i = 0; i < string.length(); i++) {
+ char c = string.charAt(i);
+ if (Arrays.binarySearch(ILLEGAL_CHARACTERS, c) < 0) {
+ builder.append(c);
+ }
+ }
+ return builder.toString();
+ }
+
+ public static long generateLong(final String str) {
+ return str.hashCode();
+ }
+}
diff --git a/src/de/danoeh/antennapod/util/NumberGenerator.java b/src/de/danoeh/antennapod/util/NumberGenerator.java
deleted file mode 100644
index ff89180e1..000000000
--- a/src/de/danoeh/antennapod/util/NumberGenerator.java
+++ /dev/null
@@ -1,21 +0,0 @@
-package de.danoeh.antennapod.util;
-
-
-/**Utility class for creating numbers.*/
-public final class NumberGenerator {
- /** Class shall not be instantiated.*/
- private NumberGenerator() {
- }
-
- /**Logging tag.*/
- private static final String TAG = "NumberGenerator";
-
- /** Takes a string and generates a random value out of
- * the hash-value of that string.
- * @param strSeed The string to take for the return value
- * @return The generated random value
- * */
- public static long generateLong(final String strSeed) {
- return strSeed.hashCode();
- }
-}