2 * (C) Copyright IBM Corp. 1998-2004. All Rights Reserved.
\r
4 * The program is provided "as is" without any warranty express or
\r
5 * implied, including the warranty of non-infringement and the implied
\r
6 * warranties of merchantibility and fitness for a particular purpose.
\r
7 * IBM will not be liable for any damages suffered by you as a result
\r
8 * of using the Program. In no event will IBM be liable for any
\r
9 * special, indirect or consequential damages or lost profits even if
\r
10 * IBM has been advised of the possibility of their occurrence. IBM
\r
11 * will not be liable for any third party claims against you.
\r
13 package com.ibm.richtext.textapps;
\r
15 import com.ibm.richtext.styledtext.MConstText;
\r
16 import com.ibm.richtext.styledtext.StyledText;
\r
17 import com.ibm.richtext.textlayout.attributes.AttributeMap;
\r
21 public final class StringToMText {
\r
23 static final String COPYRIGHT =
\r
24 "(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";
\r
25 public static void main(String[] args) {
\r
28 if (args.length != 2 || args[0].equals(args[1])) {
\r
32 String str = loadString(new File(args[0]));
\r
34 throw new Error("Couldn't load String from file " + args[0]);
\r
36 MConstText text = new StyledText(str, AttributeMap.EMPTY_ATTRIBUTE_MAP);
\r
37 FileUtils.saveMText(new File(args[1]), text);
\r
41 private static void usage() {
\r
43 System.out.println("Usage: StringToMText inFile outFile");
\r
44 System.out.println("inFile must be a serialized String");
\r
45 System.out.println("On exit, outFile will be a serialized MText ");
\r
46 System.out.println("containing the characters in the string.");
\r
47 System.out.println("inFile and outFile must not be the same.");
\r
51 public static String loadString(File file) {
\r
56 FileInputStream inStream = new FileInputStream(file);
\r
57 ObjectInputStream objStream = new ObjectInputStream(inStream);
\r
59 String str = (String) objStream.readObject();
\r
63 catch(IOException e) {
\r
66 catch(ClassNotFoundException e) {
\r
69 catch(ClassCastException e) {
\r
73 error.printStackTrace();
\r