Example #1
0
  public OMultiFileSegment(
      final OStorageLocal iStorage,
      final OStorageSegmentConfiguration iConfig,
      final String iFileExtension,
      final int iRoundMaxSize)
      throws IOException {
    super(iStorage, iConfig.name);

    config = iConfig;
    fileExtension = iFileExtension;
    type = iConfig.fileType;
    defrag = iConfig.defrag;
    maxSize = OFileUtils.getSizeAsNumber(iConfig.maxSize);
    fileStartSize = (int) OFileUtils.getSizeAsNumber(iConfig.fileStartSize);
    final int tmpFileMaxSize = (int) OFileUtils.getSizeAsNumber(iConfig.fileMaxSize);
    fileIncrementSize = (int) OFileUtils.getSizeAsNumber(iConfig.fileIncrementSize);

    if (iRoundMaxSize > 0)
      // ROUND THE FILE SIZE TO AVOID ERRORS ON ROUNDING BY DIVIDING FOR FIXED RECORD SIZE
      fileMaxSize = (tmpFileMaxSize / iRoundMaxSize) * iRoundMaxSize;
    else fileMaxSize = tmpFileMaxSize;
    // INSTANTIATE ALL THE FILES
    int perFileMaxSize;

    if (iConfig.infoFiles.length == 0) {
      // EMPTY FILE: CREATE THE FIRST FILE BY DEFAULT
      files = new OFile[1];
      files[0] =
          OFileFactory.instance()
              .create(
                  type,
                  iStorage
                      .getVariableParser()
                      .resolveVariables(
                          config.getLocation() + "/" + name + "." + 0 + fileExtension),
                  iStorage.getMode());
      perFileMaxSize = fileMaxSize;
      files[0].setMaxSize(perFileMaxSize);
      files[0].setIncrementSize(fileIncrementSize);

    } else {
      files = new OFile[iConfig.infoFiles.length];
      for (int i = 0; i < files.length; ++i) {
        files[i] =
            OFileFactory.instance()
                .create(
                    type,
                    iStorage.getVariableParser().resolveVariables(iConfig.infoFiles[i].path),
                    iStorage.getMode());
        perFileMaxSize = fileMaxSize;

        files[i].setMaxSize(perFileMaxSize);
        files[i].setIncrementSize(fileIncrementSize);
      }
    }
  }
Example #2
0
  private OFile createNewFile() throws IOException {
    final int num = files.length - 1;

    final OFile file =
        OFileFactory.instance()
            .create(
                type,
                config.getLocation() + "/" + name + "." + num + fileExtension,
                storage.getMode());
    file.setMaxSize(fileMaxSize);
    file.create(fileStartSize);
    files[num] = file;

    addInfoFileConfigEntry(file);

    return file;
  }