コード例 #1
0
 @Override
 public void saveLatestModel(ComputationGraph net, double score) throws IOException {
   String confOut = FilenameUtils.concat(directory, latestFileNameConf);
   String paramOut = FilenameUtils.concat(directory, latestFileNameParam);
   String updaterOut = FilenameUtils.concat(directory, latestFileNameUpdater);
   save(net, confOut, paramOut, updaterOut);
 }
コード例 #2
0
ファイル: BaseService.java プロジェクト: Jannievzyl/TestGit
 /** Puts a response loopback path together */
 private String buildResponseLoopbackPath(
     String root, String serviceName, EEnvironment environment) throws ServiceException {
   String result = "";
   String servicePath = FilenameUtils.concat(root, serviceName);
   String environmentPath = FilenameUtils.concat(servicePath, environment.value());
   String loopbackPath = FilenameUtils.concat(environmentPath, "Loopbacks");
   String loopbackResponse = FilenameUtils.concat(loopbackPath, "Response");
   if (folderExists(loopbackResponse)) result = loopbackResponse;
   else {
     try {
       createLogFolder(servicePath);
       createLogFolder(environmentPath);
       createLogFolder(loopbackPath);
       createLogFolder(loopbackResponse);
     } catch (IOException e) {
       throw new ServiceException(
           "COR006#Could not build path(s);"
               + servicePath
               + ":"
               + environmentPath
               + ":"
               + loopbackPath);
     }
   }
   return result;
 }
コード例 #3
0
 @Override
 public ComputationGraph getLatestModel() throws IOException {
   String confOut = FilenameUtils.concat(directory, bestFileNameConf);
   String paramOut = FilenameUtils.concat(directory, bestFileNameParam);
   String updaterOut = FilenameUtils.concat(directory, bestFileNameUpdater);
   return load(confOut, paramOut, updaterOut);
 }
コード例 #4
0
ファイル: UserController.java プロジェクト: chookin/snapshot
  /** 修改头像 */
  @RequestMapping(value = "/avatar/mod", method = RequestMethod.POST)
  public ResponseMessage modAvatar(
      HttpServletRequest request, long uid, @RequestParam(value = "img") MultipartFile file)
      throws Exception {
    // save the source avatar image file, 原始尺寸
    String filename = ImageController.uploadImg(request, file).getValue();
    AvatarDetail origin = new AvatarDetail();
    origin.setPhoto(filename);
    origin.setUserId(uid);
    origin.setTime(new Timestamp(System.currentTimeMillis()));
    avatarDetailRepository.save(origin);

    // generate image of the specified size and save,指定尺寸
    String avatar =
        ThumbnailGen.getInstance(request)
            .setUploadPath(FilenameUtils.concat(ConfigManager.get("upload.basePath"), "avatar"))
            .setUid(String.valueOf(uid))
            .gen(FilenameUtils.concat(ServerHelper.getContextPath(request), filename));

    AvatarDetail thumbnail = new AvatarDetail();
    thumbnail.setPhoto(avatar);
    thumbnail.setUserId(uid);
    thumbnail.setTime(new Timestamp(System.currentTimeMillis()));
    avatarDetailRepository.save(thumbnail);

    User user = userRepository.findById(uid);
    user.setAvatar(avatar);
    userRepository.save(user);
    return new ResponseMessage().set("filename", avatar).set("url", WebMvcConfig.getUrl(avatar));
  }
コード例 #5
0
  public BasicDatastore(String dir, String name) throws SQLException, IOException {
    Preconditions.checkNotNull(dir);
    Preconditions.checkNotNull(name);

    this.datastoreDir = dir;
    this.datastoreName = name;
    this.extensionsDir = FilenameUtils.concat(this.datastoreDir, "extensions");
    String dbFilename = FilenameUtils.concat(this.datastoreDir, DB_FILE_NAME);
    this.sqlDb = SQLDatabaseFactory.openSqlDatabase(dbFilename);
    this.updateSchema();
    this.eventBus = new EventBus();
    this.attachmentManager = new AttachmentManager(this);
  }
コード例 #6
0
 @Override
 public String extensionDataFolder(String extensionName) {
   Preconditions.checkState(this.isOpen(), "Database is closed");
   Preconditions.checkArgument(
       !Strings.isNullOrEmpty(extensionName), "extension name can not be null or empty");
   return FilenameUtils.concat(this.extensionsDir, extensionName);
 }
コード例 #7
0
  public static void compress(
      File[] srcFiles, File zipFile, String compressPath, String encoding, String comment) {

    ZipArchiveOutputStream zaos = null;
    try {
      zaos = new ZipArchiveOutputStream(zipFile);

      CompressUtilsHelper.config(zaos, encoding, comment);

      if (ValidateUtilsHelper.isBlank(compressPath)) {
        compressPath = CommonsConstants.EMPTY;
      }

      for (File file : srcFiles) {
        String zipFilePath = FilenameUtils.concat(compressPath, file.getName());
        CompressUtilsHelper.compress(file, zaos, zipFilePath);
      }

      zaos.closeArchiveEntry();
      zaos.finish();
    } catch (Exception e) {
      throw new CommonsException("Compress files to " + zipFile.getPath() + " failed!", e);
    } finally {
      IOUtils.closeQuietly(zaos);
    }
  }
コード例 #8
0
ファイル: ImageController.java プロジェクト: chookin/PicWall
 /**
  * 上传图片文件
  *
  * @param request http 请求
  * @param file 照片文件
  * @throws IOException
  */
 public static Pair<String, String> uploadImg(HttpServletRequest request, MultipartFile file)
     throws IOException {
   String uploadPath = FilenameUtils.concat(ConfigManager.get("upload.basePath"), "image");
   return MultipartFileUploader.getInstance(request)
       .setUploadPath(uploadPath)
       .setDefaultExtension("png")
       .upload(file);
 }
コード例 #9
0
ファイル: GenreXmlTools.java プロジェクト: deblockt/yamj-v3
  @PostConstruct
  public void init() {
    String genreFileName = PropertyTools.getProperty("yamj3.genre.fileName");
    if (StringUtils.isBlank(genreFileName)) {
      LOG.trace("No valid genre file name configured");
      return;
    }
    if (!StringUtils.endsWithIgnoreCase(genreFileName, "xml")) {
      LOG.warn("Invalid genre file name specified: {}", genreFileName);
      return;
    }

    File xmlFile;
    if (StringUtils.isBlank(FilenameUtils.getPrefix(genreFileName))) {
      // relative path given
      String path = System.getProperty("yamj3.home");
      if (StringUtils.isEmpty(path)) {
        path = ".";
      }
      xmlFile = new File(FilenameUtils.concat(path, genreFileName));
    } else {
      // absolute path given
      xmlFile = new File(genreFileName);
    }

    if (!xmlFile.exists() || !xmlFile.isFile()) {
      LOG.warn("Genres file does not exist: {}", xmlFile.getPath());
      return;
    }
    if (!xmlFile.canRead()) {
      LOG.warn("Genres file not readble: {}", xmlFile.getPath());
      return;
    }

    LOG.debug("Initialize genres from file: {}", xmlFile.getPath());

    try {
      XMLConfiguration c = new XMLConfiguration(xmlFile);

      List<HierarchicalConfiguration> genres = c.configurationsAt("genre");
      for (HierarchicalConfiguration genre : genres) {
        String masterGenre = genre.getString("[@name]");
        List<Object> subGenres = genre.getList("subgenre");
        for (Object subGenre : subGenres) {
          LOG.debug("New genre added to map: {} -> {}", subGenre, masterGenre);
          GENRES_MAP.put(((String) subGenre).toLowerCase(), masterGenre);
        }
      }

      try {
        this.commonStorageService.updateGenresXml(GENRES_MAP);
      } catch (Exception ex) {
        LOG.warn("Failed update genres xml in database", ex);
      }
    } catch (Exception ex) {
      LOG.error("Failed parsing genre input file: " + xmlFile.getPath(), ex);
    }
  }
コード例 #10
0
  /**
   * Creates a file in the supplied path on the file system to export the contents of the supplied
   * DirectivesFile. If there is an existing file with the same name, it will be backed up and
   * deleted.
   *
   * @param file the DirectiveFile to be exported.
   * @param directoryPath the directory in which the file should be created.
   * @return a File to which the directives can be written.
   */
  public File createExportFile(DirectiveFile file, String directoryPath) {
    String fileName = file.getShortFileName();
    FileUtils.backupAndDelete(fileName, directoryPath);

    FilenameUtils.concat(directoryPath, fileName);
    File directivesFile = new File(directoryPath + fileName);

    return directivesFile;
  }
コード例 #11
0
ファイル: BaseService.java プロジェクト: Jannievzyl/TestGit
 /** Builds a logging path in the format <logRoot>/<service-name>/ */
 private String buildLogPath(String root, String serviceName) throws ServiceException {
   String servicePath = FilenameUtils.concat(root, serviceName);
   try {
     createLogFolder(servicePath);
   } catch (IOException e) {
     throw new ServiceException("COR006#Could not build path(s);" + servicePath, e);
   }
   return servicePath;
 }
コード例 #12
0
 @SneakyThrows
 public void writeFrameworkFiles(FilePath frameworkPath) {
   for (String asset : ASSETS) {
     String source = IOUtils.toString(getClass().getResourceAsStream(asset));
     String assetFileName = FilenameUtils.getName(asset);
     String destinationFilename = FilenameUtils.concat(frameworkPath.getPath(), assetFileName);
     FileUtils.write(new File(destinationFilename), source);
   }
 }
コード例 #13
0
ファイル: BaseService.java プロジェクト: Jannievzyl/TestGit
 /** Builds a logging path in the format <logRoot>/<service-name>/<environment>/ */
 private String buildLogPath(String root, String serviceName, EEnvironment environment)
     throws ServiceException {
   String servicePath = buildLogPath(root, serviceName);
   String environmentPath = FilenameUtils.concat(servicePath, environment.value());
   try {
     createLogFolder(environmentPath);
   } catch (IOException e) {
     throw new ServiceException(
         "COR006#Could not build path(s);" + servicePath + ":" + environmentPath, e);
   }
   return environmentPath;
 }
コード例 #14
0
  /** Loads all spreadsheet data into this container */
  public void load(String rootFolder) {
    try {

      File froles = new File(FilenameUtils.concat(rootFolder, FILE_ROLE));
      ExcelUtils<ImportRole> eroles = new ExcelUtils<ImportRole>(ImportRole.class, froles);
      roles = eroles.read();
      logger.debug("Read " + roles.size() + " roles from sheet");

      File fpermissions = new File(FilenameUtils.concat(rootFolder, FILE_PER));
      ExcelUtils<ImportPermission> epermissions =
          new ExcelUtils<ImportPermission>(ImportPermission.class, fpermissions);
      permissions = epermissions.read();
      logger.debug("Read " + permissions.size() + " permissions from sheet");

      // File fusers = new File(FilenameUtils.concat(rootFolder, FILE_USER));
      // ExcelUtils<ImportUser> eusers = new ExcelUtils<ImportUser>(ImportUser.class, fusers);
      // users = eusers.read();
      // logger.debug("Read " + users.size() + " users from sheet");

      // File fuserdata = new File(FilenameUtils.concat(rootFolder, FILE_USER_DATA));
      // ExcelUtils<ImportUserData> euserdata = new ExcelUtils<ImportUserData>(ImportUserData.class,
      // fuserdata);
      // userData = euserdata.read();
      // logger.debug("Read " + userData.size() + " user data from sheet");

      File fuserdata = new File(FilenameUtils.concat(rootFolder, FILE_USER_PROFILE));
      ExcelUtils<ImportUserProfile> euserdata =
          new ExcelUtils<ImportUserProfile>(ImportUserProfile.class, fuserdata);
      userProfiles = euserdata.read();
      logger.debug("Read " + userData.size() + " user data from sheet");

      File faccess = new File(FilenameUtils.concat(rootFolder, FILE_ACCESS));
      ExcelUtils<ImportAccess> eaccess = new ExcelUtils<ImportAccess>(ImportAccess.class, faccess);
      access = eaccess.read();
      logger.debug("Read " + access.size() + " access data from sheet");

    } catch (Exception e) {
      e.printStackTrace();
    }
  }
コード例 #15
0
  private static void findSourceFiles(LinkedHashSet<String> files, String file) {
    File f = new File(file);
    if (f.isFile()) {
      String ext = FilenameUtils.getExtension(f.getName());
      if ("java".equalsIgnoreCase(ext)) files.add(file);
    } else if (f.isDirectory()) {
      for (String sub : f.list()) {
        if (sub.equals(".") || sub.equals("..")) continue;

        findSourceFiles(files, FilenameUtils.concat(f.getAbsolutePath(), sub));
      }
    }
  }
コード例 #16
0
  @Override
  public void process(final Model model) {
    String identifier = null;
    try {
      identifier =
          model
              .listObjectsOfProperty(model.createProperty(filenameUtil.property))
              .next()
              .toString();
      LOG.debug("Going to store identifier=" + identifier);
    } catch (NoSuchElementException e) {
      LOG.warn("No identifier => cannot derive a filename for " + model.toString());
      return;
    }

    String directory = identifier;
    if (directory.length() >= filenameUtil.endIndex) {
      directory = directory.substring(filenameUtil.startIndex, filenameUtil.endIndex);
    }
    final String file =
        FilenameUtils.concat(
            filenameUtil.target,
            FilenameUtils.concat(
                directory + File.separator, identifier + "." + filenameUtil.fileSuffix));
    LOG.debug("Write to " + file);
    filenameUtil.ensurePathExists(file);

    try (final Writer writer =
        new OutputStreamWriter(new FileOutputStream(file), filenameUtil.encoding)) {
      final StringWriter tripleWriter = new StringWriter();
      RDFDataMgr.write(tripleWriter, model, this.serialization);
      IOUtils.write(tripleWriter.toString(), writer);
      writer.close();
    } catch (IOException e) {
      e.printStackTrace();
      throw new MetafactureException(e);
    }
  }
コード例 #17
0
 @Test
 public void testSerDeserPerf2() throws Exception {
   Kryo kryo = new Kryo();
   String outputPath = FilenameUtils.concat(getTmpPath(), "file2.bin");
   Output output = new Output(new FileOutputStream(outputPath));
   for (int i = 0; i < 1000; i++) {
     kryo.writeObject(output, constructNewPE());
   }
   output.close();
   Input input = new Input(new FileInputStream(outputPath));
   NewPartitionedEvent someObject = kryo.readObject(input, NewPartitionedEvent.class);
   input.close();
   Assert.assertTrue(someObject.getData().length == 1);
 }
コード例 #18
0
ファイル: BaseService.java プロジェクト: Jannievzyl/TestGit
 /**
  * Builds a logging path in the format <logRoot>/<service-name>/<environment>/<request or response
  * or error>
  */
 private String buildLogPath(
     String root, String serviceName, EEnvironment environment, EMessagePart part)
     throws ServiceException {
   String result = "";
   String environmentPath = buildLogPath(root, serviceName, environment);
   String partPath = FilenameUtils.concat(environmentPath, part.value());
   String loopbackPath = FilenameUtils.concat(environmentPath, "Loopbacks");
   String loopbackRequest = FilenameUtils.concat(loopbackPath, "Request");
   String loopbackResponse = FilenameUtils.concat(loopbackPath, "Response");
   if (folderExists(partPath)) result = partPath;
   else {
     try {
       createLogFolder(partPath);
       // create loopback folders
       createLogFolder(loopbackPath);
       createLogFolder(loopbackRequest);
       createLogFolder(loopbackResponse);
     } catch (IOException e) {
       throw new ServiceException(
           "COR006#Could not build path(s);" + environmentPath + ":" + partPath, e);
     }
   }
   return result;
 }
コード例 #19
0
 // Create a file by append uploadId to filePath with "_" separator
 private void createUploadResource(String filePath, String uploadId) throws IOException {
   String tempPath =
       FilenameUtils.removeExtension(filePath)
           + "_"
           + uploadId
           + "."
           + FilenameUtils.getExtension(filePath);
   tempPath = tempPath.replaceAll("^/", "");
   tempPath = FilenameUtils.concat(tmpUploadFolder.dir().getCanonicalPath(), tempPath);
   try {
     new File(tempPath).getParentFile().mkdirs();
     new File(tempPath).createNewFile();
   } catch (IOException e) {
     throw new IllegalStateException("Unable to create upload resource");
   }
 }
コード例 #20
0
  /**
   * Submits a resourceJob installation job.
   *
   * @param session
   * @param resourceJob
   * @throws Exception
   */
  public void submitResourceInstall(JobArea jobArea, Session session, ResourceJob resourceJob)
      throws Exception {
    resourceJob.setTag(this.jobTag);

    jobArea.createTag(resourceJob.getTag());
    final File taskLocalDir = new File(jobArea.getBasename(resourceJob.getTag()));

    // get the wrapper script
    URL wrapperScriptURL = getClass().getClassLoader().getResource(this.wrapperScript);
    FileUtils.copyURLToFile(
        wrapperScriptURL, new File(jobArea.getBasename(resourceJob.getTag()), this.wrapperScript));

    FileUtils.writeStringToFile(
        new File(jobArea.getBasename(resourceJob.getTag()), constantsTemplate),
        writeConstants(jobArea, resourceJob));

    copyArtifactsPbRequests(
        resourceJob.getSourceConfig(), this.environmentScriptFilename, taskLocalDir);

    copyResourceFiles(
        registry.findByTypedId("GOBYWEB_SERVER_SIDE", ResourceConfig.class), taskLocalDir);

    copyResourceFiles(resourceJob.getSourceConfig(), taskLocalDir);
    AutoOptionsFileHelper helper = new AutoOptionsFileHelper(registry);

    File autoOptions =
        helper.generateAutoOptionsFile(new ResourceJobWrapper(resourceJob.getSourceConfig()));
    FileUtils.moveFile(
        autoOptions,
        new File(FilenameUtils.concat(taskLocalDir.getAbsolutePath(), "auto-options.sh")));
    // give execute permission to resourceJob scripts
    String[] binaryFiles =
        new String[] {"groovy", this.wrapperScript, "auto-options.sh", "constants.sh"};
    jobArea.grantExecutePermissions(resourceJob.getTag(), binaryFiles);

    // execute the resourceJob
    logger.info(
        String.format(
            "Resource %s: submitting to local cluster at %s...",
            resourceJob.getTag(), taskLocalDir.getAbsolutePath()));
    Map<String, String> env = new HashMap<String, String>();
    env.put("JOB_DIR", taskLocalDir.getAbsolutePath());
    env.put("PATH", System.getenv("PATH"));
    jobArea.execute(resourceJob.getTag(), this.wrapperScript, env);
  }
コード例 #21
0
 /*
  * (non-Javadoc)
  *
  * @see org.abstracthorizon.proximity.storage.local.AbstractLocalStorage#listItems(java.lang.String)
  */
 public List listItems(String path) {
   logger.debug("Listing {} in storage directory {}", path, getStorageBaseDir());
   List result = new ArrayList();
   File target = new File(getStorageBaseDir(), path);
   if (target.exists()) {
     if (target.isDirectory()) {
       File[] files = target.listFiles();
       for (int i = 0; i < files.length; i++) {
         ItemProperties item = loadItemProperties(FilenameUtils.concat(path, files[i].getName()));
         result.add(item);
       }
     } else {
       ItemProperties item = loadItemProperties(path);
       result.add(item);
     }
   }
   return result;
 }
コード例 #22
0
  public TimelineMetricClusterAggregatorHourly(
      PhoenixHBaseAccessor hBaseAccessor, Configuration metricsConf) {
    super(hBaseAccessor, metricsConf);

    String checkpointDir =
        metricsConf.get(TIMELINE_METRICS_AGGREGATOR_CHECKPOINT_DIR, DEFAULT_CHECKPOINT_LOCATION);

    checkpointLocation =
        FilenameUtils.concat(checkpointDir, CLUSTER_AGGREGATOR_HOURLY_CHECKPOINT_FILE);

    sleepIntervalMillis =
        SECONDS.toMillis(metricsConf.getLong(CLUSTER_AGGREGATOR_HOUR_SLEEP_INTERVAL, 3600l));
    checkpointCutOffIntervalMillis =
        SECONDS.toMillis(
            metricsConf.getLong(CLUSTER_AGGREGATOR_HOUR_CHECKPOINT_CUTOFF_INTERVAL, 7200l));
    checkpointCutOffMultiplier =
        metricsConf.getInt(CLUSTER_AGGREGATOR_HOUR_CHECKPOINT_CUTOFF_MULTIPLIER, 2);
  }
コード例 #23
0
ファイル: ZipLister.java プロジェクト: shrekwang/jvifm
  private File extractToTemp(FileObject fileObject) {
    String basename = fileObject.getName().getBaseName();
    File tempFile = null;
    try {
      String tmpPath = System.getProperty("java.io.tmpdir");
      tempFile = new File(FilenameUtils.concat(tmpPath, basename));

      byte[] buf = new byte[4096];
      BufferedInputStream bin = new BufferedInputStream(fileObject.getContent().getInputStream());
      BufferedOutputStream bout = new BufferedOutputStream(new FileOutputStream(tempFile));
      while (bin.read(buf, 0, 1) != -1) {
        bout.write(buf, 0, 1);
      }
      bout.close();
      bin.close(); // by barney
    } catch (Throwable e) {
      e.printStackTrace();
    }
    return tempFile;
  }
コード例 #24
0
ファイル: ExecutionOrder.java プロジェクト: panwoman/JBEAM
 /**
  * Saves the state of the batch for revision runs usage If the current batch is 1000 and revision
  * is 1 then the file would be saved as '1000_1.savepoint'
  *
  * @param batchContext The job batchContext of the batch
  * @throws BatchException Any exception occurred during the serialization process
  */
 public static synchronized void saveBatchState(BatchContext batchContext) throws BatchException {
   BatchInfo toSaveBatchInfo = batchContext.getBatchInfo();
   toSaveBatchInfo.setProgressLevelAtLastSavePoint(
       (ProgressLevel)
           ProgressLevel.getProgressLevel(toSaveBatchInfo.getBatchNo())
               .clone()); // clone is necessary as ProgresLevel is static
   if (logger.isDebugEnabled()) {
     logger.debug(
         "Saving Current Batch progress level as ==>"
             + ProgressLevel.getProgressLevel(toSaveBatchInfo.getBatchNo()).toString());
   }
   String savepointFilePath =
       Configurations.getConfigurations().getConfigurations("CORE", "SAVEPOINT", "DIRECTORY");
   ObjectOutputStream oos = null;
   try {
     oos =
         new ObjectOutputStream(
             new FileOutputStream(
                 FilenameUtils.concat(
                     savepointFilePath,
                     toSaveBatchInfo.getBatchNo()
                         + "_"
                         + toSaveBatchInfo.getBatchRevNo()
                         + ".savepoint")));
     oos.writeObject(toSaveBatchInfo);
     oos.flush();
     batchContext.setBatchStateSaved(true);
   } catch (FileNotFoundException e) {
     batchContext.setBatchStateSaved(false);
     logger.error(e);
     throw new BatchException(e.getMessage(), e);
   } catch (IOException e) {
     batchContext.setBatchStateSaved(false);
     logger.error(e);
     throw new BatchException(e.getMessage(), e);
   } finally {
     IOUtils.closeQuietly(oos);
   }
 }
コード例 #25
0
  public static void compress(File srcFile, ZipArchiveOutputStream zaos, String compressPath) {

    // 压缩文件
    if (srcFile.isFile()) {
      CompressUtilsHelper.addZipEntry(srcFile, zaos, compressPath);
      return;
    }

    File[] subFiles = srcFile.listFiles();

    // 压缩空目录
    if (subFiles.length == 0) {
      CompressUtilsHelper.addZipEntry(srcFile, zaos, compressPath);
      return;
    }

    // 压缩非空目录
    for (File subFile : subFiles) {
      String zipFileName = subFile.getName();
      String zipFilePath = FilenameUtils.concat(compressPath, zipFileName);
      CompressUtilsHelper.compress(subFile, zaos, zipFilePath);
    }
  }
コード例 #26
0
 /**
  * Upload files.
  *
  * @param user current user
  * @param path path
  * @param description description
  * @param file multipart file
  * @param model model
  * @return script/scriptList
  */
 @RequestMapping(value = "/upload/**", method = RequestMethod.POST)
 public String uploadFiles(
     User user,
     @RemainedPath String path,
     @RequestParam("description") String description,
     @RequestParam("uploadFile") MultipartFile file,
     ModelMap model) {
   try {
     FileEntry fileEntry = new FileEntry();
     if (fileEntry.getFileType().isEditable()) {
       fileEntry.setContent(new String(file.getBytes()));
     } else {
       fileEntry.setContentBytes(file.getBytes());
     }
     fileEntry.setDescription(description);
     fileEntry.setPath(
         FilenameUtils.separatorsToUnix(FilenameUtils.concat(path, file.getOriginalFilename())));
     fileEntryService.save(user, fileEntry);
     return "redirect:/script/list/" + path;
   } catch (IOException e) {
     LOG.error("Error while getting file content:" + e.getMessage(), e);
     throw new NGrinderRuntimeException("Error while getting file content:" + e.getMessage(), e);
   }
 }
コード例 #27
0
 /** 获取存放监控指标的目录 */
 public static File getStorageDirectory(String application) {
   String directoryPath = FilenameUtils.concat(SystemUtils.JAVA_IO_TMPDIR, "javamelody");
   return new File(FilenameUtils.concat(directoryPath, application));
 }
コード例 #28
0
ファイル: Main.java プロジェクト: ianjohnson/testrobot
 static {
   defaultTestInfoDirName = FilenameUtils.concat(".", ITRTestInputProvider.testInfDirName);
   defaultTestResultsDirName = FilenameUtils.concat(".", ITRTestOutputManager.testResDirName);
   defaultPropertiesFileName = FilenameUtils.concat(defaultTestInfoDirName, propertiesFile);
   defaultLogFileName = FilenameUtils.concat(".", logFile);
 }
コード例 #29
0
  /**
   * Generate N source models (each represented by an array list of GEMSourceData objects), by
   * randomly sampling the source model logic tree.
   *
   * @param lt : source model logic tree
   * @param N : number of models to be generated
   * @param seed : seed number for the random number generator
   * @return
   */
  public List<GEMSourceData> sampleSourceModelLogicTree(
      LogicTree<ArrayList<GEMSourceData>> lt, long seed) {

    List<GEMSourceData> srcList = null;
    Random rn = new Random(seed);

    // sample first branching level to get the starting source model
    int branchNumber = lt.sampleBranchingLevel(0, rn);
    LogicTreeBranch branch = lt.getBranchingLevel(0).getBranch(branchNumber - 1);
    if (branch.getNameInputFile() != null) {
      String sourceName = null;
      if (hasPath) { // job from file
        sourceName = configFilesPath() + branch.getNameInputFile();
      } else { // job from kvs
        sourceName = FilenameUtils.concat(config.getString("BASE_PATH"), branch.getNameInputFile());
      }

      SourceModelReader sourceModelReader =
          new SourceModelReader(sourceName, config.getDouble(ConfigItems.WIDTH_OF_MFD_BIN.name()));

      // load sources
      srcList = sourceModelReader.read();

    } else {
      String msg =
          "The first branching level of the ERF logic tree does"
              + " not contain a source model!!\n"
              + "Please correct your input!\n Execution stopped!";
      logger.info(msg);
      throw new IllegalArgumentException(msg);
    }

    // loop over sources
    // for each source, loop over remaining branching levels and apply
    // uncertainties
    int numBranchingLevels = lt.getBranchingLevelsList().size();
    int sourceIndex = 0;
    for (GEMSourceData src : srcList) {
      for (int i = 1; i < numBranchingLevels; i++) {
        // sample the current branching level
        branchNumber = lt.sampleBranchingLevel(i, rn);
        // get the sampled branch
        branch = lt.getBranchingLevel(i).getBranch(branchNumber - 1);
        if (branch.getRule() != null) {
          // at the moment we apply rules to all source
          // typologies. In
          // the future we may want
          // to apply some filter (i.e. apply rule to this source
          // type
          // only...)
          // if area source
          if (src instanceof GEMAreaSourceData) {
            // replace the old source with the new source
            // accordingly to the rule
            srcList.set(
                sourceIndex, applyRuleToAreaSource((GEMAreaSourceData) src, branch.getRule()));
          }
          // if point source
          if (src instanceof GEMPointSourceData) {
            // replace the old source with the new source
            // accordingly to the rule
            srcList.set(
                sourceIndex, applyRuleToPointSource((GEMPointSourceData) src, branch.getRule()));
          }
          // if fault source
          if (src instanceof GEMFaultSourceData) {
            // replace the old source with the new source
            // accordingly to the rule
            srcList.set(
                sourceIndex, applyRuleToFaultSource((GEMFaultSourceData) src, branch.getRule()));
          }
          // if subduction source
          if (src instanceof GEMSubductionFaultSourceData) {
            // replace the old source with the new source
            // accordingly to the rule
            srcList.set(
                sourceIndex,
                applyRuleToSubductionFaultSource(
                    (GEMSubductionFaultSourceData) src, branch.getRule()));
          }
        } else {
          // rule is not defined:
          String msg =
              "No rule is defined at branching level: "
                  + i
                  + "\n"
                  + "Please correct your input!\n"
                  + "Execution stopped!";
          logger.info(msg);
          throw new IllegalArgumentException(msg);
        } // end if no rule is defined
      } // end loop over branching levels
      sourceIndex = sourceIndex + 1;
    } // end loop over sources
    return srcList;
  }
コード例 #30
0
ファイル: ExecutionOrder.java プロジェクト: panwoman/JBEAM
  /**
   * Reads the saved state of the batch for revision runs If the current batch number it 1000 and
   * revision is 5, then this method would look for saved state of batch 1000 with revision (5 - 1)
   * i.e. '1000_4.savepoint'
   *
   * @param batchContext The context for the batch
   * @throws BatchException Any exception thrown during reading of the serialized file
   */
  public static synchronized void updateBatchState(BatchContext batchContext)
      throws BatchException {
    BatchInfo newBatchInfo = batchContext.getBatchInfo();
    String savepointFilePath =
        Configurations.getConfigurations().getConfigurations("CORE", "SAVEPOINT", "DIRECTORY");
    String savePointFile =
        FilenameUtils.concat(
            savepointFilePath,
            newBatchInfo.getBatchNo() + "_" + (newBatchInfo.getBatchRevNo() - 1) + ".savepoint");
    if (logger.isDebugEnabled()) {
      logger.debug("Reading the saved state from file : " + savePointFile);
    }
    FileInputStream fis = null;
    try {

      // Check whether the file exists
      File f = new File(savePointFile);
      if (!f.exists())
        throw new BatchException("Cannot locate the the save point file named :" + savePointFile);

      fis = new FileInputStream(f);
      ObjectInputStream ois = new ObjectInputStream(fis);
      BatchInfo savedBatchInfo = (BatchInfo) ois.readObject();
      newBatchInfo.setOrderedMap(savedBatchInfo.getOrderedMap());
      newBatchInfo.setProgressLevelAtLastSavePoint(
          (ProgressLevel)
              savedBatchInfo
                  .getProgressLevelAtLastSavePoint()); // This object is different but still cloned.
      newBatchInfo.setBatchRunDate(savedBatchInfo.getBatchRunDate());
      newBatchInfo.setDateRun(savedBatchInfo.isDateRun());

      if (logger.isDebugEnabled()) {
        logger.debug(
            "Last batch saved state is "
                + savedBatchInfo.getProgressLevelAtLastSavePoint().toString());
      }
      // Set the ExecutionStatus in the ProgressLevel
      ExecutionStatus savedExecutionStatus =
          newBatchInfo.getProgressLevelAtLastSavePoint().getExecutionStatus();
      ProgressLevel.getProgressLevel(newBatchInfo.getBatchNo())
          .setExecutionStatus(
              savedExecutionStatus.getEntity(), savedExecutionStatus.getStageCode());
      fis.close();
      fis = null;
      ois.close();
      ois = null;
    } catch (FileNotFoundException e) {
      logger.error(e);
      throw new BatchException(e.getMessage(), e);
    } catch (IOException e) {
      logger.error(e);
      throw new BatchException(e.getMessage(), e);
    } catch (ClassNotFoundException e) {
      logger.error(e);
      throw new BatchException(e.getMessage(), e);
    } finally {
      if (fis != null) {
        try {
          fis.close();
        } catch (IOException e) {
        }
      }
    }
  }