Example usage for com.google.common.io Files toString

List of usage examples for com.google.common.io Files toString

Introduction

In this page you can find the example usage for com.google.common.io Files toString.

Prototype

public static String toString(File file, Charset charset) throws IOException 

Source Link

Usage

From source file:com.android.build.gradle.integration.instant.InstantRunTestUtils.java

@NonNull
public static InstantRunBuildContext loadBuildContext(int apiLevel, @NonNull InstantRun instantRunModel)
        throws Exception {
    InstantRunBuildContext context = new InstantRunBuildContext();
    context.setApiLevel(apiLevel, null, null);
    context.loadFromXml(Files.toString(instantRunModel.getInfoFile(), Charsets.UTF_8));
    return context;
}

From source file:org.apache.whirr.service.ServiceSpec.java

public String readPublicKey() throws IOException {
    return Files.toString(new File(getSecretKeyFile() + ".pub"), Charsets.UTF_8);
}

From source file:hu.petabyte.redflags.engine.scope.AutoScope.java

private NoticeID load() {
    try {//from   ww  w  .  j  a  v a 2s .  c o m
        String s = Files.toString(new File(FILENAME), Charsets.UTF_8);
        String nid = s.split("\n")[0].trim();
        LOG.trace("Loaded notice id: {}", nid);
        return new NoticeID(nid);
    } catch (IOException e) {
        NoticeID id = new NoticeID(1, Calendar.getInstance().get(Calendar.YEAR));
        LOG.debug("Couldn't load last notice id, using {} as first", id);
        return id;
    }
}

From source file:net.chris54721.infinitycubed.workers.PackLoader.java

@Override
public void run() {
    try {//  w ww  .j  a  v  a 2 s . c om
        LogHelper.info("Loading and updating modpacks");
        String publicJson = Utils.toString(new URL(Reference.FILES_URL + "public.json"));
        Type stringIntMap = new TypeToken<LinkedHashMap<String, Integer>>() {
        }.getType();
        LinkedHashMap<String, Integer> publicObjects = Reference.DEFAULT_GSON.fromJson(publicJson,
                stringIntMap);
        File localJson = new File(Resources.getFolder(Reference.PACKS_FOLDER), "public.json");
        List<String> updatePacks = new ArrayList<String>();
        if (localJson.isFile()) {
            String localPublicJson = Files.toString(localJson, Charsets.UTF_8);
            LinkedHashMap<String, Integer> localPublicObjects = Reference.DEFAULT_GSON.fromJson(localPublicJson,
                    stringIntMap);
            for (String pack : publicObjects.keySet()) {
                if (!localPublicObjects.containsKey(pack)
                        || !localPublicObjects.get(pack).equals(publicObjects.get(pack))) {
                    updatePacks.add(pack);
                }
            }
        } else
            updatePacks.addAll(publicObjects.keySet());
        Files.write(publicJson, localJson, Charsets.UTF_8);
        if (updatePacks.size() > 0) {
            for (String pack : updatePacks) {
                LogHelper.info("Updating JSON file for modpack " + pack);
                URL packJsonURL = Resources.getUrl(Resources.ResourceType.PACK_JSON, pack + ".json");
                File packJsonFile = Resources.getFile(Resources.ResourceType.PACK_JSON, pack + ".json");
                if (packJsonFile.isFile())
                    packJsonFile.delete();
                Downloadable packJsonDownloadable = new Downloadable(packJsonURL, packJsonFile);
                if (!packJsonDownloadable.download())
                    LogHelper.error("Failed updating JSON for modpack " + pack);
            }
        }
        Collection<File> packJsons = FileUtils.listFiles(Resources.getFolder(Reference.DATA_FOLDER),
                new String[] { "json" }, false);
        for (File packJsonFile : packJsons)
            loadPack(FilenameUtils.getBaseName(packJsonFile.getName()));
    } catch (Exception e) {
        LogHelper.fatal("Failed updating and loading public packs", e);
    }
}

From source file:org.freeeed.lotus.FileStorage.java

public LotusEmail readEmail(File file) {
    try {/*from  w w w. j a va 2s  .c  o m*/
        String content = Files.toString(file, Charset.defaultCharset());
        Gson gson = gsonBuilder.create();

        return gson.fromJson(content, LotusEmail.class);
    } catch (IOException e) {
        System.out.println("Unable to read file content: " + file);
    }

    return null;
}

From source file:com.shmsoft.dmass.lotus.FileStorage.java

public LotusEmail readEmail(File file) {
    try {/*from  w  w w  .jav  a 2 s  . c o m*/
        String content = Files.toString(file, Charset.defaultCharset());
        Gson gson = gsonBuilder.create();

        LotusEmail email = gson.fromJson(content, LotusEmail.class);
        return email;
    } catch (IOException e) {
        System.out.println("Unable to read file content: " + file);
    }

    return null;
}

From source file:net.minecraftforge.gradle.util.caching.CacheCheckSpec.java

public boolean isSatisfiedBy(ICachableTask task) {
    Logger logger = task.getProject().getLogger();

    task.getInputs();/*w  ww.  j ava  2s.  c  o  m*/

    if (!task.doesCache() || container.cachedList.isEmpty())
        return true;

    for (Annotated field : container.cachedList) {
        try {
            File file = task.getProject().file(field.getValue(task));

            // not there? do the task.
            if (!file.exists()) {
                logger.info("No output file found.");
                return true;
            }

            File hashFile = CacheUtil.getHashFile(file);
            if (!hashFile.exists()) {
                logger.info("No cache file found.");
                file.delete(); // Kill the output file if the hash doesn't exist, else gradle will think it's up-to-date
                return true;
            }

            String foundMD5 = Files.toString(CacheUtil.getHashFile(file), Charset.defaultCharset());
            String calcMD5 = CacheUtil.getHashes(field, container.inputList, task);

            if (!calcMD5.equals(foundMD5)) {
                logger.info(" Corrupted Cache!");
                logger.info("Checksums found: " + foundMD5);
                logger.info("Checksums calculated: " + calcMD5);
                file.delete();
                CacheUtil.getHashFile(file).delete();
                return true;
            }

            logger.debug("Checksums found: " + foundMD5);
            logger.debug("Checksums calculated: " + calcMD5);

        }
        // error? spit it and do the task.
        catch (Exception e) {
            e.printStackTrace();
            return true;
        }
    }

    // no problems? all of em are here? skip the task.
    return false;
}

From source file:org.spdx.tools.MatchingStandardLicenses.java

/**
 * @param textFile//  www .j av a  2  s  . c om
 * @return
 * @throws IOException 
 */
private static String readAll(File textFile) throws IOException {
    return Files.toString(textFile, Charset.defaultCharset());
}

From source file:group.id.groovy.GroovyScenarioSupplier.java

public void setScript(Resource script) {
    try {/*  w  ww.ja  va 2 s . c  o m*/
        this.script = Files.toString(script.getFile(), Charset.defaultCharset());
    } catch (IOException e) {
        throw new TechnicalException(e);
    }
}

From source file:com.addthis.hydra.job.web.SpawnService.java

private static String readFile(String path) throws IOException {
    return Files.toString(new File(path), Charsets.UTF_8).trim();
}