/** Loads the resources */
  void initResources() {
    final Class<ControlExample> clazz = ControlExample.class;
    if (resourceBundle != null) {
      try {
        if (images == null) {
          images = new Image[imageLocations.length];

          for (int i = 0; i < imageLocations.length; ++i) {
            InputStream sourceStream = clazz.getResourceAsStream(imageLocations[i]);
            ImageData source = new ImageData(sourceStream);
            if (imageTypes[i] == SWT.ICON) {
              ImageData mask = source.getTransparencyMask();
              images[i] = new Image(null, source, mask);
            } else {
              images[i] = new Image(null, source);
            }
            try {
              sourceStream.close();
            } catch (IOException e) {
              e.printStackTrace();
            }
          }
        }
        return;
      } catch (Throwable t) {
      }
    }
    String error =
        (resourceBundle != null)
            ? getResourceString("error.CouldNotLoadResources")
            : "Unable to load resources"; //$NON-NLS-1$
    freeResources();
    throw new RuntimeException(error);
  }
Example #2
0
 public static String loadText(String aResourceName, Class aBaseClass) {
   String result = null;
   try {
     InputStream inputStream = aBaseClass.getResourceAsStream(aResourceName);
     result = loadText(inputStream);
   } catch (Exception ex) {
     System.err.println(
         (new StringBuilder()).append("Can't load resource ").append(aResourceName).toString());
   }
   return result;
 }
Example #3
0
 public static FragmentShader load(Class<?> base, String name) {
   InputStream in = base.getResourceAsStream(name);
   try {
     try {
       return (parse(new InputStreamReader(in, Utils.ascii)));
     } finally {
       in.close();
     }
   } catch (IOException e) {
     throw (new RuntimeException(e));
   }
 }
Example #4
0
 private DesignDocument.View loadViewFromFile(
     Map<String, DesignDocument.View> views, View input, Class<?> repositoryClass) {
   try {
     InputStream in = repositoryClass.getResourceAsStream(input.file());
     if (in == null) {
       throw new FileNotFoundException("Could not load view file with path: " + input.file());
     }
     String json = IOUtils.toString(in, "UTF-8");
     return mapper().readValue(json.replaceAll("\n", ""), DesignDocument.View.class);
   } catch (Exception e) {
     throw Exceptions.propagate(e);
   }
 }
Example #5
0
 /**
  * Gets an image resource.
  *
  * @param strResourceFilename Name of the image file.
  * @param srcClass Class from which the location of the resource is determined.
  * @return Instance of an <code>Image</code>.
  */
 public static Image getImageResourceFile(String strResourceFilename, Class srcClass) {
   PngImage pngImage = null;
   Image image = null;
   try {
     BufferedInputStream in =
         new BufferedInputStream(srcClass.getResourceAsStream(strResourceFilename));
     if (in == null) {
       System.err.println("Image not found:" + strResourceFilename);
       return null;
     }
     if (strResourceFilename.endsWith(".png")) {
       pngImage = new PngImage(in);
       image = Toolkit.getDefaultToolkit().createImage(pngImage);
     } else {
       ByteArrayOutputStream out = new ByteArrayOutputStream();
       copy(in, out);
       image = Toolkit.getDefaultToolkit().createImage(out.toByteArray());
     }
   } catch (java.io.IOException e) {
     System.err.println("Unable to read image " + strResourceFilename + ".");
     e.printStackTrace();
   }
   return (image);
 }
 private void createFromTemplate() {
   InputStream istr = null;
   OutputStream ostr = null;
   try {
     istr = resourceClass.getResourceAsStream(templateName);
     if (istr == null) {
       LOGGER.log(Level.SEVERE, tl("couldNotFindTemplate", templateName));
       return;
     }
     ostr = new FileOutputStream(configFile);
     byte[] buffer = new byte[1024];
     int length = 0;
     length = istr.read(buffer);
     while (length > 0) {
       ostr.write(buffer, 0, length);
       length = istr.read(buffer);
     }
   } catch (IOException ex) {
     LOGGER.log(Level.SEVERE, tl("failedToWriteConfig", configFile.toString()), ex);
   } finally {
     try {
       if (istr != null) {
         istr.close();
       }
     } catch (IOException ex) {
       Logger.getLogger(EssentialsConf.class.getName()).log(Level.SEVERE, null, ex);
     }
     try {
       if (ostr != null) {
         ostr.close();
       }
     } catch (IOException ex) {
       LOGGER.log(Level.SEVERE, tl("failedToCloseConfig", configFile.toString()), ex);
     }
   }
 }