/*
*******************************************************************************
- * 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;
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;
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.*");
);
}
//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());
/*
*******************************************************************************
- * 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;
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 = ",";
UnicodeSet set2,
int flags)
{
- if (pw == null) pw = CONSOLE;
+ if (pw == null) pw = FileUtilities.CONSOLE;
String[] names = { name1, name2 };
UnicodeSet temp;
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
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,
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;
}
/*
*******************************************************************************
- * 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);
}
/**
- * 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;
/*
*******************************************************************************
- * 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;
//#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) {