<commit_before>/*
 *  Copyright 2017 <NAME>.
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */

package org.teavm.classlib.java.io;

import java.io.File;
import java.io.IOException;
import java.io.Serializable;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Arrays;
import java.util.Objects;
import org.teavm.classlib.fs.VirtualFile;
import org.teavm.classlib.fs.VirtualFileSystem;
import org.teavm.classlib.fs.VirtualFileSystemProvider;
import org.teavm.classlib.java.util.TRandom;

public class TFile implements Serializable, Comparable<TFile> {
    private String path;

    public static final char separatorChar = fs().isWindows() ? '\\' : '/';
    public static final String separator = String.valueOf(separatorChar);
    public static final char pathSeparatorChar = fs().isWindows() ? ';' : ':';
    public static final String pathSeparator = String.valueOf(pathSeparatorChar);

    private static int counter;

    public TFile(TFile dir, String name) {
        Objects.requireNonNull(name);
        path = dir == null ? fixSlashes(name) : calculatePath(dir.getPath(), name);
    }

    public TFile(String path) {
        Objects.requireNonNull(path);
        this.path = fixSlashes(path);
    }

    public TFile(String dir, String name) {
        Objects.requireNonNull(name);
        path = dir == null ? fixSlashes(name) : calculatePath(dir, name);
    }

    public TFile(URI uri) {
        // check pre-conditions
        checkURI(uri);
        String path = uri.getPath();
        if (fs().isWindows() && path.startsWith("/") && path.length() >= 4) {
            if (isDriveLetter(path.charAt(1)) && path.charAt(2) == ':' && path.charAt(3) == '/') {
                path = path.substring(1);
            }
        }
        this.path = fixSlashes(path);
    }

    private void checkURI(URI uri) {
        if (!uri.isAbsolute()) {
            throw new IllegalArgumentException();
        } else if (!uri.getRawSchemeSpecificPart().startsWith("/")) {
            throw new IllegalArgumentException();
        }

        String temp = uri.getScheme();
        if (temp == null || !temp.equals("file")) {
            throw new IllegalArgumentException();
        }

        temp = uri.getRawPath();
        if (temp == null || temp.length() == 0) {
            throw new IllegalArgumentException();
        }

        if (uri.getRawAuthority() != null) {
            throw new IllegalArgumentException();
        }

        if (uri.getRawQuery() != null) {
            throw new IllegalArgumentException();
        }

        if (uri.getRawFragment() != null) {
            throw new IllegalArgumentException();
        }
    }

    public boolean canRead() {
        VirtualFile virtualFile = findVirtualFile();
        return virtualFile != null && virtualFile.canRead();
    }

    public boolean canWrite() {
        VirtualFile virtualFile = findVirtualFile();
        return virtualFile != null && virtualFile.canWrite();
    }

    @Override
    public int compareTo(TFile o) {
        return path.compareTo(o.path);
    }

    public String getPath() {
        return path;
    }

    public String getName() {
        int separatorIndex = path.lastIndexOf(separator);
        return separatorIndex < 0 ? path : path.substring(separatorIndex + 1, path.length());
    }

    private static VirtualFileSystem fs() {
        return VirtualFileSystemProvider.getInstance();
    }

    public String getAbsolutePath() {
        if (isAbsolute()) {
            return path;
        }

        String userdir = fs().getUserDir();

        if (path.isEmpty()) {
            return userdir;
        }
        int length = userdir.length();

        StringBuilder result = new StringBuilder(userdir);
        if (userdir.charAt(length - 1) != separatorChar) {
            if (path.charAt(0) != separatorChar) {
                result.append(separator);
            }
        } if (fs().isWindows() && path.charAt(0) == separatorChar) {
            result.setLength(3);
        }
        result.append(path);

        return result.toString();
    }

    public TFile getAbsoluteFile() {
        return new TFile(getAbsolutePath());
    }

    public boolean isAbsolute() {
        return isAbsolutePath(path);
    }

    private boolean isAbsolutePath(String path) {
        if (fs().isWindows()) {
            if (path.length() < 3) {
                return false;
            }
            return isDriveLetter(path.charAt(0)) && path.charAt(1) == ':' && path.charAt(2) == '\\';
        } else {
            return !path.isEmpty() && path.charAt(0) == separatorChar;
        }
    }<commit_msg>Fix build<commit_after>/*
 *  Copyright 2017 <NAME>.
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */

package org.teavm.classlib.java.io;

import java.io.File;
import java.io.IOException;
import java.io.Serializable;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Arrays;
import java.util.Objects;
import org.teavm.classlib.fs.VirtualFile;
import org.teavm.classlib.fs.VirtualFileSystem;
import org.teavm.classlib.fs.VirtualFileSystemProvider;
import org.teavm.classlib.java.util.TRandom;

public class TFile implements Serializable, Comparable<TFile> {
    private String path;

    public static final char separatorChar = fs().isWindows() ? '\\' : '/';
    public static final String separator = String.valueOf(separatorChar);
    public static final char pathSeparatorChar = fs().isWindows() ? ';' : ':';
    public static final String pathSeparator = String.valueOf(pathSeparatorChar);

    private static int counter;

    public TFile(TFile dir, String name) {
        Objects.requireNonNull(name);
        path = dir == null ? fixSlashes(name) : calculatePath(dir.getPath(), name);
    }

    public TFile(String path) {
        Objects.requireNonNull(path);
        this.path = fixSlashes(path);
    }

    public TFile(String dir, String name) {
        Objects.requireNonNull(name);
        path = dir == null ? fixSlashes(name) : calculatePath(dir, name);
    }

    public TFile(URI uri) {
        // check pre-conditions
        checkURI(uri);
        String path = uri.getPath();
        if (fs().isWindows() && path.startsWith("/") && path.length() >= 4) {
            if (isDriveLetter(path.charAt(1)) && path.charAt(2) == ':' && path.charAt(3) == '/') {
                path = path.substring(1);
            }
        }
        this.path = fixSlashes(path);
    }

    private void checkURI(URI uri) {
        if (!uri.isAbsolute()) {
            throw new IllegalArgumentException();
        } else if (!uri.getRawSchemeSpecificPart().startsWith("/")) {
            throw new IllegalArgumentException();
        }

        String temp = uri.getScheme();
        if (temp == null || !temp.equals("file")) {
            throw new IllegalArgumentException();
        }

        temp = uri.getRawPath();
        if (temp == null || temp.length() == 0) {
            throw new IllegalArgumentException();
        }

        if (uri.getRawAuthority() != null) {
            throw new IllegalArgumentException();
        }

        if (uri.getRawQuery() != null) {
            throw new IllegalArgumentException();
        }

        if (uri.getRawFragment() != null) {
            throw new IllegalArgumentException();
        }
    }

    public boolean canRead() {
        VirtualFile virtualFile = findVirtualFile();
        return virtualFile != null && virtualFile.canRead();
    }

    public boolean canWrite() {
        VirtualFile virtualFile = findVirtualFile();
        return virtualFile != null && virtualFile.canWrite();
    }

    @Override
    public int compareTo(TFile o) {
        return path.compareTo(o.path);
    }

    public String getPath() {
        return path;
    }

    public String getName() {
        int separatorIndex = path.lastIndexOf(separator);
        return separatorIndex < 0 ? path : path.substring(separatorIndex + 1, path.length());
    }

    private static VirtualFileSystem fs() {
        return VirtualFileSystemProvider.getInstance();
    }

    public String getAbsolutePath() {
        if (isAbsolute()) {
            return path;
        }

        String userdir = fs().getUserDir();

        if (path.isEmpty()) {
            return userdir;
        }
        int length = userdir.length();

        StringBuilder result = new StringBuilder(userdir);
        if (userdir.charAt(length - 1) != separatorChar) {
            if (path.charAt(0) != separatorChar) {
                result.append(separator);
            }
        } else if (fs().isWindows() && path.charAt(0) == separatorChar) {
            result.setLength(3);
        }
        result.append(path);

        return result.toString();
    }

    public TFile getAbsoluteFile() {
        return new TFile(getAbsolutePath());
    }

    public boolean isAbsolute() {
        return isAbsolutePath(path);
    }

    private boolean isAbsolutePath(String path) {
        if (fs().isWindows()) {
            if (path.length() < 3) {
                return false;
            }
            return isDriveLetter(path.charAt(0)) && path.charAt(1) == ':' && path.charAt(2) == '\\';
        } else {
            return !path.isEmpty() && path.charAt(0) == separatorChar;
        }
    }
{'fraction_non_alphanumeric': 0.12157052835676199, 'fraction_numerical': 0.004847309743092583, 'mean_word_length': 2.374550212626758, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '7319096', 'n_tokens_mistral': 2913, 'n_tokens_neox': 2823, 'n_words': 736}