public static void copy(final InputStream input, final File target) throws IOException {
        if (target.exists()) {
            throw new IOException("File already exists!");
        }

        if (!target.createNewFile()) {
            throw new IOException("Failed at creating new empty file!");
        }
        byte[] buffer = new byte[BUFFER];

        OutputStream output = new FileOutputStream(target);

        int realLength;

        while ((realLength = input.read(buffer)) > 0) {
            output.write(buffer, 0, realLength);
        }

        output.flush();
        output.close();
    }