package com.cflint.tools;

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.List;

import org.apache.commons.io.ByteOrderMark;
import org.apache.commons.io.input.BOMInputStream;
import org.apache.tools.ant.util.FileUtils;

public class FileUtil {
    
    static final String defaultEncoding = "UTF-8";

    static public String loadFile(final File file) {
        FileInputStream fis = null;
        try {
            fis = new FileInputStream(file);
            try {
                final BOMInputStream bOMInputStream = new BOMInputStream(fis);
                final ByteOrderMark bom = bOMInputStream.getBOM();
                final String charsetName = bom == null ? defaultEncoding : bom.getCharsetName();
                InputStreamReader reader = new InputStreamReader(new BufferedInputStream(bOMInputStream), charsetName);
                return FileUtils.readFully(reader);
            } finally {
                fis.close();
            }
        } catch (final Exception e) {
            return null;
        } finally {
            try {
                if (fis != null) {
                    fis.close();
                }
            } catch (final IOException e) {
                return null;
            }
        }
    }

    static public boolean checkExtension(final File file, final List<String> allowedExtensions) {
        for (final String ext : allowedExtensions) {
            if (file.getName().endsWith(ext)) {
                return true;
            }
        }
        return false;
    }
}

@@ -171,16 +171,39 @@
 Reader;%0A
+import java.io.Reader;%0A
 import j
@@ -217,16 +217,16 @@
 l.List;%0A
-
 %0Aimport 
@@ -316,52 +316,8 @@
 eam;
-%0Aimport org.apache.tools.ant.util.FileUtils;
 %0A%0Apu
@@ -393,16 +393,54 @@
 %22UTF-8%22;
+%0A    static final int BUF_SIZE = 8192;
 %0A%0A    st
@@ -989,18 +989,8 @@
 urn 
-FileUtils.
 read
@@ -1636,16 +1636,1514 @@
  false;%0A
-
     %7D%0A
+    %0A    /**%0A     * Read from reader till EOF.%0A     * @param rdr the reader from which to read.%0A     * @return the contents read out of the given reader.%0A     *%0A     * @throws IOException if the contents could not be read out from the%0A     *         reader.%0A     */%0A    public static final String readFully(Reader rdr) throws IOException %7B%0A        return readFully(rdr, BUF_SIZE);%0A    %7D%0A%0A    /**%0A     * Read from reader till EOF.%0A     *%0A     * @param rdr the reader from which to read.%0A     * @param bufferSize the buffer size to use when reading.%0A     *%0A     * @return the contents read out of the given reader.%0A     *%0A     * @throws IOException if the contents could not be read out from the%0A     *         reader.%0A     */%0A    public static final String readFully(Reader rdr, int bufferSize)%0A        throws IOException %7B%0A        if (bufferSize %3C= 0) %7B%0A            throw new IllegalArgumentException(%22Buffer size must be greater %22%0A                                               + %22than 0%22);%0A        %7D%0A        final char%5B%5D buffer = new char%5BbufferSize%5D;%0A        int bufferLength = 0;%0A        StringBuffer textBuffer = null;%0A        while (bufferLength != -1) %7B%0A            bufferLength = rdr.read(buffer);%0A            if (bufferLength %3E 0) %7B%0A                textBuffer = (textBuffer == null) ? new StringBuffer() : textBuffer;%0A                textBuffer.append(new String(buffer, 0, bufferLength));%0A            %7D%0A        %7D%0A        return (textBuffer == null) ? null : textBuffer.toString();%0A    %7D%0A%0A
 %7D%0A

Remove org.apache.tools.ant.util.FileUtils runtime dependency