<commit_before>package com.danielkueffer.filehosting.service.impl;

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.StringWriter;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import java.util.ResourceBundle;
import java.util.zip.ZipOutputStream;

import javax.ejb.EJB;
import javax.ejb.Stateless;
import javax.inject.Inject;
import javax.json.Json;
import javax.json.stream.JsonGenerator;
import javax.json.stream.JsonGeneratorFactory;

import org.apache.commons.io.FileUtils;
import org.apache.tika.detect.Detector;
import org.apache.tika.metadata.Metadata;
import org.apache.tika.mime.MediaType;
import org.apache.tika.parser.AutoDetectParser;
import org.jboss.resteasy.plugins.providers.multipart.InputPart;

import com.danielkueffer.filehosting.auth.AuthManager;
import com.danielkueffer.filehosting.i18n.MessageProvider;
import com.danielkueffer.filehosting.persistence.dao.FileDao;
import com.danielkueffer.filehosting.persistence.dao.FilesDeletedDao;
import com.danielkueffer.filehosting.persistence.model.FilesDeleted;
import com.danielkueffer.filehosting.persistence.model.UploadFile;
import com.danielkueffer.filehosting.persistence.model.User;
import com.danielkueffer.filehosting.service.ConfigurationService;
import com.danielkueffer.filehosting.service.FileService;
import com.danielkueffer.filehosting.util.FileUtil;
import com.danielkueffer.filehosting.util.MimeType;

/**
 * The file service implementation
 * 
 * @author dkueffer
 * 
 */
@Stateless
public class FileServiceImpl implements FileService {

	private static final String BASE_DIR = "jboss.server.data.dir";
	private static final String FILE_DIR = "files";

	private String altFolder;
	private int altNum;
	private List<UploadFile> childFolders = new ArrayList<UploadFile>();

	@EJB
	FileDao fileDao;

	@EJB
	FilesDeletedDao filesDeletedDao;

	@EJB
	ConfigurationService configurationService;

	@Inject
	AuthManager authManager;

	@Inject
	MessageProvider messageProvider;

	/**
	 * Upload files
	 */
	@Override
	public boolean uploadFiles(List<InputPart> inputParts, int parent,
			String fileName, long lastModified, long contentLength) {

		int maxFileSize = this.configurationService.getConfiguration()
				.getMaxUploadSize();

		// Check if the content is too long
		if (contentLength > maxFileSize) {
			return false;
		}

		long diskQuota = this.authManager.getCurrentUser().getDiskQuota();

		// Check if the disk quota of the current user is full
		if ((this.getUsedDiskSpaceByCurrentUser() + contentLength) > diskQuota) {
			return false;
		}

		// Check if a directory for the current user exists
		this.createUserDir();

		for (InputPart inputPart : inputParts) {

			try {
				String filePath = fileName;

				if (parent != 0) {
					UploadFile uf = this.fileDao.get(parent);
					filePath = uf.getPath() + "/" + fileName;
				}

				// constructs upload file path
				String systemFilePath = System.getProperty(BASE_DIR) + "/"<commit_msg>only check disk quota if the quota is greater than zero<commit_after>package com.danielkueffer.filehosting.service.impl;

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.StringWriter;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import java.util.ResourceBundle;
import java.util.zip.ZipOutputStream;

import javax.ejb.EJB;
import javax.ejb.Stateless;
import javax.inject.Inject;
import javax.json.Json;
import javax.json.stream.JsonGenerator;
import javax.json.stream.JsonGeneratorFactory;

import org.apache.commons.io.FileUtils;
import org.apache.tika.detect.Detector;
import org.apache.tika.metadata.Metadata;
import org.apache.tika.mime.MediaType;
import org.apache.tika.parser.AutoDetectParser;
import org.jboss.resteasy.plugins.providers.multipart.InputPart;

import com.danielkueffer.filehosting.auth.AuthManager;
import com.danielkueffer.filehosting.i18n.MessageProvider;
import com.danielkueffer.filehosting.persistence.dao.FileDao;
import com.danielkueffer.filehosting.persistence.dao.FilesDeletedDao;
import com.danielkueffer.filehosting.persistence.model.FilesDeleted;
import com.danielkueffer.filehosting.persistence.model.UploadFile;
import com.danielkueffer.filehosting.persistence.model.User;
import com.danielkueffer.filehosting.service.ConfigurationService;
import com.danielkueffer.filehosting.service.FileService;
import com.danielkueffer.filehosting.util.FileUtil;
import com.danielkueffer.filehosting.util.MimeType;

/**
 * The file service implementation
 * 
 * @author dkueffer
 * 
 */
@Stateless
public class FileServiceImpl implements FileService {

	private static final String BASE_DIR = "jboss.server.data.dir";
	private static final String FILE_DIR = "files";

	private String altFolder;
	private int altNum;
	private List<UploadFile> childFolders = new ArrayList<UploadFile>();

	@EJB
	FileDao fileDao;

	@EJB
	FilesDeletedDao filesDeletedDao;

	@EJB
	ConfigurationService configurationService;

	@Inject
	AuthManager authManager;

	@Inject
	MessageProvider messageProvider;

	/**
	 * Upload files
	 */
	@Override
	public boolean uploadFiles(List<InputPart> inputParts, int parent,
			String fileName, long lastModified, long contentLength) {

		int maxFileSize = this.configurationService.getConfiguration()
				.getMaxUploadSize();

		// Check if the content is too long
		if (contentLength > maxFileSize) {
			return false;
		}

		long diskQuota = this.authManager.getCurrentUser().getDiskQuota();

		// Check if the disk quota of the current user is full. Only check if
		// the disk quota is greater than 0. 0 is unlimited
		if (diskQuota > 0) {
			if ((this.getUsedDiskSpaceByCurrentUser() + contentLength) > diskQuota) {
				return false;
			}
		}

		// Check if a directory for the current user exists
		this.createUserDir();

		for (InputPart inputPart : inputParts) {

			try {
				String filePath = fileName;

				if (parent != 0) {
					UploadFile uf = this.fileDao.get(parent);
					filePath = uf.getPath() + "/" + fileName;
				}

				// constructs upload file path
				String systemFilePath = System.getProperty(BASE_DIR) + "/"
{'fraction_non_alphanumeric': 0.0978824226269806, 'fraction_numerical': 0.0013327410039982231, 'mean_word_length': 4.945422535211268, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 14, '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': '19776', 'n_tokens_mistral': 2270, 'n_tokens_neox': 2122, 'n_words': 468}