<commit_before>package com.orientechnologies.common.io;

import java.io.File;

public class OFileUtils {
	private static final int	KILOBYTE	= 1024;
	private static final int	MEGABYTE	= 1048576;
	private static final int	GIGABYTE	= 1073741824;
	private static final long	TERABYTE	= 1099511627776L;

	public static long getSizeAsNumber(String iSize) {
		try {
			return Long.parseLong(iSize);
		} catch (NumberFormatException e) {
			iSize = iSize.toUpperCase();
			int pos = iSize.indexOf("KB");
			if (pos > -1)
				return Long.parseLong(iSize.substring(0, pos)) * KILOBYTE;

			pos = iSize.indexOf("MB");
			if (pos > -1)
				return Long.parseLong(iSize.substring(0, pos)) * MEGABYTE;

			pos = iSize.indexOf("GB");
			if (pos > -1)
				return Long.parseLong(iSize.substring(0, pos)) * GIGABYTE;

			pos = iSize.indexOf("TB");
			if (pos > -1)
				return Long.parseLong(iSize.substring(0, pos)) * TERABYTE;

			pos = iSize.indexOf("B");
			if (pos > -1)
				return Long.parseLong(iSize.substring(0, pos));

			pos = iSize.indexOf("%");
			if (pos > -1)
				return -1 * Long.parseLong(iSize.substring(0, pos));

			// RE-THROW THE EXCEPTION
			throw e;
		}
	}

	public static String getSizeAsString(long iSize) {
		if (iSize > TERABYTE)
			return String.format("%2.2fTb", (float) iSize / TERABYTE);
		if (iSize > GIGABYTE)
			return String.format("%2.2fGb", (float) iSize / GIGABYTE);
		if (iSize > MEGABYTE)
			return String.format("%2.2fMb", (float) iSize / MEGABYTE);
		if (iSize > KILOBYTE)
			return String.format("%2.2fKb", (float) iSize / KILOBYTE);

		return String.valueOf(iSize) + "b";
	}

	public static String getDirectory(String iPath) {
		iPath = getPath(iPath);<commit_msg>Removed nasty checked exception on format conversion.<commit_after>package com.orientechnologies.common.io;

import java.io.File;

public class OFileUtils {
	private static final int	KILOBYTE	= 1024;
	private static final int	MEGABYTE	= 1048576;
	private static final int	GIGABYTE	= 1073741824;
	private static final long	TERABYTE	= 1099511627776L;

	public static long getSizeAsNumber(String iSize) {
		if (iSize == null)
			throw new IllegalArgumentException("Size " + iSize + " is null");

		boolean number = true;
		for (int i = iSize.length() - 1; i >= 0; --i) {
			if (!Character.isDigit(iSize.charAt(i))) {
				number = false;
				break;
			}
		}

		if (number)
			return Long.parseLong(iSize);
		else {
			iSize = iSize.toUpperCase();
			int pos = iSize.indexOf("KB");
			if (pos > -1)
				return Long.parseLong(iSize.substring(0, pos)) * KILOBYTE;

			pos = iSize.indexOf("MB");
			if (pos > -1)
				return Long.parseLong(iSize.substring(0, pos)) * MEGABYTE;

			pos = iSize.indexOf("GB");
			if (pos > -1)
				return Long.parseLong(iSize.substring(0, pos)) * GIGABYTE;

			pos = iSize.indexOf("TB");
			if (pos > -1)
				return Long.parseLong(iSize.substring(0, pos)) * TERABYTE;

			pos = iSize.indexOf("B");
			if (pos > -1)
				return Long.parseLong(iSize.substring(0, pos));

			pos = iSize.indexOf("%");
			if (pos > -1)
				return -1 * Long.parseLong(iSize.substring(0, pos));

			// RE-THROW THE EXCEPTION
			throw new IllegalArgumentException("Size " + iSize + " has a unrecognizable format");
		}
	}

	public static String getSizeAsString(long iSize) {
		if (iSize > TERABYTE)
			return String.format("%2.2fTb", (float) iSize / TERABYTE);
		if (iSize > GIGABYTE)
			return String.format("%2.2fGb", (float) iSize / GIGABYTE);
		if (iSize > MEGABYTE)
			return String.format("%2.2fMb", (float) iSize / MEGABYTE);
		if (iSize > KILOBYTE)
			return String.format("%2.2fKb", (float) iSize / KILOBYTE);

		return String.valueOf(iSize) + "b";
	}

	public static String getDirectory(String iPath) {
		iPath = getPath(iPath);
{'fraction_non_alphanumeric': 0.1431641149610529, 'fraction_numerical': 0.030083266183185603, 'mean_word_length': 3.5805658056580567, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 24, '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': '3403675', 'n_tokens_mistral': 1630, 'n_tokens_neox': 1401, 'n_words': 335}