protected String validate(final File file) throws Exception {
        final int readBytes = 1024;
        String format = "invalid";
        if (file.exists() && file.length() > 0) {
            FileInputStream fis = null;
            byte[] buff = null;
            try {
                fis = new FileInputStream(file);
                buff = new byte[readBytes];
                fis.read(buff);
            } finally {
                IOUtils.closeQuietly(fis);
            }
            final Pattern xmlPattern = Pattern.compile("<");
            final Matcher xmlMatcher =
                    xmlPattern.matcher(new String(buff).trim()
                            .toLowerCase());
            if (xmlMatcher.find()) {
                format = "xml";
            } else {
                final Pattern jsonPattern = Pattern.compile(":");
                final Matcher jsonMatcher =
                        jsonPattern.matcher(new String(buff).trim()
                                .toLowerCase());
                if (jsonMatcher.find()) {
                    format = "json";
                } else {
                    final Pattern csvPattern = Pattern.compile(",");
                    final Matcher csvMatcher =
                            csvPattern.matcher(new String(buff).trim()
                                    .toLowerCase());
                    if (csvMatcher.find()) {
                        format = "csv";
                    } else  if (buff[0] == MAGIC[0] && buff[1] == MAGIC[1]
                            && buff[2] == MAGIC[2] && buff[3] == MAGIC[3]) {
                        format = "zip";
                    } else {
                        LOG.error("Fail, document does not exists!");
                    }
                }

            }
        }
        return format;
    }