View Javadoc

1   // Copyright 2000-2002 FreeHEP
2   package org.freehep.graphicsio;
3   
4   import java.awt.Dimension;
5   import java.io.BufferedReader;
6   import java.io.InputStream;
7   import java.io.InputStreamReader;
8   import java.io.OutputStreamWriter;
9   import java.io.PrintStream;
10  import java.io.PrintWriter;
11  
12  import org.freehep.graphics2d.AbstractVectorGraphics;
13  
14  /**
15   * This class provides specifies added methods for VectorGraphicsIO. All added
16   * methods are declared abstract.
17   * 
18   * @author Charles Loomis
19   * @author Mark Donszelmann
20   * @version $Id: VectorGraphicsIO.java 8584 2006-08-10 23:06:37Z duns $
21   */
22  public abstract class VectorGraphicsIO extends AbstractVectorGraphics {
23  
24      public VectorGraphicsIO() {
25          super();
26      }
27  
28      public VectorGraphicsIO(VectorGraphicsIO graphics) {
29          super(graphics);
30      }
31  
32      public abstract Dimension getSize();
33  
34      public abstract void printComment(String comment);
35  
36      /**
37       * copies the full file referenced by filenam onto the os (PrintWriter). The
38       * file location is relative to the current class
39       * 
40       * @param object from which to refer to resource file
41       * @param fileName name of file to be copied
42       * @param os output to copy the file to
43       */
44      public static void copyResourceTo(Object object, String fileName,
45              PrintStream os) {
46          copyResourceTo(object, fileName, new PrintWriter(
47                  new OutputStreamWriter(os)));
48      }
49  
50      public static void copyResourceTo(Object object, String fileName,
51              PrintWriter os) {
52          InputStream is = null;
53          BufferedReader br = null;
54          try {
55              is = object.getClass().getResourceAsStream(fileName);
56              br = new BufferedReader(new InputStreamReader(is));
57              String s;
58              while ((s = br.readLine()) != null) {
59                  os.println(s);
60              }
61              os.flush();
62          } catch (Exception e) {
63              e.printStackTrace();
64          } finally {
65              try {
66                  if (br != null)
67                      br.close();
68                  if (is != null)
69                      is.close();
70              } catch (Exception e) {
71                  e.printStackTrace();
72              }
73          }
74      }
75  }