// Path: apache-rat-core/src/test/java/org/apache/rat/document/MockDocument.java
// public class MockDocument implements Document {
// 
//     private final Reader reader;
//     private final String name;
//     private final MetaData metaData = new MetaData();
// 
//     public MockDocument() {
//         this(null, "name");
//     }
// 
//     public MockDocument(String name) {
//         this(null, name);
//     }
//     
//     public MockDocument(Reader reader, String name) {
//         super();
//         this.reader = reader;
//         this.name = name;
//     }
// 
//     public Reader reader() throws IOException {
//         return reader;
//     }
// 
//     public String getName() {
//         return name;
//     }
// 
//     public boolean isComposite() {
//         return false;
//     }
//     
//     public MetaData getMetaData() {
//         return metaData;
//     }
//     
// 
//     public InputStream inputStream() throws IOException {
//         throw new UnsupportedOperationException();
//     }
// }
// 
// Path: apache-rat-core/src/test/java/org/apache/rat/test/utils/Resources.java
// public class Resources {
//     /**
//      * Private constructor, to prevent accidental instantiation.
//      */
//     private Resources() {
//         // Does nothing
//     }
// 
//     public static final String SRC_TEST_RESOURCES = "src/test/resources";
//     public static final String SRC_MAIN_RESOURCES = "src/main/resources";
//     private static final File TEST_RESOURCE_BASE_PATH = new File(SRC_TEST_RESOURCES);
//     private static final File RESOURCE_BASE_PATH = new File(SRC_MAIN_RESOURCES);
// 
//     /**
//      * Locates a test resource file in the class path.
//      */
//     public static File getResourceFile(String pResource) throws IOException {
//         return getResourceFromBase(TEST_RESOURCE_BASE_PATH, pResource);
//     }
// 
//     /**
//      * Locates a main resource file in the class path.
//      */
//     public static File getMainResourceFile(String pResource) throws IOException {
//         return getResourceFromBase(RESOURCE_BASE_PATH, pResource);
//     }
// 
//     /**
//      * Try to to load the given file from baseDir, in case of errors try to add module names to fix behaviour from within IntelliJ.
//      */
//     private static File getResourceFromBase(File baseDir, String pResource) throws IOException {
//         File f = new File(baseDir, pResource);
//         if (!f.isFile()) {
//             throw new FileNotFoundException("Unable to locate resource file: " + pResource);
//         }
//         return f;
//     }
// 
//     /**
//      * Locates a set of resource files in the class path.
//      * In case of errors try to add module names to fix behaviour from within IntelliJ.
//      */
//     public static File[] getResourceFiles(String pResource) throws IOException {
//         File f = new File(TEST_RESOURCE_BASE_PATH, pResource);
//         if (!f.isDirectory()) {
//             throw new FileNotFoundException("Unable to locate resource directory: " + pResource);
//         }
// 
//         return f.listFiles(new FileFilter() {
//             public boolean accept(File pathname) {
//                 return pathname.isFile();
//             }
//         });
//     }
// 
//     /**
//      * Locates a resource file in the class path and returns an {@link InputStream}.
//      */
//     public static InputStream getResourceStream(String pResource) throws IOException {
//         return new FileInputStream(getResourceFile(pResource));
//     }
// 
//     /**
//      * Locates a resource file in the class path and returns a {@link Reader}.
//      */
//     public static Reader getResourceReader(String pResource) throws IOException {
//         return new InputStreamReader(getResourceStream(pResource), StandardCharsets.UTF_8);
//     }
// 
//     /**
//      * Locates a resource file in the class path and returns a {@link BufferedReader}.
//      */
//     public static BufferedReader getBufferedResourceReader(String pResource) throws IOException {
//         return new BufferedReader(getResourceReader(pResource));
//     }
// 
//     /**
//      * Locates a resource file in the class path and returns a {@link BufferedReader}.
//      */
//     public static BufferedReader getBufferedReader(File file) throws IOException {
//         return new BufferedReader(new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_8));
//     }
// 
//     /**
//      * Locates the name of a directory, which contains the given
//      * resource file.
//      */
//     public static String getResourceDirectory(String pResource) throws IOException {
//         final File resource = getResourceFile(pResource);
//         final File dir = resource.getParentFile();
//         return DocumentImplUtils.toName(dir);
//     }
// }


import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import org.apache.commons.io.IOUtils;
import org.apache.rat.document.MockDocument;
import org.apache.rat.document.impl.FileDocument;
import org.apache.rat.test.utils.Resources;
import org.junit.Test;
import java.io.IOException;
import java.io.Reader;
import java.util.Arrays;
import java.util.List;
import static org.junit.Assert.assertEquals;
        FileDocument doc = new FileDocument(Resources.getResourceFile("/binaries/UTF16_with_signature.xml"));
        Reader r = doc.reader(); // this will fail test if file is not readable
        try {
            char[] dummy = new char[100];
            r.read(dummy);
            // if we get here, the UTF-16 encoded file didn't throw
            // any exception, try the UTF-8 encoded one
            r.close();
            r = null; // ensure we detect failure to read second file
            doc = new FileDocument(Resources.getResourceFile("/binaries/UTF8_with_signature.xml"));
            r = doc.reader();
            r.read(dummy);
            // still here?  can't test on this platform
            System.err.println("Skipping testBinaryWithMalformedInput");
        } catch (IOException e) {
            if (r != null) {
                IOUtils.closeQuietly(r);
            } else {
                throw e; // could not open the second file
            }
            r = null;
            assertTrue("Expected binary for " + doc.getName(), BinaryGuesser.isBinary(doc));
        } finally {
            IOUtils.closeQuietly(r);
        }
    }

    @Test
    public void realBinaryContent() throws IOException {
        // This test is not accurate on all platforms
// Path: apache-rat-core/src/test/java/org/apache/rat/document/MockDocument.java
// public class MockDocument implements Document {
// 
//     private final Reader reader;
//     private final String name;
//     private final MetaData metaData = new MetaData();
// 
//     public MockDocument() {
//         this(null, "name");
//     }
// 
//     public MockDocument(String name) {
//         this(null, name);
//     }
//     
//     public MockDocument(Reader reader, String name) {
//         super();
//         this.reader = reader;
//         this.name = name;
//     }
// 
//     public Reader reader() throws IOException {
//         return reader;
//     }
// 
//     public String getName() {
//         return name;
//     }
// 
//     public boolean isComposite() {
//         return false;
//     }
//     
//     public MetaData getMetaData() {
//         return metaData;
//     }
//     
// 
//     public InputStream inputStream() throws IOException {
//         throw new UnsupportedOperationException();
//     }
// }
// 
// Path: apache-rat-core/src/test/java/org/apache/rat/test/utils/Resources.java
// public class Resources {
//     /**
//      * Private constructor, to prevent accidental instantiation.
//      */
//     private Resources() {
//         // Does nothing
//     }
// 
//     public static final String SRC_TEST_RESOURCES = "src/test/resources";
//     public static final String SRC_MAIN_RESOURCES = "src/main/resources";
//     private static final File TEST_RESOURCE_BASE_PATH = new File(SRC_TEST_RESOURCES);
//     private static final File RESOURCE_BASE_PATH = new File(SRC_MAIN_RESOURCES);
// 
//     /**
//      * Locates a test resource file in the class path.
//      */
//     public static File getResourceFile(String pResource) throws IOException {
//         return getResourceFromBase(TEST_RESOURCE_BASE_PATH, pResource);
//     }
// 
//     /**
//      * Locates a main resource file in the class path.
//      */
//     public static File getMainResourceFile(String pResource) throws IOException {
//         return getResourceFromBase(RESOURCE_BASE_PATH, pResource);
//     }
// 
//     /**
//      * Try to to load the given file from baseDir, in case of errors try to add module names to fix behaviour from within IntelliJ.
//      */
//     private static File getResourceFromBase(File baseDir, String pResource) throws IOException {
//         File f = new File(baseDir, pResource);
//         if (!f.isFile()) {
//             throw new FileNotFoundException("Unable to locate resource file: " + pResource);
//         }
//         return f;
//     }
// 
//     /**
//      * Locates a set of resource files in the class path.
//      * In case of errors try to add module names to fix behaviour from within IntelliJ.
//      */
//     public static File[] getResourceFiles(String pResource) throws IOException {
//         File f = new File(TEST_RESOURCE_BASE_PATH, pResource);
//         if (!f.isDirectory()) {
//             throw new FileNotFoundException("Unable to locate resource directory: " + pResource);
//         }
// 
//         return f.listFiles(new FileFilter() {
//             public boolean accept(File pathname) {
//                 return pathname.isFile();
//             }
//         });
//     }
// 
//     /**
//      * Locates a resource file in the class path and returns an {@link InputStream}.
//      */
//     public static InputStream getResourceStream(String pResource) throws IOException {
//         return new FileInputStream(getResourceFile(pResource));
//     }
// 
//     /**
//      * Locates a resource file in the class path and returns a {@link Reader}.
//      */
//     public static Reader getResourceReader(String pResource) throws IOException {
//         return new InputStreamReader(getResourceStream(pResource), StandardCharsets.UTF_8);
//     }
// 
//     /**
//      * Locates a resource file in the class path and returns a {@link BufferedReader}.
//      */
//     public static BufferedReader getBufferedResourceReader(String pResource) throws IOException {
//         return new BufferedReader(getResourceReader(pResource));
//     }
// 
//     /**
//      * Locates a resource file in the class path and returns a {@link BufferedReader}.
//      */
//     public static BufferedReader getBufferedReader(File file) throws IOException {
//         return new BufferedReader(new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_8));
//     }
// 
//     /**
//      * Locates the name of a directory, which contains the given
//      * resource file.
//      */
//     public static String getResourceDirectory(String pResource) throws IOException {
//         final File resource = getResourceFile(pResource);
//         final File dir = resource.getParentFile();
//         return DocumentImplUtils.toName(dir);
//     }
// }


// Path: apache-rat-core/src/test/java/org/apache/rat/document/impl/guesser/BinaryGuesserTest.java
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import org.apache.commons.io.IOUtils;
import org.apache.rat.document.MockDocument;
import org.apache.rat.document.impl.FileDocument;
import org.apache.rat.test.utils.Resources;
import org.junit.Test;
import java.io.IOException;
import java.io.Reader;
import java.util.Arrays;
import java.util.List;
import static org.junit.Assert.assertEquals;

        FileDocument doc = new FileDocument(Resources.getResourceFile("/binaries/UTF16_with_signature.xml"));
        Reader r = doc.reader(); // this will fail test if file is not readable
        try {
            char[] dummy = new char[100];
            r.read(dummy);
            // if we get here, the UTF-16 encoded file didn't throw
            // any exception, try the UTF-8 encoded one
            r.close();
            r = null; // ensure we detect failure to read second file
            doc = new FileDocument(Resources.getResourceFile("/binaries/UTF8_with_signature.xml"));
            r = doc.reader();
            r.read(dummy);
            // still here?  can't test on this platform
            System.err.println("Skipping testBinaryWithMalformedInput");
        } catch (IOException e) {
            if (r != null) {
                IOUtils.closeQuietly(r);
            } else {
                throw e; // could not open the second file
            }
            r = null;
            assertTrue("Expected binary for " + doc.getName(), BinaryGuesser.isBinary(doc));
        } finally {
            IOUtils.closeQuietly(r);
        }
    }

    @Test
    public void realBinaryContent() throws IOException {
        // This test is not accurate on all platforms
        final String encoding = System.getProperty("file.encoding");