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
19 public final class MTextToString {
\r
21 static final String COPYRIGHT =
\r
22 "(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";
\r
23 public static void main(String[] args) {
\r
26 if (args.length != 2) {
\r
30 writeMTextAsString(args[0], args[1]);
\r
34 private static void usage() {
\r
36 System.out.println("Usage: MTextToString inFile outFile");
\r
37 System.out.println("inFile must be a serialized MConstText");
\r
38 System.out.println("On exit, outFile will be a serialized String ");
\r
39 System.out.println("containing the characters in the text.");
\r
40 System.out.println("inFile and outFile must not be the same.");
\r
44 public static void writeMTextAsString(String inFile, String outFile) {
\r
46 File file = new File(inFile);
\r
47 MConstText text = FileUtils.loadMText(file);
\r
50 char[] ch = new char[text.length()];
\r
51 text.extractChars(0, ch.length, ch, 0);
\r
52 String str = new String(ch);
\r
53 writeString(str, outFile);
\r
56 System.out.println("Can't read inFile.");
\r
60 public static void writeString(String stringToWrite, String outFile) {
\r
62 File file = new File(outFile);
\r
63 Throwable error = null;
\r
66 OutputStream outStream = new FileOutputStream(file);
\r
67 ObjectOutputStream objStream = new ObjectOutputStream(outStream);
\r
69 objStream.writeObject(stringToWrite);
\r
73 catch(IOException e) {
\r
76 catch(ClassCastException e) {
\r
80 error.printStackTrace();
\r