org.sonar.css.FileUtils.java Source code

Java tutorial

Introduction

Here is the source code for org.sonar.css.FileUtils.java

Source

/*
 * SonarQube CSS Plugin
 * Copyright (C) 2013-2016 Tamas Kende and David RACODON
 * mailto: kende.tamas@gmail.com and david.racodon@gmail.com
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 3 of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */
package org.sonar.css;

import com.google.common.io.Files;

import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;

public class FileUtils {

    private FileUtils() {
    }

    public static boolean startsWithBOM(File file, Charset charset) {
        return fileContent(file, charset).startsWith(Character.toString('\uFEFF'));
    }

    public static String fileContent(File file, Charset charset) {
        String fileContent;
        try {
            fileContent = Files.toString(file, charset);
        } catch (IOException e) {
            throw new IllegalStateException("Could not read " + file, e);
        }
        return fileContent;
    }

}