From: Markus Scherer Date: Fri, 15 Apr 2016 21:51:58 +0000 (+0000) Subject: ICU-12450 move com.ibm.icu.dev.util.BagFormatter.openUTF8Writer() and siblings to... X-Git-Tag: milestone-59-0-1~504 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=96f349b049ec10a7e17274afdc829449f24948ee;p=icu ICU-12450 move com.ibm.icu.dev.util.BagFormatter.openUTF8Writer() and siblings to com.ibm.icu.dev.util.FileUtilities and also to org.unicode.cldr.draft.FileUtilities: CLDR & Unicode Tools cannot use new ICU code until their ICU jar files are updated X-SVN-Rev: 38618 --- diff --git a/icu4j/main/tests/translit/src/com/ibm/icu/dev/test/util/TestBagFormatter.java b/icu4j/main/tests/translit/src/com/ibm/icu/dev/test/util/TestBagFormatter.java index b3b04410296..50458c3f45f 100644 --- a/icu4j/main/tests/translit/src/com/ibm/icu/dev/test/util/TestBagFormatter.java +++ b/icu4j/main/tests/translit/src/com/ibm/icu/dev/test/util/TestBagFormatter.java @@ -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()); diff --git a/icu4j/main/tests/translit/src/com/ibm/icu/dev/util/BagFormatter.java b/icu4j/main/tests/translit/src/com/ibm/icu/dev/util/BagFormatter.java index 5ca583ecee0..024d1c73653 100644 --- a/icu4j/main/tests/translit/src/com/ibm/icu/dev/util/BagFormatter.java +++ b/icu4j/main/tests/translit/src/com/ibm/icu/dev/util/BagFormatter.java @@ -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; } diff --git a/icu4j/main/tests/translit/src/com/ibm/icu/dev/util/FileUtilities.java b/icu4j/main/tests/translit/src/com/ibm/icu/dev/util/FileUtilities.java index c91194c72c8..22465f6060e 100644 --- a/icu4j/main/tests/translit/src/com/ibm/icu/dev/util/FileUtilities.java +++ b/icu4j/main/tests/translit/src/com/ibm/icu/dev/util/FileUtilities.java @@ -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; diff --git a/icu4j/main/tests/translit/src/com/ibm/icu/dev/util/TransliteratorUtilities.java b/icu4j/main/tests/translit/src/com/ibm/icu/dev/util/TransliteratorUtilities.java index 536258f745f..3d8a55f5583 100644 --- a/icu4j/main/tests/translit/src/com/ibm/icu/dev/util/TransliteratorUtilities.java +++ b/icu4j/main/tests/translit/src/com/ibm/icu/dev/util/TransliteratorUtilities.java @@ -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) {