<commit_before>package org.basex.examples.create;

import static org.basex.util.Token.*;
import java.io.File;
import java.io.IOException;
import org.basex.build.Builder;
import org.basex.build.Parser;

/**
 * This class serves as a simple filesystem parser and creates an XML
 * representation, which resembles the DeepFS markup.
 *
 * @author BaseX Team 2005-11, BSD License
 * @author <NAME>
 */
public final class SimpleFSParser extends Parser {
  /** FS Token. */
  private static final byte[] DIR = token("dir");
  /** FS Token. */
  private static final byte[] FILE = token("file");
  /** FS Token. */
  private static final byte[] FSML = token("fsml");
  /** FS Token. */
  private static final byte[] MTIME = token("mtime");
  /** FS Token. */
  private static final byte[] NAME = token("name");
  /** FS Token. */
  private static final byte[] SIZE = token("size");
  /** FS Token. */
  private static final byte[] SUFFIX = token("suffix");

  /**
   * Constructor.
   * @param path file path
   */
  public SimpleFSParser(final String path) {
    super(path);
  }

  @Override
  public void parse(final Builder b) throws IOException {
    b.startDoc(token(src.name()));
    b.startElem(FSML, atts.reset());
    parse(new File(src.path()), b);
    b.endElem(FSML);
    b.endDoc();
  }

  /**
   * Recursively parses the specified directory.
   * @param dir directory to be parsed
   * @param b builder instance
   * @throws IOException I/O exception
   */
  private void parse(final File dir, final Builder b) throws IOException {
    atts.reset();
    atts.add(NAME, token(dir.getName()));
    atts.add(MTIME, token(dir.lastModified()));
    b.startElem(DIR, atts);
    for(final File f : dir.listFiles()) {
      if(f.isDirectory()) {
        parse(f, b);
      } else {
        atts.reset();
        final String name = f.getName();
        atts.add(NAME, token(name));
        atts.add(SIZE, token(f.length()));
        atts.add(MTIME, token(f.lastModified()));
        int i = name.lastIndexOf('.');
        if(i != -1) atts.add(SUFFIX, token(name.substring(i + 1)));
        b.emptyElem(FILE, atts);
      }
    }
    b.endElem(DIR);
  }
}<commit_msg>[MOD] Storage: builder simplified; tag removed from Builder.endElem()<commit_after>package org.basex.examples.create;

import static org.basex.util.Token.*;
import java.io.File;
import java.io.IOException;
import org.basex.build.Builder;
import org.basex.build.Parser;

/**
 * This class serves as a simple filesystem parser and creates an XML
 * representation, which resembles the DeepFS markup.
 *
 * @author BaseX Team 2005-11, BSD License
 * @author <NAME>
 */
public final class SimpleFSParser extends Parser {
  /** FS Token. */
  private static final byte[] DIR = token("dir");
  /** FS Token. */
  private static final byte[] FILE = token("file");
  /** FS Token. */
  private static final byte[] FSML = token("fsml");
  /** FS Token. */
  private static final byte[] MTIME = token("mtime");
  /** FS Token. */
  private static final byte[] NAME = token("name");
  /** FS Token. */
  private static final byte[] SIZE = token("size");
  /** FS Token. */
  private static final byte[] SUFFIX = token("suffix");

  /**
   * Constructor.
   * @param path file path
   */
  public SimpleFSParser(final String path) {
    super(path);
  }

  @Override
  public void parse(final Builder b) throws IOException {
    b.startDoc(token(src.name()));
    b.startElem(FSML, atts.reset());
    parse(new File(src.path()), b);
    b.endElem();
    b.endDoc();
  }

  /**
   * Recursively parses the specified directory.
   * @param dir directory to be parsed
   * @param b builder instance
   * @throws IOException I/O exception
   */
  private void parse(final File dir, final Builder b) throws IOException {
    atts.reset();
    atts.add(NAME, token(dir.getName()));
    atts.add(MTIME, token(dir.lastModified()));
    b.startElem(DIR, atts);
    for(final File f : dir.listFiles()) {
      if(f.isDirectory()) {
        parse(f, b);
      } else {
        atts.reset();
        final String name = f.getName();
        atts.add(NAME, token(name));
        atts.add(SIZE, token(f.length()));
        atts.add(MTIME, token(f.lastModified()));
        int i = name.lastIndexOf('.');
        if(i != -1) atts.add(SUFFIX, token(name.substring(i + 1)));
        b.emptyElem(FILE, atts);
      }
    }
    b.endElem();
  }
}
{'fraction_non_alphanumeric': 0.15590047934261583, 'fraction_numerical': 0.0036521342159324356, 'mean_word_length': 2.951307484220018, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4151686', 'n_tokens_mistral': 1436, 'n_tokens_neox': 1366, 'n_words': 393}