* This program is free software; you can redistribute it and/or
* modify it under the terms of version 2 of the GNU General Public License
* as published by the Free Software Foundation.
* This program is free software; you can redistribute it and/or
* modify it under the terms of version 2 of the GNU General Public License
* as published by the Free Software Foundation.
- final byte[] currentFileHeader = new byte[2];
- fileInputStream.read(currentFileHeader);
- fileInputStream.close();
+ final byte[] currentFileHeader = new byte[bomHeader.length];
+ fileInputStream.read(currentFileHeader);
+ fileInputStream.close();
- public boolean fileMatchesInputPattern(final File file) {
- final String fileName = file.getName().toLowerCase();
+ private boolean fileMatchesInputPattern(final File file) {
+ final String fileName = file.getName().toLowerCase();
- for (final String inputPattern : options.inputPatterns)
- if (WildCardMatcher.match(fileName, inputPattern.toLowerCase()))
- return true;
+ for (final String inputPattern : options.inputPatterns)
+ if (WildCardMatcher.match(fileName, inputPattern.toLowerCase()))
+ return true;
- @Override
- public String getDescription() {
- return "Remove byte order mark (bom) from UTF text files of they are present.";
- }
+ @Override
+ public String getDescription() {
+ return "Remove byte order mark (bom) from UTF text files if they are present.";
+ }
- for (final File subFile : directory.listFiles())
- if (subFile.isDirectory()) {
- if (options.recursive)
- processDirectory(subFile);
- } else if (fileMatchesInputPattern(subFile))
- try {
- processFile(subFile);
- } catch (final IOException exception) {
- System.out.println("Error processing file: "
- + subFile.getAbsolutePath());
- System.out.println(" exception: "
- + exception.getMessage());
- }
+ for (final File subFile : directory.listFiles())
+ if (subFile.isDirectory()) {
+ if (options.recursive)
+ processDirectory(subFile);
+ } else if (fileMatchesInputPattern(subFile))
+ try {
+ processFile(subFile);
+ } catch (final IOException exception) {
+ System.out.println("Error processing file: "
+ + subFile.getAbsolutePath());
+ System.out.println(" exception: "
+ + exception.getMessage());
+ }
- public void stripFileFromHeader(final File file)
- throws FileNotFoundException, IOException {
- // read entire file
- final byte[] fileContents = IOHelper.getFileContents(file);
+ private void stripFileFromHeader(final File file)
+ throws IOException {
+ // read entire file
+ final byte[] fileContents = IOHelper.getFileContents(file);
- // remove BOM header form file
- final byte[] newFileContents = Arrays.copyOfRange(fileContents,
- bomHeader.length, fileContents.length);
+ // remove BOM header form file
+ final byte[] newFileContents = Arrays.copyOfRange(fileContents,
+ bomHeader.length, fileContents.length);
- // overwrite file with new contents
- IOHelper.saveToFile(file, newFileContents);
- }
+ // overwrite file with new contents
+ IOHelper.saveToFile(file, newFileContents);
+ }