<commit_before>package com.hotcats.mp4artextractor.parse;

import java.io.FileInputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.Arrays;

import com.hotcats.mp4artextractor.data.atom.Atom;

public abstract class AtomParser {

  public static final int INT_SIZE = 4;
  public static final int LONG_SIZE = 4;
  public static final int TYPE_SIZE = 4;
  public static final byte[] FTYP_BYTES = {'f', 't', 'y', 'p'};

  private final FileInputStream fileInput;
  private final int size;
  private final long extendedSize;

  public AtomParser(FileInputStream fileInput, int size, long extendedSize) {
    this.fileInput = fileInput;
    this.size = size;
    this.extendedSize = extendedSize;
  }

  public abstract Atom parse() throws IOException;

  public int getSize() {
    return size;
  }

  public long getExtendedSize() {
    return extendedSize;
  }

  public static AtomParser getAtomParser(FileInputStream fileInput) throws IOException {
    int size = readInt(fileInput);
    if (size == 0) {
      // last atom of file
    }

    byte[] type = readBytes(fileInput, TYPE_SIZE);

    long extendedSize = 0;
    if (size == 1) {
      extendedSize = readLong(fileInput);
    }

    if (Arrays.equals(FTYP_BYTES, type)) {
      return new FtypAtomParser(fileInput, size, extendedSize);
    }
    throw new UnsupportedOperationException("Illegal type: "
        + Arrays.toString(type) + " (" + new String(type) + ")");
  }

  protected int readInt() throws IOException {
    return readInt(fileInput);
  }

  private static int readInt(FileInputStream fileInput) throws IOException {
    byte[] bytes = readBytes(fileInput, INT_SIZE);
    return ByteBuffer.wrap(bytes).getInt();
  }

  protected long readLong() throws IOException {
    return readLong(fileInput);
  }

  private static long readLong(FileInputStream fileInput) throws IOException {
    byte[] bytes = readBytes(fileInput, LONG_SIZE);
    return ByteBuffer.wrap(bytes).getLong();
  }

  protected byte[] readBytes(int num) throws IOException {
    return readBytes(fileInput, num);
  }

  private static byte[] readBytes(FileInputStream fileInput, int num) throws IOException {
    byte[] bytes = new byte[num];
    fileInput.read(bytes);
    return bytes;
  }
}<commit_msg>Style cleanups.<commit_after>package com.hotcats.mp4artextractor.parse;

import java.io.FileInputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.Arrays;

import com.hotcats.mp4artextractor.data.atom.Atom;

public abstract class AtomParser {

  public static final int INT_SIZE = 4;
  public static final int LONG_SIZE = 4;
  public static final int TYPE_SIZE = 4;
  public static final byte[] FTYP_BYTES = { 'f', 't', 'y', 'p' };

  private final FileInputStream fileInput;
  private final int size;
  private final long extendedSize;

  public AtomParser(FileInputStream fileInput, int size, long extendedSize) {
    this.fileInput = fileInput;
    this.size = size;
    this.extendedSize = extendedSize;
  }

  public abstract Atom parse() throws IOException;

  public int getSize() {
    return size;
  }

  public long getExtendedSize() {
    return extendedSize;
  }

  public static AtomParser getAtomParser(FileInputStream fileInput)
      throws IOException {
    int size = readInt(fileInput);
    if (size == 0) {
      // last atom of file
    }

    byte[] type = readBytes(fileInput, TYPE_SIZE);

    long extendedSize = 0;
    if (size == 1) {
      extendedSize = readLong(fileInput);
    }

    if (Arrays.equals(FTYP_BYTES, type)) {
      return new FtypAtomParser(fileInput, size, extendedSize);
    }
    throw new UnsupportedOperationException("Illegal type: "
        + Arrays.toString(type) + " (" + new String(type) + ")");
  }

  protected int readInt() throws IOException {
    return readInt(fileInput);
  }

  private static int readInt(FileInputStream fileInput) throws IOException {
    byte[] bytes = readBytes(fileInput, INT_SIZE);
    return ByteBuffer.wrap(bytes).getInt();
  }

  protected long readLong() throws IOException {
    return readLong(fileInput);
  }

  private static long readLong(FileInputStream fileInput) throws IOException {
    byte[] bytes = readBytes(fileInput, LONG_SIZE);
    return ByteBuffer.wrap(bytes).getLong();
  }

  protected byte[] readBytes(int num) throws IOException {
    return readBytes(fileInput, num);
  }

  private static byte[] readBytes(FileInputStream fileInput, int num)
      throws IOException {
    byte[] bytes = new byte[num];
    fileInput.read(bytes);
    return bytes;
  }
}
{'fraction_non_alphanumeric': 0.09986888111888112, 'fraction_numerical': 0.0034965034965034965, 'mean_word_length': 3.7430051813471503, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '6715744', 'n_tokens_mistral': 1392, 'n_tokens_neox': 1332, 'n_words': 387}