]> granicus.if.org Git - icu/commitdiff
ICU-12450 move com.ibm.icu.dev.util.BagFormatter.openUTF8Writer() and siblings to...
authorMarkus Scherer <markus.icu@gmail.com>
Fri, 15 Apr 2016 21:51:58 +0000 (21:51 +0000)
committerMarkus Scherer <markus.icu@gmail.com>
Fri, 15 Apr 2016 21:51:58 +0000 (21:51 +0000)
X-SVN-Rev: 38618

icu4j/main/tests/translit/src/com/ibm/icu/dev/test/util/TestBagFormatter.java
icu4j/main/tests/translit/src/com/ibm/icu/dev/util/BagFormatter.java
icu4j/main/tests/translit/src/com/ibm/icu/dev/util/FileUtilities.java
icu4j/main/tests/translit/src/com/ibm/icu/dev/util/TransliteratorUtilities.java

index b3b044102969b39adf3d1ef025a49ac390560bc1..50458c3f45fd58650c16b31df592b7d71c3408d6 100644 (file)
@@ -1,7 +1,7 @@
 /*
  *******************************************************************************
- * Copyright (C) 2002-2012, International Business Machines Corporation and    *
- * others. All Rights Reserved.                                                *
+ * Copyright (C) 2002-2016, International Business Machines Corporation and
+ * others. All Rights Reserved.
  *******************************************************************************
  */
 package com.ibm.icu.dev.test.util;
@@ -18,6 +18,7 @@ import java.util.Set;
 import java.util.TreeSet;
 
 import com.ibm.icu.dev.util.BagFormatter;
+import com.ibm.icu.dev.util.FileUtilities;
 import com.ibm.icu.dev.util.ICUPropertyFactory;
 import com.ibm.icu.dev.util.UnicodeMap;
 import com.ibm.icu.dev.util.UnicodeProperty;
@@ -91,21 +92,21 @@ public class TestBagFormatter {
             BagFormatter bf = new BagFormatter();
 
             UnicodeSet us = new UnicodeSet("[:gc=nd:]");  
-            BagFormatter.CONSOLE.println("[:gc=nd:]");
-            bf.showSetNames(BagFormatter.CONSOLE,us);
+            FileUtilities.CONSOLE.println("[:gc=nd:]");
+            bf.showSetNames(FileUtilities.CONSOLE,us);
 
             us = new UnicodeSet("[:numeric_value=2:]");  
-            BagFormatter.CONSOLE.println("[:numeric_value=2:]");
-            bf.showSetNames(BagFormatter.CONSOLE,us);
+            FileUtilities.CONSOLE.println("[:numeric_value=2:]");
+            bf.showSetNames(FileUtilities.CONSOLE,us);
             
             us = new UnicodeSet("[:numeric_type=numeric:]");   
-            BagFormatter.CONSOLE.println("[:numeric_type=numeric:]");
-            bf.showSetNames(BagFormatter.CONSOLE,us);
+            FileUtilities.CONSOLE.println("[:numeric_type=numeric:]");
+            bf.showSetNames(FileUtilities.CONSOLE,us);
             
             UnicodeProperty.Factory ups = ICUPropertyFactory.make();
             us = ups.getSet("gc=mn", null, null); 
-            BagFormatter.CONSOLE.println("gc=mn");
-            bf.showSetNames(BagFormatter.CONSOLE, us);
+            FileUtilities.CONSOLE.println("gc=mn");
+            bf.showSetNames(FileUtilities.CONSOLE, us);
             
             if (true) return;
             //showNames("Name", ".*MARK.*");
@@ -162,7 +163,7 @@ public class TestBagFormatter {
             );
         }
         //CollectionFormatter cf = new CollectionFormatter();
-        PrintWriter pw = BagFormatter.openUTF8Writer("", "countries.txt");
+        PrintWriter pw = FileUtilities.openUTF8Writer("", "countries.txt");
         Iterator it = s.iterator();
         while (it.hasNext()) {
             pw.println(it.next());
index 5ca583ecee0b0cb21f50d693fdffc0b108969151..024d1c73653939c60a3ab5d5c951a8efcbedddea 100644 (file)
@@ -1,19 +1,11 @@
 /*
  *******************************************************************************
- * Copyright (C) 2002-2012, International Business Machines Corporation and    *
- * others. All Rights Reserved.                                                *
+ * Copyright (C) 2002-2016, International Business Machines Corporation and
+ * others. All Rights Reserved.
  *******************************************************************************
  */
 package com.ibm.icu.dev.util;
 
-import java.io.BufferedReader;
-import java.io.BufferedWriter;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.io.OutputStreamWriter;
 import java.io.PrintWriter;
 import java.io.StringWriter;
 import java.text.MessageFormat;
@@ -31,20 +23,6 @@ import com.ibm.icu.text.UnicodeSet;
 
 public class BagFormatter {
     static final boolean DEBUG = false;
-    public static final boolean SHOW_FILES;
-    static {
-    boolean showFiles = false;
-    try {
-        showFiles = System.getProperty("SHOW_FILES") != null;
-    }
-    catch (SecurityException e) {
-    }
-    SHOW_FILES = showFiles;
-    }
-
-    public static final PrintWriter CONSOLE = new PrintWriter(System.out,true);
-
-    private static PrintWriter log = CONSOLE;
 
     private boolean abbreviated = false;
     private String separator = ",";
@@ -120,7 +98,7 @@ public class BagFormatter {
         UnicodeSet set2,
         int flags) 
     {
-        if (pw == null) pw = CONSOLE;
+        if (pw == null) pw = FileUtilities.CONSOLE;
         String[] names = { name1, name2 };
 
         UnicodeSet temp;
@@ -158,7 +136,7 @@ public class BagFormatter {
         String name2,
         Collection set2) {
 
-        if (pw == null) pw = CONSOLE;
+        if (pw == null) pw = FileUtilities.CONSOLE;
         String[] names = { name1, name2 };
         // damn'd collection doesn't have a clone, so
         // we go with Set, even though that
@@ -208,20 +186,6 @@ public class BagFormatter {
         output.flush();
     }
 
-    /**
-     * Returns a list of items in the collection, with each separated by the separator.
-     * Each item must not be null; its toString() is called for a printable representation
-     * @param filename destination to which to write names
-     * @param c source collection
-     */
-    public void showSetNames(String filename, Object c) throws IOException {
-        PrintWriter pw = new PrintWriter(
-            new OutputStreamWriter(
-                new FileOutputStream(filename),"utf-8"));
-        showSetNames(log,c);
-        pw.close();
-    }
-
     public String getAbbreviatedName(
         String src,
         String pattern,
@@ -850,52 +814,6 @@ public class BagFormatter {
     public static final Transliterator hex = Transliterator.getInstance(
         "[^\\u0009\\u0020-\\u007E\\u00A0-\\u00FF] hex");
 
-    public static BufferedReader openUTF8Reader(String dir, String filename) throws IOException {
-        return openReader(dir,filename,"UTF-8");
-    }
-
-    public static BufferedReader openReader(String dir, String filename, String encoding) throws IOException {
-        File file = dir.length() == 0 ? new File(filename) : new File(dir, filename);
-        if (SHOW_FILES && log != null) {
-            log.println("Opening File: "
-                + file.getCanonicalPath());
-        }
-        return new BufferedReader(
-            new InputStreamReader(
-                new FileInputStream(file),
-                encoding),
-            4*1024);
-    }
-
-    public static PrintWriter openUTF8Writer(String dir, String filename) throws IOException {
-        return openWriter(dir,filename,"UTF-8");
-    }
-
-    public static PrintWriter openWriter(String dir, String filename, String encoding) throws IOException {
-        File file = new File(dir, filename);
-        if (SHOW_FILES && log != null) {
-            log.println("Creating File: "
-                + file.getCanonicalPath());
-        }
-        String parentName = file.getParent();
-        if (parentName != null) {
-            File parent = new File(parentName);
-            parent.mkdirs();
-        }
-        return new PrintWriter(
-            new BufferedWriter(
-                new OutputStreamWriter(
-                    new FileOutputStream(file),
-                    encoding),
-                4*1024));
-    }
-    public static PrintWriter getLog() {
-        return log;
-    }
-    public BagFormatter setLog(PrintWriter writer) {
-        log = writer;
-        return this;
-    }
     public String getSeparator() {
         return separator;
     }
index c91194c72c82138c935c1eb670dcce9ce7f2b96b..22465f6060ed5710c914959fe7b4ab197e39019f 100644 (file)
@@ -1,23 +1,83 @@
 /*
  *******************************************************************************
- * Copyright (C) 2002-2015, International Business Machines Corporation and
+ * Copyright (C) 2002-2016, International Business Machines Corporation and
  * others. All Rights Reserved.
  *******************************************************************************
  */
 package com.ibm.icu.dev.util;
 
 import java.io.BufferedReader;
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
 import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.OutputStreamWriter;
 import java.io.PrintWriter;
 import java.util.Locale;
 
 public class FileUtilities {
+    public static final boolean SHOW_FILES;
+    static {
+        boolean showFiles = false;
+        try {
+            showFiles = System.getProperty("SHOW_FILES") != null;
+        } catch (SecurityException ignored) {
+        }
+        SHOW_FILES = showFiles;
+    }
+
+    public static final PrintWriter CONSOLE = new PrintWriter(System.out,true);
+
+    private static PrintWriter log = CONSOLE;
+
+    public static BufferedReader openUTF8Reader(String dir, String filename) throws IOException {
+        return openReader(dir, filename, "UTF-8");
+    }
+
+    public static BufferedReader openReader(String dir, String filename, String encoding) throws IOException {
+        File file = dir.length() == 0 ? new File(filename) : new File(dir, filename);
+        if (SHOW_FILES && log != null) {
+            log.println("Opening File: "
+                + file.getCanonicalPath());
+        }
+        return new BufferedReader(
+            new InputStreamReader(
+                new FileInputStream(file),
+                encoding),
+            4*1024);
+    }
+
+    public static PrintWriter openUTF8Writer(String dir, String filename) throws IOException {
+        return openWriter(dir, filename, "UTF-8");
+    }
+
+    public static PrintWriter openWriter(String dir, String filename, String encoding) throws IOException {
+        File file = new File(dir, filename);
+        if (SHOW_FILES && log != null) {
+            log.println("Creating File: "
+                + file.getCanonicalPath());
+        }
+        String parentName = file.getParent();
+        if (parentName != null) {
+            File parent = new File(parentName);
+            parent.mkdirs();
+        }
+        return new PrintWriter(
+            new BufferedWriter(
+                new OutputStreamWriter(
+                    new FileOutputStream(file),
+                    encoding),
+                4*1024));
+    }
+
     public static void appendFile(String filename, String encoding, PrintWriter output) throws IOException {
         appendFile(filename, encoding, output, null);
     }
-    
+
     public static void appendFile(String filename, String encoding, PrintWriter output, String[] replacementList) throws IOException {
-        BufferedReader br = BagFormatter.openReader("", filename, encoding);
+        BufferedReader br = openReader("", filename, encoding);
         /*
         FileInputStream fis = new FileInputStream(filename);
         InputStreamReader isr = (encoding == UTF8_UNIX || encoding == UTF8_WINDOWS) ? new InputStreamReader(fis, "UTF8") :  new InputStreamReader(fis);
@@ -46,7 +106,7 @@ public class FileUtilities {
     }
 
     /**
-     * Replaces all occurances of piece with replacement, and returns new String
+     * Replaces all occurrences of piece with replacement, and returns new String
      */
     public static String replace(String source, String piece, String replacement) {
         if (source == null || source.length() < piece.length()) return source;
index 536258f745f2cabaa5636e9b1052957cf079272b..3d8a55f55834199569c3cea728de8f894561ebfb 100644 (file)
@@ -1,7 +1,7 @@
 /*
  *******************************************************************************
- * Copyright (C) 2002-2012, International Business Machines Corporation and    *
- * others. All Rights Reserved.                                                *
+ * Copyright (C) 2002-2016, International Business Machines Corporation and
+ * others. All Rights Reserved.
  *******************************************************************************
  */
 package com.ibm.icu.dev.util;
@@ -57,7 +57,7 @@ public class TransliteratorUtilities {
 //#if defined(FOUNDATION10) || defined(J2SE13)
 //##        BufferedReader br = TestUtil.openUTF8Reader(dir, filename);
 //#else
-        BufferedReader br = BagFormatter.openUTF8Reader(dir, filename);
+        BufferedReader br = FileUtilities.openUTF8Reader(dir, filename);
 //#endif 
         StringBuffer buffer = new StringBuffer();
         while (true) {