1 /* GENERATED SOURCE. DO NOT MODIFY. */ 2 // 2016 and later: Unicode, Inc. and others. 3 // License & terms of use: http://www.unicode.org/copyright.html#License 4 /* 5 ******************************************************************************* 6 * Copyright (C) 1996-2011, International Business Machines Corporation and * 7 * others. All Rights Reserved. * 8 ******************************************************************************* 9 * 10 */ 11 12 package android.icu.dev.test.serializable; 13 14 import java.io.File; 15 import java.io.IOException; 16 import java.net.URL; 17 import java.util.List; 18 19 import android.icu.dev.test.serializable.SerializableTestUtility.Handler; 20 import android.icu.util.TimeZone; 21 import android.icu.util.VersionInfo; 22 import android.icu.testsharding.MainTestShard; 23 24 /** 25 * This class writes the test objects for each class to a file. The work is 26 * actually done by the superclass, CoverageTest. This class just constructs 27 * a CoverageTest w/ a non-null path, which tells it to write the data. 28 * 29 */ 30 @MainTestShard 31 public class SerializableWriter 32 { 33 String path; 34 35 public SerializableWriter(String path) 36 { 37 this.path = path; 38 } 39 40 private static String folderName() 41 { 42 int major = VersionInfo.ICU_VERSION.getMajor(); 43 int minor = VersionInfo.ICU_VERSION.getMinor(); 44 int milli = VersionInfo.ICU_VERSION.getMilli(); 45 int micro = VersionInfo.ICU_VERSION.getMicro(); 46 StringBuffer result = new StringBuffer("ICU_"); 47 48 result.append(major); 49 result.append("."); 50 result.append(minor); 51 52 if (milli != 0 || micro != 0) { 53 result.append("."); 54 result.append(milli); 55 56 if (micro != 0) { 57 result.append("."); 58 result.append(micro); 59 } 60 } 61 62 return result.toString(); 63 } 64 65 public static void main(String[] args) throws IOException 66 { 67 String outDir = null; 68 if (args.length == 0) { 69 URL dataURL = SerializableWriter.class.getResource("data"); 70 outDir = dataURL.getPath() + "/" + folderName(); 71 } else { 72 outDir = args[0] + "/" + folderName(); 73 } 74 75 // Override default TimeZone, so serialized data always use 76 // the consistent zone if not specified. 77 TimeZone.setDefault(TimeZone.getTimeZone("America/Los_Angeles")); 78 79 SerializableWriter writer = new SerializableWriter(outDir); 80 81 writer.serialize(); 82 } 83 84 public void serialize() throws IOException { 85 File outDir = new File(this.path); 86 if (!outDir.exists()) { 87 outDir.mkdirs(); 88 } 89 90 List<String> classList = SerializableTestUtility.getSerializationClassList(this); 91 for (String className : classList) { 92 Handler classHandler = SerializableTestUtility.getHandler(className); 93 if (classHandler == null) { 94 System.out.println("No Handler - Skipping Class: " + className); 95 continue; 96 } 97 Object[] testObjects = classHandler.getTestObjects(); 98 File oof = new File(this.path, className + ".dat"); 99 SerializableTestUtility.serializeObjects(oof, testObjects); 100 } 101 } 102 } 103