Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.io.Reader;
import java.io.Writer;
import java.nio.charset.Charset;
import java.nio.charset.MalformedInputException;
import java.nio.file.FileSystemException;
import java.nio.file.Files;
import java.nio.file.NoSuchFileException;
Expand Down Expand Up @@ -317,6 +318,9 @@ public static void copyFile(Path from, Path to, String encoding, FilterWrapper[]
writer.write(buffer, 0, nRead);
}
}
} catch (MalformedInputException e) {
// Most likely a binary; just copy it then
copyFile(from, to, encoding, null, overwrite);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
import org.junit.jupiter.api.Test;

import static org.apache.maven.api.di.testing.MavenDIExtension.getBasedir;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertEquals;

/**
Expand Down Expand Up @@ -147,4 +149,24 @@ public void testEscapeWindowsPathNotAtBeginning() {
"jdbc:derby:C:\\\\Users\\\\Administrator/test;create=true",
FilteringUtils.escapeWindowsPath("jdbc:derby:C:\\Users\\Administrator/test;create=true"));
}

@Test
public void testBinaryFileWithFiltering() throws IOException {
Path fromFile = Paths.get(getBasedir() + "/src/test/units-files/binary-file/binary-file");
Path toFile = TEST_DIRECTORY.resolve("binary-file-copied");
assertDoesNotThrow(() -> FilteringUtils.copyFile(
fromFile,
toFile,
"UTF-8",
new FilterWrapper[] {
new FilterWrapper() {
@Override
public Reader getReader(Reader fileReader) {
return fileReader;
}
}
},
false));
assertArrayEquals(Files.readAllBytes(toFile), Files.readAllBytes(fromFile), "Binary files differ");
}
}
Binary file added src/test/units-files/binary-file/binary-file
Binary file not shown.