Пример #1
1
  public void doRFileEvaluate(final IScope scope, final IContainer param) {
    int size = param.length(scope);
    // if ( size == 0 ) { throw GamaRuntimeException.error("Missing Parameter Exception", scope); }

    final String RFile = getPath();
    try {
      // Call R
      RCaller caller = new RCaller();

      String RPath = GamaPreferences.LIB_R.value(scope).getPath();
      caller.setRscriptExecutable(RPath);

      double[] vectorParam = new double[param.length(scope)];

      int k = 0;
      for (Object o : param.iterable(scope)) {
        vectorParam[k++] = Cast.asFloat(scope, o);
      }

      RCode c = new RCode();
      // Adding the parameters
      c.addDoubleArray("vectorParam", vectorParam);

      // Adding the codes in file
      List<String> R_statements = new ArrayList<String>();

      // tmthai.begin----------------------------------------------------------------------------
      String fullPath = FileUtils.constructAbsoluteFilePath(scope, RFile, true);
      if (DEBUG) {
        GuiUtils.debug("Stats.R_compute_param.RScript:" + RPath);
        GuiUtils.debug("Stats.R_compute_param.Param:" + vectorParam.toString());
        GuiUtils.debug("Stats.R_compute_param.RFile:" + RFile);
        GuiUtils.debug("Stats.R_compute_param.fullPath:" + fullPath);
      }

      // FileReader fr = new FileReader(RFile);
      FileReader fr = new FileReader(fullPath);
      // tmthai.end----------------------------------------------------------------------------

      BufferedReader br = new BufferedReader(fr);
      String statement;

      while ((statement = br.readLine()) != null) {
        c.addRCode(statement);
        R_statements.add(statement);
        // java.lang.System.out.println(statement);
      }
      br.close();
      fr.close();
      caller.setRCode(c);

      GamaMap<String, IList> result = GamaMapFactory.create(Types.STRING, Types.LIST);

      String var = computeVariable(R_statements.get(R_statements.size() - 1).toString());
      caller.runAndReturnResult(var);

      // DEBUG:
      // java.lang.System.out.println("Name: '" + R_statements.length(scope) + "'");
      if (DEBUG) {
        GuiUtils.debug("Stats.R_compute_param.R_statements.length: '" + R_statements.size() + "'");
      }

      for (String name : caller.getParser().getNames()) {
        String[] results = null;
        results = caller.getParser().getAsStringArray(name);
        // java.lang.System.out.println("Name: '" + name + "'");
        if (DEBUG) {
          GuiUtils.debug(
              "Stats.R_compute_param.caller.Name: '"
                  + name
                  + "' length: "
                  + results.length
                  + " - Value: "
                  + results.toString());
        }

        result.put(name, GamaListFactory.create(scope, Types.NO_TYPE, results));
      }

      if (DEBUG) {
        GuiUtils.debug("Stats.R_compute_param.return:" + result.serialize(false));
      }

      setBuffer(result);

    } catch (Exception ex) {

      throw GamaRuntimeException.error("RCallerExecutionException " + ex.getMessage(), scope);
    }
  }
Пример #2
0
  private Integer seekToSubColumn(
      CFMetaData metadata,
      FileDataInput file,
      ByteBuffer sblockId,
      List<IndexHelper.IndexInfo> indexList)
      throws IOException {
    file.readInt(); // column count

    /* get the various column ranges we have to read */
    AbstractType comparator = metadata.comparator;

    int index = IndexHelper.indexFor(sblockId, indexList, comparator, false);
    if (index == indexList.size()) return null;

    IndexHelper.IndexInfo indexInfo = indexList.get(index);
    if (comparator.compare(sblockId, indexInfo.firstName) < 0) return null;

    FileMark mark = file.mark();

    FileUtils.skipBytesFully(file, indexInfo.offset);

    while (file.bytesPastMark(mark) < indexInfo.offset + indexInfo.width) {
      Integer dataLength = isSubBlockFound(metadata, file, sblockId);

      if (dataLength == null) return null;

      if (dataLength < 0) continue;

      return dataLength;
    }

    return null;
  }
 private Class<?> findClassInComponents(final String name) throws ClassNotFoundException {
   final String classFilename = this.getClassFilename(name);
   final Enumeration<File> e = this.pathComponents.elements();
   while (e.hasMoreElements()) {
     final File pathComponent = e.nextElement();
     InputStream stream = null;
     try {
       stream = this.getResourceStream(pathComponent, classFilename);
       if (stream != null) {
         this.log("Loaded from " + pathComponent + " " + classFilename, 4);
         return this.getClassFromStream(stream, name, pathComponent);
       }
       continue;
     } catch (SecurityException se) {
       throw se;
     } catch (IOException ioe) {
       this.log(
           "Exception reading component " + pathComponent + " (reason: " + ioe.getMessage() + ")",
           3);
     } finally {
       FileUtils.close(stream);
     }
   }
   throw new ClassNotFoundException(name);
 }
 /*
  * Set up the platform binary download and get it ready to run the tests.
  * This method is not intended to be called by clients, it will be called
  * automatically when the clients use a ReconcilerTestSuite. If the executable isn't
  * found on the file-system after the call, then we fail.
  */
 public void initialize() throws Exception {
   initialized = false;
   File file = getPlatformZip();
   output = getUniqueFolder();
   toRemove.add(output);
   // for now we will exec to un-tar archives to keep the executable bits
   if (file.getName().toLowerCase().endsWith(".zip")) {
     try {
       FileUtils.unzipFile(file, output);
     } catch (IOException e) {
       fail("0.99", e);
     }
   } else {
     untar("1.0", file);
   }
   File exe = new File(output, getExeFolder() + "eclipse.exe");
   if (!exe.exists()) {
     exe = new File(output, getExeFolder() + "eclipse");
     if (!exe.exists())
       fail(
           "Executable file: "
               + exe.getAbsolutePath()
               + "(or .exe) not found after extracting: "
               + file.getAbsolutePath()
               + " to: "
               + output);
   }
   initialized = true;
 }
Пример #5
0
 /** Creates a .gitignore file into the working directory */
 private void createGitIgnoreFile() {
   /**
    * create .gitignore file as in
    * https://github.com/cloudspokes/jenkins-test/blob/master/.gitignore if no filenames are give,
    * creates an empty one (if .gitignore file does not already exists). If .gitfile present,
    * appends to the end.
    */
   File gitIgnore = new File(this.workingFolderPath.concat("/.gitignore"));
   FileUtils.writeToFile(gitIgnore, ignoreList, true);
 }
  protected ModelAndView onSubmit(
      HttpServletRequest request,
      HttpServletResponse response,
      Object command,
      BindException errors)
      throws ServletException, IOException, Exception {

    // cast the bean.  i only care about the File property in this controller
    UploadMasterBean bean = (UploadMasterBean) command;

    MultipartFile multipartFile = bean.getFile();
    if (multipartFile != null) {
      System.out.println("name " + multipartFile.getOriginalFilename());
      System.out.println("size " + multipartFile.getSize());

      File fileOut = new File(FileUtils.createTempDir(), multipartFile.getOriginalFilename());

      System.out.println("File written to " + fileOut.getCanonicalPath());

      multipartFile.transferTo(fileOut);

      String path = fileOut.getCanonicalPath();
      String extension = FileUtils.getFileExtension(path);

      if (("png".equals(extension))
          || ("PNG".equals(extension))
          || ("jpg".equals(extension))
          || ("JPG".equals(extension))
          || ("gif".equals(extension))
          || ("GIF".equals(extension))) {

        // TODO check and warn if this isn't transparent.  Alpha?

        catalogManager.addWatermark(fileOut);

      } else {
        System.out.println(path + " not imported.");
      }
    }

    // return new ModelAndView("uploadResults", "model", model);
    return new ModelAndView("redirect:listWatermarks.html");
  }
Пример #7
0
  public void uploadAttachments(JiraTickets tickets)
      throws ExecutionException, InterruptedException, IOException {
    for (JiraTicket t : tickets) {
      Promise<Issue> issuePromise = issueRestClient.getIssue(t.getId());
      Issue i = issuePromise.get();
      File rollback = t.getRollback();
      File hotfix = t.getHotfix();

      if (rollback != null && rollback.canRead()) {
        issueRestClient.addAttachment(
            i.getAttachmentsUri(), FileUtils.openInputStream(rollback), rollback.getName());
      }

      if (hotfix != null && hotfix.canRead()) {
        issueRestClient.addAttachment(
            i.getAttachmentsUri(), FileUtils.openInputStream(hotfix), hotfix.getName());
      }
    }
  }
Пример #8
0
  public void checkPermission(
      ExtractorLayerRequest request, String secureHost, String username, String roles)
      throws IOException {
    URL capabilitiesURL = request.capabilitiesURL("WFS", "1.0.0");

    final HttpClientBuilder httpClientBuilder = HttpClientBuilder.create();
    httpClientBuilder.setUserAgent(this.userAgent);

    HttpClientContext localContext = HttpClientContext.create();
    final HttpHost httpHost =
        new HttpHost(
            capabilitiesURL.getHost(), capabilitiesURL.getPort(), capabilitiesURL.getProtocol());

    HttpGet get = new HttpGet(capabilitiesURL.toExternalForm());
    if (username != null
        && (secureHost.equalsIgnoreCase(request._url.getHost())
            || "127.0.0.1".equalsIgnoreCase(request._url.getHost())
            || "localhost".equalsIgnoreCase(request._url.getHost()))) {
      LOG.debug(
          "WfsExtractor.checkPermission - Secured Server: adding username header and role headers to request for checkPermission");

      addImpersonateUserHeaders(username, roles, get);

      enablePreemptiveBasicAuth(
          capabilitiesURL,
          httpClientBuilder,
          localContext,
          httpHost,
          _adminUsername,
          _adminPassword);
    } else {
      // use a user agent that does *not* trigger basic auth on remote server
      httpClientBuilder.setUserAgent("Apache-HttpClient");
      LOG.debug("WfsExtractor.checkPermission - Non Secured Server");
    }

    final CloseableHttpClient httpclient = httpClientBuilder.build();
    String capabilities =
        FileUtils.asString(
            httpclient.execute(httpHost, get, localContext).getEntity().getContent());
    Pattern regex =
        Pattern.compile(
            "(?m)<FeatureType[^>]*>(\\\\n|\\s)*<Name>\\s*(\\w*:)?"
                + Pattern.quote(request._layerName)
                + "\\s*</Name>");
    boolean permitted = regex.matcher(capabilities).find();

    if (!permitted) {
      throw new SecurityException(
          "User does not have sufficient privileges to access the Layer: "
              + request._layerName
              + ". \n\nCapabilities:  "
              + capabilities);
    }
  }
 static {
   FILE_UTILS = FileUtils.getFileUtils();
   AntClassLoader.pathMap = Collections.synchronizedMap(new HashMap<String, String>());
   AntClassLoader.subClassToLoad = null;
   CONSTRUCTOR_ARGS = new Class[] {ClassLoader.class, Project.class, Path.class, Boolean.TYPE};
   if (JavaEnvUtils.isAtLeastJavaVersion("1.5")) {
     try {
       AntClassLoader.subClassToLoad =
           Class.forName("org.apache.tools.ant.loader.AntClassLoader5");
     } catch (ClassNotFoundException ex) {
     }
   }
 }
Пример #10
0
  /** Create the working folder (later deleted) */
  private void createWorkingFolder() throws RuntimeException {
    if (this.workingFolder == null
        && (this.workingFolderPath == null || this.workingFolderPath.equals("")))
      throw new RuntimeException("Class needs a valid working folder!");

    if (this.workingFolder == null) {
      this.workingFolder = new File(this.workingFolderPath);
    } else {
      // sanitize working folder. If it exists and is a directory, delete
      // it. If it is a file, refuse to continue.
      if (this.workingFolder.exists()) {
        if (this.workingFolder.isFile()) {
          throw new RuntimeException("Working folder exists, and is a file!");
        }
        if (this.workingFolder.isDirectory()) {
          Logger.log("Deleting existing working directory.");
          FileUtils.deleteFolder(this.workingFolder);
        }
      }
    }

    // create temporary directory for the local repository...
    this.workingFolder = FileUtils.createFolder(this.workingFolder);
  }
 /*
  * Copy the bundle with the given id to the specified location. (location
  * is parent directory)
  */
 public void copyBundle(String bundlename, File source, File destination) throws IOException {
   if (destination == null) destination = output;
   destination = new File(destination, "eclipse/plugins");
   if (source == null) {
     Bundle bundle = TestActivator.getBundle(bundlename);
     if (bundle == null) {
       throw new IOException("Could not find: " + bundlename);
     }
     String location = bundle.getLocation();
     if (location.startsWith("reference:")) location = location.substring("reference:".length());
     source = new File(FileLocator.toFileURL(new URL(location)).getFile());
   }
   destination = new File(destination, source.getName());
   if (destination.exists()) return;
   FileUtils.copy(source, destination, new File(""), false);
   // if the target of the copy doesn't exist, then signal an error
   assertTrue("Unable to copy " + source + " to " + destination, destination.exists());
 }
Пример #12
0
  public static void main(String[] args) {
    Debug.enableAll();
    String HEADER =
        "<HEADER>"
            + "<REQUEST value=\"LSR_ORDER\"/>"
            + "<SUB_REQUEST value=\"loop\"/>"
            + "<SUPPLIER value=\"VZE\"/>"
            + "</HEADER>";
    RequestHandlerClient sr = null;

    try {
      String xml = FileUtils.readFile(args[0]);
      MessageProcessorContext ctx = new MessageProcessorContext();
      ctx.set("NF_HEADER_LOCATION_PROP", HEADER);
      sr = new RequestHandlerClient();
      sr.serverName = "Nightfire.Router";
      NVPair[] result = sr.process(ctx, new MessageObject((Object) xml));
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
Пример #13
0
  /**
   * Checks if the current column is the one we are looking for
   *
   * @param metadata
   * @param file
   * @param sblockId
   * @return if > 0 the length to read from current file offset. if -1 not relevent. if null out of
   *     bounds
   */
  private Integer isSubBlockFound(CFMetaData metadata, FileDataInput file, ByteBuffer sblockId)
      throws IOException {
    ByteBuffer name = ByteBufferUtil.readWithShortLength(file);

    // Stop if we've gone too far (return null)
    if (metadata.comparator.compare(name, sblockId) > 0) return null;

    // verify column type;
    int b = file.readUnsignedByte();

    // skip ts (since we know block ids are unique)
    long ts = file.readLong();
    int sblockLength = file.readInt();

    if (!name.equals(sblockId)
        || (b & ColumnSerializer.DELETION_MASK) != 0
        || (b & ColumnSerializer.EXPIRATION_MASK) != 0) {
      FileUtils.skipBytesFully(file, sblockLength);
      return -1;
    }

    return sblockLength;
  }
Пример #14
0
  /**
   * Save the document to a file.
   *
   * @see #write
   */
  public boolean save(String filename) {

    try {
      setFilename(filename);

      // write to tmp file
      File tmpfile = File.createTempFile("gwb", null);
      write(new FileOutputStream(tmpfile));

      // copy to dest file and delete tmp file
      FileUtils.copy(tmpfile, new File(filename));
      tmpfile.delete();

      //

      //
      fireDocumentInit();
      return true;
    } catch (Exception e) {
      LogUtils.report(e);
      return false;
    }
  }
Пример #15
0
  public static void main(String[] args) {

    Debug.enable(Debug.UNIT_TEST);
    Debug.enable(Debug.BENCHMARK);
    Debug.showLevels();
    if (args.length != 3) {
      Debug.log(
          Debug.ALL_ERRORS,
          "UnBatcher: USAGE:  " + " jdbc:oracle:thin:@192.168.164.238:1521:e911 e911 e911 ");
      return;
    }
    try {

      DBInterface.initialize(args[0], args[1], args[2]);
    } catch (DatabaseException e) {
      Debug.log(
          Debug.MAPPING_ERROR,
          "UnBatcher: " + "Database initialization failure: " + e.getMessage());
    }

    Splitter spl = new Splitter();

    try {
      MessageProcessorContext mpx = new MessageProcessorContext();
      mpx.set("FileName", "MANS9999");

      String s = FileUtils.readFile("D:\\Response\\DECCCORR.txt");
      System.out.println("length----------->>>>>" + s.length());
      MessageObject msob = new MessageObject();
      msob.set(s);
      spl.initialize("E911BATCHER", "FAX_MESSAGE_SPLITTER");
      spl.process(mpx, msob);

    } catch (Exception ex) {
      System.out.println(ex.getMessage());
    }
  }
Пример #16
0
 /** Deletes the working folder */
 private void cleanupWorkingFolder() {
   // cleanup temporary folder...
   FileUtils.deleteFolder(this.workingFolder);
 }
Пример #17
0
 private void editFile(ClientServices clientServices, File file) throws IOException {
   addBaserevEntry(clientServices, file);
   FileUtils.copyFile(file, EditCommand.getEditBackupFile(file));
   FileUtils.setFileReadOnly(file, false);
 }
Пример #18
0
  /**
   * Process one file.
   *
   * <p>\u0040param xmlFileName Input file name to check for part of speech/lemma mismatches..
   */
  protected static void processOneFile(String xmlFileName) {
    try {
      //  Report document being processed.

      System.out.println(
          "(" + ++currentDocNumber + "/" + docsToProcess + ") " + "processing " + xmlFileName);
      //  Create filter to strip <w> and <c>
      //  elements.

      XMLFilter filter = new StripAllWordElementsFilter(XMLReaderFactory.createXMLReader());
      //  Strip path from input file name.

      String strippedFileName = FileNameUtils.stripPathName(xmlFileName);

      strippedFileName = FileNameUtils.changeFileExtension(strippedFileName, "");

      //  Generate output file name.

      String xmlOutputFileName =
          new File(outputDirectoryName, strippedFileName + ".xml").getAbsolutePath();

      //  Make sure output directory exists.

      FileUtils.createPathForFile(xmlOutputFileName);

      //  Copy input xml to output xml,
      //  stripping <w> and <c> elements.

      new FilterAdornedFile(xmlFileName, xmlOutputFileName, filter);
      //  Read it back and fix spacing.

      String fixedXML = FileUtils.readTextFile(xmlOutputFileName, "utf-8");

      fixedXML = fixedXML.replaceAll("(\\s+)", " ");

      fixedXML = fixedXML.replaceAll(" ([\\.?!,;:\\)])", "\u00241");

      fixedXML = fixedXML.replaceAll("\\( ", "(");

      fixedXML = fixedXML.replaceAll("\u00b6 ", "\u00b6");

      fixedXML = fixedXML.replaceAll("__NS1:", "");

      fixedXML = fixedXML.replaceAll("__NS1", "");
      /*
                  fixedXML    =
                      fixedXML.replaceAll
                      (
                          "</__NS1:" ,
                          ""
                      );
      */
      //  Emit unadorned XML.

      SAXBuilder builder = new SAXBuilder();

      Document document = builder.build(new StringReader(fixedXML));

      new AdornedXMLWriter(document, xmlOutputFileName);
    } catch (Exception e) {
      System.out.println("   Error: " + e.getMessage());

      e.printStackTrace();
    }
  }
Пример #19
0
  /**
   * If we know in advance that the table is numeric, can optimize a lot... For example, on 9803 x
   * 294 table, TableFileLoader.readNumeric takes 6s compared to 12s for WekaMine readFromTable.
   */
  public static Instances readNumeric(String fileName, String relationName, String delimiter)
      throws Exception {

    int numAttributes = FileUtils.fastCountLines(fileName) - 1; // -1 exclude heading.
    String[] attrNames = new String[numAttributes];

    // Read the col headings and figure out the number of columns in the table..
    BufferedReader reader = new BufferedReader(new FileReader(fileName), 4194304);
    String line = reader.readLine();
    String[] instanceNames = parseColNames(line, delimiter);
    int numInstances = instanceNames.length;

    System.err.print("reading " + numAttributes + " x " + numInstances + " table..");

    // Create an array to hold the data as we read it in...
    double dataArray[][] = new double[numAttributes][numInstances];

    // Populate the matrix with values...
    String valToken = "";
    try {
      int rowIdx = 0;
      while ((line = reader.readLine()) != null) {

        String[] tokens = line.split(delimiter, -1);
        attrNames[rowIdx] = tokens[0].trim();
        for (int colIdx = 0; colIdx < (tokens.length - 1); colIdx++) {
          valToken = tokens[colIdx + 1];
          double value;

          if (valToken.equals("null")) {
            value = Instance.missingValue();
          } else if (valToken.equals("?")) {
            value = Instance.missingValue();
          } else if (valToken.equals("NA")) {
            value = Instance.missingValue();
          } else if (valToken.equals("")) {
            value = Instance.missingValue();
            // }else value = DoubleParser.lightningParse(valToken); // faster double parser with
            // MANY assumptions
          } else value = Double.parseDouble(valToken);
          dataArray[rowIdx][colIdx] = value;
        }
        rowIdx++;
      }
    } catch (NumberFormatException e) {
      System.err.println(e.toString());
      System.err.println("Parsing line: " + line);
      System.err.println("Parsing token: " + valToken);
    }

    // Set up attributes, which for colInstances will be the rowNames...
    FastVector atts = new FastVector();
    for (int a = 0; a < numAttributes; a++) {
      atts.addElement(new Attribute(attrNames[a]));
    }

    // Create Instances object..
    Instances data = new Instances(relationName, atts, 0);
    data.setRelationName(relationName);

    System.err.print("creating instances..");

    // System.err.println("DEBUG: numAttributes "+numAttributes);

    /** ***** CREATE INSTANCES ************* */
    // Fill the instances with data...
    // For each instance...
    for (int c = 0; c < numInstances; c++) {
      double[] vals =
          new double[data.numAttributes()]; // Even nominal values are stored as double pointers.

      for (int r = 0; r < numAttributes; r++) {
        double val = dataArray[r][c];
        vals[r] = val;
      }
      // Add the a newly minted instance with those attribute values...
      data.add(new Instance(1.0, vals));
    }

    // System.err.println("DEBUG: data.numInstances: "+data.numInstances());
    // System.err.println("DEBUG: data.numAttributes: "+data.numAttributes());
    // System.err.println("DEBUG: data.relationNAme"+data.relationName());
    System.err.print("add feature names..");

    /** ***** ADD FEATURE NAMES ************* */
    // takes basically zero time... all time is in previous 2 chunks.
    Instances newData = new Instances(data);
    newData.insertAttributeAt(new Attribute("ID", (FastVector) null), 0);
    int attrIdx = newData.attribute("ID").index(); // Paranoid... should be 0

    for (int c = 0; c < numInstances; c++) {
      newData.instance(c).setValue(attrIdx, instanceNames[c]);
    }
    data = newData;

    // System.err.println("DEBUG: data.numInstances: "+data.numInstances());
    // System.err.println("DEBUG: data.numAttributes: "+data.numAttributes());

    return (data);
  }
 protected void definePackage(
     final File container, final String packageName, final Manifest manifest) {
   final String sectionName = packageName.replace('.', '/') + "/";
   String specificationTitle = null;
   String specificationVendor = null;
   String specificationVersion = null;
   String implementationTitle = null;
   String implementationVendor = null;
   String implementationVersion = null;
   String sealedString = null;
   URL sealBase = null;
   final Attributes sectionAttributes = manifest.getAttributes(sectionName);
   if (sectionAttributes != null) {
     specificationTitle = sectionAttributes.getValue(Attributes.Name.SPECIFICATION_TITLE);
     specificationVendor = sectionAttributes.getValue(Attributes.Name.SPECIFICATION_VENDOR);
     specificationVersion = sectionAttributes.getValue(Attributes.Name.SPECIFICATION_VERSION);
     implementationTitle = sectionAttributes.getValue(Attributes.Name.IMPLEMENTATION_TITLE);
     implementationVendor = sectionAttributes.getValue(Attributes.Name.IMPLEMENTATION_VENDOR);
     implementationVersion = sectionAttributes.getValue(Attributes.Name.IMPLEMENTATION_VERSION);
     sealedString = sectionAttributes.getValue(Attributes.Name.SEALED);
   }
   final Attributes mainAttributes = manifest.getMainAttributes();
   if (mainAttributes != null) {
     if (specificationTitle == null) {
       specificationTitle = mainAttributes.getValue(Attributes.Name.SPECIFICATION_TITLE);
     }
     if (specificationVendor == null) {
       specificationVendor = mainAttributes.getValue(Attributes.Name.SPECIFICATION_VENDOR);
     }
     if (specificationVersion == null) {
       specificationVersion = mainAttributes.getValue(Attributes.Name.SPECIFICATION_VERSION);
     }
     if (implementationTitle == null) {
       implementationTitle = mainAttributes.getValue(Attributes.Name.IMPLEMENTATION_TITLE);
     }
     if (implementationVendor == null) {
       implementationVendor = mainAttributes.getValue(Attributes.Name.IMPLEMENTATION_VENDOR);
     }
     if (implementationVersion == null) {
       implementationVersion = mainAttributes.getValue(Attributes.Name.IMPLEMENTATION_VERSION);
     }
     if (sealedString == null) {
       sealedString = mainAttributes.getValue(Attributes.Name.SEALED);
     }
   }
   if (sealedString != null && sealedString.equalsIgnoreCase("true")) {
     try {
       sealBase = new URL(FileUtils.getFileUtils().toURI(container.getAbsolutePath()));
     } catch (MalformedURLException ex) {
     }
   }
   this.definePackage(
       packageName,
       specificationTitle,
       specificationVersion,
       specificationVendor,
       implementationTitle,
       implementationVersion,
       implementationVendor,
       sealBase);
 }
Пример #21
0
  public void doRFileEvaluate(final IScope scope) {
    final String RFile = getPath();
    try {
      // Call R
      RCaller caller = new RCaller();

      String RPath = GamaPreferences.LIB_R.value(scope).getPath();
      caller.setRscriptExecutable(RPath);
      // caller.setRscriptExecutable("\"" + RPath + "\"");
      // if(java.lang.System.getProperty("os.name").startsWith("Mac"))
      // {
      // caller.setRscriptExecutable(RPath);
      // }

      RCode c = new RCode();
      List<String> R_statements = new ArrayList<String>();

      // tmthai.begin----------------------------------------------------------------------------
      String fullPath = FileUtils.constructAbsoluteFilePath(scope, RFile, true);
      if (DEBUG) {
        GuiUtils.debug("Stats.R_compute.RScript:" + RPath);
        GuiUtils.debug("Stats.R_compute.RFile:" + RFile);
        GuiUtils.debug("Stats.R_compute.fullPath:" + fullPath);
      }

      // FileReader fr = new FileReader(RFile);
      FileReader fr = new FileReader(fullPath);
      // tmthai.end----------------------------------------------------------------------------

      BufferedReader br = new BufferedReader(fr);
      String statement;
      while ((statement = br.readLine()) != null) {
        c.addRCode(statement);
        R_statements.add(statement);
        // java.lang.System.out.println(statement);
        if (DEBUG) {
          GuiUtils.debug("Stats.R_compute.statement:" + statement);
        }
      }

      fr.close();
      br.close();
      caller.setRCode(c);

      GamaMap<String, IList> result = GamaMapFactory.create(Types.STRING, Types.LIST);

      String var = computeVariable(R_statements.get(R_statements.size() - 1).toString());
      caller.runAndReturnResult(var);
      for (String name : caller.getParser().getNames()) {
        Object[] results = null;
        results = caller.getParser().getAsStringArray(name);
        // for (int i = 0; i < results.length; i++) {
        // java.lang.System.out.println(results[i]);
        // }
        if (DEBUG) {
          GuiUtils.debug(
              "Stats.R_compute_param.caller.Name: '"
                  + name
                  + "' length: "
                  + results.length
                  + " - Value: "
                  + results.toString());
        }
        result.put(name, GamaListFactory.createWithoutCasting(Types.NO_TYPE, results));
      }
      if (DEBUG) {
        GuiUtils.debug("Stats.R_compute.return:" + result.serialize(false));
      }
      // return result;
      setBuffer(result);

    } catch (Exception ex) {

      throw GamaRuntimeException.error("RCallerExecutionException " + ex.getMessage(), scope);
    }
  }
Пример #22
0
  /**
   * Retrieves a local subBlock
   *
   * @param blockId row key
   * @param sblockId SubBlock column name
   * @param offset inside the sblock
   * @return a local sublock
   * @throws TException
   */
  private LocalBlock getLocalSubBlock(
      String subBlockCFName, ByteBuffer blockId, ByteBuffer sblockId, int offset)
      throws TException {
    DecoratedKey<Token<?>> decoratedKey =
        new DecoratedKey<Token<?>>(StorageService.getPartitioner().getToken(blockId), blockId);

    Table table = Table.open(cfsKeyspace);
    ColumnFamilyStore sblockStore = table.getColumnFamilyStore(subBlockCFName);

    Collection<SSTableReader> sstables = sblockStore.getSSTables();

    for (SSTableReader sstable : sstables) {

      long position = sstable.getPosition(decoratedKey, Operator.EQ);

      if (position == -1) continue;

      String filename = sstable.descriptor.filenameFor(Component.DATA);
      RandomAccessFile raf = null;
      int mappedLength = -1;
      MappedByteBuffer mappedData = null;
      MappedFileDataInput file = null;
      try {
        raf = new RandomAccessFile(filename, "r");
        assert position < raf.length();

        mappedLength =
            (raf.length() - position) < Integer.MAX_VALUE
                ? (int) (raf.length() - position)
                : Integer.MAX_VALUE;

        mappedData = raf.getChannel().map(FileChannel.MapMode.READ_ONLY, position, mappedLength);

        file = new MappedFileDataInput(mappedData, filename, 0);

        if (file == null) continue;

        // Verify key was found in data file
        DecoratedKey keyInDisk =
            SSTableReader.decodeKey(
                sstable.partitioner, sstable.descriptor, ByteBufferUtil.readWithShortLength(file));
        assert keyInDisk.equals(decoratedKey)
            : String.format("%s != %s in %s", keyInDisk, decoratedKey, file.getPath());

        long rowSize = SSTableReader.readRowSize(file, sstable.descriptor);

        assert rowSize > 0;
        assert rowSize < mappedLength;

        Filter bf = IndexHelper.defreezeBloomFilter(file, sstable.descriptor.usesOldBloomFilter);

        // verify this column in in this version of the row.
        if (!bf.isPresent(sblockId)) continue;

        List<IndexHelper.IndexInfo> indexList = IndexHelper.deserializeIndex(file);

        // we can stop early if bloom filter says none of the
        // columns actually exist -- but,
        // we can't stop before initializing the cf above, in
        // case there's a relevant tombstone
        ColumnFamilySerializer serializer = ColumnFamily.serializer();
        try {
          ColumnFamily cf =
              serializer.deserializeFromSSTableNoColumns(
                  ColumnFamily.create(sstable.metadata), file);

          if (cf.isMarkedForDelete()) continue;

        } catch (Exception e) {
          e.printStackTrace();

          throw new IOException(
              serializer
                  + " failed to deserialize "
                  + sstable.getColumnFamilyName()
                  + " with "
                  + sstable.metadata
                  + " from "
                  + file,
              e);
        }

        Integer sblockLength = null;

        if (indexList == null) sblockLength = seekToSubColumn(sstable.metadata, file, sblockId);
        else sblockLength = seekToSubColumn(sstable.metadata, file, sblockId, indexList);

        if (sblockLength == null || sblockLength < 0) continue;

        int bytesReadFromStart = mappedLength - (int) file.bytesRemaining();

        if (logger.isDebugEnabled())
          logger.debug("BlockLength = " + sblockLength + " Availible " + file.bytesRemaining());

        assert offset <= sblockLength : String.format("%d > %d", offset, sblockLength);

        long dataOffset = position + bytesReadFromStart;

        if (file.bytesRemaining() == 0 || sblockLength == 0) continue;

        return new LocalBlock(file.getPath(), dataOffset + offset, sblockLength - offset);

      } catch (IOException e) {
        throw new TException(e);
      } finally {
        FileUtils.closeQuietly(raf);
      }
    }

    return null;
  }
Пример #23
0
 /**
  * Check if the Tangara application is executed from a jar file.
  *
  * @return <code>true</code> if the application is executed from a jar file, <code>false</code>
  *     otherwise.
  */
 public boolean isExecutedFromJAR() {
   return FileUtils.isExtension(getTangaraPath(), JAR_FILE_EXT);
 }