private void writeFile(Path filePath, ReadableByteChannel channel) throws StorageCorruptedException,
            NotEnoughFreeSpaceException, StorageServiceIsNotStartedError {
        if (LOG.isInfoEnabled())
            LOG.info("Writing of '{}' onto a disk space...", filePath);

        try (final FileChannel out = new FileOutputStream(String.valueOf(filePath)).getChannel()) {

            final ByteBuffer buffer = ByteBuffer.allocate(1024);
            while (channel.read(buffer) != -1) {
                if (getFreeStorageSpaceInBytes() < 1024) {
                    throw new NotEnoughFreeSpaceException();
                }
                buffer.flip();
                out.write(buffer);

                storageSpaceInspector.incrementUsedSpace(buffer.position());

                buffer.clear();
            }
        } catch (FileNotFoundException e) {
            // arises when destination folders hierarchy corrupted
            throw new StorageCorruptedException();
        } catch (IOException e) {
            if (LOG.isErrorEnabled())
                LOG.error("Can't write to the file: '{}'", filePath);
            throw new IllegalStateException(e.getMessage());
        }

        if (LOG.isInfoEnabled())
            LOG.info("'{}' successfully written", filePath);
    }