public int saveFile(String path, InputStream inputStream, long freeDiskSpace) throws NotEnoughFreeDiskSpaceException {
        int bytesCount = 0;
        final File file = new File(path);
        createFolder(file.getParent());
        try {
            file.createNewFile();
        } catch (IOException e) {
            throw new RuntimeException("Can't create file.");
        }
        OutputStream outStream = null;
        try {
            outStream = new FileOutputStream(file);
        } catch (FileNotFoundException e) {
            throw new RuntimeException("Problem with reading file.");
        }

        byte[] buffer = new byte[1024];
        int bytesRead;
        try {
            while ((bytesRead = inputStream.read(buffer)) != -1) {
                outStream.write(buffer, 0, bytesRead);
                bytesCount += bytesRead;
            }
        } catch (IOException e) {
            throw new RuntimeException("Problem with storing data. " + e.getMessage());
        }

        if (bytesCount > freeDiskSpace) {
            throw new NotEnoughFreeDiskSpaceException("Not enough free disk space.");
        }

        return bytesCount * Byte.SIZE;
    }