- I don't want to load the whole file into memory
- I don't want to make any assumptions about the underlying OS.
I'm left with this:
echo it, "Checking file.. ${file.absolutePath}"
def fis = new FileInputStream(file)
def openingBytes = new byte[3]
try {
fis.read(openingBytes)
if (openingBytes.encodeHex() =~ /^efbbbf/) {
errors << file.path + " - File needs to be converted from UTF-8 BOM to UTF-8 without BOM"
}
} catch (Exception e) {
errors << "Encountered an error trying to check " + file.path + " for BOMs."
} finally {
fis.close()
}
But that seems awfully verbose and Java-like. :-(