コード例 #1
0
ファイル: DiskData.java プロジェクト: LukasK/basex
  @Override
  public void createIndex(final IndexType type, final MainOptions options, final Command cmd)
      throws IOException {

    // close existing index
    close(type);
    final IndexBuilder ib;
    switch (type) {
      case TEXT:
        ib = new DiskValuesBuilder(this, options, true);
        break;
      case ATTRIBUTE:
        ib = new DiskValuesBuilder(this, options, false);
        break;
      case FULLTEXT:
        ib = new FTBuilder(this, options);
        break;
      default:
        throw Util.notExpected();
    }
    if (cmd != null) cmd.proc(ib);
    set(type, ib.build());
  }
コード例 #2
0
    public Reader() {
      File indexFile = getIndexFile();
      File outputsFile = getOutputsFile();

      if (outputsFile.exists()) {
        if (!indexFile.exists()) {
          throw new IllegalStateException(
              String.format(
                  "Test outputs data file '%s' exists but the index file '%s' does not",
                  outputsFile, indexFile));
        }

        Input input;
        try {
          input = new Input(new FileInputStream(indexFile));
        } catch (FileNotFoundException e) {
          throw new UncheckedIOException(e);
        }

        IndexBuilder rootBuilder = null;
        try {
          int numClasses = input.readInt(true);
          rootBuilder = new IndexBuilder();

          for (int classCounter = 0; classCounter < numClasses; ++classCounter) {
            long classId = input.readLong(true);
            IndexBuilder classBuilder = new IndexBuilder();

            int numEntries = input.readInt(true);
            for (int entryCounter = 0; entryCounter < numEntries; ++entryCounter) {
              long testId = input.readLong(true);
              Region stdOut = new Region(input.readLong(), input.readLong());
              Region stdErr = new Region(input.readLong(), input.readLong());
              classBuilder.add(testId, new Index(stdOut, stdErr));
            }

            rootBuilder.add(classId, classBuilder.build());
          }
        } finally {
          input.close();
        }

        index = rootBuilder.build();

        try {
          dataFile = new RandomAccessFile(getOutputsFile(), "r");
        } catch (FileNotFoundException e) {
          throw new UncheckedIOException(e);
        }
      } else { // no outputs file
        if (indexFile.exists()) {
          throw new IllegalStateException(
              String.format(
                  "Test outputs data file '{}' does not exist but the index file '{}' does",
                  outputsFile,
                  indexFile));
        }

        index = null;
        dataFile = null;
      }
    }