@Override
  protected void execInitField() throws ProcessingException {
    URL url = Activator.getDefault().getBundle().getResource("/resources/images/bird_1008.jpg");

    try {
      byte[] content = IOUtility.getContent(new BufferedInputStream(url.openStream()));
      File file = IOUtility.createTempFile("bird.jpg", (byte[]) content);
      getTable().addRowByArray(fileToArray(file));
    } catch (Exception e) {
      throw new ProcessingException("", e);
    }
  }
 protected void setLocationFromScout() {
   m_browserExtension.clearResourceCache();
   m_browserExtension.clearLocalHyperlinkCache();
   String location = getScoutObject().getLocation();
   RemoteFile r = getScoutObject().getValue();
   if (location == null && r != null && r.exists()) {
     try {
       if (r.getName().matches(".*\\.(zip|jar)")) {
         location = registerResourcesInZip(r);
       } else {
         String content = IOUtility.getContent(r.getDecompressedReader());
         content = m_browserExtension.adaptLocalHyperlinks(content, 1);
         location =
             m_browserExtension.addResource(
                 r.getName(), new ByteArrayInputStream(content.getBytes("UTF-8")));
       }
       // Prevent caching by making the request unique
       if (location != null) {
         location += "?nocache=" + System.currentTimeMillis();
       }
     } catch (Throwable t) {
       LOG.error("preparing html content for " + r, t);
     }
   }
   m_currentLocation = location;
   if (m_currentLocation != null) {
     getUiField().setUrl(m_currentLocation);
   } else {
     getUiField().setText("");
   }
 }
 private String registerResourcesInZip(RemoteFile zipFile)
     throws ProcessingException, IOException, UnsupportedEncodingException, FileNotFoundException {
   String location = null;
   File tempDir = IOUtility.createTempDirectory("browser");
   try {
     zipFile.writeZipContentToDirectory(tempDir);
     String simpleName = zipFile.getName().replaceAll("\\.(zip|jar)", ".htm");
     // rewrite local urls and register resource
     int prefixLen = tempDir.getAbsolutePath().length() + 1;
     for (File f : IOUtility.listFilesInSubtree(tempDir, null)) {
       if (f.isFile()) {
         String path = f.getAbsolutePath().substring(prefixLen);
         if (path.toLowerCase().matches(".*\\.(htm|html)")) {
           String content =
               IOUtility.getContent(new InputStreamReader(new FileInputStream(f), "UTF-8"));
           content = m_browserExtension.adaptLocalHyperlinks(content, 1);
           if (location == null && path.startsWith(simpleName)) {
             // this is the index.html
             location =
                 m_browserExtension.addResource(
                     simpleName, new ByteArrayInputStream(content.getBytes("UTF-8")));
           } else {
             m_browserExtension.addResource(
                 path, new ByteArrayInputStream(content.getBytes("UTF-8")));
           }
         } else if (path.toLowerCase().matches(".*\\.(svg)")) {
           String content = IOUtility.getContent(new InputStreamReader(new FileInputStream(f)));
           content = m_browserExtension.adaptLocalHyperlinks(content, 1);
           m_browserExtension.addResource(
               path, new ByteArrayInputStream(content.getBytes("UTF-8")));
         } else {
           m_browserExtension.addResource(path, new FileInputStream(f));
         }
       }
     }
   } finally {
     if (tempDir != null) {
       IOUtility.deleteDirectory(tempDir);
     }
   }
   return location;
 }
  private Object[] fileToArray(File file) {
    String type = IOUtility.getFileExtension(file.getName());
    Long size = file.length();

    if (file.isDirectory()) {
      type = FileCodeType.DirectoryCode.ID;
      size = null;
    } else {
      if (CODES.getCodeType(FileCodeType.class).getCode(type) == null) {
        type = FileCodeType.UknownCode.ID;
      }

      size /= FILE_SIZE_FACTOR;
    }

    return new Object[] {
      file, file.getName(), size, type, new Date(file.lastModified()), !file.canWrite()
    };
  }
 private void deleteTestFolders() {
   IOUtility.deleteDirectory(new File(TEST_DIR_IN));
   IOUtility.deleteDirectory(new File(TEST_DIR_OUT));
 }