<commit_before>package eu.stratuslab.storage.disk.plugins;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.List;

import org.restlet.data.Status;
import org.restlet.resource.ResourceException;

import eu.stratuslab.storage.disk.main.RootApplication;
import eu.stratuslab.storage.disk.utils.FileUtils;
import eu.stratuslab.storage.disk.utils.ProcessUtils;

public final class PosixStorage implements DiskStorage {

	public PosixStorage() {

	}

	public void create(String uuid, int size) {
		File diskFile = new File(
				RootApplication.CONFIGURATION.STORAGE_LOCATION, uuid);

		if (diskFile.exists()) {
			throw new ResourceException(Status.SERVER_ERROR_INTERNAL,
					"A disk with the same name already exists.");
		}

		FileUtils.createZeroFile(diskFile, size);
	}

	public void delete(String uuid) {
		File diskFile = new File(
				RootApplication.CONFIGURATION.STORAGE_LOCATION, uuid);

		if (!diskFile.delete()) {
			throw new ResourceException(Status.SERVER_ERROR_INTERNAL,
					"An error occcured while removing disk content " + uuid);
		}
	}

	public void createCopyOnWrite(String baseUuid, String cowUuid, int size) {
		// TODO Auto-generated method stub
	}

	public String rebase(String uuid, String rebaseUuid) {
		// TODO Auto-generated method stub
		return null;
	}

	public String zip(String uuid) {
		String cachedDisk = RootApplication.CONFIGURATION.CACHE_LOCATION + "/"
				+ uuid;

		copyfile(
				RootApplication.CONFIGURATION.STORAGE_LOCATION.getAbsolutePath()
						+ "/" + uuid, cachedDisk);

		List<String> zipCmd = new ArrayList<String>();
		zipCmd.add("gzip");
		zipCmd.add("-f");
		zipCmd.add(cachedDisk);

		ProcessBuilder pb = new ProcessBuilder(zipCmd);
		ProcessUtils.execute(pb, "Unable to attach persistent disk");

		return cachedDisk + ".gz";
	}

	private static void copyfile(String srFile, String dtFile) {
		try {
			File src = new File(srFile);
			File dst = new File(dtFile);

			InputStream in = new FileInputStream(src);
			OutputStream out = new FileOutputStream(dst);

			byte[] buf = new byte[1024];
			int len;
			while ((len = in.read(buf)) > 0) {
				out.write(buf, 0, len);
			}

			in.close();
			out.close();
		} catch (FileNotFoundException ex) {
			throw new ResourceException(Status.SERVER_ERROR_INTERNAL,
					"Error while copying disk");
		} catch (IOException e) {
			throw new ResourceException(Status.SERVER_ERROR_INTERNAL,
					"Error while copying disk");
		}
	}
}<commit_msg>Check that disk exist on ZIP request for Posix<commit_after>package eu.stratuslab.storage.disk.plugins;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import org.restlet.data.Status;
import org.restlet.resource.ResourceException;

import eu.stratuslab.storage.disk.main.RootApplication;
import eu.stratuslab.storage.disk.utils.FileUtils;
import eu.stratuslab.storage.disk.utils.ProcessUtils;

public final class PosixStorage implements DiskStorage {

	public PosixStorage() {

	}

	public void create(String uuid, int size) {
		File diskFile = new File(
				RootApplication.CONFIGURATION.STORAGE_LOCATION, uuid);

		if (diskFile.exists()) {
			throw new ResourceException(Status.SERVER_ERROR_INTERNAL,
					"A disk with the same name already exists.");
		}

		FileUtils.createZeroFile(diskFile, size);
	}

	public void delete(String uuid) {
		File diskFile = new File(
				RootApplication.CONFIGURATION.STORAGE_LOCATION, uuid);

		if (!diskFile.delete()) {
			throw new ResourceException(Status.SERVER_ERROR_INTERNAL,
					"An error occcured while removing disk content " + uuid);
		}
	}

	public void createCopyOnWrite(String baseUuid, String cowUuid, int size) {
		// TODO Auto-generated method stub
	}

	public String rebase(String uuid, String rebaseUuid) {
		// TODO Auto-generated method stub
		return null;
	}

	public String zip(String uuid) {
		File disk = new File(
				RootApplication.CONFIGURATION.STORAGE_LOCATION
						.getAbsolutePath() + "/" + uuid);

		if (!disk.isFile()) {
			throw new ResourceException(Status.SERVER_ERROR_INTERNAL, "Disk "
					+ uuid + " does not exists");
		}

		String cachedDisk = RootApplication.CONFIGURATION.CACHE_LOCATION + "/"
				+ uuid;

		FileUtils.copyFile(
				RootApplication.CONFIGURATION.STORAGE_LOCATION
						.getAbsolutePath() + "/" + uuid, cachedDisk);

		List<String> zipCmd = new ArrayList<String>();
		zipCmd.add("gzip");
		zipCmd.add("-f");
		zipCmd.add(cachedDisk);

		ProcessBuilder pb = new ProcessBuilder(zipCmd);
		ProcessUtils.execute(pb, "Unable to attach persistent disk");

		return cachedDisk + ".gz";
	}
	
}
{'fraction_non_alphanumeric': 0.1087962962962963, 'fraction_numerical': 0.0012626262626262627, 'mean_word_length': 4.257743362831858, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 8, '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': '2896787', 'n_tokens_mistral': 1648, 'n_tokens_neox': 1473, 'n_words': 361}