<commit_before>/**
 * 
 */
package org.carcv.core;

import java.awt.Rectangle;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardOpenOption;

import javax.imageio.ImageIO;
import javax.imageio.ImageReadParam;
import javax.imageio.ImageReader;
import javax.imageio.stream.ImageInputStream;

/**
 * @author oskopek
 * 
 */
public class ImageFile { //TODO finish

    private BufferedImage bufImage;

    //private URI filepath;

    private Path filepath;

    public ImageFile(Path filepath) {
        this.filepath = filepath;
    }

    public void loadImage() throws IOException {
        InputStream inStream = Files.newInputStream(filepath, StandardOpenOption.READ);

        ImageInputStream imageStream = ImageIO.createImageInputStream(inStream);
        ImageReader reader = ImageIO.getImageReaders(imageStream).next();
        ImageReadParam param = reader.getDefaultReadParam();

        reader.setInput(imageStream, true, true);

        this.bufImage = reader.read(0, param);

        reader.dispose();
        imageStream.close();
        inStream.close();
    }

    public void loadFragment(InputStream stream, Rectangle rect) throws IOException {
        ImageInputStream imageStream = ImageIO.createImageInputStream(stream);
        ImageReader reader = ImageIO.getImageReaders(imageStream).next();
        ImageReadParam param = reader.getDefaultReadParam();

        param.setSourceRegion(rect);
        reader.setInput(imageStream, true, true);

        this.bufImage = reader.read(0, param);

        reader.dispose();
        imageStream.close();
    }
<commit_msg>ImageFile implements AutoCloseable<commit_after>/**
 * 
 */
package org.carcv.core;

import java.awt.Rectangle;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardOpenOption;

import javax.imageio.ImageIO;
import javax.imageio.ImageReadParam;
import javax.imageio.ImageReader;
import javax.imageio.stream.ImageInputStream;

/**
 * @author oskopek
 * 
 */
public class ImageFile implements AutoCloseable { //TODO finish

    private BufferedImage bufImage;

    private Path filepath;

    public ImageFile(Path filepath) {
        this.filepath = filepath;
    }

    public void loadImage() throws IOException {
        InputStream inStream = Files.newInputStream(filepath, StandardOpenOption.READ);

        ImageInputStream imageStream = ImageIO.createImageInputStream(inStream);
        ImageReader reader = ImageIO.getImageReaders(imageStream).next();
        ImageReadParam param = reader.getDefaultReadParam();

        reader.setInput(imageStream, true, true);

        this.bufImage = reader.read(0, param);

        reader.dispose();
        imageStream.close();
        inStream.close();
    }

    public void loadFragment(InputStream stream, Rectangle rect) throws IOException {
        ImageInputStream imageStream = ImageIO.createImageInputStream(stream);
        ImageReader reader = ImageIO.getImageReaders(imageStream).next();
        ImageReadParam param = reader.getDefaultReadParam();

        param.setSourceRegion(rect);
        reader.setInput(imageStream, true, true);

        this.bufImage = reader.read(0, param);

        reader.dispose();
        imageStream.close();
    }

    @Override
    public void close() throws Exception {
        bufImage.flush();
    }

{'fraction_non_alphanumeric': 0.10076422303990942, 'fraction_numerical': 0.0011321822813472968, 'mean_word_length': 3.4396984924623117, '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': '4437025', 'n_tokens_mistral': 985, 'n_tokens_neox': 956, 'n_words': 206}