<commit_before>package step.grid.filemanager;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;

import step.commons.helpers.FileHelper;
import step.grid.io.Attachment;
import step.grid.io.AttachmentHelper;

public class FileManagerServer implements FileProvider {

	Map<String, File> registry = new ConcurrentHashMap<>();
	
	Map<File, String> reverseRegistry = new HashMap<>();
	
	public synchronized String registerFile(File file) {
		if(!file.exists()||!file.canRead()) {
			throw new RuntimeException("Unable to find or read file "+file.getAbsolutePath());
		}
		
		String handle = reverseRegistry.get(file);
		if(handle==null) {
			String newHandle = UUID.randomUUID().toString();
			registry.put(newHandle, file);
			reverseRegistry.put(file, newHandle);
			handle = newHandle;
		}
		return handle;
	}
	
	public Attachment getFileAsAttachment(String fileHandle) {
		File file = getFile(fileHandle);<commit_msg>Fixing scaling issue in FileManagerServer<commit_after>package step.grid.filemanager;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Function;

import step.commons.helpers.FileHelper;
import step.grid.io.Attachment;
import step.grid.io.AttachmentHelper;

public class FileManagerServer implements FileProvider {

	ConcurrentHashMap<String, File> registry = new ConcurrentHashMap<>();
	
	ConcurrentHashMap<File, String> reverseRegistry = new ConcurrentHashMap<>();
	
	public String registerFile(File file) {
		String handle = reverseRegistry.computeIfAbsent(file, new Function<File, String>() {
			@Override
			public String apply(File t) {
				if(!file.exists()||!file.canRead()) {
					throw new RuntimeException("Unable to find or read file "+file.getAbsolutePath());
				}
				
				String handle = UUID.randomUUID().toString();
				registry.put(handle, file);
				return handle;
			}
		});
		return handle;
	}
	
	public Attachment getFileAsAttachment(String fileHandle) {
		File file = getFile(fileHandle);
{'fraction_non_alphanumeric': 0.11419472247497725, 'fraction_numerical': 0.0, 'mean_word_length': 5.125348189415042, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 12, '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': '3955321', 'n_tokens_mistral': 688, 'n_tokens_neox': 640, 'n_words': 153}